Skip to content

Commit

Permalink
List lifecycle phases per invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
skuro committed Apr 28, 2012
1 parent db6803a commit f139d4f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Expand Up @@ -4,17 +4,21 @@
import com.samskivert.mustache.Template; import com.samskivert.mustache.Template;
import org.apache.maven.lifecycle.MavenExecutionPlan; import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.logging.AbstractLogEnabled;


import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;


/** /**
* Renders a {@link MavenExecutionPlan} using JMustache * Renders a {@link MavenExecutionPlan} using JMustache
*/ */
@Component( role = MavenExecutionPlanRenderer.class ) @Component(role = MavenExecutionPlanRenderer.class)
public class JMustacheMavenExecutionPlanRenderer implements MavenExecutionPlanRenderer { public class JMustacheMavenExecutionPlanRenderer extends AbstractLogEnabled implements MavenExecutionPlanRenderer {


private static final Template template; private static final Template template;


Expand All @@ -29,7 +33,19 @@ public class JMustacheMavenExecutionPlanRenderer implements MavenExecutionPlanRe
*/ */
public String render(MavenExecutionPlan plan) { public String render(MavenExecutionPlan plan) {
Map<String, Object> ctx = new HashMap<String, Object>(); Map<String, Object> ctx = new HashMap<String, Object>();
List<String> phases = extractPhasesInLifecycle(plan);
ctx.put("plan", plan); ctx.put("plan", plan);
ctx.put("phases", phases.isEmpty() ? new String[]{} : new String[]{"true"});
return template.execute(ctx); 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();
}
}
} }
10 changes: 8 additions & 2 deletions 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}} {{#plan}}
[{{lifecyclePhase}}] {{mojoExecution.groupId}}:{{mojoExecution.artifactId}}:{{mojoExecution.goal}} ({{mojoExecution.executionId}}) [{{lifecyclePhase}}] {{mojoExecution.groupId}}:{{mojoExecution.artifactId}}:{{mojoExecution.goal}} ({{mojoExecution.executionId}})
{{/plan}} {{/plan}}

0 comments on commit f139d4f

Please sign in to comment.