diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index e0dc2fe81e..4121c6039b 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -97,7 +97,17 @@ public class DefaultMaven { MavenSession session = createSession( request ); - MavenProject project = getProject( (File) request.getProjectFiles().get( 0 ), request.getLocalRepository() ); + List projectFiles = request.getProjectFiles(); + + MavenProject project = null; + if(projectFiles != null && !projectFiles.isEmpty()) + { + project = getProject( (File) request.getProjectFiles().get( 0 ), request.getLocalRepository() ); + } + else + { + project = projectBuilder.buildSuperProject( request.getLocalRepository() ); + } session.setProject( project ); diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenInitializingExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenInitializingExecutionRequest.java index 085446fdd9..905d8aa362 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenInitializingExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenInitializingExecutionRequest.java @@ -21,6 +21,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.user.UserModel; import org.apache.maven.monitor.event.EventDispatcher; +import java.util.Collections; import java.util.List; /** @@ -39,6 +40,6 @@ extends AbstractMavenExecutionRequest public List getProjectFiles() { - return null; + return Collections.EMPTY_LIST; } } 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 f8b8c82feb..2da6a0558c 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 @@ -22,6 +22,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.execution.MavenExecutionResponse; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.monitor.event.MavenEvents; import org.apache.maven.plugin.PluginExecutionResponse; @@ -81,9 +82,11 @@ public class DefaultLifecycleExecutor try { + MavenProject project = session.getProject(); + // TODO: should enrich this with the type handler, but for now just // use "type" as is - ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( session.getProject().getPackaging() ); + ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( project.getPackaging() ); if ( handler != null ) { @@ -96,6 +99,11 @@ public class DefaultLifecycleExecutor } if ( handler.additionalPlugin() != null ) { + String additionalPluginGroupId = "maven"; + String additionalPluginArtifactId = "maven-" + handler.additionalPlugin() + "-plugin"; + + injectHandlerPluginConfiguration( project, additionalPluginGroupId, additionalPluginArtifactId ); + processPluginPhases( "maven", "maven-" + handler.additionalPlugin() + "-plugin", session ); } } @@ -139,6 +147,31 @@ public class DefaultLifecycleExecutor return response; } + private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId ) + { + PluginManagement mgmt = project.getPluginManagement(); + if( mgmt != null ) + { + List pluginList = mgmt.getPlugins(); + + Plugin handlerPlugin = null; + for ( Iterator it = pluginList.iterator(); it.hasNext(); ) + { + Plugin plugin = (Plugin) it.next(); + if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) ) + { + handlerPlugin = plugin; + break; + } + } + + if ( handlerPlugin != null ) + { + project.addPlugin( handlerPlugin ); + } + } + } + // TODO: don't throw Exception private void processPluginConfiguration( MavenProject project, MavenSession mavenSession ) throws Exception diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 8a991d2937..e520fbdb21 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -31,6 +31,7 @@ import org.apache.maven.model.Repository; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.project.inheritance.ModelInheritanceAssembler; import org.apache.maven.project.injection.ModelDefaultsInjector; +import org.apache.maven.project.interpolation.ModelInterpolationException; import org.apache.maven.project.interpolation.ModelInterpolator; import org.apache.maven.project.path.PathTranslator; import org.apache.maven.project.validation.ModelValidationResult; @@ -118,57 +119,11 @@ public class DefaultMavenProjectBuilder previous = current; } - Model model = modelInterpolator.interpolate( project.getModel() ); - - // interpolation is before injection, because interpolation is off-limits in the injected variables - modelDefaultsInjector.injectDefaults( model ); - - MavenProject parentProject = project.getParent(); - - project = new MavenProject( model ); - project.setFile( projectDescriptor ); - project.setParent( parentProject ); - project.setArtifacts( artifactFactory.createArtifacts( project.getDependencies(), localRepository, null ) ); - - // ---------------------------------------------------------------------- - // Typically when the project builder is being used from maven proper - // the transitive dependencies will not be resolved here because this - // requires a lot of work when we may only be interested in running - // something simple like 'm2 clean'. So the artifact collector is used - // in the dependency resolution phase if it is required by any of the - // goals being executed. But when used as a component in another piece - // of code people may just want to build maven projects and have the - // dependencies resolved for whatever reason: this is why we keep - // this snippet of code here. - // ---------------------------------------------------------------------- - - if ( resolveDependencies ) - { - List repos = buildArtifactRepositories( project.getRepositories() ); - - MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, this ); - - ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), repos, - localRepository, sourceReader ); - - project.getArtifacts().addAll( result.getArtifacts().values() ); - } - - ModelValidationResult validationResult = validator.validate( project.getModel() ); - - if ( validationResult.getMessageCount() > 0 ) - { - throw new ProjectBuildingException( "Exception while building project: " + validationResult.toString() ); - } + project = processProjectLogic( project, localRepository, resolveDependencies ); project.setFile( projectDescriptor ); - pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor ); - project.addCompileSourceRoot( project.getBuild().getSourceDirectory() ); - project.addScriptSourceRoot( project.getBuild().getScriptSourceDirectory() ); - project.addTestCompileSourceRoot( project.getBuild().getTestSourceDirectory() ); - return project; } catch ( Exception e ) @@ -177,8 +132,61 @@ public class DefaultMavenProjectBuilder } } + private MavenProject processProjectLogic( MavenProject project, ArtifactRepository localRepository, + boolean resolveDependencies ) + throws ProjectBuildingException, ModelInterpolationException, ArtifactResolutionException + { + Model model = modelInterpolator.interpolate( project.getModel() ); + + // interpolation is before injection, because interpolation is off-limits in the injected variables + modelDefaultsInjector.injectDefaults( model ); + + MavenProject parentProject = project.getParent(); + + project = new MavenProject( model ); + project.setParent( parentProject ); + project.setArtifacts( artifactFactory.createArtifacts( project.getDependencies(), localRepository, null ) ); + + // ---------------------------------------------------------------------- + // Typically when the project builder is being used from maven proper + // the transitive dependencies will not be resolved here because this + // requires a lot of work when we may only be interested in running + // something simple like 'm2 clean'. So the artifact collector is used + // in the dependency resolution phase if it is required by any of the + // goals being executed. But when used as a component in another piece + // of code people may just want to build maven projects and have the + // dependencies resolved for whatever reason: this is why we keep + // this snippet of code here. + // ---------------------------------------------------------------------- + + if ( resolveDependencies ) + { + List repos = buildArtifactRepositories( project.getRepositories() ); + + MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, this ); + + ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), repos, + localRepository, sourceReader ); + + project.getArtifacts().addAll( result.getArtifacts().values() ); + } + + ModelValidationResult validationResult = validator.validate( project.getModel() ); + + if ( validationResult.getMessageCount() > 0 ) + { + throw new ProjectBuildingException( "Exception while building project: " + validationResult.toString() ); + } + + project.addCompileSourceRoot( project.getBuild().getSourceDirectory() ); + project.addScriptSourceRoot( project.getBuild().getScriptSourceDirectory() ); + project.addTestCompileSourceRoot( project.getBuild().getTestSourceDirectory() ); + + return project; + } + private MavenProject assembleLineage( File projectDescriptor, ArtifactRepository localRepository, - LinkedList lineage, List aggregatedRemoteWagonRepositories ) + LinkedList lineage, List aggregatedRemoteWagonRepositories ) throws ProjectBuildingException { Model model = readModel( projectDescriptor ); @@ -245,8 +253,7 @@ public class DefaultMavenProjectBuilder return repos; } - private Model readModel( File file ) - throws ProjectBuildingException + private Model readModel( File file ) throws ProjectBuildingException { try { @@ -259,12 +266,12 @@ public class DefaultMavenProjectBuilder catch ( Exception e ) { throw new ProjectBuildingException( - "Error while reading model from file '" + file.getAbsolutePath() + "'.", e ); + "Error while reading model from file '" + file.getAbsolutePath() + "'.", + e ); } } - private Model readModel( URL url ) - throws ProjectBuildingException + private Model readModel( URL url ) throws ProjectBuildingException { try { @@ -293,8 +300,8 @@ public class DefaultMavenProjectBuilder catch ( ArtifactResolutionException e ) { // @todo use parent.toString() if modello could generate it, or specify in a code segment - throw new ProjectBuildingException( "Missing parent POM: " + parent.getGroupId() + ":" + - parent.getArtifactId() + "-" + parent.getVersion(), e ); + throw new ProjectBuildingException( "Missing parent POM: " + parent.getGroupId() + ":" + + parent.getArtifactId() + "-" + parent.getVersion(), e ); } return artifact.getFile(); @@ -311,8 +318,7 @@ public class DefaultMavenProjectBuilder *