Search in sources :

Example 1 with PerforceCheckOutCommand

use of org.apache.maven.scm.provider.perforce.command.checkout.PerforceCheckOutCommand 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)

Example 2 with PerforceCheckOutCommand

use of org.apache.maven.scm.provider.perforce.command.checkout.PerforceCheckOutCommand in project maven-scm by apache.

the class PerforceScmProvider method checkout.

protected CheckOutScmResult checkout(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params) throws ScmException {
    PerforceCheckOutCommand command = new PerforceCheckOutCommand();
    command.setLogger(getLogger());
    return (CheckOutScmResult) command.execute(repository, fileSet, params);
}
Also used : CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) PerforceCheckOutCommand(org.apache.maven.scm.provider.perforce.command.checkout.PerforceCheckOutCommand)

Aggregations

CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)2 PerforceCheckOutCommand (org.apache.maven.scm.provider.perforce.command.checkout.PerforceCheckOutCommand)2 CommandParameters (org.apache.maven.scm.CommandParameters)1 UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)1 UpdateScmResultWithRevision (org.apache.maven.scm.command.update.UpdateScmResultWithRevision)1 PerforceScmProviderRepository (org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository)1 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)1 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)1 Commandline (org.codehaus.plexus.util.cli.Commandline)1