Search in sources :

Example 76 with ScmFile

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));
        }
    }
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile)

Example 77 with ScmFile

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);
}
Also used : DefaultLog(org.apache.maven.scm.log.DefaultLog) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) GitRemoveConsumer(org.apache.maven.scm.provider.git.gitexe.command.remove.GitRemoveConsumer) ScmFile(org.apache.maven.scm.ScmFile)

Example 78 with ScmFile

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());
}
Also used : DefaultLog(org.apache.maven.scm.log.DefaultLog) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) GitRemoveConsumer(org.apache.maven.scm.provider.git.gitexe.command.remove.GitRemoveConsumer) ScmFile(org.apache.maven.scm.ScmFile)

Example 79 with ScmFile

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);
}
Also used : ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 80 with ScmFile

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);
}
Also used : ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Aggregations

ScmFile (org.apache.maven.scm.ScmFile)198 File (java.io.File)102 ArrayList (java.util.ArrayList)51 ScmException (org.apache.maven.scm.ScmException)34 BufferedReader (java.io.BufferedReader)21 DefaultLog (org.apache.maven.scm.log.DefaultLog)20 ScmFileStatus (org.apache.maven.scm.ScmFileStatus)19 ScmFileSet (org.apache.maven.scm.ScmFileSet)17 InputStreamReader (java.io.InputStreamReader)16 ScmResult (org.apache.maven.scm.ScmResult)15 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)15 IOException (java.io.IOException)14 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)13 Matcher (java.util.regex.Matcher)11 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)11 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)10 UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)10 Commandline (org.codehaus.plexus.util.cli.Commandline)10 SynergyScmProviderRepository (org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository)9 FileInputStream (java.io.FileInputStream)8