Search in sources :

Example 16 with CommandLineException

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

the class PerforceUnEditCommand method executeUnEditCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeUnEditCommand(ScmProviderRepository repo, ScmFileSet files) throws ScmException {
    Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), files);
    PerforceUnEditConsumer consumer = new PerforceUnEditConsumer();
    try {
        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
        int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
        if (exitCode != 0) {
            String cmdLine = CommandLineUtils.toString(cl.getCommandline());
            StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
            msg.append('\n');
            msg.append("Command line was:" + cmdLine);
            throw new CommandLineException(msg.toString());
        }
    } catch (CommandLineException e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("CommandLineException " + e.getMessage(), e);
        }
    }
    if (consumer.isSuccess()) {
        return new UnEditScmResult(cl.toString(), consumer.getEdits());
    }
    return new UnEditScmResult(cl.toString(), "Unable to revert", consumer.getOutput(), consumer.isSuccess());
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) UnEditScmResult(org.apache.maven.scm.command.unedit.UnEditScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 17 with CommandLineException

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

the class PerforceAddCommand method executeAddCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet files, String message, boolean binary) throws ScmException {
    Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), files);
    PerforceAddConsumer consumer = new PerforceAddConsumer();
    try {
        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
        int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
        if (exitCode != 0) {
            String cmdLine = CommandLineUtils.toString(cl.getCommandline());
            StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
            msg.append('\n');
            msg.append("Command line was:" + cmdLine);
            throw new CommandLineException(msg.toString());
        }
    } catch (CommandLineException e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("CommandLineException " + e.getMessage(), e);
        }
    }
    return new AddScmResult(cl.toString(), consumer.getAdditions());
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 18 with CommandLineException

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

the class PerforceBlameCommand method executeBlameCommand.

public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename) throws ScmException {
    // Call annotate command
    PerforceScmProviderRepository p4repo = (PerforceScmProviderRepository) repo;
    String clientspec = PerforceScmProvider.getClientspecName(getLogger(), p4repo, workingDirectory.getBasedir());
    Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, workingDirectory.getBasedir(), filename, clientspec);
    PerforceBlameConsumer blameConsumer = new PerforceBlameConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, blameConsumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new BlameScmResult(cl.toString(), "The perforce command failed.", stderr.getOutput(), false);
    }
    // Call filelog command
    cl = createFilelogCommandLine((PerforceScmProviderRepository) repo, workingDirectory.getBasedir(), filename, clientspec);
    PerforceFilelogConsumer filelogConsumer = new PerforceFilelogConsumer(getLogger());
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, filelogConsumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new BlameScmResult(cl.toString(), "The perforce command failed.", stderr.getOutput(), false);
    }
    // Combine results
    List<BlameLine> lines = blameConsumer.getLines();
    for (int i = 0; i < lines.size(); i++) {
        BlameLine line = lines.get(i);
        String revision = line.getRevision();
        line.setAuthor(filelogConsumer.getAuthor(revision));
        line.setDate(filelogConsumer.getDate(revision));
    }
    return new BlameScmResult(cl.toString(), lines);
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) BlameLine(org.apache.maven.scm.command.blame.BlameLine) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) PerforceScmProviderRepository(org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository)

Example 19 with CommandLineException

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

the class PerforceChangeLogCommand method executeChangeLogCommand.

protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern, ScmVersion startVersion, ScmVersion endVersion) throws ScmException {
    PerforceScmProviderRepository p4repo = (PerforceScmProviderRepository) repo;
    String clientspec = PerforceScmProvider.getClientspecName(getLogger(), p4repo, fileSet.getBasedir());
    Commandline cl = createCommandLine(p4repo, fileSet.getBasedir(), clientspec, null, startDate, endDate, startVersion, endVersion);
    String location = PerforceScmProvider.getRepoPath(getLogger(), p4repo, fileSet.getBasedir());
    PerforceChangesConsumer consumer = new PerforceChangesConsumer(getLogger());
    try {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
        }
        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
        int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
        if (exitCode != 0) {
            String cmdLine = CommandLineUtils.toString(cl.getCommandline());
            StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
            msg.append('\n');
            msg.append("Command line was:" + cmdLine);
            throw new CommandLineException(msg.toString());
        }
    } catch (CommandLineException e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("CommandLineException " + e.getMessage(), e);
        }
    }
    List<String> changes = consumer.getChanges();
    cl = PerforceScmProvider.createP4Command(p4repo, fileSet.getBasedir());
    cl.createArg().setValue("describe");
    cl.createArg().setValue("-s");
    for (String change : changes) {
        cl.createArg().setValue(change);
    }
    PerforceDescribeConsumer describeConsumer = new PerforceDescribeConsumer(location, datePattern, getLogger());
    try {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
        }
        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
        int exitCode = CommandLineUtils.executeCommandLine(cl, describeConsumer, err);
        if (exitCode != 0) {
            String cmdLine = CommandLineUtils.toString(cl.getCommandline());
            StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
            msg.append('\n');
            msg.append("Command line was:" + cmdLine);
            throw new CommandLineException(msg.toString());
        }
    } catch (CommandLineException e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("CommandLineException " + e.getMessage(), e);
        }
    }
    ChangeLogSet cls = new ChangeLogSet(describeConsumer.getModifications(), null, null);
    cls.setStartVersion(startVersion);
    cls.setEndVersion(endVersion);
    return new ChangeLogScmResult(cl.toString(), cls);
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) PerforceScmProviderRepository(org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository)

Example 20 with CommandLineException

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

the class PerforceUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet files, ScmVersion scmVersion) throws ScmException {
    // In Perforce, there is no difference between update and checkout.
    // Here we just run the checkout command and map the result onto an
    // UpdateScmResult.
    PerforceCheckOutCommand command = new PerforceCheckOutCommand();
    command.setLogger(getLogger());
    CommandParameters params = new CommandParameters();
    params.setScmVersion(CommandParameter.SCM_VERSION, scmVersion);
    CheckOutScmResult cosr = (CheckOutScmResult) command.execute(repo, files, params);
    if (!cosr.isSuccess()) {
        return new UpdateScmResult(cosr.getCommandLine(), cosr.getProviderMessage(), cosr.getCommandOutput(), false);
    }
    PerforceScmProviderRepository p4repo = (PerforceScmProviderRepository) repo;
    String clientspec = PerforceScmProvider.getClientspecName(getLogger(), p4repo, files.getBasedir());
    Commandline cl = createCommandLine(p4repo, files.getBasedir(), clientspec);
    @SuppressWarnings("unused") String location = PerforceScmProvider.getRepoPath(getLogger(), p4repo, files.getBasedir());
    PerforceHaveConsumer consumer = new PerforceHaveConsumer(getLogger());
    try {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
        }
        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
        int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
        if (exitCode != 0) {
            String cmdLine = CommandLineUtils.toString(cl.getCommandline());
            StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
            msg.append('\n');
            msg.append("Command line was:" + cmdLine);
            throw new CommandLineException(msg.toString());
        }
    } catch (CommandLineException e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("CommandLineException " + e.getMessage(), e);
        }
    }
    return new UpdateScmResultWithRevision(cosr.getCommandLine(), cosr.getCheckedOutFiles(), String.valueOf(consumer.getHave()));
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) CommandParameters(org.apache.maven.scm.CommandParameters) PerforceScmProviderRepository(org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository) PerforceCheckOutCommand(org.apache.maven.scm.provider.perforce.command.checkout.PerforceCheckOutCommand)

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