Search in sources :

Example 1 with PrintStreamHandler

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

the class JavadocUtil method invoke.

/**
     * @param log could be null
     * @param invoker not null
     * @param request not null
     * @param invokerLog not null
     * @param goals not null
     * @param properties could be null
     * @param mavenOpts could be null
     * @return the invocation result
     * @throws MavenInvocationException if any
     * @since 2.6
     */
private static InvocationResult invoke(Log log, Invoker invoker, InvocationRequest request, File invokerLog, List<String> goals, Properties properties, String mavenOpts) throws MavenInvocationException {
    PrintStream ps;
    OutputStream os = null;
    if (invokerLog != null) {
        if (log != null && log.isDebugEnabled()) {
            log.debug("Using " + invokerLog.getAbsolutePath() + " to log the invoker");
        }
        try {
            if (!invokerLog.exists()) {
                //noinspection ResultOfMethodCallIgnored
                invokerLog.getParentFile().mkdirs();
            }
            os = new FileOutputStream(invokerLog);
            ps = new PrintStream(os, true, "UTF-8");
        } catch (FileNotFoundException e) {
            if (log != null && log.isErrorEnabled()) {
                log.error("FileNotFoundException: " + e.getMessage() + ". Using System.out to log the invoker.");
            }
            ps = System.out;
        } catch (UnsupportedEncodingException e) {
            if (log != null && log.isErrorEnabled()) {
                log.error("UnsupportedEncodingException: " + e.getMessage() + ". Using System.out to log the invoker.");
            }
            ps = System.out;
        }
    } else {
        if (log != null && log.isDebugEnabled()) {
            log.debug("Using System.out to log the invoker.");
        }
        ps = System.out;
    }
    if (mavenOpts != null) {
        request.setMavenOpts(mavenOpts);
    }
    InvocationOutputHandler outputHandler = new PrintStreamHandler(ps, false);
    request.setOutputHandler(outputHandler);
    outputHandler.consumeLine("Invoking Maven for the goals: " + goals + " with " + (properties == null ? "no properties" : "properties=" + properties));
    outputHandler.consumeLine("");
    outputHandler.consumeLine("M2_HOME=" + getMavenHome(log));
    outputHandler.consumeLine("MAVEN_OPTS=" + getMavenOpts(log));
    outputHandler.consumeLine("JAVA_HOME=" + getJavaHome(log));
    outputHandler.consumeLine("JAVA_OPTS=" + getJavaOpts(log));
    outputHandler.consumeLine("");
    try {
        return invoker.execute(request);
    } finally {
        IOUtil.close(os);
    }
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationOutputHandler(org.apache.maven.shared.invoker.InvocationOutputHandler) PrintStreamHandler(org.apache.maven.shared.invoker.PrintStreamHandler)

Example 2 with PrintStreamHandler

use of org.apache.maven.shared.invoker.PrintStreamHandler in project syncope by apache.

the class MavenUtils method invoke.

private InvocationResult invoke(final InvocationRequest request, final String path) {
    InvocationResult result = null;
    final Invoker invoker = new DefaultInvoker();
    try {
        invoker.setLogger(new PrintStreamLogger(new PrintStream(InstallLog.getInstance().getFileAbsolutePath()), 1000));
        invoker.setOutputHandler(new PrintStreamHandler(new PrintStream(InstallLog.getInstance().getFileAbsolutePath()), true));
        invoker.setWorkingDirectory(new File(path));
        result = invoker.execute(request);
    } catch (MavenInvocationException | FileNotFoundException ex) {
        final String messageError = "Maven exception: " + ex.getMessage();
        handler.emitError(messageError, messageError);
        InstallLog.getInstance().info(messageError);
    }
    return result;
}
Also used : PrintStream(java.io.PrintStream) Invoker(org.apache.maven.shared.invoker.Invoker) DefaultInvoker(org.apache.maven.shared.invoker.DefaultInvoker) PrintStreamLogger(org.apache.maven.shared.invoker.PrintStreamLogger) MavenInvocationException(org.apache.maven.shared.invoker.MavenInvocationException) DefaultInvoker(org.apache.maven.shared.invoker.DefaultInvoker) FileNotFoundException(java.io.FileNotFoundException) InvocationResult(org.apache.maven.shared.invoker.InvocationResult) File(java.io.File) PrintStreamHandler(org.apache.maven.shared.invoker.PrintStreamHandler)

Example 3 with PrintStreamHandler

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

the class SiteInvoker method invoke.

/**
 * @param invoker not null
 * @param request not null
 * @param invokerLog not null
 * @param goals the list of goals
 * @param properties the properties for the invoker
 * @param mavenOpts could be null
 * @return the invocation result
 * @throws MavenInvocationException if any
 */
private InvocationResult invoke(Invoker invoker, InvocationRequest request, File invokerLog, List goals, Properties properties, String mavenOpts) throws MavenInvocationException {
    PrintStream ps;
    OutputStream os = null;
    if (invokerLog != null) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("Using " + invokerLog.getAbsolutePath() + " to log the invoker");
        }
        try {
            if (!invokerLog.exists()) {
                invokerLog.getParentFile().mkdirs();
            }
            os = new FileOutputStream(invokerLog);
            ps = new PrintStream(os, true, "UTF-8");
        } catch (FileNotFoundException e) {
            if (getLog().isErrorEnabled()) {
                getLog().error("FileNotFoundException: " + e.getMessage() + ". Using System.out to log the invoker.");
            }
            ps = System.out;
        } catch (UnsupportedEncodingException e) {
            if (getLog().isErrorEnabled()) {
                getLog().error("UnsupportedEncodingException: " + e.getMessage() + ". Using System.out to log the invoker.");
            }
            ps = System.out;
        }
    } else {
        getLog().debug("Using System.out to log the invoker.");
        ps = System.out;
    }
    if (mavenOpts != null) {
        request.setMavenOpts(mavenOpts);
    }
    InvocationOutputHandler outputHandler = new PrintStreamHandler(ps, false);
    request.setOutputHandler(outputHandler);
    request.setErrorHandler(outputHandler);
    outputHandler.consumeLine("Invoking Maven for the goals: " + goals + " with properties=" + properties);
    outputHandler.consumeLine("");
    outputHandler.consumeLine("M2_HOME=" + getMavenHome());
    outputHandler.consumeLine("MAVEN_OPTS=" + getMavenOpts());
    outputHandler.consumeLine("JAVA_HOME=" + getJavaHome());
    outputHandler.consumeLine("JAVA_OPTS=" + getJavaOpts());
    outputHandler.consumeLine("");
    try {
        return invoker.execute(request);
    } finally {
        IOUtil.close(os);
        ps = null;
    }
}
Also used : PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationOutputHandler(org.apache.maven.shared.invoker.InvocationOutputHandler) PrintStreamHandler(org.apache.maven.shared.invoker.PrintStreamHandler)

Example 4 with PrintStreamHandler

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

the class JavadocUtil method invoke.

/**
 * @param log could be null
 * @param invoker not null
 * @param request not null
 * @param invokerLog not null
 * @param goals not null
 * @param properties could be null
 * @param mavenOpts could be null
 * @return the invocation result
 * @throws MavenInvocationException if any
 * @since 2.6
 */
private static InvocationResult invoke(Log log, Invoker invoker, InvocationRequest request, File invokerLog, List<String> goals, Properties properties, String mavenOpts) throws MavenInvocationException {
    PrintStream ps;
    OutputStream os = null;
    if (invokerLog != null) {
        if (log != null && log.isDebugEnabled()) {
            log.debug("Using " + invokerLog.getAbsolutePath() + " to log the invoker");
        }
        try {
            if (!invokerLog.exists()) {
                // noinspection ResultOfMethodCallIgnored
                invokerLog.getParentFile().mkdirs();
            }
            os = new FileOutputStream(invokerLog);
            ps = new PrintStream(os, true, "UTF-8");
        } catch (FileNotFoundException e) {
            if (log != null && log.isErrorEnabled()) {
                log.error("FileNotFoundException: " + e.getMessage() + ". Using System.out to log the invoker.");
            }
            ps = System.out;
        } catch (UnsupportedEncodingException e) {
            if (log != null && log.isErrorEnabled()) {
                log.error("UnsupportedEncodingException: " + e.getMessage() + ". Using System.out to log the invoker.");
            }
            ps = System.out;
        }
    } else {
        if (log != null && log.isDebugEnabled()) {
            log.debug("Using System.out to log the invoker.");
        }
        ps = System.out;
    }
    if (mavenOpts != null) {
        request.setMavenOpts(mavenOpts);
    }
    InvocationOutputHandler outputHandler = new PrintStreamHandler(ps, false);
    request.setOutputHandler(outputHandler);
    outputHandler.consumeLine("Invoking Maven for the goals: " + goals + " with " + (properties == null ? "no properties" : "properties=" + properties));
    outputHandler.consumeLine("");
    outputHandler.consumeLine("M2_HOME=" + getMavenHome(log));
    outputHandler.consumeLine("MAVEN_OPTS=" + getMavenOpts(log));
    outputHandler.consumeLine("JAVA_HOME=" + getJavaHome(log));
    outputHandler.consumeLine("JAVA_OPTS=" + getJavaOpts(log));
    outputHandler.consumeLine("");
    try {
        return invoker.execute(request);
    } finally {
        IOUtil.close(os);
    }
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationOutputHandler(org.apache.maven.shared.invoker.InvocationOutputHandler) PrintStreamHandler(org.apache.maven.shared.invoker.PrintStreamHandler)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)4 PrintStream (java.io.PrintStream)4 PrintStreamHandler (org.apache.maven.shared.invoker.PrintStreamHandler)4 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InvocationOutputHandler (org.apache.maven.shared.invoker.InvocationOutputHandler)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)1 DefaultInvoker (org.apache.maven.shared.invoker.DefaultInvoker)1 InvocationResult (org.apache.maven.shared.invoker.InvocationResult)1 Invoker (org.apache.maven.shared.invoker.Invoker)1 MavenInvocationException (org.apache.maven.shared.invoker.MavenInvocationException)1 PrintStreamLogger (org.apache.maven.shared.invoker.PrintStreamLogger)1