in maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/changelog/LocalChangeLogCommand.java [46:139]
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<>();
try {
File repoRoot = new File(repo.getRoot(), repo.getModule());
List<File> files = fileSet.getFileList();
if (files.isEmpty()) {
files = FileUtils.getFiles(baseDestination, "**", null, false);
}
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));
}