Search in sources :

Example 1 with BazaarDiffConsumer

use of org.apache.maven.scm.provider.bazaar.command.diff.BazaarDiffConsumer 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)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 ChangeSet (org.apache.maven.scm.ChangeSet)1 ScmException (org.apache.maven.scm.ScmException)1 ScmFile (org.apache.maven.scm.ScmFile)1 ScmResult (org.apache.maven.scm.ScmResult)1 UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)1 UpdateScmResultWithRevision (org.apache.maven.scm.command.update.UpdateScmResultWithRevision)1 BazaarConsumer (org.apache.maven.scm.provider.bazaar.command.BazaarConsumer)1 BazaarDiffConsumer (org.apache.maven.scm.provider.bazaar.command.diff.BazaarDiffConsumer)1