use of org.apache.maven.scm.ChangeSet 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);
}
use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class HgChangeLogConsumer method doConsume.
/**
* {@inheritDoc}
*/
public void doConsume(ScmFileStatus status, String line) {
String tmpLine;
// new changeset
if (line.startsWith(REVNO_TAG)) {
// Init a new changeset
currentChange = new ChangeSet();
currentChange.setFiles(new ArrayList<ChangeFile>(0));
logEntries.add(currentChange);
// parse revision
tmpLine = line.substring(REVNO_TAG.length()).trim();
currentRevision = tmpLine.substring(tmpLine.indexOf(':') + 1);
currentChange.setRevision(currentRevision);
} else if (line.startsWith(BRANCH_TAG)) {
tmpLine = line.substring(BRANCH_TAG.length()).trim();
currentBranch = tmpLine;
} else if (line.startsWith(AUTHOR_TAG)) {
tmpLine = line.substring(AUTHOR_TAG.length()).trim();
currentChange.setAuthor(tmpLine);
} else if (line.startsWith(TIME_STAMP_TOKEN)) {
tmpLine = line.substring(TIME_STAMP_TOKEN.length()).trim();
Date date = parseDate(tmpLine, userDatePattern, TIME_PATTERN, Locale.ENGLISH);
currentChange.setDate(date);
} else if (line.startsWith(TAG_TAG)) {
tmpLine = line.substring(TAG_TAG.length()).trim();
currentTag = tmpLine;
} else if (line.startsWith(FILES_TOKEN)) {
tmpLine = line.substring(FILES_TOKEN.length()).trim();
String[] files = tmpLine.split(" ");
for (int i = 0; i < files.length; i++) {
String file = files[i];
ChangeFile changeFile = new ChangeFile(file, currentRevision);
currentChange.addFile(changeFile);
}
} else if (line.startsWith(MESSAGE_TOKEN)) {
currentChange.setComment("");
} else {
StringBuilder comment = new StringBuilder(currentChange.getComment());
comment.append(line);
comment.append('\n');
currentChange.setComment(comment.toString());
}
}
use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class CvsChangeLogConsumer method getModifications.
public List<ChangeSet> getModifications() {
Collections.sort(entries, new Comparator<ChangeSet>() {
public int compare(ChangeSet set1, ChangeSet set2) {
return set1.getDate().compareTo(set2.getDate());
}
});
List<ChangeSet> fixedModifications = new ArrayList<ChangeSet>();
ChangeSet currentEntry = null;
for (Iterator<ChangeSet> entryIterator = entries.iterator(); entryIterator.hasNext(); ) {
ChangeSet entry = (ChangeSet) entryIterator.next();
if (currentEntry == null) {
currentEntry = entry;
} else if (areEqual(currentEntry, entry)) {
currentEntry.addFile((ChangeFile) entry.getFiles().get(0));
} else {
fixedModifications.add(currentEntry);
currentEntry = entry;
}
}
if (currentEntry != null) {
fixedModifications.add(currentEntry);
}
return fixedModifications;
}
use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class ChangeLogMojo method execute.
/**
* {@inheritDoc}
*/
public void execute() throws MojoExecutionException {
super.execute();
SimpleDateFormat localFormat = new SimpleDateFormat(userDateFormat);
try {
ScmRepository repository = getScmRepository();
ScmProvider provider = getScmManager().getProviderByRepository(repository);
ScmVersion startRev = getScmVersion(StringUtils.isEmpty(startScmVersionType) ? "revision" : startScmVersionType, startScmVersion);
ScmVersion endRev = getScmVersion(StringUtils.isEmpty(endScmVersionType) ? "revision" : endScmVersionType, endScmVersion);
ChangeLogScmResult result;
if (startRev != null || endRev != null) {
result = provider.changeLog(repository, getFileSet(), startRev, endRev, dateFormat);
} else {
result = provider.changeLog(repository, getFileSet(), this.parseDate(localFormat, this.startDate), this.parseDate(localFormat, this.endDate), 0, (ScmBranch) getScmVersion(scmVersionType, scmVersion), dateFormat);
}
checkResult(result);
ChangeLogSet changeLogSet = result.getChangeLog();
for (ChangeSet changeSet : changeLogSet.getChangeSets()) {
getLog().info(changeSet.toString());
}
} catch (IOException e) {
throw new MojoExecutionException("Cannot run changelog command : ", e);
} catch (ScmException e) {
throw new MojoExecutionException("Cannot run changelog command : ", e);
}
}
use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class AccuRevScmProvider method update.
@Override
protected UpdateScmResult update(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
AccuRevScmProviderRepository accurevRepo = (AccuRevScmProviderRepository) repository;
AccuRevUpdateCommand command = new AccuRevUpdateCommand(getLogger());
UpdateScmResult result = command.update(repository, fileSet, parameters);
if (result.isSuccess() && parameters.getBoolean(CommandParameter.RUN_CHANGELOG_WITH_UPDATE)) {
AccuRevUpdateScmResult accuRevResult = (AccuRevUpdateScmResult) result;
ScmRevision fromRevision = new ScmRevision(accuRevResult.getFromRevision());
ScmRevision toRevision = new ScmRevision(accuRevResult.getToRevision());
parameters.setScmVersion(CommandParameter.START_SCM_VERSION, fromRevision);
parameters.setScmVersion(CommandParameter.END_SCM_VERSION, toRevision);
AccuRevVersion startVersion = accurevRepo.getAccuRevVersion(fromRevision);
AccuRevVersion endVersion = accurevRepo.getAccuRevVersion(toRevision);
if (startVersion.getBasisStream().equals(endVersion.getBasisStream())) {
ChangeLogScmResult changeLogResult = changelog(repository, fileSet, parameters);
if (changeLogResult.isSuccess()) {
result.setChanges(changeLogResult.getChangeLog().getChangeSets());
} else {
getLogger().warn("Changelog from " + fromRevision + " to " + toRevision + " failed");
}
} else {
String comment = "Cross stream update result from " + startVersion + " to " + endVersion;
String author = "";
List<ScmFile> files = result.getUpdatedFiles();
List<ChangeFile> changeFiles = new ArrayList<ChangeFile>(files.size());
for (ScmFile scmFile : files) {
changeFiles.add(new ChangeFile(scmFile.getPath()));
}
ChangeSet dummyChangeSet = new ChangeSet(new Date(), comment, author, changeFiles);
// different streams invalidates the change log, insert a dummy change instead.
List<ChangeSet> changeSets = Collections.singletonList(dummyChangeSet);
result.setChanges(changeSets);
}
}
return result;
}
Aggregations