Resolving: MNG-282

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@227259 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-08-03 20:43:58 +00:00
parent 395fe63613
commit 71cb5dc399
14 changed files with 236 additions and 5 deletions

View File

@ -33,6 +33,7 @@ import java.util.Map;
* Builds archetype containers.
*
* @goal create
* @requiresProject false
*/
public class MavenArchetypeMojo
extends AbstractMojo

View File

@ -0,0 +1,143 @@
package org.apache.maven.plugin.coreit;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;
/**
* Mojo which touches a file without requiring a project.
*
* @goal light-touch
* @requiresProject false
*
*/
public class NoProjectMojo
extends AbstractMojo
{
/**
* @parameter expression="${project}"
*/
private MavenProject project;
/**
* @parameter expression="${project.build.directory}"
* @required
*/
private String outputDirectory;
/** Test setting of plugin-artifacts on the PluginDescriptor instance.
* @parameter expression="${plugin.artifactMap}"
* @required
*/
private Map pluginArtifacts;
/**
* @parameter expression="target/test-basedir-alignment"
*/
private File basedirAlignmentDirectory;
/**
* @parameter
*/
private String pluginItem = "foo";
/**
* @parameter
*/
private String goalItem = "bar";
/**
* @parameter expression="${artifactToFile}"
*/
private String artifactToFile;
public void execute()
throws MojoExecutionException
{
touch( new File( outputDirectory ), "touch.txt" );
// This parameter should be aligned to the basedir as the parameter type is specified
// as java.io.File
if ( basedirAlignmentDirectory.getPath().equals( "target/test-basedir-alignment" ) )
{
throw new MojoExecutionException( "basedirAlignmentDirectory not aligned" );
}
touch( basedirAlignmentDirectory, "touch.txt" );
File outDir = new File( outputDirectory );
// Test parameter setting
if ( pluginItem != null )
{
touch( outDir, pluginItem );
}
if ( goalItem != null )
{
touch( outDir, goalItem );
}
if ( artifactToFile != null )
{
Artifact artifact = (Artifact) pluginArtifacts.get( artifactToFile );
File artifactFile = artifact.getFile();
String filename = artifactFile.getAbsolutePath().replace('/', '_').replace(':', '_') + ".txt";
touch( outDir, filename );
}
project.getBuild().setFinalName( "coreitified" );
}
private void touch( File dir, String file )
throws MojoExecutionException
{
try
{
if ( !dir.exists() )
{
dir.mkdirs();
}
File touch = new File( dir, file );
getLog().info( "Touching: " + touch );
FileWriter w = new FileWriter( touch );
w.write( file );
w.close();
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error touching file", e );
}
}
}

View File

@ -126,6 +126,8 @@ it0043: Test for repository inheritence - ensure using the same id overrides the
it0044: Test --settings CLI option
it0045: Test non-reactor behavior when plugin declares "@requiresProject false"
-------------------------------------------------------------------------------
- generated sources

View File

@ -1,3 +1,4 @@
it0045
it0044
it0043
it0042

View File

@ -1,7 +1,7 @@
<model>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-it0023</artifactId>
<artifactId>maven-it0044</artifactId>
<version>1.0-SNAPSHOT</version>
<build>

View File

@ -0,0 +1 @@
--no-plugin-registry --check-plugin-latest

View File

@ -0,0 +1,2 @@
target/touch.txt
!subproject/target/touch.txt

View File

@ -0,0 +1 @@
core-it:light-touch

View File

@ -0,0 +1,17 @@
<model>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core-it0009</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<pluginRepositories>
<pluginRepository>
<id>snapshots</id>
<name>Maven Central Plugins Development Repository</name>
<url>http://snapshots.maven.codehaus.org/maven2/plugins</url>
</pluginRepository>
</pluginRepositories>
<modules>
<module>subproject</module>
</modules>
</model>

View File

@ -0,0 +1 @@
#rm ${artifact:org.apache.maven.plugins:maven-core-it-plugin:1.0-SNAPSHOT:maven-plugin}

View File

@ -0,0 +1,10 @@
<model>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core-it0045</artifactId>
<version>1.0</version>
</parent>
<artifactId>maven-core-it0045-subproject</artifactId>
<packaging>jar</packaging>
</model>

View File

@ -140,14 +140,15 @@ public class DefaultMaven
projects = collectProjects( files, request.getLocalRepository(), request.isRecursive(),
request.getSettings() );
// the reasoning here is that the list is still unsorted according to dependency, so the first project
// SHOULD BE the top-level, or the one we want to start with if we're doing an aggregated build.
if ( !projects.isEmpty() )
{
// TODO: !![jc; 28-jul-2005] check this; if we're using '-r' and there are aggregator tasks, this will result in weirdness.
topLevelProject = (MavenProject) projects.get( 0 );
topLevelProject = findTopLevelProject( projects, request.getPomFile() );
projects = ProjectSorter.getSortedProjects( projects );
}
else
@ -268,6 +269,49 @@ public class DefaultMaven
}
}
private MavenProject findTopLevelProject( List projects, String customPomPath ) throws IOException
{
File topPomFile;
if ( customPomPath != null )
{
topPomFile = new File( customPomPath ).getCanonicalFile();
}
else
{
topPomFile = new File( userDir, RELEASE_POMv4 );
if ( !topPomFile.exists() )
{
topPomFile = new File( userDir, POMv4 );
if ( !topPomFile.exists() )
{
getLogger().warn( "Cannot find top-level project file in directory: " + userDir + ". Using first project in project-list." );
return (MavenProject) projects.get( 0 );
}
}
}
MavenProject topProject = null;
for ( Iterator it = projects.iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
File projectFile = project.getFile().getCanonicalFile();
if ( topPomFile.equals( projectFile ) )
{
topProject = project;
break;
}
}
return topProject;
}
private List collectProjects( List files, ArtifactRepository localRepository, boolean recursive, Settings settings )
throws ProjectBuildingException, ReactorException, IOException, ArtifactResolutionException
{

View File

@ -289,7 +289,10 @@ public class DefaultLifecycleExecutor
getLogger().debug( "", e );
}
if ( mojo != null && mojo.isAggregator() )
// if the mojo descriptor was found, determine aggregator status according to:
// 1. whether the mojo declares itself an aggregator
// 2. whether the mojo DOES NOT require a project to function (implicitly avoid reactor)
if ( mojo != null && ( mojo.isAggregator() || !mojo.isProjectRequired() ) )
{
if ( currentSegment != null && !currentSegment.aggregate() )
{

View File

@ -236,7 +236,12 @@ public class JavaMojoDescriptorExtractor
if ( requiresProject != null )
{
mojoDescriptor.setProjectRequired( true );
String requiresProjectValue = requiresProject.getValue();
if ( requiresProjectValue != null )
{
mojoDescriptor.setProjectRequired( Boolean.valueOf( requiresProjectValue ).booleanValue() );
}
}
// ----------------------------------------------------------------------