org.apache.maven.shared.invoker.InvocationRequest Java Examples

The following examples show how to use org.apache.maven.shared.invoker.InvocationRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NativeBuildMojo.java    From client-maven-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void execute() throws MojoExecutionException {
    getLog().debug("Start building");

    // prepare the execution:
    final InvocationRequest invocationRequest = new DefaultInvocationRequest();
    invocationRequest.setProfiles(project.getActiveProfiles().stream()
            .map(Profile::getId)
            .collect(Collectors.toList()));
    invocationRequest.setPomFile(new File(pom));

    invocationRequest.setGoals(Arrays.asList("client:compile", "client:link"));

    final Invoker invoker = new DefaultInvoker();
    // execute:
    try {
        final InvocationResult invocationResult = invoker.execute(invocationRequest);
        if (invocationResult.getExitCode() != 0) {
            throw new MojoExecutionException("Error, client:build failed", invocationResult.getExecutionException());
        }
    } catch (MavenInvocationException e) {
        e.printStackTrace();
        throw new MojoExecutionException("Error", e);
    }

}
 
Example #2
Source File: HookMethodDefTest.java    From sahagin-java with Apache License 2.0 6 votes vote down vote up
private String mavenJreVersion() {
    InvocationRequest versionRequest = new DefaultInvocationRequest();
    if (System.getProperty("sahagin.maven.java.home") != null) {
        versionRequest.setJavaHome(new File(System.getProperty("sahagin.maven.java.home")));
    }
    versionRequest.setGoals(Arrays.asList("-v"));
    MavenInvokeResult versionResult = mavenInvoke(versionRequest, "version");
    for (String stdOut : versionResult.stdOuts) {
        String[] entries = stdOut.split(",");
        for (String entry : entries) {
            String[] keyValue = entry.split(":");
            if (keyValue.length != 2) {
                continue;
            }
            if (keyValue[0].trim().equals("Java version")) {
                return keyValue[1].trim();
            }
        }
    }
    versionResult.printStdOutsAndErrs();
    throw new RuntimeException(String.format("fails to get JRE verion"));
}
 
Example #3
Source File: CreateMojo.java    From opoopress with Apache License 2.0 6 votes vote down vote up
private void invokePostArchetypeGenerationGoals(String goals, String artifactId, Properties properties)
        throws MojoExecutionException, MojoFailureException {
    getLog().info("Invoking post-archetype-generation goals: " + goals);

    File projectBasedir = new File(basedir, artifactId);

    if (projectBasedir.exists()) {
        InvocationRequest request = new DefaultInvocationRequest()
                .setBaseDirectory(projectBasedir)
                .setGoals(Arrays.asList(StringUtils.split(goals, ",")));

        if(properties != null){
            request.setProperties(properties);
        }

        try {
            invoker.execute(request);
        } catch (MavenInvocationException e) {
            throw new MojoExecutionException("Cannot run additions goals.", e);
        }
    } else {
        getLog().info("Additional goals aborted: unavailable basedir " + projectBasedir);
    }
}
 
Example #4
Source File: MavenRun.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
	InvocationRequest request = new DefaultInvocationRequest();
	request.setPomFile(new File("pom.xml"));
	if (args.length > 0) {
		if (args[0] != null && args[1] != null) {
			Properties projectProperties = new Properties();
			projectProperties.setProperty("deviceOS", args[0]);
			projectProperties.setProperty("appPath", args[1]);
			projectProperties.setProperty("osVersion", args[2]);
			projectProperties.setProperty("deviceName", args[3]);
			projectProperties.setProperty("udid", args[4]);
			request.setProperties(projectProperties);
		}
	}

	request.setGoals(Collections.singletonList("test"));
	Invoker invoker = new DefaultInvoker();
	invoker.setMavenHome(new File(System.getenv("M2_HOME")));
	try {
		invoker.execute(request);
	} catch (MavenInvocationException e) {
		e.printStackTrace();
	}
}
 
Example #5
Source File: AbstractSundrioMojo.java    From sundrio with Apache License 2.0 6 votes vote down vote up
void backGroundBuild(MavenProject project) throws MojoExecutionException {
    MavenExecutionRequest executionRequest = session.getRequest();

    InvocationRequest request = new DefaultInvocationRequest();
    request.setBaseDirectory(project.getBasedir());
    request.setPomFile(project.getFile());
    request.setGoals(executionRequest.getGoals());
    request.setRecursive(false);
    request.setInteractive(false);

    request.setProfiles(executionRequest.getActiveProfiles());
    request.setProperties(executionRequest.getUserProperties());
    Invoker invoker = new DefaultInvoker();
    try {
        InvocationResult result = invoker.execute(request);
        if (result.getExitCode() != 0) {
            throw new IllegalStateException("Error invoking Maven goals:[" + StringUtils.join(executionRequest.getGoals(), ", ") + "]", result.getExecutionException());
        }
    } catch (MavenInvocationException e) {
        throw new IllegalStateException("Error invoking Maven goals:[" + StringUtils.join(executionRequest.getGoals(), ", ") + "]", e);
    }
}
 
Example #6
Source File: MavenRunnerFactory.java    From app-runner with MIT License 6 votes vote down vote up
public static Optional<MavenRunnerFactory> createIfAvailable(Config config) {
    HomeProvider homeProvider = config.javaHomeProvider();

    StringBuffer out = new StringBuffer();
    InvocationRequest request = new DefaultInvocationRequest()
        .setOutputHandler((str) -> out.append(str).append(" - "))
        .setErrorHandler((str) -> out.append(str).append(" - "))
        .setShowVersion(true)
        .setGoals(Collections.singletonList("--version"))
        .setBaseDirectory(new File("."));
    try {
        MavenRunner.runRequest(request, homeProvider);
        String versionInfo = StringUtils.removeEndIgnoreCase(out.toString(), " - ");
        return Optional.of(new MavenRunnerFactory(homeProvider, versionInfo));
    } catch (Exception e) {
        return Optional.empty();
    }
}
 
Example #7
Source File: AbstractInvokerMojoTest.java    From iterator-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddItemProperties()
{
    mock.getMavenProject().getProperties().put( "prop1", "value1" );
    mock.getProperties().put( "prop1", "value2" );
    Properties itemProperties = new Properties();
    itemProperties.put( "prop1", "value3" );
    
    ItemWithProperties prop = new ItemWithProperties( "item" , itemProperties );
    InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop );
    
    assertThat( createAndConfigureAnInvocationRequest.getProperties().entrySet() )
            .hasSize( 1 )
            .extracting( "key", "value" )
            .containsExactly(Tuple.tuple( "prop1", "value3" ));
}
 
Example #8
Source File: BuildProject.java    From unleash-maven-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException {
  this.log.info("Starting release build.");

  try {
    InvocationRequest request = setupInvocationRequest();
    Invoker invoker = setupInvoker();

    InvocationResult result = invoker.execute(request);
    if (result.getExitCode() != 0) {
      CommandLineException executionException = result.getExecutionException();
      if (executionException != null) {
        throw new MojoFailureException("Error during project build: " + executionException.getMessage(),
            executionException);
      } else {
        throw new MojoFailureException("Error during project build: " + result.getExitCode());
      }
    }
  } catch (MavenInvocationException e) {
    throw new MojoFailureException(e.getMessage(), e);
  }
}
 
Example #9
Source File: AbstractInvokerMojoTest.java    From iterator-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddSystemProperties()
{
    mock.getMavenProject().getProperties().put( "prop1", "value1" );
    mock.getProperties().put( "prop1", "value2" );
    Properties itemProperties = new Properties();
    itemProperties.put( "prop1", "value3" );
    System.getProperties().put( "prop1", "value4" );
    
    ItemWithProperties prop = new ItemWithProperties( "item" , itemProperties );
    InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop );
    
    assertThat( createAndConfigureAnInvocationRequest.getProperties().entrySet() )
            .hasSize( 1 )
            .extracting( "key", "value" )
            .containsExactly(Tuple.tuple( "prop1", "value4" ));
}
 
Example #10
Source File: ProjectGenerator.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected void runMavenGoals(File outputDir, String... goals) throws MavenInvocationException {
    List<String> goalList = Arrays.asList(goals);
    LOG.info("Invoking maven with goals: " + goalList + " in folder: " + outputDir);
    File pomFile = new File(outputDir, "pom.xml");

    InvocationRequest request = new DefaultInvocationRequest();
    request.setLocalRepositoryDirectory(localMavenRepo);
    request.setInteractive(false);
    request.setPomFile(pomFile);
    request.setGoals(goalList);

    // lets use a dummy service name to avoid it being too long
    request.setMavenOpts("-Dfabric8.service.name=dummy-name");

    Invoker invoker = new DefaultInvoker();
    InvocationResult result = invoker.execute(request);
    int exitCode = result.getExitCode();
    LOG.info("maven result " + exitCode + " exception: " + result.getExecutionException());
    if (exitCode != 0) {
        LOG.error("Failed to invoke maven goals: " + goalList + " in folder: " + outputDir + ". Exit Code: " + exitCode);
        failedFolders.add(outputDir);
    }
}
 
Example #11
Source File: ProjectGenerator.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public File getArtifactJar(String groupId, String artifactId, String version) {
    Properties properties = new Properties();
    properties.put("groupId", groupId);
    properties.put("artifactId", artifactId);
    properties.put("version", version);

    InvocationRequest request = new DefaultInvocationRequest();
    request.setLocalRepositoryDirectory(localMavenRepo);
    request.setInteractive(false);
    List<String> goalList = Arrays.asList("org.apache.maven.plugins:maven-dependency-plugin:2.10:get");
    request.setGoals(goalList);
    request.setProperties(properties);

    try {
        Invoker invoker = new DefaultInvoker();
        InvocationResult result = invoker.execute(request);
        int exitCode = result.getExitCode();
        LOG.info("maven result " + exitCode + " exception: " + result.getExecutionException());
        assertEquals("Failed to invoke maven goals: " + goalList + " with properties: " + properties + ". Exit Code: ", 0, exitCode);
    } catch (MavenInvocationException e) {
        fail("Failed to invoke maven goals: " + goalList + " with properties: " + properties + ". Exception " + e, e);
    }
    String path = groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar";
    return new File(localMavenRepo, path);
}
 
Example #12
Source File: MavenDependencyResolver.java    From carnotzet with Apache License 2.0 6 votes vote down vote up
private void executeMavenBuild(List<String> goals, InvocationOutputHandler outputHandler) {
	log.debug("Invoking maven with goals {}", goals);
	InvocationRequest request = new DefaultInvocationRequest();
	request.setBatchMode(true);
	request.setGoals(goals);
	// reset MAVEN_DEBUG_OPTS to allow debugging without blocking the invoker calls
	request.addShellEnvironment("MAVEN_DEBUG_OPTS", "");
	InvocationOutputHandler outHandler = outputHandler;
	if (outHandler == null) {
		outHandler = log::debug;
	}
	request.setOutputHandler(outHandler);
	try {
		InvocationResult result = maven.execute(request);
		if (result.getExitCode() != 0) {
			throw new MavenInvocationException("Maven process exited with non-zero code [" + result.getExitCode() + "]. "
					+ "Retry with debug log level enabled to see the maven invocation logs");
		}
	}
	catch (MavenInvocationException e) {
		throw new CarnotzetDefinitionException("Error invoking mvn " + goals, e);
	}
}
 
Example #13
Source File: TestPackager.java    From justtestlah with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a test package for AWS Devicefarm.
 *
 * @param logger {@link InvokerLogger} logger to be used for the Maven build output
 * @param clean true, if the target directory should be cleaned (forcing recompilation)
 * @return {@link File} of the ZIP package to be used by AWS Devicefarm
 * @throws MavenInvocationException error during Maven build
 */
protected File packageProjectForDeviceFarm(InvocationOutputHandler logger, boolean clean)
    throws MavenInvocationException {
  InvocationRequest request = new DefaultInvocationRequest();
  request.setPomFile(
      new File(properties.getProperty("aws.demo.path") + File.separator + "pom.xml"));
  request.setProfiles(List.of("aws"));
  if (clean) {
    request.setGoals(List.of("clean", "package"));
  } else {
    request.setGoals(List.of("package"));
  }
  request.setUpdateSnapshots(true);
  new DefaultInvoker().setOutputHandler(logger).execute(request);
  return new File(
      properties.getProperty("aws.demo.path")
          + File.separator
          + "target"
          + File.separator
          + properties.getProperty("aws.testpackage.name")
          + ".zip");
}
 
Example #14
Source File: ExecuteUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public static void executeMaven(File projectDirectory, CommandInvocation invocation, String buildTarget) {
    String mvnPath = findExecutable("mvn");
    System.setProperty("maven.home", mvnPath);

    InvocationRequest request = new DefaultInvocationRequest();
    request.setPomFile(new File(projectDirectory.getAbsolutePath() + File.separatorChar + "pom.xml"));
    request.setGoals(Collections.singletonList(buildTarget));

    Invoker invoker = new DefaultInvoker();

    InvocationResult result = null;
    try {
        result = invoker.execute(request);
    } catch (MavenInvocationException e) {
        invocation.println("Failed during invocation: " + e.getMessage());
    }

    if (result.getExitCode() != 0) {
        invocation.println("Build failed.");
    }
}
 
Example #15
Source File: CreateProjectMojoIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private InvocationResult setup(Properties params)
        throws MavenInvocationException, FileNotFoundException, UnsupportedEncodingException {

    params.setProperty("platformGroupId", ToolsConstants.IO_QUARKUS);
    params.setProperty("platformArtifactId", "quarkus-bom");
    params.setProperty("platformVersion", getPluginVersion());

    InvocationRequest request = new DefaultInvocationRequest();
    request.setBatchMode(true);
    request.setGoals(Collections.singletonList(
            getPluginGroupId() + ":" + getPluginArtifactId() + ":" + getPluginVersion() + ":create"));
    request.setDebug(false);
    request.setShowErrors(false);
    request.setProperties(params);
    getEnv().forEach(request::addShellEnvironment);
    File log = new File(testDir, "build-create-" + testDir.getName() + ".log");
    PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
            InvokerLogger.DEBUG);
    invoker.setLogger(logger);
    return invoker.execute(request);
}
 
Example #16
Source File: AddExtensionIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void addExtension(boolean plural, String ext)
        throws MavenInvocationException, FileNotFoundException, UnsupportedEncodingException {
    InvocationRequest request = new DefaultInvocationRequest();
    request.setBatchMode(true);
    request.setGoals(Collections.singletonList(
            getPluginGroupId() + ":" + getPluginArtifactId() + ":" + getPluginVersion() + ":add-extension"));
    Properties properties = new Properties();
    properties.setProperty("platformGroupId", "io.quarkus");
    properties.setProperty("platformArtifactId", "quarkus-bom");
    properties.setProperty("platformVersion", getPluginVersion());
    if (plural) {
        properties.setProperty("extensions", ext);
    } else {
        properties.setProperty("extension", ext);
    }
    request.setProperties(properties);
    getEnv().forEach(request::addShellEnvironment);
    File log = new File(testDir, "build-add-extension-" + testDir.getName() + ".log");
    PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
            InvokerLogger.DEBUG);
    invoker.setLogger(logger);
    invoker.execute(request);
}
 
Example #17
Source File: GenerateConfigIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void generateConfig(String filename)
        throws MavenInvocationException, FileNotFoundException, UnsupportedEncodingException {
    InvocationRequest request = new DefaultInvocationRequest();
    request.setBatchMode(true);
    request.setGoals(Collections
            .singletonList(getPluginGroupId() + ":" + getPluginArtifactId() + ":"
                    + getPluginVersion() + ":generate-config"));
    Properties properties = new Properties();
    properties.setProperty("file", filename);
    request.setProperties(properties);
    getEnv().forEach(request::addShellEnvironment);
    File log = new File(testDir, "build-generate-config-" + testDir.getName() + ".log");
    PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
            InvokerLogger.DEBUG);
    invoker.setLogger(logger);
    invoker.execute(request);
}
 
Example #18
Source File: MavenJarResolver.java    From beakerx with Apache License 2.0 6 votes vote down vote up
private AddMvnCommandResult retrieveDeps(String dependencies, Message parent, String pomAsString) {
  File finalPom = null;
  try {
    finalPom = saveToFile(commandParams.getPathToNotebookJars(), pomAsString);
    InvocationRequest request = createInvocationRequest(finalPom);
    MvnDownloadLoggerWidget progress = new MvnDownloadLoggerWidget(parent);
    this.logs = manageOutput(this.logs, parent);
    MavenInvocationSilentOutputHandler outputHandler = new MavenInvocationSilentOutputHandler(progress, this.logs);
    Invoker invoker = getInvoker(outputHandler);
    progress.display();
    InvocationResult invocationResult = invoker.execute(request);
    progress.close();
    this.logs.stop();
    return getResult(invocationResult, dependencies);
  } catch (Exception e) {
    return AddMvnCommandResult.error(e.getMessage());
  } finally {
    deletePomFolder(finalPom);
  }
}
 
Example #19
Source File: ListExtensionsIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private List<String> listExtensions()
        throws MavenInvocationException, IOException {
    InvocationRequest request = new DefaultInvocationRequest();
    request.setBatchMode(true);
    request.setGoals(Collections.singletonList(
            getPluginGroupId() + ":" + getPluginArtifactId() + ":" + getPluginVersion() + ":list-extensions"));
    getEnv().forEach(request::addShellEnvironment);

    File outputLog = new File(testDir, "output.log");
    InvocationOutputHandler outputHandler = new PrintStreamHandler(
            new PrintStream(new TeeOutputStream(System.out, Files.newOutputStream(outputLog.toPath())), true, "UTF-8"),
            true);
    invoker.setOutputHandler(outputHandler);

    File invokerLog = new File(testDir, "invoker.log");
    PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(invokerLog), false, "UTF-8"),
            InvokerLogger.DEBUG);
    invoker.setLogger(logger);

    invoker.execute(request);
    return Files.readAllLines(outputLog.toPath());
}
 
Example #20
Source File: AbstractInvokerMojoTest.java    From iterator-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReplaceInMultipleProfiles()
{
    mock.setProfiles( Arrays.asList( "profile-@item@", "profile-second-@item@", "@item@-profile" ) );

    ItemWithProperties prop = new ItemWithProperties( "two", ItemWithProperties.NO_PROPERTIES );
    InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop );

    assertThat( createAndConfigureAnInvocationRequest.getProfiles() ).hasSize( 3 ).containsExactly( "profile-two",
                                                                                                    "profile-second-two",
                                                                                                    "two-profile" );
}
 
Example #21
Source File: LibertySettingsDirectoryTest.java    From ci.maven with Apache License 2.0 5 votes vote down vote up
@Test
public void testLibertyConfigDirInvalidDir() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    File pomFilePath = new File("../pom.xml");
    Document pomFile = builder.parse(pomFilePath);
    pomFile.getDocumentElement().normalize();

    XPathFactory xpathFactory = XPathFactory.newInstance();
    XPath xpath = xpathFactory.newXPath();
    String pomVersion = xpath.evaluate("/project/build/plugins/plugin[artifactId='liberty-maven-plugin']/version", pomFile);

    Properties props = new Properties();
    props.put("pluginVersion", pomVersion);

    InvocationRequest request = new DefaultInvocationRequest()
    .setPomFile( new File("../src/test/resources/invalidDirPom.xml"))
    .setGoals( Collections.singletonList("package"))
    .setProperties(props);

    InvocationOutputHandler outputHandler = new InvocationOutputHandler(){
        @Override
        public void consumeLine(String line) throws IOException {
            if (line.contains("<libertySettingsFolder> must be a directory")) {
                throw new IOException("Caught expected MojoExecutionException - " + line);
            }
        }
    };

    Invoker invoker = new DefaultInvoker();
    invoker.setOutputHandler(outputHandler);

    InvocationResult result = invoker.execute( request );

    assertTrue("Exited successfully, expected non-zero exit code.", result.getExitCode() != 0);
    assertNotNull("Expected MojoExecutionException to be thrown.", result.getExecutionException());
}
 
Example #22
Source File: ArchetypeTest.java    From ipaas-quickstarts with Apache License 2.0 5 votes vote down vote up
protected static int invokeMaven(String[] args, String outDir, File logFile) {
    List<String> goals = Arrays.asList(args);
    String commandLine = Strings.join(goals, " ");

    InvocationResult result = null;
    try {
        File dir = new File(outDir);

        InvocationRequest request = new DefaultInvocationRequest();
        request.setGoals(goals);

        InvocationOutputHandler outputHandler = new SystemOutAndFileHandler(logFile);
        outputHandler.consumeLine("");
        outputHandler.consumeLine("");
        outputHandler.consumeLine(dir.getName() + " : starting: mvn " + commandLine);
        outputHandler.consumeLine("");
        request.setOutputHandler(outputHandler);
        request.setErrorHandler(outputHandler);

        DefaultInvoker invoker = new DefaultInvoker();
        request.setPomFile(new File(dir, "pom.xml"));
        result = invoker.execute(request);
        CommandLineException executionException = result.getExecutionException();
        if (executionException != null) {
            LOG.error("Failed to invoke maven with: mvn " + commandLine + ". " + executionException, executionException);
        }
    } catch (Exception e) {
        LOG.error("Failed to invoke maven with: mvn " + commandLine + ". " + e, e);
    }
    return result == null ? 1 : result.getExitCode();
}
 
Example #23
Source File: AbstractBuildMojo.java    From opoopress with Apache License 2.0 5 votes vote down vote up
private void invokeGoals( String goals, File projectBasedir) throws MavenInvocationException {
    getLog().info( "[" + projectBasedir +"] Invoking goals: " + goals );

    InvocationRequest request = new DefaultInvocationRequest()
            .setBaseDirectory(projectBasedir)
            .setGoals(Arrays.asList(StringUtils.split(goals, ",")));

    invoker.execute( request );
}
 
Example #24
Source File: InvokerMojo.java    From iterator-maven-plugin with Apache License 2.0 5 votes vote down vote up
private InvocationResult mavenCall( ItemWithProperties item )
    throws MavenInvocationException
{
    InvocationRequest request = createAndConfigureAnInvocationRequest( item );

    OutputConsumer output = new OutputConsumer( getLog() );
    request.setOutputHandler( output );

    invoker.setWorkingDirectory( getWorkingDirectoryAfterPlaceHolderIsReplaced( item ) );

    return invoker.execute( request );
}
 
Example #25
Source File: AbstractInvokerMojoTest.java    From iterator-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReplaceInBaseDirectory()
{
    mock.setBaseDirectory( new File( "first-@item@" ) );

    ItemWithProperties prop = new ItemWithProperties( "one", ItemWithProperties.NO_PROPERTIES );
    InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop );

    assertThat( createAndConfigureAnInvocationRequest.getBaseDirectory() ).isEqualTo( new File( "first-one" ) );
}
 
Example #26
Source File: AbstractInvokerMojoTest.java    From iterator-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReplaceInGoal()
{
    mock.setGoals( Collections.singletonList( "java:@item@-environment" ) );

    ItemWithProperties prop = new ItemWithProperties( "one", ItemWithProperties.NO_PROPERTIES );
    InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop );

    assertThat( createAndConfigureAnInvocationRequest.getGoals() ).hasSize( 1 ).containsExactly( "java:one-environment" );
}
 
Example #27
Source File: AbstractInvokerMojoTest.java    From iterator-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReplaceInMultipleGoals()
{
    mock.setGoals( Arrays.asList( "java:@item@-environment", "@item@", "selection-@item@-choice" ) );

    ItemWithProperties prop = new ItemWithProperties( "one", ItemWithProperties.NO_PROPERTIES );
    InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop );

    assertThat( createAndConfigureAnInvocationRequest.getGoals() ).hasSize( 3 ).containsExactly( "java:one-environment",
                                                                                                 "one",
                                                                                                 "selection-one-choice" );
}
 
Example #28
Source File: AbstractInvokerMojoTest.java    From iterator-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReplaceInProfile()
{
    mock.setProfiles( Collections.singletonList( "profile-@item@" ) );

    ItemWithProperties prop = new ItemWithProperties( "two", ItemWithProperties.NO_PROPERTIES );
    InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop );

    assertThat( createAndConfigureAnInvocationRequest.getProfiles() ).hasSize( 1 ).containsExactly( "profile-two" );
}
 
Example #29
Source File: AbstractInvokerMojoTest.java    From iterator-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReplaceInProject()
{
    mock.setProjects( Collections.singletonList( "project-@item@-a" ) );

    ItemWithProperties prop = new ItemWithProperties( "three", ItemWithProperties.NO_PROPERTIES );
    InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop );

    assertThat( createAndConfigureAnInvocationRequest.getProjects() ).hasSize( 1 ).containsExactly( "project-three-a" );
}
 
Example #30
Source File: AbstractInvokerMojoTest.java    From iterator-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReplaceInMultipleProjects()
{
    mock.setProjects( Arrays.asList( "project-@item@-a", "@item@project", "@item@" ) );

    ItemWithProperties prop = new ItemWithProperties( "three", ItemWithProperties.NO_PROPERTIES );
    InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop );

    assertThat( createAndConfigureAnInvocationRequest.getProjects() ).hasSize( 3 ).containsExactly( "project-three-a",
                                                                                                    "threeproject",
                                                                                                    "three" );
}