You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2018/09/16 19:09:59 UTC
[maven] 02/02: [MNG-5666] Divide lifecycle in prePhases,
phases and postPhases Expose lifecyclePhaseGroup in MojoExecution
This is an automated email from the ASF dual-hosted git repository.
khmarbaise pushed a commit to branch MNG-5666
in repository https://gitbox.apache.org/repos/asf/maven.git
commit d19c649919ec886a7fca539ff7d628eb3bf91f8c
Author: rfscholte <rf...@apache.org>
AuthorDate: Wed Aug 29 16:55:16 2018 +0200
[MNG-5666] Divide lifecycle in prePhases, phases and postPhases
Expose lifecyclePhaseGroup in MojoExecution
---
.../internal/DefaultLifecycleMappingDelegate.java | 23 ++++++++++++++--
.../org/apache/maven/plugin/MojoExecution.java | 32 +++++++++++++++++++++-
.../stub/LifecycleExecutionPlanCalculatorStub.java | 19 ++++++++++++-
3 files changed, 70 insertions(+), 4 deletions(-)
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleMappingDelegate.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleMappingDelegate.java
index 9c8277f..7ee92ec 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleMappingDelegate.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleMappingDelegate.java
@@ -37,6 +37,7 @@ import org.apache.maven.plugin.MojoNotFoundException;
import org.apache.maven.plugin.PluginDescriptorParsingException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.MojoExecution.LifecyclePhaseGroup;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
@@ -56,6 +57,7 @@ public class DefaultLifecycleMappingDelegate
@Requirement
private BuildPluginManager pluginManager;
+ @Override
public Map<String, List<MojoExecution>> calculateLifecycleMappings( MavenSession session, MavenProject project,
Lifecycle lifecycle, String lifecyclePhase )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
@@ -102,7 +104,8 @@ public class DefaultLifecycleMappingDelegate
for ( String goal : execution.getGoals() )
{
MojoExecution mojoExecution = new MojoExecution( plugin, goal, execution.getId() );
- mojoExecution.setLifecyclePhase( execution.getPhase() );
+ mojoExecution.setLifecyclePhase( execution.getPhase(),
+ getPhaseGroup( lifecycle, execution.getPhase() ) );
addMojoExecution( phaseBindings, mojoExecution, execution.getPriority() );
}
}
@@ -120,7 +123,8 @@ public class DefaultLifecycleMappingDelegate
if ( phaseBindings != null )
{
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, execution.getId() );
- mojoExecution.setLifecyclePhase( mojoDescriptor.getPhase() );
+ mojoExecution.setLifecyclePhase( mojoDescriptor.getPhase(),
+ getPhaseGroup( lifecycle, execution.getPhase() ) );
addMojoExecution( phaseBindings, mojoExecution, execution.getPriority() );
}
}
@@ -160,4 +164,19 @@ public class DefaultLifecycleMappingDelegate
mojoExecutions.add( mojoExecution );
}
+ private LifecyclePhaseGroup getPhaseGroup( Lifecycle lifecycle, String phase )
+ {
+ if ( lifecycle.getPrePhases().contains( phase ) )
+ {
+ return LifecyclePhaseGroup.PREPHASES;
+ }
+ else if ( lifecycle.getPostPhases().contains( phase ) )
+ {
+ return LifecyclePhaseGroup.POSTPHASES;
+ }
+ else
+ {
+ return LifecyclePhaseGroup.PHASES;
+ }
+ }
}
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java
index fa72c18..0c407fb 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java
@@ -59,6 +59,18 @@ public class MojoExecution
*/
LIFECYCLE,
}
+
+ /**
+ * The group of the phase. Could have been combined with {@link Source} like CLI, LIFECYCLE_PREPHASES,
+ * LIFECYCLE_PHASES, LIFECYCLE_POSTPHASES but that would break backwards compatibility.
+ *
+ * @author Robert Scholte
+ * @since 3.6.0
+ */
+ public enum LifecyclePhaseGroup
+ {
+ PREPHASES, PHASES, POSTPHASES
+ }
private Source source = Source.LIFECYCLE;
@@ -67,7 +79,9 @@ public class MojoExecution
* this mojo execution is going to run in.
*/
private String lifecyclePhase;
-
+
+ private LifecyclePhaseGroup lifecyclePhaseGroup;
+
/**
* The executions to fork before this execution, indexed by the groupId:artifactId:version of the project on which
* the forked execution are to be run and in reactor build order.
@@ -165,11 +179,27 @@ public class MojoExecution
return lifecyclePhase;
}
+ public LifecyclePhaseGroup getLifecyclePhaseGroup()
+ {
+ return lifecyclePhaseGroup;
+ }
+
+ /**
+ * @param lifecyclePhase
+ * @deprecated instead use {@link #setLifecyclePhase(String, LifecyclePhaseGroup)}
+ */
+ @Deprecated
public void setLifecyclePhase( String lifecyclePhase )
{
this.lifecyclePhase = lifecyclePhase;
}
+ public void setLifecyclePhase( String lifecyclePhase, LifecyclePhaseGroup group )
+ {
+ this.lifecyclePhase = lifecyclePhase;
+ this.lifecyclePhaseGroup = group;
+ }
+
@Override
public String toString()
{
diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifecycleExecutionPlanCalculatorStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifecycleExecutionPlanCalculatorStub.java
index 90de4d8..9aafd1c 100644
--- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifecycleExecutionPlanCalculatorStub.java
+++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifecycleExecutionPlanCalculatorStub.java
@@ -26,6 +26,7 @@ import org.apache.maven.lifecycle.internal.ProjectSegment;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.InvalidPluginDescriptorException;
import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.MojoExecution.LifecyclePhaseGroup;
import org.apache.maven.plugin.MojoNotFoundException;
import org.apache.maven.plugin.PluginDescriptorParsingException;
import org.apache.maven.plugin.PluginNotFoundException;
@@ -207,7 +208,7 @@ public class LifecycleExecutionPlanCalculatorStub
MojoExecution result = new MojoExecution( plugin, goal, executionId );
result.setConfiguration( new Xpp3Dom( executionId + "-" + goal ) );
result.setMojoDescriptor( mojoDescriptor );
- result.setLifecyclePhase( mojoDescriptor.getPhase() );
+ result.setLifecyclePhase( mojoDescriptor.getPhase(), getPhaseGroup( mojoDescriptor.getPhase() ) );
return result;
@@ -239,4 +240,20 @@ public class LifecycleExecutionPlanCalculatorStub
return new HashSet<>( Arrays.asList( "compile" ) );
}
+ private static LifecyclePhaseGroup getPhaseGroup( String phase )
+ {
+ if ( "validate".equals( phase ) )
+ {
+ return LifecyclePhaseGroup.PREPHASES;
+ }
+ else if ( "install".equals( phase ) || "site-deploy".equals( phase ))
+ {
+ return LifecyclePhaseGroup.POSTPHASES;
+ }
+ else
+ {
+ return LifecyclePhaseGroup.PHASES;
+ }
+ }
+
}