Search in sources :

Example 11 with DefaultInvoker

use of org.apache.maven.shared.invoker.DefaultInvoker in project beakerx by twosigma.

the class MavenJarResolver method getInvoker.

private Invoker getInvoker(MvnLoggerWidget progress) {
    Invoker invoker = new DefaultInvoker();
    String mvn = findMvn();
    System.setProperty("maven.home", mvn);
    invoker.setLogger(new MavenJarResolverSilentLogger());
    invoker.setOutputHandler(new MavenInvocationSilentOutputHandler(progress));
    invoker.setLocalRepositoryDirectory(getOrCreateFile(this.commandParams.getPathToCache()));
    return invoker;
}
Also used : Invoker(org.apache.maven.shared.invoker.Invoker) DefaultInvoker(org.apache.maven.shared.invoker.DefaultInvoker) MavenInvocationSilentOutputHandler(com.twosigma.beakerx.kernel.commands.MavenInvocationSilentOutputHandler) DefaultInvoker(org.apache.maven.shared.invoker.DefaultInvoker) MavenJarResolverSilentLogger(com.twosigma.beakerx.kernel.commands.MavenJarResolverSilentLogger)

Example 12 with DefaultInvoker

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

the class MavenAutomaticBuilder method runGoals.

private int runGoals(String pathToRootOfProject, String... goals) {
    InvocationRequest request = new DefaultInvocationRequest();
    request.setGoals(Arrays.asList(goals));
    request.setPomFile(new File(pathToRootOfProject + FILE_SEPARATOR + POM_FILE));
    request.setJavaHome(new File(System.getProperty("java.home")));
    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);
    Invoker invoker = new DefaultInvoker();
    invoker.setMavenHome(new File(this.mavenHome));
    LOGGER.info(String.format("run maven %s", Arrays.stream(goals).collect(Collectors.joining(" "))));
    if (Main.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)

Example 13 with DefaultInvoker

use of org.apache.maven.shared.invoker.DefaultInvoker in project maven-plugins by apache.

the class SiteInvoker method invoke.

/**
 * @param projectFile not null, should be in the ${project.basedir}
 * @param invokerLog not null
 * @param mavenHome not null
 * @param goals the list of goals
 * @param properties the properties for the invoker
 */
private void invoke(File projectFile, File invokerLog, String mavenHome, List goals, List activeProfiles, Properties properties) {
    Invoker invoker = new DefaultInvoker();
    invoker.setMavenHome(new File(mavenHome));
    File localRepoDir = new File(localRepository.getBasedir());
    invoker.setLocalRepositoryDirectory(localRepoDir);
    InvocationRequest request = new DefaultInvocationRequest();
    request.setLocalRepositoryDirectory(localRepoDir);
    // request.setUserSettingsFile( settingsFile );
    request.setBatchMode(true);
    request.setShowErrors(getLog().isErrorEnabled());
    request.setDebug(getLog().isDebugEnabled());
    // request.setShowVersion( false );
    request.setBaseDirectory(projectFile.getParentFile());
    request.setPomFile(projectFile);
    request.setGoals(goals);
    request.setProperties(properties);
    request.setProfiles(activeProfiles);
    File javaHome = getJavaHome();
    if (javaHome != null) {
        request.setJavaHome(javaHome);
    }
    InvocationResult invocationResult;
    try {
        if (getLog().isDebugEnabled()) {
            getLog().debug("Invoking Maven for the goals: " + goals + " with properties=" + properties);
        }
        invocationResult = invoke(invoker, request, invokerLog, goals, properties, null);
    } catch (MavenInvocationException e) {
        getLog().error("Error when invoking Maven, consult the invoker log.");
        getLog().debug(e);
        return;
    }
    String invokerLogContent = null;
    Reader reader = null;
    try {
        reader = ReaderFactory.newReader(invokerLog, "UTF-8");
        invokerLogContent = IOUtil.toString(reader);
        reader.close();
        reader = null;
    } catch (IOException e) {
        getLog().error("IOException: " + e.getMessage());
        getLog().debug(e);
    } finally {
        IOUtil.close(reader);
    }
    if (invokerLogContent != null && invokerLogContent.contains("Error occurred during initialization of VM")) {
        getLog().info("Error occurred during initialization of VM, try to use an empty MAVEN_OPTS.");
        if (getLog().isDebugEnabled()) {
            getLog().debug("Reinvoking Maven for the goals: " + goals + " with an empty MAVEN_OPTS");
        }
        try {
            invocationResult = invoke(invoker, request, invokerLog, goals, properties, "");
        } catch (MavenInvocationException e) {
            getLog().error("Error when reinvoking Maven, consult the invoker log.");
            getLog().debug(e);
            return;
        }
    }
    if (invocationResult.getExitCode() != 0) {
        if (getLog().isErrorEnabled()) {
            getLog().error("Error when invoking Maven, consult the invoker log file: " + invokerLog.getAbsolutePath());
        }
    }
}
Also used : Invoker(org.apache.maven.shared.invoker.Invoker) DefaultInvoker(org.apache.maven.shared.invoker.DefaultInvoker) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvocationRequest(org.apache.maven.shared.invoker.InvocationRequest) MavenInvocationException(org.apache.maven.shared.invoker.MavenInvocationException) DefaultInvoker(org.apache.maven.shared.invoker.DefaultInvoker) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) Reader(java.io.Reader) IOException(java.io.IOException) File(java.io.File) InvocationResult(org.apache.maven.shared.invoker.InvocationResult)

Aggregations

DefaultInvoker (org.apache.maven.shared.invoker.DefaultInvoker)13 Invoker (org.apache.maven.shared.invoker.Invoker)12 File (java.io.File)10 DefaultInvocationRequest (org.apache.maven.shared.invoker.DefaultInvocationRequest)10 InvocationRequest (org.apache.maven.shared.invoker.InvocationRequest)10 MavenInvocationException (org.apache.maven.shared.invoker.MavenInvocationException)10 InvocationResult (org.apache.maven.shared.invoker.InvocationResult)9 Properties (java.util.Properties)3 IOException (java.io.IOException)2 MavenInvocationSilentOutputHandler (com.twosigma.beakerx.kernel.commands.MavenInvocationSilentOutputHandler)1 MavenJarResolverSilentLogger (com.twosigma.beakerx.kernel.commands.MavenJarResolverSilentLogger)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 FileVisitResult (java.nio.file.FileVisitResult)1 Path (java.nio.file.Path)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 ArrayList (java.util.ArrayList)1