Search in sources :

Example 31 with InvocationRequest

use of org.apache.maven.shared.invoker.InvocationRequest in project dspot by STAMP-project.

the class MavenAutomaticBuilder method _runGoals.

private int _runGoals(boolean specificPom, final String pomPathname, String... goals) {
    InvocationRequest request = new DefaultInvocationRequest();
    request.setGoals(Arrays.asList(goals));
    request.setPomFile(new File(pomPathname));
    request.setJavaHome(new File(System.getProperty("java.home")));
    if (specificPom) {
        request.setProfiles(Collections.singletonList(DSpotPOMCreator.PROFILE_ID));
    }
    Properties properties = new Properties();
    properties.setProperty("enforcer.skip", "true");
    properties.setProperty("checkstyle.skip", "true");
    properties.setProperty("cobertura.skip", "true");
    properties.setProperty("skipITs", "true");
    properties.setProperty("rat.skip", "true");
    properties.setProperty("license.skip", "true");
    properties.setProperty("findbugs.skip", "true");
    properties.setProperty("gpg.skip", "true");
    request.setProperties(properties);
    request.setInputStream(new NullInputStream(1000));
    Invoker invoker = new DefaultInvoker();
    LOGGER.info("Using {} for maven home", mavenHome);
    invoker.setMavenHome(new File(mavenHome));
    LOGGER.info(String.format("run maven: %s/bin/mvn %s", mavenHome, String.join(" ", goals)));
    if (DSpotState.verbose) {
        invoker.setOutputHandler(System.out::println);
        invoker.setErrorHandler(System.err::println);
    } else {
        invoker.setOutputHandler(null);
        invoker.setErrorHandler(null);
    }
    try {
        return invoker.execute(request).getExitCode();
    } catch (MavenInvocationException e) {
        throw new RuntimeException(e);
    }
}
Also used : DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvocationRequest(org.apache.maven.shared.invoker.InvocationRequest) Invoker(org.apache.maven.shared.invoker.Invoker) DefaultInvoker(org.apache.maven.shared.invoker.DefaultInvoker) MavenInvocationException(org.apache.maven.shared.invoker.MavenInvocationException) DefaultInvoker(org.apache.maven.shared.invoker.DefaultInvoker) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) Properties(java.util.Properties) File(java.io.File) NullInputStream(org.apache.commons.io.input.NullInputStream)

Aggregations

DefaultInvocationRequest (org.apache.maven.shared.invoker.DefaultInvocationRequest)31 InvocationRequest (org.apache.maven.shared.invoker.InvocationRequest)31 File (java.io.File)19 MavenInvocationException (org.apache.maven.shared.invoker.MavenInvocationException)17 Properties (java.util.Properties)15 InvocationResult (org.apache.maven.shared.invoker.InvocationResult)15 DefaultInvoker (org.apache.maven.shared.invoker.DefaultInvoker)14 Invoker (org.apache.maven.shared.invoker.Invoker)13 InvokerProperties (org.apache.maven.plugins.invoker.InvokerProperties)7 IOException (java.io.IOException)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 CommandLineConfigurationException (org.apache.maven.shared.invoker.CommandLineConfigurationException)2 MavenCommandLineBuilder (org.apache.maven.shared.invoker.MavenCommandLineBuilder)2 RunFailureException (org.apache.maven.shared.scriptinterpreter.RunFailureException)2 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1