Search in sources :

Example 31 with ChangeSet

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

the class BazaarChangeLogConsumer method doConsume.

/**
 * {@inheritDoc}
 */
public void doConsume(ScmFileStatus status, String line) {
    String tmpLine = line;
    // Parse line
    if (line.startsWith(START_LOG_TAG)) {
        // If last entry was part a merged entry
        if (isMergeEntry && lastChange != null) {
            String comment = lastChange.getComment();
            comment += "\n[MAVEN]: Merged from " + currentChange.getAuthor();
            comment += "\n[MAVEN]:    " + currentChange.getDateFormatted();
            comment += "\n[MAVEN]:    " + currentChange.getComment();
            lastChange.setComment(comment);
        }
        // Init a new changeset
        currentChange = new ChangeSet();
        currentChange.setFiles(new ArrayList<ChangeFile>());
        logEntries.add(currentChange);
        // Reset memeber vars
        currentComment = new StringBuilder();
        currentStatus = null;
        currentRevision = "";
        isMergeEntry = false;
    } else if (line.startsWith(MERGED_TOKEN)) {
        // This is part of lastChange and is not a separate log entry
        isMergeEntry = true;
        logEntries.remove(currentChange);
        if (logEntries.size() > 0) {
            lastChange = (ChangeSet) logEntries.get(logEntries.size() - 1);
        } else {
            if (getLogger().isWarnEnabled()) {
                getLogger().warn("First entry was unexpectedly a merged entry");
            }
            lastChange = null;
        }
    } else if (line.startsWith(REVNO_TAG)) {
        tmpLine = line.substring(REVNO_TAG.length());
        tmpLine = tmpLine.trim();
        currentRevision = tmpLine;
    } else if (line.startsWith(AUTHOR_TAG)) {
        tmpLine = line.substring(AUTHOR_TAG.length());
        tmpLine = tmpLine.trim();
        currentChange.setAuthor(tmpLine);
    } else if (line.startsWith(TIME_STAMP_TOKEN)) {
        tmpLine = line.substring(TIME_STAMP_TOKEN.length() + 3);
        tmpLine = tmpLine.trim();
        Date date = parseDate(tmpLine, userDatePattern, BAZAAR_TIME_PATTERN);
        currentChange.setDate(date);
    } else if (line.startsWith(MESSAGE_TOKEN)) {
        currentStatus = ScmFileStatus.UNKNOWN;
    } else if (status != null) {
        currentStatus = status;
    } else if (currentStatus == ScmFileStatus.UNKNOWN) {
        currentComment.append(line);
        currentChange.setComment(currentComment.toString());
        currentComment.append("\n");
    } else if (currentStatus != null) {
        tmpLine = tmpLine.trim();
        final ChangeFile changeFile;
        if (currentStatus == ScmFileStatus.RENAMED) {
            final String[] parts = tmpLine.split(RENAME_SEPARATOR);
            if (parts.length != 2) {
                changeFile = new ChangeFile(tmpLine, currentRevision);
            } else {
                changeFile = new ChangeFile(parts[1], currentRevision);
                changeFile.setOriginalName(parts[0]);
            }
        } else {
            changeFile = new ChangeFile(tmpLine, currentRevision);
        }
        changeFile.setAction(currentStatus);
        currentChange.addFile(changeFile);
    } else if (line.startsWith(BRANCH_NICK_TOKEN)) {
    // ignore
    } else {
        if (getLogger().isWarnEnabled()) {
            getLogger().warn("Could not figure out of: " + line);
        }
    }
}
Also used : ChangeFile(org.apache.maven.scm.ChangeFile) ChangeSet(org.apache.maven.scm.ChangeSet) Date(java.util.Date)

Example 32 with ChangeSet

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

the class BazaarUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    if (version != null && StringUtils.isNotEmpty(version.getName())) {
        throw new ScmException("This provider can't handle tags.");
    }
    File workingDir = fileSet.getBasedir();
    // Update branch
    String[] updateCmd = new String[] { BazaarConstants.PULL_CMD };
    ScmResult updateResult = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), workingDir, updateCmd);
    if (!updateResult.isSuccess()) {
        return new UpdateScmResult(null, null, updateResult);
    }
    // Find changes from last revision
    int currentRevision = BazaarUtils.getCurrentRevisionNumber(getLogger(), workingDir);
    int previousRevision = currentRevision - 1;
    String[] diffCmd = new String[] { BazaarConstants.DIFF_CMD, BazaarConstants.REVISION_OPTION, "" + previousRevision };
    BazaarDiffConsumer diffConsumer = new BazaarDiffConsumer(getLogger(), workingDir);
    ScmResult diffResult = BazaarUtils.execute(diffConsumer, getLogger(), workingDir, diffCmd);
    // Now translate between diff and update file status
    List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
    List<CharSequence> changes = new ArrayList<CharSequence>();
    List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
    Map<String, CharSequence> diffChanges = diffConsumer.getDifferences();
    for (Iterator<ScmFile> it = diffFiles.iterator(); it.hasNext(); ) {
        ScmFile file = it.next();
        changes.add(diffChanges.get(file));
        if (file.getStatus() == ScmFileStatus.MODIFIED) {
            updatedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.PATCHED));
        } else {
            updatedFiles.add(file);
        }
    }
    return new UpdateScmResultWithRevision(updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf(currentRevision), diffResult);
}
Also used : ScmException(org.apache.maven.scm.ScmException) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ScmResult(org.apache.maven.scm.ScmResult) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) BazaarDiffConsumer(org.apache.maven.scm.provider.bazaar.command.diff.BazaarDiffConsumer) BazaarConsumer(org.apache.maven.scm.provider.bazaar.command.BazaarConsumer) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 33 with ChangeSet

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

the class AccuRevChangeLogCommandTest method testStandardCase.

@Test
public void testStandardCase() throws Exception {
    // Workspace to root stream, keeps and promotes
    // Setup test data so that the checkin area is the repo's project path.
    final ScmFileSet testFileSet = new ScmFileSet(new File(basedir, "project/dir"));
    // stream 1 only => not found
    // stream 2 only => created
    // stream 1 and 2 => version or moved
    // comment to contain all the changes eg file moved from to
    // files to contain all the referenced files
    // NOTE: The version specs, and stream numbers used in this test are
    // important!!
    // start tran (35)
    List<Transaction> startTransaction = Collections.singletonList(new Transaction(35L, new Date(), "sometran", "anyone"));
    when(accurev.history("myStream", "2009/01/01 10:00:00", null, 1, true, true)).thenReturn(startTransaction);
    // end tran (42)
    List<Transaction> endTransaction = Collections.singletonList(new Transaction(42L, new Date(), "sometran", "anyone"));
    Stream basisStream = new Stream("myStream", 10, "myDepot", 1, "myDepot", getDate(2008, 1, 1), "normal");
    when(accurev.showStream("myStream")).thenReturn(basisStream);
    when(accurev.history("myStream", "2009/01/12 13:00:00", null, 1, true, true)).thenReturn(endTransaction);
    // now we call diff between the tran ids - 35 to 42
    FileDifference promoted = new FileDifference(10L, "/promoted/file", "4/2", "/promoted/file", "6/1");
    FileDifference removed = new FileDifference(20L, null, null, "/removed/file", "6/1");
    FileDifference created = new FileDifference(30L, "/created/file", "6/1", null, null);
    FileDifference moved = new FileDifference(40L, "/moved/to", "4/2", "/moved/from", "6/1");
    when(accurev.diff("myStream", "35", "42")).thenReturn(Arrays.asList(promoted, removed, created, moved));
    // and we call hist for tranid + 1 to end trand id
    // getDate uses calendar's zero indexed months
    final Date dateFrom = getDate(2009, 0, 1, 10, 0, 0, null);
    final Date dateTo = getDate(2009, 0, 12, 13, 0, 0, null);
    final Date keepWhen = getDate(2009, 0, 2, 9, 0, 0, null);
    final Date promoteWhen = getDate(2009, 0, 4, 23, 0, 0, null);
    final Transaction promoteOne = new Transaction(10L, keepWhen, "promote", "aUser");
    promoteOne.addVersion(5L, "/./kept/file", "10/5", "5/5", "3/2");
    promoteOne.setComment("a Comment");
    final Transaction promoteTwo = new Transaction(12L, promoteWhen, "promote", "anOther");
    promoteTwo.addVersion(10L, "/./promoted/file", "10/5", "4/2", null);
    promoteTwo.setComment("my Promotion");
    when(accurev.history("myStream", "36", "42", 0, false, false)).thenReturn(Arrays.asList(promoteOne, promoteTwo));
    AccuRevChangeLogCommand command = new AccuRevChangeLogCommand(getLogger());
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setString(CommandParameter.MESSAGE, "A commit message");
    commandParameters.setDate(CommandParameter.START_DATE, dateFrom);
    commandParameters.setDate(CommandParameter.END_DATE, dateTo);
    ChangeLogScmResult result = command.changelog(repo, testFileSet, commandParameters);
    assertThat(result.isSuccess(), is(true));
    List<ChangeSet> changeSets = result.getChangeLog().getChangeSets();
    assertThat(changeSets.size(), is(3));
    ChangeSet cs = (ChangeSet) changeSets.get(0);
    assertThat(cs.getAuthor(), is("aUser"));
    assertThat(cs.getComment(), is("a Comment"));
    assertThat(cs.getDate(), is(keepWhen));
    assertThat(cs.getFiles().size(), is(1));
    ChangeFile cf = (ChangeFile) cs.getFiles().get(0);
    assertThat(cf.getName(), is("/./kept/file"));
    assertThat(cf.getRevision(), is("10/5 (5/5)"));
    cs = (ChangeSet) changeSets.get(2);
    assertThat(cs.getAuthor(), is("various"));
    // created/removed/moved but not the file that was in the promoted
    // set...
    assertThat(cs.getComment(), is("Upstream changes"));
    assertThat(cs.getFiles().size(), is(3));
    assertThat(cs.containsFilename("created/file"), is(true));
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) Date(java.util.Date) Transaction(org.apache.maven.scm.provider.accurev.Transaction) ChangeFile(org.apache.maven.scm.ChangeFile) Stream(org.apache.maven.scm.provider.accurev.Stream) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) FileDifference(org.apache.maven.scm.provider.accurev.FileDifference) CommandParameters(org.apache.maven.scm.CommandParameters) ChangeFile(org.apache.maven.scm.ChangeFile) ChangeFileMatcher.changeFile(org.apache.maven.scm.ChangeFileMatcher.changeFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 34 with ChangeSet

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

the class BazaarChangeLogConsumerTest method testChanglogWithMergeEntries.

public void testChanglogWithMergeEntries() throws IOException {
    File testFile = getTestFile("src/test/resources/bazaar/changeLogWithMerge.txt");
    BazaarChangeLogConsumer consumer = new BazaarChangeLogConsumer(new DefaultLog(), null);
    FileInputStream fis = new FileInputStream(testFile);
    BufferedReader in = new BufferedReader(new InputStreamReader(fis));
    String s = in.readLine();
    while (s != null) {
        consumer.consumeLine(s);
        s = in.readLine();
    }
    List<ChangeSet> mods = consumer.getModifications();
    assertEquals(4, mods.size());
    final ChangeSet ch2 = mods.get(2);
    Assert.assertEquals("Unexpected committer", "tsmoergrav@slb.com", ch2.getAuthor());
    Assert.assertEquals("Unexpected comment", "Second", ch2.getComment());
    Assert.assertEquals("File count", 2, ch2.getFiles().size());
    final ChangeFile ch2f1 = ch2.getFiles().get(0);
    Assert.assertEquals("Invalid action", ScmFileStatus.MODIFIED, ch2f1.getAction());
    Assert.assertEquals("Invalid  file name", "changeLogWithMerge.txt", ch2f1.getName());
    Assert.assertNull("Unexpected originalName", ch2f1.getOriginalName());
    final ChangeFile ch2f2 = ch2.getFiles().get(1);
    Assert.assertEquals("Invalid action", ScmFileStatus.RENAMED, ch2f2.getAction());
    Assert.assertEquals("Invalid file name", "blablabla.txt", ch2f2.getName());
    Assert.assertEquals("Invalid original name", "a", ch2f2.getOriginalName());
}
Also used : InputStreamReader(java.io.InputStreamReader) ChangeFile(org.apache.maven.scm.ChangeFile) DefaultLog(org.apache.maven.scm.log.DefaultLog) BufferedReader(java.io.BufferedReader) ChangeFile(org.apache.maven.scm.ChangeFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet) FileInputStream(java.io.FileInputStream)

Example 35 with ChangeSet

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

the class VssChangeLogConsumer method addEntry.

/**
 * Add a change log entry to the list (if it's not already there) with the
 * given file.
 *
 * @param entry a {@link ChangeSet}to be added to the list if another
 *              with the same key doesn't exist already. If the entry's author
 *              is null, the entry wont be added
 * @param file  a {@link ChangeFile}to be added to the entry
 */
private void addEntry(ChangeSet entry, ChangeFile file) {
    // do not add if entry is not populated
    if (entry.getAuthor() == null) {
        return;
    }
    String key = ENTRY_KEY_TIMESTAMP_FORMAT.format(entry.getDate()) + entry.getAuthor() + entry.getComment();
    if (!entries.containsKey(key)) {
        entry.addFile(file);
        entries.put(key, entry);
    } else {
        ChangeSet existingEntry = (ChangeSet) entries.get(key);
        existingEntry.addFile(file);
    }
}
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