Search in sources :

Example 51 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project maven-plugins by apache.

the class JavadocUtil method getJavadocVersion.

/**
     * Call the Javadoc tool and parse its output to find its version, i.e.:
     * <pre>
     * javadoc.exe(or .sh) -J-version
     * </pre>
     *
     * @param javadocExe not null file
     * @return the javadoc version as float
     * @throws IOException if javadocExe is null, doesn't exist or is not a file
     * @throws CommandLineException if any
     * @throws IllegalArgumentException if no output was found in the command line
     * @throws PatternSyntaxException if the output contains a syntax error in the regular-expression pattern.
     * @see #parseJavadocVersion(String)
     */
protected static float getJavadocVersion(File javadocExe) throws IOException, CommandLineException, IllegalArgumentException {
    if ((javadocExe == null) || (!javadocExe.exists()) || (!javadocExe.isFile())) {
        throw new IOException("The javadoc executable '" + javadocExe + "' doesn't exist or is not a file. ");
    }
    Commandline cmd = new Commandline();
    cmd.setExecutable(javadocExe.getAbsolutePath());
    cmd.setWorkingDirectory(javadocExe.getParentFile());
    cmd.createArg().setValue("-J-version");
    CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
    int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
    if (exitCode != 0) {
        StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
        msg.append('\n');
        msg.append("Command line was:" + CommandLineUtils.toString(cmd.getCommandline()));
        throw new CommandLineException(msg.toString());
    }
    if (StringUtils.isNotEmpty(err.getOutput())) {
        return parseJavadocVersion(err.getOutput());
    } else if (StringUtils.isNotEmpty(out.getOutput())) {
        return parseJavadocVersion(out.getOutput());
    }
    throw new IllegalArgumentException("No output found from the command line 'javadoc -J-version'");
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) IOException(java.io.IOException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 52 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project maven-plugins by apache.

the class AbstractJavadocMojo method executeJavadocCommandLine.

/**
     * Execute the Javadoc command line
     *
     * @param cmd                    not null
     * @param javadocOutputDirectory not null
     * @throws MavenReportException if any errors occur
     */
private void executeJavadocCommandLine(Commandline cmd, File javadocOutputDirectory) throws MavenReportException {
    if (getLog().isDebugEnabled()) {
        // no quoted arguments
        getLog().debug(CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", ""));
    }
    String cmdLine = null;
    if (debug) {
        cmdLine = CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", "");
        cmdLine = JavadocUtil.hideProxyPassword(cmdLine, settings);
        writeDebugJavadocScript(cmdLine, javadocOutputDirectory);
    }
    CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
    try {
        int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
        String output = (StringUtils.isEmpty(out.getOutput()) ? null : '\n' + out.getOutput().trim());
        if (exitCode != 0) {
            if (cmdLine == null) {
                cmdLine = CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", "");
                cmdLine = JavadocUtil.hideProxyPassword(cmdLine, settings);
            }
            writeDebugJavadocScript(cmdLine, javadocOutputDirectory);
            if (StringUtils.isNotEmpty(output) && StringUtils.isEmpty(err.getOutput()) && isJavadocVMInitError(output)) {
                throw new MavenReportException(output + '\n' + '\n' + JavadocUtil.ERROR_INIT_VM + '\n' + "Or, try to reduce the Java heap size for the Javadoc goal using " + "-Dminmemory=<size> and -Dmaxmemory=<size>." + '\n' + '\n' + "Command line was: " + cmdLine + '\n' + '\n' + "Refer to the generated Javadoc files in '" + javadocOutputDirectory + "' dir.\n");
            }
            if (StringUtils.isNotEmpty(output)) {
                getLog().info(output);
            }
            StringBuilder msg = new StringBuilder("\nExit code: ");
            msg.append(exitCode);
            if (StringUtils.isNotEmpty(err.getOutput())) {
                msg.append(" - ").append(err.getOutput());
            }
            msg.append('\n');
            msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
            msg.append("Refer to the generated Javadoc files in '").append(javadocOutputDirectory).append("' dir.\n");
            throw new MavenReportException(msg.toString());
        }
        if (StringUtils.isNotEmpty(output)) {
            getLog().info(output);
        }
    } catch (CommandLineException e) {
        throw new MavenReportException("Unable to execute javadoc command: " + e.getMessage(), e);
    }
    if (StringUtils.isNotEmpty(err.getOutput()) && getLog().isWarnEnabled()) {
        getLog().warn("Javadoc Warnings");
        StringTokenizer token = new StringTokenizer(err.getOutput(), "\n");
        while (token.hasMoreTokens()) {
            String current = token.nextToken().trim();
            getLog().warn(current);
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 53 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.

the class CvsCommandUtils method isCvsNT.

public static boolean isCvsNT() throws ScmException {
    Commandline cl = new Commandline();
    cl.setExecutable("cvs");
    cl.createArg().setValue("-v");
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    try {
        CommandLineUtils.executeCommandLine(cl, stdout, stderr);
    } catch (CommandLineException e) {
        throw new ScmException("Error while executing command.", e);
    }
    return stdout.getOutput().indexOf("CVSNT") >= 0;
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 54 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.

the class TfsBlameCommand method executeBlameCommand.

public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename) throws ScmException {
    Commandline cl = createCommandLine(workingDirectory.getBasedir(), filename);
    TfsBlameConsumer consumer = new TfsBlameConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new BlameScmResult(cl.toString(), "The tfs command failed.", stderr.getOutput(), false);
    }
    return new BlameScmResult(cl.toString(), consumer.getLines());
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 55 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.

the class CvsExeAddCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected AddScmResult executeCvsCommand(Commandline cl, List<ScmFile> addedFiles) throws ScmException {
    CommandLineUtils.StringStreamConsumer consumer = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    // TODO: actually it may have partially succeeded - should we cvs update the files and parse "A " responses?
    if (exitCode != 0) {
        return new AddScmResult(cl.toString(), "The cvs command failed.", stderr.getOutput(), false);
    }
    return new AddScmResult(cl.toString(), addedFiles);
}
Also used : ScmException(org.apache.maven.scm.ScmException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Aggregations

CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)94 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)76 Commandline (org.codehaus.plexus.util.cli.Commandline)67 ScmException (org.apache.maven.scm.ScmException)56 IOException (java.io.IOException)20 SvnCommandLineUtils (org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils)18 File (java.io.File)14 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)13 BufferedReader (java.io.BufferedReader)6 BlameScmResult (org.apache.maven.scm.command.blame.BlameScmResult)6 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)6 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)6 InputStreamReader (java.io.InputStreamReader)5 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)5 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)5 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)5 StreamConsumer (org.codehaus.plexus.util.cli.StreamConsumer)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 StringTokenizer (java.util.StringTokenizer)4 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)4