/** * @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 void executeMojo( File basedir, String goal ) throws Exception { MavenProject project = readMavenProject( basedir ); MavenSession session = newMavenSession( project ); MojoExecution execution = newMojoExecution( goal ); executeMojo( session, project, execution ); }
/** * @since 3.1.0 */ public final <T> T lookup( final Class<T> role ) throws ComponentLookupException { return getContainer().lookup( role ); }
/** * @since 3.2.0 */ public void executeMojo( MavenProject project, String goal, Xpp3Dom... parameters ) throws Exception { MavenSession session = newMavenSession( project ); executeMojo( session, project, goal, parameters ); }
throws Exception SessionScope sessionScope = lookup( SessionScope.class ); try sessionScope.seed( MavenSession.class, session ); MojoExecutionScope executionScope = lookup( MojoExecutionScope.class ); try executionScope.seed( MojoExecution.class, execution ); Mojo mojo = lookupConfiguredMojo( session, execution ); mojo.execute(); for ( MojoExecutionListener listener : getContainer().lookupList( MojoExecutionListener.class ) )
/** * @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(); configuration.setRepositorySession( new DefaultRepositorySystemSession() ); MavenProject project = lookup( ProjectBuilder.class ).build( pom, configuration ).getProject(); Assert.assertNotNull( project ); return project; }
/** * @since 3.2.0 */ public void executeMojo( MavenSession session, MavenProject project, String goal, Xpp3Dom... parameters ) throws Exception { MojoExecution execution = newMojoExecution( goal ); if ( parameters != null ) { Xpp3Dom configuration = execution.getConfiguration(); for ( Xpp3Dom parameter : parameters ) { configuration.addChild( parameter ); } } executeMojo( session, project, execution ); }
/** * Configures a MOJO based on the goal and the pom file then verifies the goal MOJO was found. * * @param goal the name of the goal being tested * @param fileName the name of the POM file to be used during testing * * @return the MOJO object under test * * @throws java.lang.AssertionError if the MOJO was not found */ public <T extends Mojo> T lookupMojoAndVerify(final String goal, final String fileName) throws Exception { final Path baseDir = Paths.get(BASE_CONFIG_DIR); assertTrue("Not a directory: " + BASE_CONFIG_DIR, Files.exists(baseDir)); final Path pom = Paths.get(BASE_CONFIG_DIR, fileName); assertTrue(Files.exists(pom)); MavenProject project = readMavenProject(pom); @SuppressWarnings("unchecked") T mojo = (T) rule.lookupConfiguredMojo(project, goal); assertNotNull(mojo); setDefaultEnvironment(mojo); return mojo; }
public MavenProject readMavenProject(Path pom) throws Exception { MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setBaseDirectory(pom.getParent().toFile()); ProjectBuildingRequest configuration = request.getProjectBuildingRequest(); configuration.setRepositorySession(new DefaultRepositorySystemSession()); MavenProject project = rule.lookup(ProjectBuilder.class).build(pom.toFile(), configuration).getProject(); Assert.assertNotNull(project); return project; }