use of org.apache.maven.scm.command.changelog.ChangeLogSet in project maven-scm by apache.
the class SvnChangeLogCommand method executeChangeLogCommand.
private ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern, ScmVersion startVersion, ScmVersion endVersion, Integer limit) throws ScmException {
Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), branch, startDate, endDate, startVersion, endVersion, limit);
SvnChangeLogConsumer consumer = new SvnChangeLogConsumer(getLogger(), datePattern);
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
if (getLogger().isInfoEnabled()) {
getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
}
}
int exitCode;
try {
exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
} catch (CommandLineException ex) {
throw new ScmException("Error while executing svn command.", ex);
}
if (exitCode != 0) {
return new ChangeLogScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
}
ChangeLogSet changeLogSet = new ChangeLogSet(consumer.getModifications(), startDate, endDate);
changeLogSet.setStartVersion(startVersion);
changeLogSet.setEndVersion(endVersion);
return new ChangeLogScmResult(cl.toString(), changeLogSet);
}
use of org.apache.maven.scm.command.changelog.ChangeLogSet 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.command.changelog.ChangeLogSet 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.command.changelog.ChangeLogSet in project maven-scm by apache.
the class GitChangeLogCommand method executeChangeLogCommand.
protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern, ScmVersion startVersion, ScmVersion endVersion, Integer limit) throws ScmException {
Commandline cl = createCommandLine((GitScmProviderRepository) repo, fileSet.getBasedir(), branch, startDate, endDate, startVersion, endVersion, limit);
GitChangeLogConsumer consumer = new GitChangeLogConsumer(getLogger(), datePattern);
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode;
exitCode = GitCommandLineUtils.execute(cl, consumer, stderr, getLogger());
if (exitCode != 0) {
return new ChangeLogScmResult(cl.toString(), "The git-log command failed.", stderr.getOutput(), false);
}
ChangeLogSet changeLogSet = new ChangeLogSet(consumer.getModifications(), startDate, endDate);
changeLogSet.setStartVersion(startVersion);
changeLogSet.setEndVersion(endVersion);
return new ChangeLogScmResult(cl.toString(), changeLogSet);
}
use of org.apache.maven.scm.command.changelog.ChangeLogSet in project maven-plugins by apache.
the class ChangeLog method loadChangedSets.
public static List<ChangeLogSet> loadChangedSets(Reader reader) throws ParserConfigurationException, SAXException, IOException {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
List<ChangeLogSet> changeLogSets = new ArrayList<ChangeLogSet>();
// CHECKSTYLE_OFF: MagicNumber
BufferedReader br = new BufferedReader(reader, 8192);
// CHECKSTYLE_ON: MagicNumber
parser.parse(new InputSource(br), new ChangeLogHandler(changeLogSets));
return changeLogSets;
}
Aggregations