Search in sources :

Example 1 with InvocationOutputHandler

use of org.apache.maven.shared.invoker.InvocationOutputHandler 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 InvocationOutputHandler

use of org.apache.maven.shared.invoker.InvocationOutputHandler 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 3 with InvocationOutputHandler

use of org.apache.maven.shared.invoker.InvocationOutputHandler 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)3 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 PrintStream (java.io.PrintStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InvocationOutputHandler (org.apache.maven.shared.invoker.InvocationOutputHandler)3 PrintStreamHandler (org.apache.maven.shared.invoker.PrintStreamHandler)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2