You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by if...@apache.org on 2014/02/04 18:14:18 UTC
[2/3] git commit: MPLUGINTESTING-37 introduced MojoRule #executeMojo
and related methods
MPLUGINTESTING-37 introduced MojoRule #executeMojo and related methods
Signed-off-by: Igor Fedorenko <if...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/maven-plugin-testing/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-plugin-testing/commit/6ac53b29
Tree: http://git-wip-us.apache.org/repos/asf/maven-plugin-testing/tree/6ac53b29
Diff: http://git-wip-us.apache.org/repos/asf/maven-plugin-testing/diff/6ac53b29
Branch: refs/heads/master
Commit: 6ac53b29a3557907607374c9fa81649d96a7f218
Parents: 30dba95
Author: Igor Fedorenko <if...@apache.org>
Authored: Sat Feb 1 14:35:16 2014 -0500
Committer: Igor Fedorenko <if...@apache.org>
Committed: Tue Feb 4 11:56:07 2014 -0500
----------------------------------------------------------------------
.../apache/maven/plugin/testing/MojoRule.java | 52 ++++++++++++++++++++
1 file changed, 52 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-plugin-testing/blob/6ac53b29/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java
----------------------------------------------------------------------
diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java
index 6abfee8..858cfe1 100644
--- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java
@@ -23,15 +23,21 @@ import java.io.File;
import java.io.InputStream;
import java.util.Map;
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuilder;
+import org.apache.maven.project.ProjectBuildingRequest;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.junit.Assert;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
@@ -303,4 +309,50 @@ public class MojoRule
}
};
}
+
+ /**
+ * @since 3.1.0
+ */
+ public MavenProject readMavenProject( File basedir )
+ throws Exception
+ {
+ File pom = new File( basedir, "pom.xml" );
+ MavenExecutionRequest request = new DefaultMavenExecutionRequest();
+ request.setBaseDirectory( basedir );
+ ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
+ MavenProject project = lookup( ProjectBuilder.class ).build( pom, configuration ).getProject();
+ Assert.assertNotNull( project );
+ return project;
+ }
+
+ /**
+ * @since 3.1.0
+ */
+ public void executeMojo( File basedir, String goal )
+ throws Exception
+ {
+ lookupConfiguredMojo( basedir, goal ).execute();
+ }
+
+ /**
+ * @since 3.1.0
+ */
+ public Mojo lookupConfiguredMojo( File basedir, String goal )
+ throws Exception, ComponentConfigurationException
+ {
+ MavenProject project = readMavenProject( basedir );
+ MavenSession session = newMavenSession( project );
+ MojoExecution execution = newMojoExecution( goal );
+ return lookupConfiguredMojo( session, execution );
+ }
+
+ /**
+ * @since 3.1.0
+ */
+ public final <T> T lookup( final Class<T> role )
+ throws ComponentLookupException
+ {
+ return getContainer().lookup( role );
+ }
+
}