Skip to content

Commit

Permalink
Initial version, includes a simple plan:plan goal
Browse files Browse the repository at this point in the history
  • Loading branch information
skuro committed Apr 27, 2012
0 parents commit 48c196a
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 0 deletions.
69 changes: 69 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>tk.skuro</groupId>
<artifactId>plan-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0</version>

<name>Maven plugin to analyse the execution plan</name>
<url>http://skuro.tk</url>

<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>

<scm>
<connection>scm:git:git://github.com/skuro/plan-maven-plugin.git</connection>
<developerConnection>scm:git:git@github.com:skuro/plan-maven-plugin.git</developerConnection>
<url>https://github.com/skuro/plan-maven-plugin</url>
</scm>

<licenses>
<license>
<url>http://www.opensource.org/licenses/MIT</url>
<name>MIT License</name>
</license>
</licenses>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<developers>
<developer>
<id>skuro</id>
<name>Carlo Sciolla</name>
<email>skuro@skuro.tk</email>
<url>http://skuro.tk</url>
<roles>
<role>developer</role>
</roles>
<timezone>+1</timezone>
<properties>
<picUrl>http://2.gravatar.com/avatar/7b21764e687cc434d41560b147ea292b?size=420</picUrl>
</properties>
</developer>
</developers>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>com.samskivert</groupId>
<artifactId>jmustache</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tk.skuro.maven.plan;

import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.codehaus.plexus.component.annotations.Component;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

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

private static final Template template;

static {
ClassLoader classLoader = JMustacheMavenExecutionPlanRenderer.class.getClassLoader();
InputStream templateStream = classLoader.getResourceAsStream("plan.mustache");
template = Mustache.compiler().defaultValue("-").compile(new InputStreamReader(templateStream));
}

/**
* {@inheritDoc}
*/
public String render(MavenExecutionPlan plan) {
Map<String, Object> ctx = new HashMap<String, Object>();
ctx.put("plan", plan);
return template.execute(ctx);
}
}
19 changes: 19 additions & 0 deletions src/main/java/tk/skuro/maven/plan/MavenExecutionPlanRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tk.skuro.maven.plan;

import org.apache.maven.lifecycle.MavenExecutionPlan;

/**
* Used to render the Plan plugin output
*
* @since 1.0
* @author Carlo Sciolla
*/
public interface MavenExecutionPlanRenderer {

/**
* Renders a {@link MavenExecutionPlan}
* @param plan The plan to render
* @return The rendered plan
*/
public String render (MavenExecutionPlan plan);
}
80 changes: 80 additions & 0 deletions src/main/java/tk/skuro/maven/plan/PlanMojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package tk.skuro.maven.plan;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
import org.apache.maven.lifecycle.internal.TaskSegment;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;

import java.util.List;
import java.util.Scanner;

/**
* Goal which prints the execution plan
*
* @goal plan
*/
public class PlanMojo extends AbstractMojo {

private Log log;

/**
* @component
*/
private LifecycleExecutionPlanCalculator planCalculator;

/**
* @component
*/
private LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator;

/**
* @component
*/
private MavenExecutionPlanRenderer renderer;

/**
* The Maven Session Object
*
* @parameter expression="${session}"
* @required
* @readonly
*/
private MavenSession session;

/**
* The Maven Project Object
*
* @parameter expression="${project}"
* @required
* @readonly
*/
protected MavenProject project;

public void execute() throws MojoExecutionException {
try {
for (TaskSegment segment : lifecycleTaskSegmentCalculator.calculateTaskSegments(session)) {
List<Object> goals = segment.getTasks();
MavenExecutionPlan plan = planCalculator.calculateExecutionPlan(session, project, goals, false);
outputPlan(plan);
}
} catch (Throwable e) {
e.printStackTrace();
}
}

private void outputPlan(MavenExecutionPlan plan) {
Scanner scanner = new Scanner(renderer.render(plan));
while(scanner.hasNextLine()) {
log.info(scanner.nextLine());
}
}

public void setLog(Log log) {
this.log = log;
}
}
16 changes: 16 additions & 0 deletions src/main/resources/META-INF/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Copyright (c) 2012 Carlo Sciolla

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
11 changes: 11 additions & 0 deletions src/main/resources/META-INF/plexus/components.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<component-set>
<components>
<component>
<role>tk.skuro.maven.plan.MavenExecutionPlanRenderer</role>
<role-hint>default</role-hint>
<implementation>
tk.skuro.maven.plan.JMustacheMavenExecutionPlanRenderer
</implementation>
</component>
</components>
</component-set>
4 changes: 4 additions & 0 deletions src/main/resources/plan.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Execution plan:
{{#plan}}
[{{lifecyclePhase}}] {{mojoExecution.groupId}}:{{mojoExecution.artifactId}}:{{mojoExecution.goal}}
{{/plan}}

0 comments on commit 48c196a

Please sign in to comment.