use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class HgChangeLogCommand method executeChangeLogCommand.
private ChangeLogScmResult executeChangeLogCommand(ScmFileSet fileSet, Date startDate, Date endDate, String datePattern, Integer limit) throws ScmException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
StringBuilder dateInterval = new StringBuilder();
// TRICK: Mercurial 1.9.3 don't accept 1970-01-01
dateInterval.append(// From 2. Jan 1970
dateFormat.format(startDate == null ? new Date(1000L * 60 * 60 * 24) : startDate));
dateInterval.append(" to ");
// Upto now
dateInterval.append(dateFormat.format(endDate == null ? new Date() : endDate));
List<String> cmd = new ArrayList<String>();
cmd.addAll(Arrays.asList(HgCommandConstants.LOG_CMD, HgCommandConstants.TEMPLATE_OPTION, HgCommandConstants.TEMPLATE_FORMAT, HgCommandConstants.NO_MERGES_OPTION, HgCommandConstants.DATE_OPTION, dateInterval.toString()));
if (limit != null && limit > 0) {
cmd.add(HgCommandConstants.LIMIT_OPTION);
cmd.add(Integer.toString(limit));
}
HgChangeLogConsumer consumer = new HgChangeLogConsumer(getLogger(), datePattern);
ScmResult result = HgUtils.execute(consumer, getLogger(), fileSet.getBasedir(), cmd.toArray(new String[cmd.size()]));
List<ChangeSet> logEntries = consumer.getModifications();
ChangeLogSet changeLogSet = new ChangeLogSet(logEntries, startDate, endDate);
return new ChangeLogScmResult(changeLogSet, result);
}
use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class HgChangeLogCommand method executeChangeLogCommand.
@Override
protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion startVersion, ScmVersion endVersion, String datePattern) throws ScmException {
StringBuilder revisionInterval = new StringBuilder();
if (startVersion != null) {
revisionInterval.append(startVersion.getName());
}
revisionInterval.append(":");
if (endVersion != null) {
revisionInterval.append(endVersion.getName());
}
String[] cmd = new String[] { HgCommandConstants.LOG_CMD, HgCommandConstants.TEMPLATE_OPTION, HgCommandConstants.TEMPLATE_FORMAT, HgCommandConstants.NO_MERGES_OPTION, HgCommandConstants.REVISION_OPTION, revisionInterval.toString() };
HgChangeLogConsumer consumer = new HgChangeLogConsumer(getLogger(), datePattern);
ScmResult result = HgUtils.execute(consumer, getLogger(), fileSet.getBasedir(), cmd);
List<ChangeSet> logEntries = consumer.getModifications();
Date startDate = null;
Date endDate = null;
if (!logEntries.isEmpty()) {
startDate = logEntries.get(0).getDate();
endDate = logEntries.get(logEntries.size() - 1).getDate();
}
ChangeLogSet changeLogSet = new ChangeLogSet(logEntries, startDate, endDate);
changeLogSet.setStartVersion(startVersion);
changeLogSet.setEndVersion(endVersion);
return new ChangeLogScmResult(changeLogSet, result);
}
use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class CvsChangeLogConsumer method processGetFile.
/**
* Process the current input line in the Get File state.
*
* @param line a line of text from the cvs log output
*/
private void processGetFile(String line) {
if (line.startsWith(START_FILE)) {
setCurrentChange(new ChangeSet());
setCurrentFile(new ChangeFile(line.substring(START_FILE.length(), line.length())));
setStatus(GET_REVISION);
}
}
use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class CvsChangeLogConsumer method processGetComment.
/**
* Process the current input line in the Get Comment state.
*
* @param line a line of text from the cvs log output
*/
private void processGetComment(String line) {
if (line.startsWith(START_REVISION)) {
// add entry, and set state to get revision
addEntry(getCurrentChange(), getCurrentFile());
// new change log entry
setCurrentChange(new ChangeSet());
// same file name, but different rev
setCurrentFile(new ChangeFile(getCurrentFile().getName()));
setStatus(GET_REVISION);
} else if (line.startsWith(END_FILE)) {
addEntry(getCurrentChange(), getCurrentFile());
setStatus(GET_FILE);
} else {
// keep gathering comments
getCurrentChange().setComment(getCurrentChange().getComment() + line + "\n");
}
}
use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class Sandbox method getChangeLog.
/**
* Executes the 'si rlog' command to generate a list of changed revision found between startDate and endDate
*
* @param startDate The date range for the beginning of the operation
* @param endDate The date range for the end of the operation
* @return ChangeLogSet containing a list of changes grouped by Change Pacakge ID
* @throws APIException
*/
public ChangeLogSet getChangeLog(Date startDate, Date endDate) throws APIException {
// Initialize our return object
ChangeLogSet changeLog = new ChangeLogSet(startDate, endDate);
// By default we're going to group-by change package
// Non change package changes will be lumped into one big Change Set
Hashtable<String, ChangeSet> changeSetHash = new Hashtable<String, ChangeSet>();
// Lets prepare our si rlog command for execution
Command siRlog = new Command(Command.SI, "rlog");
siRlog.addOption(new Option("recurse"));
MultiValue rFilter = new MultiValue(":");
rFilter.add("daterange");
rFilter.add("'" + RLOG_DATEFORMAT.format(startDate) + "'-'" + RLOG_DATEFORMAT.format(endDate) + "'");
siRlog.addOption(new Option("rfilter", rFilter));
siRlog.addOption(new Option("cwd", sandboxDir));
// Execute the si rlog command
Response response = api.runCommand(siRlog);
for (WorkItemIterator wit = response.getWorkItems(); wit.hasNext(); ) {
WorkItem wi = wit.next();
String memberName = wi.getContext();
// We're going to have to do a little dance to get the correct server file name
memberName = memberName.substring(0, memberName.lastIndexOf('/'));
memberName = memberName + '/' + wi.getId();
memberName = memberName.replace('\\', '/');
// Now lets get the revisions for this file
Field revisionsFld = wi.getField("revisions");
if (null != revisionsFld && revisionsFld.getDataType().equals(Field.ITEM_LIST_TYPE) && null != revisionsFld.getList()) {
@SuppressWarnings("unchecked") List<Item> revList = revisionsFld.getList();
for (Iterator<Item> lit = revList.iterator(); lit.hasNext(); ) {
Item revisionItem = lit.next();
String revision = revisionItem.getId();
String author = revisionItem.getField("author").getItem().getId();
// Attempt to get the full name, if available
try {
author = revisionItem.getField("author").getItem().getField("fullname").getValueAsString();
} catch (NullPointerException npe) {
/* ignore */
}
String cpid = ":none";
// Attempt to get the cpid for this revision
try {
cpid = revisionItem.getField("cpid").getItem().getId();
} catch (NullPointerException npe) {
/* ignore */
}
// Get the Change Package summary for this revision
String comment = cpid + ": " + revisionItem.getField("cpsummary").getValueAsString();
// Get the date associated with this revision
Date date = revisionItem.getField("date").getDateTime();
// Lets create our ChangeFile based on the information we've gathered so far
ChangeFile changeFile = new ChangeFile(memberName, revision);
// Check to see if we already have a ChangeSet grouping for this revision
ChangeSet changeSet = changeSetHash.get(cpid);
if (null != changeSet) {
// Set the date of the ChangeSet to the oldest entry
if (changeSet.getDate().after(date)) {
changeSet.setDate(date);
}
// Add the new ChangeFile
changeSet.addFile(changeFile);
// Update the changeSetHash
changeSetHash.put(cpid, changeSet);
} else // Create a new ChangeSet grouping and add the ChangeFile
{
List<ChangeFile> changeFileList = new ArrayList<ChangeFile>();
changeFileList.add(changeFile);
changeSet = new ChangeSet(date, comment, author, changeFileList);
// Update the changeSetHash with an initial entry for the cpid
changeSetHash.put(cpid, changeSet);
}
}
}
}
// Update the Change Log with the Change Sets
List<ChangeSet> changeSetList = new ArrayList<ChangeSet>();
changeSetList.addAll(changeSetHash.values());
changeLog.setChangeSets(changeSetList);
return changeLog;
}
Aggregations