From 360ae403b2d6061477b9b214b320329d0d4763a5 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Fri, 25 Feb 2005 01:23:20 +0000 Subject: [PATCH] refactoring to simplify - taking notes of potential clean up after lifecycle is completed git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163410 13f79535-47bb-0310-9956-ffa450edef68 --- .../lifecycle/DefaultLifecycleExecutor.java | 95 +------------------ .../goal/phase/GoalAttainmentPhase.java | 16 +--- .../DefaultMavenSessionPhaseManager.java | 2 + .../maven/plugin/DefaultPluginManager.java | 65 ++++++++++++- .../apache/maven/plugin/PluginManager.java | 3 +- 5 files changed, 69 insertions(+), 112 deletions(-) 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 0ff37ec079..f9dfcc3160 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 @@ -17,16 +17,10 @@ package org.apache.maven.lifecycle; * ==================================================================== */ -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.MavenMetadataSource; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.goal.GoalExecutionException; import org.apache.maven.plugin.PluginManager; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; @@ -89,12 +83,6 @@ public class DefaultLifecycleExecutor protected void executePhase( String phase, MavenSession session ) throws LifecycleExecutionException { - resolveTransitiveDependencies( session ); - - downloadDependencies( session ); - - System.out.println( "executing phase = " + phase ); - int i = phases.indexOf( phaseMap.get( phase ) ); for ( int j = 0; j <= i; j++ ) @@ -103,14 +91,7 @@ public class DefaultLifecycleExecutor if ( p.getGoal() != null ) { - try - { - pluginManager.executeMojo( session, p.getGoal() ); - } - catch ( GoalExecutionException e ) - { - throw new LifecycleExecutionException( "Problem executing " + p.getGoal(), e ); - } + executeMojo( p.getGoal(), session ); } } } @@ -127,29 +108,6 @@ public class DefaultLifecycleExecutor // archetype:create // ---------------------------------------------------------------------- - try - { - pluginManager.verifyPluginForGoal( id, session ); - } - catch ( Exception e ) - { - throw new LifecycleExecutionException( "Problem getting plugin for " + id, e ); - } - - MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( id ); - if ( mojoDescriptor == null ) - { - // TODO: goal not found exception? - throw new LifecycleExecutionException( "Goal not found: " + id ); - } - - if ( mojoDescriptor.requiresDependencyResolution() ) - { - resolveTransitiveDependencies( session ); - - downloadDependencies( session ); - } - try { pluginManager.executeMojo( session, id ); @@ -160,57 +118,6 @@ public class DefaultLifecycleExecutor } } - // ---------------------------------------------------------------------- - // Artifact resolution - // ---------------------------------------------------------------------- - - private void resolveTransitiveDependencies( MavenSession context ) - throws LifecycleExecutionException - { - MavenProject project = context.getProject(); - - try - { - MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, projectBuilder ); - - ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), - context.getRemoteRepositories(), - context.getLocalRepository(), - sourceReader ); - - project.getArtifacts().addAll( result.getArtifacts().values() ); - - } - catch ( Exception e ) - { - throw new LifecycleExecutionException( "Error resolving transitive dependencies.", e ); - } - } - - // ---------------------------------------------------------------------- - // Artifact downloading - // ---------------------------------------------------------------------- - - public void downloadDependencies( MavenSession context ) - throws LifecycleExecutionException - { - try - { - for ( Iterator it = context.getProject().getArtifacts().iterator(); it.hasNext(); ) - { - Artifact artifact = (Artifact) it.next(); - - artifactResolver.resolve( artifact, - context.getRemoteRepositories(), - context.getLocalRepository() ); - } - } - catch ( ArtifactResolutionException e ) - { - throw new LifecycleExecutionException( "Can't resolve artifact: ", e ); - } - } - // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java b/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java index 16cef0819f..c66391b76b 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java @@ -20,24 +20,9 @@ package org.apache.maven.lifecycle.goal.phase; import org.apache.maven.lifecycle.goal.AbstractMavenGoalPhase; import org.apache.maven.lifecycle.goal.GoalExecutionException; import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.Plugin; -import org.apache.maven.plugin.PluginConfigurationException; -import org.apache.maven.plugin.PluginExecutionRequest; import org.apache.maven.plugin.PluginExecutionResponse; -import org.apache.maven.plugin.PluginParameterExpressionEvaluator; -import org.apache.maven.plugin.DefaultPluginManager; -import org.apache.maven.plugin.PluginManager; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.util.CollectionUtils; -import java.util.HashMap; import java.util.Iterator; -import java.util.List; -import java.util.Map; /** * @author Jason van Zyl @@ -51,6 +36,7 @@ public class GoalAttainmentPhase { PluginExecutionResponse response; + // TODO: remove - most likely empty as there are no prereqs and I don't think the pre/postGoals are being walked for ( Iterator it = context.getResolvedGoals().iterator(); it.hasNext(); ) { String goalName = (String) it.next(); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/session/DefaultMavenSessionPhaseManager.java b/maven-core/src/main/java/org/apache/maven/lifecycle/session/DefaultMavenSessionPhaseManager.java index a9506dab1c..7e4eb1079a 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/session/DefaultMavenSessionPhaseManager.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/session/DefaultMavenSessionPhaseManager.java @@ -42,6 +42,8 @@ public class DefaultMavenSessionPhaseManager public void execute( MavenExecutionRequest request, MavenExecutionResponse response ) throws Exception { + // TODO: no longer executed. Remove this, components, etc. + for ( Iterator iterator = lifecyclePhases.iterator(); iterator.hasNext(); ) { MavenSessionPhase phase = (MavenSessionPhase) iterator.next(); 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 5ddd5c3980..08e5e3a34e 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 @@ -22,6 +22,8 @@ import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.MavenMetadataSource; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter; @@ -236,14 +238,21 @@ public class DefaultPluginManager } catch ( Exception e ) { - e.printStackTrace(); + throw new GoalExecutionException( "Unable to execute goal: " + goalName, e ); } PluginExecutionRequest request; PluginExecutionResponse response; - MojoDescriptor mojoDescriptor = getMojoDescriptor( goalName );; + MojoDescriptor mojoDescriptor = getMojoDescriptor( goalName ); + + if ( mojoDescriptor.requiresDependencyResolution() ) + { + resolveTransitiveDependencies( session ); + + downloadDependencies( session ); + } try { @@ -442,5 +451,57 @@ public class DefaultPluginManager // TODO: needs to be configured from the POM element remotePluginRepositories.add( new ArtifactRepository( "plugin-repository", "http://repo1.maven.org" ) ); } + + // ---------------------------------------------------------------------- + // Artifact resolution + // ---------------------------------------------------------------------- + + private void resolveTransitiveDependencies( MavenSession context ) + throws GoalExecutionException + { + MavenProject project = context.getProject(); + + try + { + MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, mavenProjectBuilder ); + + ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), + context.getRemoteRepositories(), + context.getLocalRepository(), + sourceReader ); + + project.getArtifacts().addAll( result.getArtifacts().values() ); + + } + catch ( Exception e ) + { + throw new GoalExecutionException( "Error resolving transitive dependencies.", e ); + } + } + + // ---------------------------------------------------------------------- + // Artifact downloading + // ---------------------------------------------------------------------- + + private void downloadDependencies( MavenSession context ) + throws GoalExecutionException + { + try + { + for ( Iterator it = context.getProject().getArtifacts().iterator(); it.hasNext(); ) + { + Artifact artifact = (Artifact) it.next(); + + artifactResolver.resolve( artifact, + context.getRemoteRepositories(), + context.getLocalRepository() ); + } + } + catch ( ArtifactResolutionException e ) + { + throw new GoalExecutionException( "Can't resolve artifact: ", e ); + } + } + } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java index 5549bf07d0..191900f097 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java @@ -20,7 +20,6 @@ package org.apache.maven.plugin; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.goal.GoalExecutionException; import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.execution.MavenSession; import java.util.Map; @@ -38,8 +37,10 @@ public interface PluginManager void processPluginDescriptor( MavenPluginDescriptor pluginDescriptor ) throws Exception; + // TODO: not currently used Map getMojoDescriptors(); + // TODO: not currently used (usages are in the phases that are no longer used) MojoDescriptor getMojoDescriptor( String goalId ); void verifyPluginForGoal( String pluginId, MavenSession session )