use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class AccuRevChangeLogCommand method getChangeLog.
private ChangeLogSet getChangeLog(Stream stream, List<FileDifference> streamDifferences, List<Transaction> streamHistory, List<Transaction> workspaceHistory, Date startDate, Date endDate) {
// Collect all the "to" versions from the streamDifferences into a Map by element id
// If that version is seen in the promote/keep history then we move it from the map
// At the end we create a pseudo ChangeSet for any remaining entries in the map as
// representing "upstream changes"
Map<Long, FileDifference> differencesMap = new HashMap<Long, FileDifference>();
for (FileDifference fileDifference : streamDifferences) {
differencesMap.put(fileDifference.getElementId(), fileDifference);
}
List<Transaction> mergedHistory = new ArrayList<Transaction>(streamHistory);
// will never match a version
String streamPrefix = "/";
mergedHistory.addAll(workspaceHistory);
streamPrefix = stream.getId() + "/";
List<ChangeSet> entries = new ArrayList<ChangeSet>(streamHistory.size());
for (Transaction t : mergedHistory) {
if ((startDate != null && t.getWhen().before(startDate)) || (endDate != null && t.getWhen().after(endDate))) {
// This is possible if dates and transactions are mixed in the time spec.
continue;
}
// the history of this stream.
if ("mkstream".equals(t.getTranType())) {
continue;
}
Collection<Version> versions = t.getVersions();
List<ChangeFile> files = new ArrayList<ChangeFile>(versions.size());
for (Version v : versions) {
// Remove diff representing this promote
FileDifference difference = differencesMap.get(v.getElementId());
// TODO: how are defuncts shown in the version history?
if (difference != null) {
String newVersionSpec = difference.getNewVersionSpec();
if (newVersionSpec != null && newVersionSpec.equals(v.getRealSpec())) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Removing difference for " + v);
}
differencesMap.remove(v.getElementId());
}
}
// to its basis stream, and is therefore NOT a change
if (v.getRealSpec().startsWith(streamPrefix) && !v.getVirtualSpec().startsWith(streamPrefix)) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Skipping workspace to basis stream promote " + v);
}
} else {
ChangeFile f = new ChangeFile(v.getElementName(), v.getVirtualSpec() + " (" + v.getRealSpec() + ")");
files.add(f);
}
}
if (versions.isEmpty() || !files.isEmpty()) {
ChangeSet changeSet = new ChangeSet(t.getWhen(), t.getComment(), t.getAuthor(), files);
entries.add(changeSet);
} else {
if (getLogger().isDebugEnabled()) {
getLogger().debug("All versions removed for " + t);
}
}
}
// detect these for CI tools like Continuum
if (!differencesMap.isEmpty()) {
List<ChangeFile> upstreamFiles = new ArrayList<ChangeFile>();
for (FileDifference difference : differencesMap.values()) {
if (difference.getNewVersionSpec() != null) {
upstreamFiles.add(new ChangeFile(difference.getNewFile().getPath(), difference.getNewVersionSpec()));
} else {
// difference is a deletion
upstreamFiles.add(new ChangeFile(difference.getOldFile().getPath(), null));
}
}
entries.add(new ChangeSet(endDate, "Upstream changes", "various", upstreamFiles));
}
return new ChangeLogSet(entries, startDate, endDate);
}
use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class LocalChangeLogCommand method executeChangeLogCommand.
/**
* {@inheritDoc}
*/
protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern) throws ScmException {
LocalScmProviderRepository repo = (LocalScmProviderRepository) repository;
if (branch != null) {
throw new ScmException("The local scm doesn't support tags.");
}
File root = new File(repo.getRoot());
String module = repo.getModule();
File source = new File(root, module);
File baseDestination = fileSet.getBasedir();
if (!baseDestination.exists()) {
throw new ScmException("The working directory doesn't exist (" + baseDestination.getAbsolutePath() + ").");
}
if (!root.exists()) {
throw new ScmException("The base directory doesn't exist (" + root.getAbsolutePath() + ").");
}
if (!source.exists()) {
throw new ScmException("The module directory doesn't exist (" + source.getAbsolutePath() + ").");
}
List<ChangeSet> changeLogList = new ArrayList<ChangeSet>();
try {
File repoRoot = new File(repo.getRoot(), repo.getModule());
List<File> files = fileSet.getFileList();
if (files.isEmpty()) {
@SuppressWarnings("unchecked") List<File> fileList = FileUtils.getFiles(baseDestination, "**", null, false);
files = fileList;
}
for (File file : files) {
String path = file.getPath().replace('\\', '/');
File repoFile = new File(repoRoot, path);
file = new File(baseDestination, path);
ChangeSet changeSet = new ChangeSet();
int chop = repoRoot.getAbsolutePath().length();
String fileName = "/" + repoFile.getAbsolutePath().substring(chop + 1);
changeSet.addFile(new ChangeFile(fileName, null));
if (repoFile.exists()) {
long lastModified = repoFile.lastModified();
Date modifiedDate = new Date(lastModified);
if (startDate != null) {
if (startDate.before(modifiedDate) || startDate.equals(modifiedDate)) {
if (endDate != null) {
if (endDate.after(modifiedDate) || endDate.equals(modifiedDate)) {
// nop
} else {
continue;
}
}
} else {
continue;
}
}
changeSet.setDate(modifiedDate);
changeLogList.add(changeSet);
} else {
// This file is deleted
changeLogList.add(changeSet);
}
}
} catch (IOException ex) {
throw new ScmException("Error while getting change logs.", ex);
}
return new ChangeLogScmResult(null, new ChangeLogSet(changeLogList, startDate, endDate));
}
use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class PerforceDescribeConsumerTest method testParse.
public void testParse() throws Exception {
File testFile = getTestFile("src/test/resources/perforce/perforcedescribelog.txt");
PerforceDescribeConsumer consumer = new PerforceDescribeConsumer("//depot/test", null, new DefaultLog());
FileInputStream fis = new FileInputStream(testFile);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
String s = in.readLine();
while (s != null) {
consumer.consumeLine(s);
s = in.readLine();
}
List<ChangeSet> entries = new ArrayList<ChangeSet>(consumer.getModifications());
assertEquals("Wrong number of entries returned", 7, entries.size());
ChangeSet entry = entries.get(0);
assertEquals("mcronin", entry.getAuthor());
assertEquals("Wrong number of files returned", 3, entry.getFiles().size());
assertEquals("demo/demo.c", ((ChangeFile) entry.getFiles().get(0)).getName());
assertEquals("2003-08-07", entry.getDateFormatted());
assertEquals("17:21:57", entry.getTimeFormatted());
entry = entries.get(6);
assertEquals("jim", entry.getAuthor());
assertEquals("Wrong number of files returned", 1, entry.getFiles().size());
assertEquals("junk/linefeed.txt", ((ChangeFile) entry.getFiles().get(0)).getName());
}
use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class GitChangeLogConsumer method processGetHeader.
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
/**
* Process the current input line in the GET_HEADER state. The
* author, date, and the revision of the entry are gathered. Note,
* Git does not have per-file revisions, instead, the entire
* branch is given a single revision number, which is also used for
* the revision number of each file.
*
* @param line A line of text from the git log output
*/
private void processGetHeader(String line) {
Matcher matcher = HEADER_PATTERN.matcher(line);
if (!matcher.matches()) {
return;
}
currentRevision = matcher.group(1);
currentChange = new ChangeSet();
currentChange.setRevision(currentRevision);
status = STATUS_GET_AUTHOR;
}
use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.
the class GitChangeLogConsumerTest method testConsumer1.
public void testConsumer1() throws Exception {
// was Date: Tue Nov 27 16:16:28 2007 +0100
// iso Date: 2007-11-24 01:13:10 +0100
// new RE( "^Date:\\s*\\w-1\\w-1\\w-1\\s(.*)" );
Pattern datePattern = Pattern.compile("^Date:\\s*(.*)");
Matcher matcher = datePattern.matcher("Date: 2007-11-24 01:13:10 +0100");
assertTrue(matcher.matches());
assertEquals("2007-11-24 01:13:10 +0100", matcher.group(1));
GitChangeLogConsumer consumer = new GitChangeLogConsumer(new DefaultLog(), null);
File f = getTestFile("/src/test/resources/git/changelog/gitwhatchanged.gitlog");
BufferedReader r = new BufferedReader(new FileReader(f));
String line;
while ((line = r.readLine()) != null) {
consumer.consumeLine(line);
}
List<ChangeSet> modifications = consumer.getModifications();
assertEquals(6, modifications.size());
for (Iterator<ChangeSet> i = modifications.iterator(); i.hasNext(); ) {
ChangeSet entry = i.next();
assertEquals("Mark Struberg <struberg@yahoo.de>", entry.getAuthor());
assertNotNull(entry.getDate());
assertTrue(entry.getComment() != null && entry.getComment().length() > 0);
assertNotNull(entry.getRevision());
assertNotNull(entry.getFiles());
assertFalse(entry.getFiles().isEmpty());
}
ChangeSet entry = modifications.get(3);
assertEquals("Mark Struberg <struberg@yahoo.de>", entry.getAuthor());
assertNotNull(entry.getDate());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
assertEquals("2007-11-24 00:10:42 +0000", sdf.format(entry.getDate()));
assertEquals("895d423689da3b36d8e9106c0ecbf3d62433978c", entry.getRevision());
assertEquals("/ added", entry.getComment());
assertNotNull(entry.getFiles());
ChangeFile cf = entry.getFiles().get(0);
assertEquals("readme.txt", cf.getName());
assertTrue(cf.getRevision() != null && cf.getRevision().length() > 0);
}
Aggregations