Search in sources :

Example 36 with CommandLineException

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

the class IntegrityBlameCommand method doShellConnect.

/**
 * Execute 'si connect' command in current shell.
 *
 * @param iRepo            the Integrity repository instance.
 * @param workingDirectory the SCM working directory.
 * @throws ScmException if connect command failed.
 */
private void doShellConnect(IntegrityScmProviderRepository iRepo, ScmFileSet workingDirectory) throws ScmException {
    Commandline shell = new Commandline();
    shell.setWorkingDirectory(workingDirectory.getBasedir());
    shell.setExecutable("si");
    shell.createArg().setValue("connect");
    shell.createArg().setValue("--hostname=" + iRepo.getHost());
    shell.createArg().setValue("--port=" + iRepo.getPort());
    shell.createArg().setValue("--user=" + iRepo.getUser());
    shell.createArg().setValue("--batch");
    shell.createArg().setValue("--password=" + iRepo.getPassword());
    CommandLineUtils.StringStreamConsumer shellConsumer = new CommandLineUtils.StringStreamConsumer();
    try {
        getLogger().debug("Executing: " + CommandLineUtils.toString(shell.getCommandline()));
        int exitCode = CommandLineUtils.executeCommandLine(shell, shellConsumer, shellConsumer);
        if (exitCode != 0) {
            throw new ScmException("Can't login to integrity. Message : " + shellConsumer.toString());
        }
    } catch (CommandLineException cle) {
        getLogger().error("Command Line Connect Exception: " + cle.getMessage());
        throw new ScmException("Can't login to integrity. Message : " + cle.getMessage());
    }
}
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 37 with CommandLineException

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

the class IntegrityBlameCommand method doShellAnnotate.

/**
 * Execute 'si annotate' command in current shell and process output as {@link BlameScmResult} instance.
 *
 * @param iRepo            the Integrity repository instance.
 * @param workingDirectory the SCM working directory.
 * @param filename         the file name.
 * @return the {@link BlameScmResult} instance.
 */
private BlameScmResult doShellAnnotate(IntegrityScmProviderRepository iRepo, ScmFileSet workingDirectory, String filename) {
    BlameScmResult result;
    Commandline shell = new Commandline();
    shell.setWorkingDirectory(workingDirectory.getBasedir());
    shell.setExecutable("si");
    shell.createArg().setValue("annotate");
    shell.createArg().setValue("--hostname=" + iRepo.getHost());
    shell.createArg().setValue("--port=" + iRepo.getPort());
    shell.createArg().setValue("--user=" + iRepo.getUser());
    shell.createArg().setValue("--fields=date,revision,author");
    shell.createArg().setValue('"' + filename + '"');
    IntegrityBlameConsumer shellConsumer = new IntegrityBlameConsumer(getLogger());
    try {
        getLogger().debug("Executing: " + CommandLineUtils.toString(shell.getCommandline()));
        int exitCode = CommandLineUtils.executeCommandLine(shell, shellConsumer, new CommandLineUtils.StringStreamConsumer());
        boolean success = (exitCode == 0 ? true : false);
        ScmResult scmResult = new ScmResult(shell.getCommandline().toString(), "", "Exit Code: " + exitCode, success);
        return new BlameScmResult(shellConsumer.getBlameList(), scmResult);
    } catch (CommandLineException cle) {
        getLogger().error("Command Line Exception: " + cle.getMessage());
        result = new BlameScmResult(shell.getCommandline().toString(), cle.getMessage(), "", false);
    }
    return result;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) ScmResult(org.apache.maven.scm.ScmResult) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 38 with CommandLineException

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

the class JazzScmCommand method execute.

public int execute(StreamConsumer out, ErrorConsumer err) throws ScmException {
    logInfoMessage("Executing: " + cryptPassword(fCommand));
    if (fCommand.getWorkingDirectory() != null) {
        logInfoMessage("Working directory: " + fCommand.getWorkingDirectory().getAbsolutePath());
    }
    int status = 0;
    try {
        status = CommandLineUtils.executeCommandLine(fCommand, out, err);
    } catch (CommandLineException e) {
        String errorOutput = err.getOutput();
        if (errorOutput.length() > 0) {
            logErrorMessage("Error: " + err.getOutput());
        }
        throw new ScmException("Error while executing Jazz SCM command line - " + getCommandString(), e);
    }
    String errorOutput = err.getOutput();
    if (errorOutput.length() > 0) {
        logErrorMessage("Error: " + err.getOutput());
    }
    return status;
}
Also used : ScmException(org.apache.maven.scm.ScmException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 39 with CommandLineException

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

the class GitCommandLineUtils method execute.

public static int execute(Commandline cl, StreamConsumer consumer, CommandLineUtils.StringStreamConsumer stderr, ScmLogger logger) throws ScmException {
    if (logger.isInfoEnabled()) {
        logger.info("Executing: " + cl);
        logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
    }
    int exitCode;
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    return exitCode;
}
Also used : ScmException(org.apache.maven.scm.ScmException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 40 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project unleash-maven-plugin by shillner.

the class BuildProject method execute.

@Override
public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException {
    this.log.info("Starting release build.");
    try {
        InvocationRequest request = setupInvocationRequest();
        Invoker invoker = setupInvoker();
        InvocationResult result = invoker.execute(request);
        if (result.getExitCode() != 0) {
            CommandLineException executionException = result.getExecutionException();
            if (executionException != null) {
                throw new MojoFailureException("Error during project build: " + executionException.getMessage(), executionException);
            } else {
                throw new MojoFailureException("Error during project build: " + result.getExitCode());
            }
        }
    } catch (MavenInvocationException e) {
        throw new MojoFailureException(e.getMessage(), 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) MojoFailureException(org.apache.maven.plugin.MojoFailureException) InvocationResult(org.apache.maven.shared.invoker.InvocationResult) 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