diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index 3313773674..3b11888220 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -428,13 +428,7 @@ public class DefaultArtifactResolver // After the collection we will have the artifact object in the result but they will not be resolved yet. result = artifactCollector.collect( artifacts, rootArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners ); - - if ( !isDummy( request ) ) - { - // Add the root artifact - result.addArtifact( rootArtifact ); - } - + // We have metadata retrieval problems, or there are cycles that have been detected // so we give this back to the calling code and let them deal with this information // appropriately. @@ -469,6 +463,14 @@ public class DefaultArtifactResolver } } + // We want to send the root artifact back in the result but we need to do this after the other dependencies + // have been resolved. + if ( !isDummy( request ) ) + { + // Add the root artifact + result.addArtifact( rootArtifact ); + } + return result; } diff --git a/maven-core/src/main/java/org/apache/maven/DefaultArtifactFilterManager.java b/maven-core/src/main/java/org/apache/maven/DefaultArtifactFilterManager.java index bed9f45f67..0f8cfc5635 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultArtifactFilterManager.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultArtifactFilterManager.java @@ -59,6 +59,7 @@ public class DefaultArtifactFilterManager artifacts.add( "maven-plugin-api" ); artifacts.add( "maven-plugin-descriptor" ); artifacts.add( "maven-plugin-parameter-documenter" ); + artifacts.add( "maven-plugin-registry" ); artifacts.add( "maven-profile" ); artifacts.add( "maven-project" ); artifacts.add( "maven-reporting-api" ); @@ -70,6 +71,7 @@ public class DefaultArtifactFilterManager artifacts.add( "plexus-component-api" ); artifacts.add( "plexus-container-default" ); artifacts.add( "plexus-interactivity-api" ); + artifacts.add( "plexus-interpolation" ); artifacts.add( "wagon-provider-api" ); artifacts.add( "wagon-file" ); artifacts.add( "wagon-http-lightweight" ); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 5e8f4bb43f..5eb9b9ae7b 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -54,11 +54,9 @@ import org.apache.maven.plugin.lifecycle.Phase; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.MavenReport; import org.apache.maven.settings.Settings; -import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -1302,7 +1300,6 @@ public class DefaultLifecycleExecutor project.addPlugin( plugin ); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal ); - return mojoDescriptor; } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 0268182c88..d9cfa64d99 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -46,6 +46,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ResolutionErrorHandler; +import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; @@ -169,7 +170,9 @@ public class DefaultPluginManager if ( ( pluginVersion == null ) || Artifact.LATEST_VERSION.equals( pluginVersion ) || Artifact.RELEASE_VERSION.equals( pluginVersion ) ) { logger.debug( "Resolving version for plugin: " + plugin.getKey() ); + pluginVersion = resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), project, session ); + plugin.setVersion( pluginVersion ); logger.debug( "Resolved to version: " + pluginVersion ); @@ -188,10 +191,8 @@ public class DefaultPluginManager // and no ChildContainer exists. The check for that below fixes // the 'Can't find plexus container for plugin: xxx' error. try - { - Artifact pluginArtifact = resolvePluginArtifact( plugin, project, session ); - - addPlugin( plugin, pluginArtifact, project, session ); + { + addPlugin( plugin, project, session ); project.addPlugin( plugin ); } @@ -230,9 +231,29 @@ public class DefaultPluginManager return plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion(); } - protected void addPlugin( Plugin plugin, Artifact pluginArtifact, MavenProject project, MavenSession session ) - throws ArtifactNotFoundException, ArtifactResolutionException, PluginManagerException, InvalidPluginException - { + protected void addPlugin( Plugin plugin, MavenProject project, MavenSession session ) + throws ArtifactNotFoundException, ArtifactResolutionException, PluginManagerException, InvalidPluginException, PluginVersionResolutionException + { + logger.debug( "Resolving plugin artifact " + plugin.getKey() + " from " + project.getRemoteArtifactRepositories() ); + + ArtifactRepository localRepository = session.getLocalRepository(); + + MavenProject pluginProject = buildPluginProject( plugin, localRepository, project.getRemoteArtifactRepositories() ); + + Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin ); + + checkRequiredMavenVersion( plugin, pluginProject, localRepository, project.getRemoteArtifactRepositories() ); + + checkPluginDependencySpec( plugin, pluginProject ); + + pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact ); + + ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, project.getRemoteArtifactRepositories() ); + + ArtifactResolutionResult result = repositorySystem.resolve( request ); + + resolutionErrorHandler.throwErrors( request, result ); + // ---------------------------------------------------------------------------- // Get the dependencies for the Plugin // ---------------------------------------------------------------------------- @@ -240,6 +261,8 @@ public class DefaultPluginManager // the only Plugin instance which will have dependencies is the one specified in the project. // We need to look for a Plugin instance there, in case the instance we're using didn't come from // the project. + + // Trying to cache the version of the plugin for a project? Plugin projectPlugin = project.getPlugin( plugin.getKey() ); if ( projectPlugin == null ) @@ -272,7 +295,7 @@ public class DefaultPluginManager // Not going to happen } } - + try { logger.debug( "Discovering components in realm: " + pluginRealm ); @@ -319,11 +342,18 @@ public class DefaultPluginManager } } + // plugin artifact + // its dependencies while filtering out what's in the core + // layering on the project level plugin dependencies + + private Set getPluginArtifacts( Artifact pluginArtifact, Plugin plugin, MavenProject project, ArtifactRepository localRepository ) throws InvalidPluginException, ArtifactNotFoundException, ArtifactResolutionException { - ArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM ); - + AndArtifactFilter filter = new AndArtifactFilter(); + filter.add( coreArtifactFilterManager.getCoreArtifactFilter() ); + filter.add( new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM ) ); + Set projectPluginDependencies; // The case where we have a plugin that can host multiple versions of a particular tool. Say the @@ -333,7 +363,7 @@ public class DefaultPluginManager try { - projectPluginDependencies = repositorySystem.createArtifacts( plugin.getDependencies(), null, coreArtifactFilterManager.getCoreArtifactFilter(), project ); + projectPluginDependencies = repositorySystem.createArtifacts( plugin.getDependencies(), null, filter, project ); } catch ( VersionNotFoundException e ) { @@ -1305,6 +1335,7 @@ public class DefaultPluginManager result.setUnresolvedArtifacts( null ); } } + resolutionErrorHandler.throwErrors( request, result ); project.setArtifacts( result.getArtifacts() ); @@ -1365,9 +1396,9 @@ public class DefaultPluginManager List remoteArtifactRepositories = project.getRemoteArtifactRepositories(); for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); ) - { + { Artifact artifact = (Artifact) it.next(); - + repositorySystem.resolve( new ArtifactResolutionRequest( artifact, localRepository, remoteArtifactRepositories ) ); } } @@ -1446,27 +1477,27 @@ public class DefaultPluginManager public String resolvePluginVersion( String groupId, String artifactId, MavenProject project, MavenSession session ) throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException { - return resolvePluginVersion( groupId, artifactId, project, session.getLocalRepository(), false ); - } - - public String resolveReportPluginVersion( String groupId, String artifactId, MavenProject project, MavenSession session ) - throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException - { - return resolvePluginVersion( groupId, artifactId, project, session.getLocalRepository(), true ); - } - - private String resolvePluginVersion( String groupId, String artifactId, MavenProject project, ArtifactRepository localRepository, boolean resolveAsReportPlugin ) - throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException - { - // first pass...if the plugin is specified in the pom, try to retrieve the version from there. - String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin ); + String version = null; + + if ( project.getBuildPlugins() != null ) + { + for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext() && ( version == null ); ) + { + Plugin plugin = (Plugin) it.next(); + if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) ) + { + version = plugin.getVersion(); + } + } + } + // final pass...retrieve the version for RELEASE and also set that resolved version as the // in settings.xml. if ( StringUtils.isEmpty( version ) || Artifact.RELEASE_VERSION.equals( version ) ) { // 1. resolve the version to be used - version = resolveMetaVersion( groupId, artifactId, project, localRepository, Artifact.RELEASE_VERSION ); + version = resolveMetaVersion( groupId, artifactId, project, session.getLocalRepository(), Artifact.RELEASE_VERSION ); logger.debug( "Version from RELEASE metadata: " + version ); } @@ -1476,42 +1507,40 @@ public class DefaultPluginManager throw new PluginVersionNotFoundException( groupId, artifactId ); } - return version; + return version; } - private String getVersionFromPluginConfig( String groupId, String artifactId, MavenProject project, boolean resolveAsReportPlugin ) + public String resolveReportPluginVersion( String groupId, String artifactId, MavenProject project, MavenSession session ) + throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException { String version = null; - - if ( resolveAsReportPlugin ) + + if ( project.getReportPlugins() != null ) { - if ( project.getReportPlugins() != null ) + for ( Iterator it = project.getReportPlugins().iterator(); it.hasNext() && ( version == null ); ) { - for ( Iterator it = project.getReportPlugins().iterator(); it.hasNext() && ( version == null ); ) - { - ReportPlugin plugin = (ReportPlugin) it.next(); + ReportPlugin plugin = (ReportPlugin) it.next(); - if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) ) - { - version = plugin.getVersion(); - } + if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) ) + { + version = plugin.getVersion(); } } } - else + + // final pass...retrieve the version for RELEASE and also set that resolved version as the + // in settings.xml. + if ( StringUtils.isEmpty( version ) || Artifact.RELEASE_VERSION.equals( version ) ) { - if ( project.getBuildPlugins() != null ) - { - for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext() && ( version == null ); ) - { - Plugin plugin = (Plugin) it.next(); + // 1. resolve the version to be used + version = resolveMetaVersion( groupId, artifactId, project, session.getLocalRepository(), Artifact.RELEASE_VERSION ); + logger.debug( "Version from RELEASE metadata: " + version ); + } - if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) ) - { - version = plugin.getVersion(); - } - } - } + // if we still haven't found a version, then fail early before we get into the update goop. + if ( StringUtils.isEmpty( version ) ) + { + throw new PluginVersionNotFoundException( groupId, artifactId ); } return version; diff --git a/maven-embedder/src/test/embedder-test-project/pom.xml b/maven-embedder/src/test/embedder-test-project/pom.xml index 899e4fa850..aed1516129 100644 --- a/maven-embedder/src/test/embedder-test-project/pom.xml +++ b/maven-embedder/src/test/embedder-test-project/pom.xml @@ -1,21 +1,13 @@ - + @@ -44,4 +36,13 @@ under the License. + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.4.3 + + + diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java index 5cdcff4f12..3574105721 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java @@ -55,7 +55,7 @@ public class MavenEmbedderTest { protected String basedir; - protected MavenEmbedder maven; + protected MavenEmbedder mavenEmbedder; protected void setUp() @@ -77,13 +77,13 @@ public class MavenEmbedderTest .setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() ); configuration.setUserSettingsFile( MavenEmbedder.DEFAULT_USER_SETTINGS_FILE ); - maven = new MavenEmbedder( configuration ); + mavenEmbedder = new MavenEmbedder( configuration ); } protected void tearDown() throws Exception { - maven.stop(); + mavenEmbedder.stop(); } protected void assertNoExceptions( MavenExecutionResult result ) @@ -119,10 +119,12 @@ public class MavenEmbedderTest FileUtils.copyDirectoryStructure( testDirectory, targetDirectory ); - MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( targetDirectory ) - .setShowErrors( true ).setGoals( Arrays.asList( new String[]{"package"} ) ); + MavenExecutionRequest request = new DefaultMavenExecutionRequest() + .setBaseDirectory( targetDirectory ) + .setShowErrors( true ) + .setGoals( Arrays.asList( new String[]{"package"} ) ); - MavenExecutionResult result = maven.execute( request ); + MavenExecutionResult result = mavenEmbedder.execute( request ); assertNoExceptions( result ); @@ -148,7 +150,7 @@ public class MavenEmbedderTest MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( targetDirectory ) .setShowErrors( true ).setGoals( Arrays.asList( new String[]{"validate"} ) ); - MavenExecutionResult result = maven.execute( request ); + MavenExecutionResult result = mavenEmbedder.execute( request ); List exceptions = result.getExceptions(); assertEquals("Incorrect number of exceptions", 1, exceptions.size()); @@ -172,7 +174,7 @@ public class MavenEmbedderTest .setPom( new File( targetDirectory, "pom.xml" ) ).setShowErrors( true ) .setGoals( Arrays.asList( new String[] { "package" } ) ); - MavenExecutionResult result = maven.execute( request ); + MavenExecutionResult result = mavenEmbedder.execute( request ); assertNoExceptions( result ); @@ -200,7 +202,7 @@ public class MavenEmbedderTest .setPom( new File( targetDirectory, "pom.xml" ) ).setShowErrors( true ) .setGoals( Arrays.asList( new String[] { "validate" } ) ); - MavenExecutionResult r0 = maven.execute( requestWithoutProfile ); + MavenExecutionResult r0 = mavenEmbedder.execute( requestWithoutProfile ); assertNoExceptions( r0 ); @@ -220,7 +222,7 @@ public class MavenEmbedderTest .setGoals( Arrays.asList( new String[] { "validate" } ) ) .addActiveProfile( "embedderProfile" ); - MavenExecutionResult r1 = maven.execute( request ); + MavenExecutionResult r1 = mavenEmbedder.execute( request ); MavenProject p1 = r1.getProject(); @@ -248,7 +250,7 @@ public class MavenEmbedderTest File pom = new File( targetDirectory, "pom.xml" ); /* Add the surefire plugin 2.2 to the pom */ - Model model = maven.readModel( pom ); + Model model = mavenEmbedder.readModel( pom ); Plugin plugin = new Plugin(); plugin.setArtifactId( "maven-surefire-plugin" ); @@ -257,14 +259,14 @@ public class MavenEmbedderTest model.getBuild().addPlugin( plugin ); Writer writer = WriterFactory.newXmlWriter( pom ); - maven.writeModel( writer, model ); + mavenEmbedder.writeModel( writer, model ); writer.close(); /* execute maven */ MavenExecutionRequest request = new DefaultMavenExecutionRequest().setPom( pom ).setShowErrors( true ) .setGoals( Arrays.asList( new String[] { "package" } ) ); - MavenExecutionResult result = maven.execute( request ); + MavenExecutionResult result = mavenEmbedder.execute( request ); assertNoExceptions( result ); @@ -276,13 +278,13 @@ public class MavenEmbedderTest /* Add the surefire plugin 2.3 to the pom */ plugin.setVersion( "2.3" ); writer = WriterFactory.newXmlWriter( pom ); - maven.writeModel( writer, model ); + mavenEmbedder.writeModel( writer, model ); writer.close(); /* execute Maven */ request = new DefaultMavenExecutionRequest().setPom( pom ).setShowErrors( true ) .setGoals( Arrays.asList( new String[] { "package" } ) ); - result = maven.execute( request ); + result = mavenEmbedder.execute( request ); assertNoExceptions( result ); @@ -299,7 +301,7 @@ public class MavenEmbedderTest public void testRetrievingLifecyclePhases() throws Exception { - List phases = maven.getLifecyclePhases(); + List phases = mavenEmbedder.getLifecyclePhases(); assertEquals( "validate", (String) phases.get( 0 ) ); @@ -315,7 +317,7 @@ public class MavenEmbedderTest public void testLocalRepositoryRetrieval() throws Exception { - assertNotNull( maven.getLocalRepository().getBasedir() ); + assertNotNull( mavenEmbedder.getLocalRepository().getBasedir() ); } // ---------------------------------------------------------------------- @@ -329,7 +331,7 @@ public class MavenEmbedderTest // Test model reading // ---------------------------------------------------------------------- - Model model = maven.readModel( getPomFile() ); + Model model = mavenEmbedder.readModel( getPomFile() ); assertEquals( "org.apache.maven", model.getGroupId() ); } @@ -339,7 +341,7 @@ public class MavenEmbedderTest { MavenExecutionRequest request = new DefaultMavenExecutionRequest().setShowErrors( true ).setPom( getPomFile() ); - MavenExecutionResult result = maven.readProjectWithDependencies( request ); + MavenExecutionResult result = mavenEmbedder.readProjectWithDependencies( request ); assertNoExceptions( result ); @@ -347,7 +349,7 @@ public class MavenEmbedderTest Set artifacts = result.getProject().getArtifacts(); - assertEquals( 1, artifacts.size() ); + assertEquals( 2, artifacts.size() ); artifacts.iterator().next(); } @@ -357,7 +359,7 @@ public class MavenEmbedderTest { File pomFile = new File( basedir, "src/test/projects/readProject-withScmInheritance/modules/child1/pom.xml" ); - MavenProject project = maven.readProject( pomFile ); + MavenProject project = mavenEmbedder.readProject( pomFile ); assertEquals( "http://host/viewer?path=/trunk/parent/child1", project.getScm().getUrl() ); assertEquals( "scm:svn:http://host/trunk/parent/child1", project.getScm().getConnection() ); @@ -370,7 +372,7 @@ public class MavenEmbedderTest File pomFile = new File( basedir, "src/test/projects/readProject-missingModuleIgnored/pom.xml" ); - maven.readProject( pomFile ); + mavenEmbedder.readProject( pomFile ); } /* @@ -402,7 +404,7 @@ public class MavenEmbedderTest public void testModelWriting() throws Exception { - Model model = maven.readModel( getPomFile() ); + Model model = mavenEmbedder.readModel( getPomFile() ); model.setGroupId( "org.apache.maven.new" ); @@ -410,11 +412,11 @@ public class MavenEmbedderTest Writer writer = WriterFactory.newXmlWriter( file ); - maven.writeModel( writer, model ); + mavenEmbedder.writeModel( writer, model ); writer.close(); - model = maven.readModel( file ); + model = mavenEmbedder.readModel( file ); assertEquals( "org.apache.maven.new", model.getGroupId() ); }