Search in sources :

Example 46 with ChangeSet

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

the class SvnUpdateConsumer method parseLine.

// ----------------------------------------------------------------------
// StreamConsumer Implementation
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
protected void parseLine(String line) {
    line = line.trim();
    String statusString = line.substring(0, 1);
    String file = line.substring(3).trim();
    // [SCM-368]
    if (file.startsWith(workingDirectory.getAbsolutePath())) {
        if (file.length() == workingDirectory.getAbsolutePath().length()) {
            file = ".";
        } else {
            file = file.substring(this.workingDirectory.getAbsolutePath().length() + 1);
        }
    }
    ScmFileStatus status;
    if (line.startsWith(UPDATED_TO_REVISION_TOKEN)) {
        String revisionString = line.substring(UPDATED_TO_REVISION_TOKEN.length() + 1, line.length() - 1);
        revision = parseInt(revisionString);
        return;
    } else if (line.startsWith(AT_REVISION_TOKEN)) {
        String revisionString = line.substring(AT_REVISION_TOKEN.length() + 1, line.length() - 1);
        revision = parseInt(revisionString);
        return;
    } else if (line.startsWith(EXPORTED_REVISION_TOKEN)) {
        String revisionString = line.substring(EXPORTED_REVISION_TOKEN.length() + 1, line.length() - 1);
        revision = parseInt(revisionString);
        return;
    } else if (line.startsWith(RESTORED_TOKEN)) {
        return;
    } else if (statusString.equals("A")) {
        status = ScmFileStatus.ADDED;
    } else if (statusString.equals("U") || statusString.equals("M")) {
        status = ScmFileStatus.UPDATED;
    } else if (statusString.equals("D")) {
        status = ScmFileStatus.DELETED;
    } else {
        return;
    }
    addFile(new ScmFile(file, status));
    List<ChangeFile> changeFiles = Arrays.asList(new ChangeFile[] { new ChangeFile(line, Integer.valueOf(revision).toString()) });
    ChangeSet changeSet = new ChangeSet(null, null, null, changeFiles);
    changeSets.add(changeSet);
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) ChangeFile(org.apache.maven.scm.ChangeFile) ChangeSet(org.apache.maven.scm.ChangeSet) ScmFile(org.apache.maven.scm.ScmFile)

Example 47 with ChangeSet

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

the class SvnChangeLogConsumerTest method testConsumeLine_ValidOutput.

/**
 * Valid svn log output should have expected values.
 *
 * @throws Exception if any problem occurs.
 */
public void testConsumeLine_ValidOutput() throws Exception {
    final File svnLog = getTestFile("/src/test/resources/svn/changelog/svnLogValidOutput.txt");
    consumeLog(svnLog);
    final ChangeSet entry = consumer.getModifications().get(0);
    final List changedFiles = entry.getFiles();
    final String revision = ((ChangeFile) changedFiles.get(0)).getRevision();
    assertEquals("Valid revision expected", "15", revision);
    assertEquals("Valid num changed files expected", 2, changedFiles.size());
    assertEquals("Valid name expected", "unconventional author output (somedata)", entry.getAuthor());
    String expectedDate = getLocalizedDate("2002-08-26 14:33:26", TimeZone.getTimeZone("GMT-4"));
    assertEquals("Valid date expected", expectedDate, entry.getDateFormatted());
    assertEquals("Valid comment expected", "Minor formatting changes.\n", entry.getComment());
}
Also used : ChangeFile(org.apache.maven.scm.ChangeFile) List(java.util.List) ChangeFile(org.apache.maven.scm.ChangeFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 48 with ChangeSet

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

the class SvnChangeLogConsumerTest method testConsumerWithPattern1.

public void testConsumerWithPattern1() throws Exception {
    StringBuilder out = new StringBuilder();
    File f = getTestFile("/src/test/resources/svn/changelog/svnlog.txt");
    BufferedReader r = new BufferedReader(new FileReader(f));
    String line;
    while ((line = r.readLine()) != null) {
        consumer.consumeLine(line);
    }
    List<ChangeSet> modifications = consumer.getModifications();
    out.append("Text format:");
    out.append("nb modifications : " + modifications.size());
    for (ChangeSet entry : modifications) {
        out.append("Author:" + entry.getAuthor());
        out.append("Date:" + entry.getDate());
        out.append("Comment:" + entry.getComment());
        for (ChangeFile file : entry.getFiles()) {
            out.append("File:" + file.getName());
        }
        out.append("==============================");
    }
    out.append("XML format:");
    out.append("nb modifications : " + modifications.size());
    for (ChangeSet entry : modifications) {
        out.append(entry.toXML());
        out.append("==============================");
    }
    if (logger.isDebugEnabled()) {
        logger.debug(out.toString());
    }
}
Also used : ChangeFile(org.apache.maven.scm.ChangeFile) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ChangeFile(org.apache.maven.scm.ChangeFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 49 with ChangeSet

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

the class SvnChangeLogConsumerTest method testConsumerWithPattern2.

public void testConsumerWithPattern2() throws Exception {
    StringBuilder out = new StringBuilder();
    File f = getTestFile("/src/test/resources/svn/changelog/svnlog2.txt");
    BufferedReader r = new BufferedReader(new FileReader(f));
    String line;
    while ((line = r.readLine()) != null) {
        consumer.consumeLine(line);
    }
    List modifications = consumer.getModifications();
    out.append("nb modifications : " + modifications.size());
    int origFileCounter = 0;
    // must use *Linked* HashMap to have predictable toString
    final Map<ScmFileStatus, AtomicInteger> summary = new LinkedHashMap<ScmFileStatus, AtomicInteger>();
    for (ChangeSet entry : consumer.getModifications()) {
        out.append("Author:" + entry.getAuthor());
        out.append("Date:" + entry.getDate());
        out.append("Comment:" + entry.getComment());
        for (ChangeFile file : entry.getFiles()) {
            final ScmFileStatus action = file.getAction();
            if (!summary.containsKey(action)) {
                summary.put(action, new AtomicInteger());
            }
            summary.get(action).incrementAndGet();
            final String fileName = file.getName();
            out.append("File:" + fileName);
            // files in this log are known to be from one subtree
            Assert.assertTrue("Unexpected file name: " + fileName, fileName.startsWith("/maven/scm/trunk"));
            // files in this log are known not to contain space
            Assert.assertEquals("Unexpected space found in filename: " + fileName, -1, fileName.indexOf(" "));
            if (file.getOriginalName() != null) {
                origFileCounter++;
            }
        }
        out.append("==============================");
    }
    Assert.assertEquals("Unexpected number of file copy records", 1, origFileCounter);
    Assert.assertEquals("Action summary differs from expectations", "{modified=626, deleted=56, added=310, copied=1}", summary.toString());
    if (logger.isDebugEnabled()) {
        logger.debug(out.toString());
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ScmFileStatus(org.apache.maven.scm.ScmFileStatus) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ChangeFile(org.apache.maven.scm.ChangeFile) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) List(java.util.List) ChangeFile(org.apache.maven.scm.ChangeFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 50 with ChangeSet

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

the class StarteamChangeLogConsumerTest method testRelativeFilePath.

public void testRelativeFilePath() throws Exception {
    List<ChangeSet> entries = parseTestFile();
    // ensure the filename in the first ChangeSet has correct relative path
    ChangeSet entry = (ChangeSet) entries.get(1);
    assertTrue(entry.containsFilename("./maven/src/File2.java"));
}
Also used : ChangeSet(org.apache.maven.scm.ChangeSet)

Aggregations

ChangeSet (org.apache.maven.scm.ChangeSet)62 ChangeFile (org.apache.maven.scm.ChangeFile)34 ArrayList (java.util.ArrayList)21 Date (java.util.Date)18 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)16 File (java.io.File)15 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)15 Matcher (java.util.regex.Matcher)8 ScmException (org.apache.maven.scm.ScmException)8 BufferedReader (java.io.BufferedReader)7 SimpleDateFormat (java.text.SimpleDateFormat)7 ScmFile (org.apache.maven.scm.ScmFile)6 ScmFileSet (org.apache.maven.scm.ScmFileSet)5 ScmResult (org.apache.maven.scm.ScmResult)5 DefaultLog (org.apache.maven.scm.log.DefaultLog)5 FileReader (java.io.FileReader)4 List (java.util.List)4 ScmFileStatus (org.apache.maven.scm.ScmFileStatus)4 FileInputStream (java.io.FileInputStream)3 InputStreamReader (java.io.InputStreamReader)3