Search in sources :

Example 31 with CommandLineException

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

the class CvsExeRemoveCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected RemoveScmResult executeCvsCommand(Commandline cl, List<ScmFile> removedFiles) 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 RemoveScmResult(cl.toString(), "The cvs command failed.", stderr.getOutput(), false);
    }
    return new RemoveScmResult(cl.toString(), removedFiles);
}
Also used : ScmException(org.apache.maven.scm.ScmException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) RemoveScmResult(org.apache.maven.scm.command.remove.RemoveScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 32 with CommandLineException

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

the class CvsExeTagCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected TagScmResult executeCvsCommand(Commandline cl) throws ScmException {
    int exitCode;
    CvsTagConsumer consumer = new CvsTagConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        // TODO: Improve this error message
        return new TagScmResult(cl.toString(), "The cvs tag command failed.", stderr.getOutput(), false);
    }
    return new TagScmResult(cl.toString(), consumer.getTaggedFiles());
}
Also used : ScmException(org.apache.maven.scm.ScmException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CvsTagConsumer(org.apache.maven.scm.provider.cvslib.command.tag.CvsTagConsumer) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 33 with CommandLineException

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

the class BootstrapMojo method runGoals.

/**
 * @param relativePathProjectDirectory the project directory's path relative to the checkout
 *                                     directory; or "" if they are the same
 * @throws MojoExecutionException if any
 */
private void runGoals(String relativePathProjectDirectory) throws MojoExecutionException {
    Commandline cl = new Commandline();
    try {
        cl.addSystemEnvironment();
    } catch (Exception e) {
        throw new MojoExecutionException("Can't add system environment variables to mvn command line.", e);
    }
    cl.addEnvironment("MAVEN_TERMINATE_CMD", "on");
    if (this.mavenHome == null) {
        // none windows only
        cl.setExecutable("mvn");
    } else {
        String mvnPath = this.mavenHome.getAbsolutePath() + "/bin/mvn";
        if (Os.isFamily("windows")) {
            String winMvnPath = mvnPath + ".cmd";
            if (!new File(winMvnPath).exists()) {
                winMvnPath = mvnPath + ".bat";
            }
            mvnPath = winMvnPath;
        }
        cl.setExecutable(mvnPath);
    }
    cl.setWorkingDirectory(determineWorkingDirectoryPath(// 
    this.getCheckoutDirectory(), relativePathProjectDirectory, goalsDirectory));
    if (this.goals != null) {
        String[] tokens = StringUtils.split(this.goals, ", ");
        for (int i = 0; i < tokens.length; ++i) {
            cl.createArg().setValue(tokens[i]);
        }
    }
    if (!StringUtils.isEmpty(this.profiles)) {
        cl.createArg().setValue("-P" + this.profiles);
    }
    StreamConsumer consumer = new DefaultConsumer();
    try {
        int result = CommandLineUtils.executeCommandLine(cl, consumer, consumer);
        if (result != 0) {
            throw new MojoExecutionException("Result of mvn execution is: \'" + result + "\'. Release failed.");
        }
    } catch (CommandLineException e) {
        throw new MojoExecutionException("Can't run goal " + goals, e);
    }
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) Commandline(org.codehaus.plexus.util.cli.Commandline) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultConsumer(org.codehaus.plexus.util.cli.DefaultConsumer) File(java.io.File) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 34 with CommandLineException

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

the class TfsCommand method execute.

public int execute(StreamConsumer out, ErrorStreamConsumer err) throws ScmException {
    info("Command line - " + getCommandString());
    int status;
    try {
        status = CommandLineUtils.executeCommandLine(command, out, err);
    } catch (CommandLineException e) {
        throw new ScmException("Error while executing TFS command line - " + getCommandString(), e);
    }
    info("err - " + err.getOutput());
    if (out instanceof StringStreamConsumer) {
        StringStreamConsumer sc = (StringStreamConsumer) out;
        debug(sc.getOutput());
    }
    if (out instanceof FileListConsumer) {
        FileListConsumer f = (FileListConsumer) out;
        for (Iterator<ScmFile> i = f.getFiles().iterator(); i.hasNext(); ) {
            ScmFile file = i.next();
            debug(file.getPath());
        }
    }
    return status;
}
Also used : FileListConsumer(org.apache.maven.scm.provider.tfs.command.consumer.FileListConsumer) ScmException(org.apache.maven.scm.ScmException) StringStreamConsumer(org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ScmFile(org.apache.maven.scm.ScmFile)

Example 35 with CommandLineException

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

the class VssCommandLineUtils method executeCommandline.

public static int executeCommandline(Commandline cl, StreamConsumer consumer, CommandLineUtils.StringStreamConsumer stderr, ScmLogger logger) throws ScmException {
    try {
        if (logger.isInfoEnabled()) {
            logger.info("Executing: " + cl);
            logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
        }
        int exitcode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
        if (logger.isDebugEnabled()) {
            logger.debug("VSS Command Exit_Code: " + exitcode);
        }
        return exitcode;
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) 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