Search in sources :

Example 66 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class JazzCheckInConsumer method consumeLine.

/**
 * Process one line of output from the execution of the "scm checkin" command.
 *
 * @param line The line of output from the external command that has been pumped to us.
 * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String)
 */
public void consumeLine(String line) {
    super.consumeLine(line);
    if (haveSeenChanges) {
        // We have already seen the "Changes:" line, so we must now be processing files.
        String trimmed = line.trim();
        int spacePos = trimmed.indexOf(" ");
        // NOTE: The second + 1 is to remove the leading slash
        String path = trimmed.substring(spacePos + 1 + 1);
        fCheckedInFiles.add(new ScmFile(path, ScmFileStatus.CHECKED_OUT));
    } else {
        if ("Changes:".equals(line.trim())) {
            haveSeenChanges = true;
        }
    }
}
Also used : ScmFile(org.apache.maven.scm.ScmFile)

Example 67 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class JazzDiffCommand method executeDiffCommand.

/**
 * {@inheritDoc}
 */
protected DiffScmResult executeDiffCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion startRevision, ScmVersion endRevision) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing diff command...");
    }
    File baseDir = fileSet.getBasedir();
    File parentFolder = (baseDir.getParentFile() != null) ? baseDir.getParentFile() : baseDir;
    // First execute the status command to get the list of changed files.
    JazzStatusCommand statusCmd = new JazzStatusCommand();
    statusCmd.setLogger(getLogger());
    StatusScmResult statusCmdResult = statusCmd.executeStatusCommand(repo, fileSet);
    List<ScmFile> statusScmFiles = statusCmdResult.getChangedFiles();
    // In this case, we also use it across multiple calls to "scm diff" so that we
    // sum all output into on.
    JazzScmCommand diffCmd = null;
    StringBuilder patch = new StringBuilder();
    Map<String, CharSequence> differences = new HashMap<String, CharSequence>();
    // Now lets iterate through them
    for (ScmFile file : statusScmFiles) {
        if (file.getStatus() == ScmFileStatus.MODIFIED) {
            // The "scm status" command returns files relative to the sandbox root.
            // Whereas the "scm diff" command needs them relative to the working directory.
            File fullPath = new File(parentFolder, file.getPath());
            String relativePath = fullPath.toString().substring(baseDir.toString().length());
            getLogger().debug("Full Path     : '" + fullPath + "'");
            getLogger().debug("Relative Path : '" + relativePath + "'");
            // Now call "scm diff on it"
            // In this case, we use the DebugLoggerConsumer's ability to store captured output
            DebugLoggerConsumer diffConsumer = new DebugLoggerConsumer(getLogger());
            ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
            diffCmd = createDiffCommand(repo, fileSet, relativePath);
            int status = diffCmd.execute(diffConsumer, errConsumer);
            if (status != 0) {
                // Return a false result (not the usual SCMResult)
                return new DiffScmResult(diffCmd.toString(), "The scm diff command failed.", errConsumer.getOutput(), false);
            }
            // Append to patch (all combined)
            patch.append(diffConsumer.getOutput());
            // Set the differences map <File, <CharSequence>
            differences.put(relativePath, diffConsumer.getOutput());
        }
    }
    return new DiffScmResult(diffCmd.toString(), statusCmdResult.getChangedFiles(), differences, patch.toString());
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) HashMap(java.util.HashMap) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) ScmFile(org.apache.maven.scm.ScmFile) JazzStatusCommand(org.apache.maven.scm.provider.jazz.command.status.JazzStatusCommand) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) DebugLoggerConsumer(org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Example 68 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class HgDiffCommandTckTest method testDiffCommand.

public void testDiffCommand() throws Exception {
    ScmRepository repository = getScmRepository();
    // ----------------------------------------------------------------------
    // Change the files
    // ----------------------------------------------------------------------
    // 
    // readme.txt is changed (changed file in the root directory)
    // project.xml is added (added file in the root directory)
    // src/test/resources is untouched (a empty directory is left untouched)
    // src/test/java is untouched (a non empty directory is left untouched)
    // This following test has no meaning to mercurial as mercurial does not track
    // empty directories, only the files contained within
    // See: http://www.selenic.com/mercurial/wiki/index.cgi/FAQ
    // src/test/java/org (a empty directory is added)
    // src/main/java/org/Foo.java (a non empty directory is added)
    // 
    // /readme.txt
    ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
    // /project.xml
    ScmTestCase.makeFile(getWorkingCopy(), "/project.xml", "changed project.xml");
    addToWorkingTree(getWorkingCopy(), new File("project.xml"), repository);
    // /src/test/java/org
    // ScmTestCase.makeDirectory(getWorkingCopy(), "/src/test/java/org");
    // 
    // addToWorkingTree(getWorkingCopy(), new File("src/test/java/org"),
    // repository);
    // /src/main/java/org/Foo.java
    ScmTestCase.makeFile(getWorkingCopy(), "/src/main/java/org/Foo.java");
    // addToWorkingTree(getWorkingCopy(), new File("src/main/java/org"),
    // repository);
    // src/main/java/org/Foo.java
    addToWorkingTree(getWorkingCopy(), new File("src/main/java/org/Foo.java"), repository);
    // ----------------------------------------------------------------------
    // Diff the project
    // ----------------------------------------------------------------------
    ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
    ScmFileSet fileSet = new ScmFileSet(getWorkingCopy());
    DiffScmResult result = provider.diff(repository, fileSet, (ScmVersion) null, null);
    // todo: check asserts
    // assertNotNull("The command returned a null result.", result);
    // assertResultIsSuccess(result);
    List<ScmFile> changedFiles = result.getChangedFiles();
    Map<String, CharSequence> differences = result.getDifferences();
    // assertEquals("Expected 3 files in the changed files list "
    // + changedFiles, 3, changedFiles.size());
    // assertEquals("Expected 3 files in the differences list " + differences,
    // 3, differences.size());
    // ----------------------------------------------------------------------
    // Assert the files in the changed files list
    // ----------------------------------------------------------------------
    Iterator<ScmFile> files = new TreeSet<ScmFile>(changedFiles).iterator();
    // Check Foo.java
    ScmFile file = (ScmFile) files.next();
    // assertPath("/src/main/java/org/Foo.java", file.getPath());
    // assertTrue(file.getStatus().isDiff());
    String postRangeStr = "+/src/main/java/org/Foo.java\n\\ No newline at end of file\n";
    String actualStr = differences.get(file.getPath()).toString();
    // assertTrue(actualStr.endsWith(postRangeStr));
    // Check readme.txt
    file = (ScmFile) files.next();
    // assertPath("/readme.txt", file.getPath());
    // assertTrue(file.getStatus().isDiff());
    postRangeStr = "-/readme.txt\n\\ No newline at end of file\n+changed readme.txt\n\\ No newline at end of file\n";
    actualStr = differences.get(file.getPath()).toString();
    // assertTrue(actualStr.endsWith(postRangeStr));
    // Check project.xml
    file = (ScmFile) files.next();
    // assertPath("/project.xml", file.getPath());
    postRangeStr = "+changed project.xml\n\\ No newline at end of file\n";
    actualStr = differences.get(file.getPath()).toString();
    // assertTrue(actualStr.endsWith(postRangeStr));
    // assertTrue(file.getStatus().isDiff());
    assertTrue(true);
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult) ScmFile(org.apache.maven.scm.ScmFile)

Example 69 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class CheckInCommandTckTest method testCheckInCommandPartialFileset.

public void testCheckInCommandPartialFileset() throws Exception {
    // Make sure that the correct files was checked out
    File fooJava = new File(getWorkingCopy(), "src/main/java/Foo.java");
    File barJava = new File(getWorkingCopy(), "src/main/java/Bar.java");
    File readmeTxt = new File(getWorkingCopy(), "readme.txt");
    assertFalse("check Foo.java doesn't yet exist", fooJava.canRead());
    assertFalse("check Bar.java doesn't yet exist", barJava.canRead());
    assertTrue("check can read readme.txt", readmeTxt.canRead());
    // Change the files
    createFooJava(fooJava);
    createBarJava(barJava);
    changeReadmeTxt(readmeTxt);
    AddScmResult addResult = getScmManager().getProviderByUrl(getScmUrl()).add(getScmRepository(), new ScmFileSet(getWorkingCopy(), "src/main/java/Foo.java", null));
    assertResultIsSuccess(addResult);
    CheckInScmResult result = getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy(), "**/Foo.java", null), "Commit message");
    assertResultIsSuccess(result);
    List<ScmFile> files = result.getCheckedInFiles();
    assertNotNull(files);
    assertEquals(1, files.size());
    ScmFile file1 = files.get(0);
    assertEquals(ScmFileStatus.CHECKED_IN, file1.getStatus());
    assertPath("/test-repo/check-in/Foo.java", file1.getPath());
    CheckOutScmResult checkoutResult = getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()));
    assertResultIsSuccess(checkoutResult);
    fooJava = new File(getAssertionCopy(), "src/main/java/Foo.java");
    barJava = new File(getAssertionCopy(), "src/main/java/Bar.java");
    readmeTxt = new File(getAssertionCopy(), "readme.txt");
    assertTrue("check can read Foo.java", fooJava.canRead());
    assertFalse("check Bar.java doesn't exist", barJava.canRead());
    assertTrue("check can read readme.txt", readmeTxt.canRead());
    assertEquals("check readme.txt contents", "/readme.txt", FileUtils.fileRead(readmeTxt));
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) ScmFile(org.apache.maven.scm.ScmFile)

Example 70 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class DiffCommandTckTest method testDiffCommand.

public void testDiffCommand() throws Exception {
    ScmRepository repository = getScmRepository();
    // ----------------------------------------------------------------------
    // Change the files
    // ----------------------------------------------------------------------
    // 
    // readme.txt is changed (changed file in the root directory)
    // project.xml is added (added file in the root directory)
    // src/test/resources is untouched (a empty directory is left untouched)
    // src/test/java is untouched (a non empty directory is left untouched)
    // src/test/java/org (a empty directory is added)
    // src/main/java/org/Foo.java (a non empty directory is added)
    // 
    // /readme.txt
    ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
    // /project.xml
    ScmTestCase.makeFile(getWorkingCopy(), "/project.xml", "changed project.xml");
    addToWorkingTree(getWorkingCopy(), new File("project.xml"), repository);
    // /src/test/java/org
    ScmTestCase.makeDirectory(getWorkingCopy(), "/src/test/java/org");
    addToWorkingTree(getWorkingCopy(), new File("src/test/java/org"), repository);
    // /src/main/java/org/Foo.java
    ScmTestCase.makeFile(getWorkingCopy(), "/src/main/java/org/Foo.java");
    addToWorkingTree(getWorkingCopy(), new File("src/main/java/org"), repository);
    // src/main/java/org/Foo.java
    addToWorkingTree(getWorkingCopy(), new File("src/main/java/org/Foo.java"), repository);
    // ----------------------------------------------------------------------
    // Diff the project
    // ----------------------------------------------------------------------
    ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
    ScmFileSet fileSet = new ScmFileSet(getWorkingCopy());
    DiffScmResult result = provider.diff(repository, fileSet, null, (ScmVersion) null);
    assertNotNull("The command returned a null result.", result);
    assertResultIsSuccess(result);
    List<ScmFile> changedFiles = result.getChangedFiles();
    Map<String, CharSequence> differences = result.getDifferences();
    assertEquals("Expected 3 files in the changed files list " + changedFiles, 3, changedFiles.size());
    assertEquals("Expected 3 files in the differences list " + differences, 3, differences.size());
    // ----------------------------------------------------------------------
    // Assert the files in the changed files list
    // ----------------------------------------------------------------------
    Iterator<ScmFile> files = new TreeSet<ScmFile>(changedFiles).iterator();
    // Check Foo.java
    ScmFile file = files.next();
    assertPath("/src/main/java/org/Foo.java", file.getPath());
    assertTrue(file.getStatus().isDiff());
    String postRangeStr = "+/src/main/java/org/Foo.java\n\\ No newline at end of file\n";
    String actualStr = differences.get(file.getPath()).toString();
    assertTrue(actualStr.endsWith(postRangeStr));
    // Check readme.txt
    file = files.next();
    assertPath("/readme.txt", file.getPath());
    assertTrue(file.getStatus().isDiff());
    postRangeStr = "-/readme.txt\n\\ No newline at end of file\n+changed readme.txt\n\\ No newline at end of file\n";
    actualStr = differences.get(file.getPath()).toString();
    assertTrue(actualStr.endsWith(postRangeStr));
    // Check project.xml
    file = files.next();
    assertPath("/project.xml", file.getPath());
    postRangeStr = "+changed project.xml\n\\ No newline at end of file\n";
    actualStr = differences.get(file.getPath()).toString();
    assertTrue(actualStr.endsWith(postRangeStr));
    assertTrue(file.getStatus().isDiff());
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult) 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