Search in sources :

Example 16 with ScmFileStatus

use of org.apache.maven.scm.ScmFileStatus 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 17 with ScmFileStatus

use of org.apache.maven.scm.ScmFileStatus 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 18 with ScmFileStatus

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

the class SvnRemoveConsumer method consumeLine.

// ----------------------------------------------------------------------
// StreamConsumer Implementation
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
public void consumeLine(String line) {
    if (line.length() <= 3) {
        if (logger.isWarnEnabled()) {
            logger.warn("Unexpected input, the line must be at least three characters long. Line: '" + line + "'.");
        }
        return;
    }
    String statusString = line.substring(0, 1);
    String file = line.substring(3);
    ScmFileStatus status;
    if (statusString.equals("D")) {
        status = ScmFileStatus.DELETED;
    } else {
        if (logger.isInfoEnabled()) {
            logger.info("Unknown file status: '" + statusString + "'.");
        }
        return;
    }
    removedFiles.add(new ScmFile(file, status));
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) ScmFile(org.apache.maven.scm.ScmFile)

Example 19 with ScmFileStatus

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

the class SvnStatusConsumer method consumeLine.

// ----------------------------------------------------------------------
// StreamConsumer Implementation
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
public void consumeLine(String line) {
    if (logger.isDebugEnabled()) {
        logger.debug(line);
    }
    if (StringUtils.isEmpty(line.trim())) {
        return;
    }
    if (line.length() <= 7) {
        if (logger.isWarnEnabled()) {
            logger.warn("Unexpected input, the line must be at least seven characters long. Line: '" + line + "'.");
        }
        return;
    }
    String statusString = line.substring(0, 1);
    String file = line.substring(7).trim();
    ScmFileStatus status;
    // ' ' the working copy is up to date
    if (statusString.equals("A")) {
        status = ScmFileStatus.ADDED;
    } else if (statusString.equals("M") || statusString.equals("R") || statusString.equals("~")) {
        status = ScmFileStatus.MODIFIED;
    } else if (statusString.equals("D")) {
        status = ScmFileStatus.DELETED;
    } else if (statusString.equals("?")) {
        status = ScmFileStatus.UNKNOWN;
    } else if (statusString.equals("!")) {
        status = ScmFileStatus.MISSING;
    } else if (statusString.equals("C")) {
        status = ScmFileStatus.CONFLICT;
    } else if (statusString.equals("L")) {
        status = ScmFileStatus.LOCKED;
    } else if (statusString.equals("X")) {
        // skip svn:external entries
        return;
    } else if (statusString.equals("I")) {
        // skip svn:external entries
        return;
    } else {
        // Parse the second column
        statusString = line.substring(1, 1);
        if (statusString.equals("M")) {
            status = ScmFileStatus.MODIFIED;
        } else if (statusString.equals("C")) {
            status = ScmFileStatus.CONFLICT;
        } else {
            // or a status defined in next columns
            return;
        }
    }
    // If the file isn't a file; don't add it.
    if (!status.equals(ScmFileStatus.DELETED) && !new File(workingDirectory, file).isFile()) {
        return;
    }
    changedFiles.add(new ScmFile(file, status));
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 20 with ScmFileStatus

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

the class SvnAddConsumer method consumeLine.

// ----------------------------------------------------------------------
// StreamConsumer Implementation
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
public void consumeLine(String line) {
    if (line.length() <= 3) {
        if (logger.isWarnEnabled()) {
            logger.warn("Unexpected input, the line must be at least three characters long. Line: '" + line + "'.");
        }
        return;
    }
    String statusString = line.substring(0, 1);
    String file = line.substring(3);
    ScmFileStatus status;
    if (statusString.equals("A")) {
        status = ScmFileStatus.ADDED;
    } else {
        if (logger.isInfoEnabled()) {
            logger.info("Unknown file status: '" + statusString + "'.");
        }
        return;
    }
    addedFiles.add(new ScmFile(file, status));
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) ScmFile(org.apache.maven.scm.ScmFile)

Aggregations

ScmFileStatus (org.apache.maven.scm.ScmFileStatus)24 ScmFile (org.apache.maven.scm.ScmFile)17 File (java.io.File)7 Matcher (java.util.regex.Matcher)6 ChangeFile (org.apache.maven.scm.ChangeFile)6 ArrayList (java.util.ArrayList)4 ChangeSet (org.apache.maven.scm.ChangeSet)4 ScmException (org.apache.maven.scm.ScmException)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 LinkedHashMap (java.util.LinkedHashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1 ScmResult (org.apache.maven.scm.ScmResult)1 BranchScmResult (org.apache.maven.scm.command.branch.BranchScmResult)1 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)1 DefaultLog (org.apache.maven.scm.log.DefaultLog)1