use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class GitStatusConsumer method consumeLine.
// ----------------------------------------------------------------------
// StreamConsumer Implementation
// ----------------------------------------------------------------------
/**
* {@inheritDoc}
*/
public void consumeLine(String line) {
if (logger.isDebugEnabled()) {
logger.debug(line);
}
if (StringUtils.isEmpty(line)) {
return;
}
ScmFileStatus status = null;
List<String> files = new ArrayList<String>();
Matcher matcher;
if ((matcher = ADDED_PATTERN.matcher(line)).find()) {
status = ScmFileStatus.ADDED;
files.add(resolvePath(matcher.group(1), relativeRepositoryPath));
} else if ((matcher = MODIFIED_PATTERN.matcher(line)).find()) {
status = ScmFileStatus.MODIFIED;
files.add(resolvePath(matcher.group(1), relativeRepositoryPath));
} else if ((matcher = DELETED_PATTERN.matcher(line)).find()) {
status = ScmFileStatus.DELETED;
files.add(resolvePath(matcher.group(1), relativeRepositoryPath));
} else if ((matcher = RENAMED_PATTERN.matcher(line)).find()) {
status = ScmFileStatus.RENAMED;
files.add(resolvePath(matcher.group(1), relativeRepositoryPath));
files.add(resolvePath(matcher.group(2), relativeRepositoryPath));
logger.debug("RENAMED status for line '" + line + "' files added '" + matcher.group(1) + "' '" + matcher.group(2));
} else {
logger.warn("Ignoring unrecognized line: " + line);
return;
}
// If the file isn't a file; don't add it.
if (!files.isEmpty() && status != null) {
if (workingDirectory != null) {
if (status == ScmFileStatus.RENAMED) {
String oldFilePath = files.get(0);
String newFilePath = files.get(1);
if (isFile(oldFilePath)) {
logger.debug("file '" + oldFilePath + "' is a file");
return;
} else {
logger.debug("file '" + oldFilePath + "' not a file");
}
if (!isFile(newFilePath)) {
logger.debug("file '" + newFilePath + "' not a file");
return;
} else {
logger.debug("file '" + newFilePath + "' is a file");
}
} else if (status == ScmFileStatus.DELETED) {
if (isFile(files.get(0))) {
return;
}
} else {
if (!isFile(files.get(0))) {
return;
}
}
}
for (String file : files) {
changedFiles.add(new ScmFile(file, status));
}
}
}
use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class GitRemoveConsumerTest method testLog1Consumer.
public void testLog1Consumer() throws Exception {
GitRemoveConsumer consumer = new GitRemoveConsumer(new DefaultLog());
File f = getTestFile("/src/test/resources/git/remove/gitrm.gitlog");
BufferedReader r = new BufferedReader(new FileReader(f));
String line;
while ((line = r.readLine()) != null) {
consumer.consumeLine(line);
}
List<ScmFile> changedFiles = consumer.getRemovedFiles();
assertEquals(2, changedFiles.size());
testScmFile((ScmFile) changedFiles.get(0), "src/main/java/Application.java", ScmFileStatus.DELETED);
testScmFile((ScmFile) changedFiles.get(1), "src/test/java/Test.java", ScmFileStatus.DELETED);
}
use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class GitRemoveConsumerTest method testEmptyLogConsumer.
public void testEmptyLogConsumer() throws Exception {
GitRemoveConsumer consumer = new GitRemoveConsumer(new DefaultLog());
File f = getTestFile("/src/test/resources/git/remove/gitrm-empty.gitlog");
BufferedReader r = new BufferedReader(new FileReader(f));
String line;
while ((line = r.readLine()) != null) {
consumer.consumeLine(line);
}
List<ScmFile> changedFiles = consumer.getRemovedFiles();
assertEquals(0, changedFiles.size());
}
use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class GitStatusConsumerTest method testConsumerModifiedFileWithDirectoryAndFile.
public void testConsumerModifiedFileWithDirectoryAndFile() throws IOException {
File dir = createTempDirectory();
FileUtils.write(new File(dir, "project.xml"), "data");
List<ScmFile> changedFiles = getChangedFiles("M project.xml", dir);
assertNotNull(changedFiles);
assertEquals(1, changedFiles.size());
assertEquals("project.xml", changedFiles.get(0).getPath());
FileUtils.write(new File(dir, "test file with spaces and a special \u007f character.xml"), "data");
changedFiles = getChangedFiles("M \"test file with spaces and a special \\177 character.xml\"", dir);
assertNotNull(changedFiles);
assertEquals(1, changedFiles.size());
assertEquals("test file with spaces and a special \u007f character.xml", changedFiles.get(0).getPath());
FileUtils.deleteDirectory(dir);
}
use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class GitStatusConsumerTest method testConsumerModifiedFileWithDirectoryAndNoFile.
public void testConsumerModifiedFileWithDirectoryAndNoFile() throws IOException {
File dir = createTempDirectory();
List<ScmFile> changedFiles = getChangedFiles("M project.xml", dir);
assertNotNull(changedFiles);
assertEquals(0, changedFiles.size());
changedFiles = getChangedFiles("M \"test file with spaces and a special \\177 character.xml\"", dir);
assertNotNull(changedFiles);
assertEquals(0, changedFiles.size());
FileUtils.deleteDirectory(dir);
}
Aggregations