Skip to content
Browse files

List lifecycle phases per invocation

  • Loading branch information...
1 parent db6803a commit f139d4f59f2a957111531495b8003f350de763b2 @skuro committed
View
20 src/main/java/tk/skuro/maven/plan/JMustacheMavenExecutionPlanRenderer.java
@@ -4,17 +4,21 @@
import com.samskivert.mustache.Template;
import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.lang.reflect.Field;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
/**
* Renders a {@link MavenExecutionPlan} using JMustache
*/
-@Component( role = MavenExecutionPlanRenderer.class )
-public class JMustacheMavenExecutionPlanRenderer implements MavenExecutionPlanRenderer {
+@Component(role = MavenExecutionPlanRenderer.class)
+public class JMustacheMavenExecutionPlanRenderer extends AbstractLogEnabled implements MavenExecutionPlanRenderer {
private static final Template template;
@@ -29,7 +33,19 @@
*/
public String render(MavenExecutionPlan plan) {
Map<String, Object> ctx = new HashMap<String, Object>();
+ List<String> phases = extractPhasesInLifecycle(plan);
ctx.put("plan", plan);
+ ctx.put("phases", phases.isEmpty() ? new String[]{} : new String[]{"true"});
return template.execute(ctx);
}
+
+ private List<String> extractPhasesInLifecycle(MavenExecutionPlan plan) {
+ try {
+ Field phasesField = plan.getClass().getDeclaredField("phasesInExecutionPlan");
+ phasesField.setAccessible(true);
+ return (List<String>) phasesField.get(plan);
+ } catch (Throwable e) {
+ return Collections.emptyList();
+ }
+ }
}
View
10 src/main/resources/plan.mustache
@@ -1,4 +1,10 @@
-Execution plan [{{#plan.phasesInExecutionPlan}} {{this}} {{/plan.phasesInExecutionPlan}}]:
+
+{{#phases}}Current lifecycle:
+ {{#plan.phasesInExecutionPlan}}{{this}}
+ {{/plan.phasesInExecutionPlan}}
+{{/phases}}
+Execution plan:
{{#plan}}
[{{lifecyclePhase}}] {{mojoExecution.groupId}}:{{mojoExecution.artifactId}}:{{mojoExecution.goal}} ({{mojoExecution.executionId}})
-{{/plan}}
+{{/plan}}
+

0 comments on commit f139d4f

Please sign in to comment.
Something went wrong with that request. Please try again.