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);
}
Aggregations