Search in sources :

Example 1 with HgDiffConsumer

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

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 ChangeSet (org.apache.maven.scm.ChangeSet)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 HgConsumer (org.apache.maven.scm.provider.hg.command.HgConsumer)1 HgDiffConsumer (org.apache.maven.scm.provider.hg.command.diff.HgDiffConsumer)1