Search in sources :

Example 1 with UpdateScmResultWithRevision

use of org.apache.maven.scm.command.update.UpdateScmResultWithRevision 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 UpdateScmResultWithRevision

use of org.apache.maven.scm.command.update.UpdateScmResultWithRevision in project maven-scm by apache.

the class HgUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion tag) throws ScmException {
    File workingDir = fileSet.getBasedir();
    String[] updateCmd;
    // Update branch
    if (repo.isPushChanges()) {
        updateCmd = new String[] { HgCommandConstants.PULL_CMD, HgCommandConstants.REVISION_OPTION, tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip" };
    } else {
        updateCmd = new String[] { HgCommandConstants.UPDATE_CMD, tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip", HgCommandConstants.CLEAN_OPTION };
    }
    ScmResult updateResult = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, updateCmd);
    if (!updateResult.isSuccess()) {
        return new UpdateScmResult(null, null, updateResult);
    }
    // Find changes from last revision
    int currentRevision = HgUtils.getCurrentRevisionNumber(getLogger(), workingDir);
    int previousRevision = currentRevision - 1;
    String[] diffCmd = new String[] { HgCommandConstants.DIFF_CMD, HgCommandConstants.REVISION_OPTION, "" + previousRevision };
    HgDiffConsumer diffConsumer = new HgDiffConsumer(getLogger(), workingDir);
    ScmResult diffResult = HgUtils.execute(diffConsumer, getLogger(), workingDir, diffCmd);
    // Now translate between diff and update file status
    List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
    List<CharSequence> changes = new ArrayList<CharSequence>();
    List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
    Map<String, CharSequence> diffChanges = diffConsumer.getDifferences();
    for (ScmFile file : diffFiles) {
        changes.add(diffChanges.get(file.getPath()));
        if (file.getStatus() == ScmFileStatus.MODIFIED) {
            updatedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.PATCHED));
        } else {
            updatedFiles.add(file);
        }
    }
    if (repo.isPushChanges()) {
        String[] hgUpdateCmd = new String[] { HgCommandConstants.UPDATE_CMD };
        HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, hgUpdateCmd);
    }
    return new UpdateScmResultWithRevision(updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf(currentRevision), diffResult);
}
Also used : UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ScmResult(org.apache.maven.scm.ScmResult) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) HgDiffConsumer(org.apache.maven.scm.provider.hg.command.diff.HgDiffConsumer) HgConsumer(org.apache.maven.scm.provider.hg.command.HgConsumer) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 3 with UpdateScmResultWithRevision

use of org.apache.maven.scm.command.update.UpdateScmResultWithRevision in project maven-scm by apache.

the class UpdateSubprojectsMojo method execute.

/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException {
    super.execute();
    try {
        ScmRepository repository = getScmRepository();
        UpdateScmResult result = getScmManager().update(repository, getFileSet(), getScmVersion(scmVersionType, scmVersion));
        checkResult(result);
        if (result instanceof UpdateScmResultWithRevision) {
            getLog().info("Storing revision in '" + revisionKey + "' project property.");
            if (// Remove the test when we'll use plugin-test-harness 1.0-alpha-2
            project.getProperties() != null) {
                project.getProperties().put(revisionKey, ((UpdateScmResultWithRevision) result).getRevision());
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot run update command : ", e);
    } catch (ScmException e) {
        throw new MojoExecutionException("Cannot run update command : ", e);
    }
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmException(org.apache.maven.scm.ScmException) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) IOException(java.io.IOException)

Example 4 with UpdateScmResultWithRevision

use of org.apache.maven.scm.command.update.UpdateScmResultWithRevision in project maven-scm by apache.

the class BazaarUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    if (version != null && StringUtils.isNotEmpty(version.getName())) {
        throw new ScmException("This provider can't handle tags.");
    }
    File workingDir = fileSet.getBasedir();
    // Update branch
    String[] updateCmd = new String[] { BazaarConstants.PULL_CMD };
    ScmResult updateResult = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), workingDir, updateCmd);
    if (!updateResult.isSuccess()) {
        return new UpdateScmResult(null, null, updateResult);
    }
    // Find changes from last revision
    int currentRevision = BazaarUtils.getCurrentRevisionNumber(getLogger(), workingDir);
    int previousRevision = currentRevision - 1;
    String[] diffCmd = new String[] { BazaarConstants.DIFF_CMD, BazaarConstants.REVISION_OPTION, "" + previousRevision };
    BazaarDiffConsumer diffConsumer = new BazaarDiffConsumer(getLogger(), workingDir);
    ScmResult diffResult = BazaarUtils.execute(diffConsumer, getLogger(), workingDir, diffCmd);
    // Now translate between diff and update file status
    List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
    List<CharSequence> changes = new ArrayList<CharSequence>();
    List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
    Map<String, CharSequence> diffChanges = diffConsumer.getDifferences();
    for (Iterator<ScmFile> it = diffFiles.iterator(); it.hasNext(); ) {
        ScmFile file = it.next();
        changes.add(diffChanges.get(file));
        if (file.getStatus() == ScmFileStatus.MODIFIED) {
            updatedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.PATCHED));
        } else {
            updatedFiles.add(file);
        }
    }
    return new UpdateScmResultWithRevision(updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf(currentRevision), diffResult);
}
Also used : ScmException(org.apache.maven.scm.ScmException) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ScmResult(org.apache.maven.scm.ScmResult) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) BazaarDiffConsumer(org.apache.maven.scm.provider.bazaar.command.diff.BazaarDiffConsumer) BazaarConsumer(org.apache.maven.scm.provider.bazaar.command.BazaarConsumer) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 5 with UpdateScmResultWithRevision

use of org.apache.maven.scm.command.update.UpdateScmResultWithRevision in project maven-scm by apache.

the class SvnUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), version);
    SvnUpdateConsumer consumer = new SvnUpdateConsumer(getLogger(), fileSet.getBasedir());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
        }
    }
    int exitCode;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new UpdateScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    UpdateScmResultWithRevision result = new UpdateScmResultWithRevision(cl.toString(), consumer.getUpdatedFiles(), String.valueOf(consumer.getRevision()));
    result.setChanges(consumer.getChangeSets());
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("changeSets " + consumer.getChangeSets());
    }
    return result;
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Aggregations

UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)7 UpdateScmResultWithRevision (org.apache.maven.scm.command.update.UpdateScmResultWithRevision)7 ScmException (org.apache.maven.scm.ScmException)5 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)3 Commandline (org.codehaus.plexus.util.cli.Commandline)3 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ChangeSet (org.apache.maven.scm.ChangeSet)2 ScmFile (org.apache.maven.scm.ScmFile)2 ScmResult (org.apache.maven.scm.ScmResult)2 ScmRepository (org.apache.maven.scm.repository.ScmRepository)2 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)2 CommandParameters (org.apache.maven.scm.CommandParameters)1 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)1 BazaarConsumer (org.apache.maven.scm.provider.bazaar.command.BazaarConsumer)1 BazaarDiffConsumer (org.apache.maven.scm.provider.bazaar.command.diff.BazaarDiffConsumer)1 GitCommandLineUtils (org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils)1 GitDiffRawConsumer (org.apache.maven.scm.provider.git.gitexe.command.diff.GitDiffRawConsumer)1