Search in sources :

Example 1 with ChangeSet

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

the class BazaarChangeLogCommand method executeChangeLogCommand.

private ChangeLogScmResult executeChangeLogCommand(ScmFileSet fileSet, Date startDate, Date endDate, String datePattern, Integer limit) throws ScmException {
    List<String> cmd = new ArrayList<String>();
    cmd.addAll(Arrays.asList(BazaarConstants.LOG_CMD, BazaarConstants.VERBOSE_OPTION));
    if (limit != null && limit > 0) {
        cmd.add(BazaarConstants.LIMIT_OPTION);
        cmd.add(Integer.toString(limit));
    }
    BazaarChangeLogConsumer consumer = new BazaarChangeLogConsumer(getLogger(), datePattern);
    ScmResult result = BazaarUtils.execute(consumer, getLogger(), fileSet.getBasedir(), cmd.toArray(new String[cmd.size()]));
    List<ChangeSet> logEntries = consumer.getModifications();
    List<ChangeSet> inRangeAndValid = new ArrayList<ChangeSet>();
    // From 1. Jan 1970
    startDate = startDate == null ? new Date(0) : startDate;
    // Upto now
    endDate = endDate == null ? new Date() : endDate;
    for (ChangeSet change : logEntries) {
        if (change.getFiles().size() > 0) {
            if (!change.getDate().before(startDate) && !change.getDate().after(endDate)) {
                inRangeAndValid.add(change);
            }
        }
    }
    ChangeLogSet changeLogSet = new ChangeLogSet(inRangeAndValid, startDate, endDate);
    return new ChangeLogScmResult(changeLogSet, result);
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) ScmResult(org.apache.maven.scm.ScmResult) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ArrayList(java.util.ArrayList) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ChangeSet(org.apache.maven.scm.ChangeSet) Date(java.util.Date)

Example 2 with ChangeSet

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

the class AccuRevChangeLogCommandTckTest method testUpstreamChangesIncludedInChangeLog.

@SuppressWarnings("unchecked")
@Test
public void testUpstreamChangesIncludedInChangeLog() throws Exception {
    AccuRevCommandLine accurev = accurevTckTestUtil.getAccuRevCL();
    // UpdatingCopy is a workspace rooted at a substream
    String workingStream = accurevTckTestUtil.getWorkingStream();
    String subStream = accurevTckTestUtil.getDepotName() + "_sub_stream";
    accurev.mkstream(workingStream, subStream);
    ScmRepository mainRepository = getScmRepository();
    ScmProvider provider = getScmManager().getProviderByRepository(mainRepository);
    // Create a workspace at the updating copy location backed by the substream
    ScmBranch branch = new ScmBranch("sub_stream");
    provider.checkOut(mainRepository, new ScmFileSet(getUpdatingCopy()), branch);
    Thread.sleep(1000);
    ScmFileSet fileSet = new ScmFileSet(getWorkingCopy());
    // Make a timestamp that we know are after initial revision but before the second
    // Current time
    Date timeBeforeUpstreamCheckin = new Date();
    // pause a couple seconds... [SCM-244]
    Thread.sleep(2000);
    // Make a change to the readme.txt and commit the change
    ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
    ScmTestCase.makeFile(getWorkingCopy(), "/src/test/java/Test.java", "changed Test.java");
    CheckInScmResult checkInResult = provider.checkIn(mainRepository, fileSet, "upstream workspace promote");
    assertTrue("Unable to checkin changes to the repository", checkInResult.isSuccess());
    Thread.sleep(2000);
    Date timeBeforeDownstreamCheckin = new Date();
    Thread.sleep(2000);
    ScmFileSet updateFileSet = new ScmFileSet(getUpdatingCopy());
    provider.update(mainRepository, updateFileSet);
    ScmTestCase.makeFile(getUpdatingCopy(), "/pom.xml", "changed pom.xml");
    ScmTestCase.makeFile(getUpdatingCopy(), "/src/test/java/Test.java", "changed again Test.java");
    checkInResult = provider.checkIn(mainRepository, updateFileSet, "downstream workspace promote");
    assertTrue("Unable to checkin changes to the repository", checkInResult.isSuccess());
    Thread.sleep(2000);
    Date timeBeforeDownstreamPromote = new Date();
    List<File> promotedFiles = new ArrayList<File>();
    accurev.promoteStream(subStream, "stream promote", promotedFiles);
    Thread.sleep(2000);
    Date timeEnd = new Date();
    // Changelog beforeUpstreamCheckin to end should contain both upstream and downstream changes. upstream change
    // should NOT include Test.java
    ChangeLogScmResult result = provider.changeLog(mainRepository, fileSet, timeBeforeUpstreamCheckin, timeEnd, 0, branch);
    assertTrue("changelog beforeUpstreamCheckin to end", result.isSuccess());
    List<ChangeSet> changeSets = result.getChangeLog().getChangeSets();
    assertThat(changeSets.size(), is(2));
    assertThat(changeSets, Matchers.<ChangeSet>hasItems(changeSet("Upstream changes", "/readme.txt"), changeSet("downstream workspace promote", "/./pom.xml", "/./src/test/java/Test.java")));
    // Changelog beforeUpstreamCheckin to beforeDownstreamCheckin should include just upstream change including
    // Test.java
    result = provider.changeLog(mainRepository, fileSet, timeBeforeUpstreamCheckin, timeBeforeDownstreamCheckin, 0, branch);
    assertTrue("changelog beforeUpstreamCheckin to beforeDownstreamCheckin", result.isSuccess());
    changeSets = result.getChangeLog().getChangeSets();
    assertThat(changeSets.size(), is(1));
    assertThat(changeSets.get(0), changeSet("Upstream changes", "/readme.txt", "/src/test/java/Test.java"));
    // Changelog beforeDownstreamCheckin to end should include just downstream change
    result = provider.changeLog(mainRepository, fileSet, timeBeforeDownstreamCheckin, timeEnd, 0, branch);
    assertTrue("changelog beforeDownstreamCheckin to end", result.isSuccess());
    changeSets = result.getChangeLog().getChangeSets();
    assertThat(changeSets.size(), is(1));
    assertThat(changeSets.get(0), changeSet("downstream workspace promote", "/./pom.xml", "/./src/test/java/Test.java"));
    // Changelog beforeDownstreamPromote to end should be empty
    result = provider.changeLog(mainRepository, fileSet, timeBeforeDownstreamPromote, timeEnd, 0, branch);
    assertTrue("changelog beforeDownstreamPromote to end", result.isSuccess());
    changeSets = result.getChangeLog().getChangeSets();
    assertThat(changeSets.size(), is(0));
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmBranch(org.apache.maven.scm.ScmBranch) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) AccuRevCommandLine(org.apache.maven.scm.provider.accurev.cli.AccuRevCommandLine) ArrayList(java.util.ArrayList) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) Date(java.util.Date) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet) Test(org.junit.Test) ChangeLogCommandTckTest(org.apache.maven.scm.tck.command.changelog.ChangeLogCommandTckTest)

Example 3 with ChangeSet

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

the class ClearCaseChangeLogConsumer method processGetFile.

// ----------------------------------------------------------------------
// 
// ----------------------------------------------------------------------
/**
 * Process the current input line in the Get File state.
 *
 * @param line a line of text from the clearcase log output
 */
private void processGetFile(String line) {
    if (line.startsWith(NAME_TAG)) {
        setCurrentChange(new ChangeSet());
        setCurrentFile(new ChangeFile(line.substring(NAME_TAG.length(), line.length())));
        setStatus(GET_DATE);
    }
}
Also used : ChangeFile(org.apache.maven.scm.ChangeFile) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 4 with ChangeSet

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

the class ChangeLogCommandTckTest method testChangeLogCommand.

public void testChangeLogCommand() throws Exception {
    Thread.sleep(1000);
    ScmProvider provider = getScmManager().getProviderByRepository(getScmRepository());
    ScmFileSet fileSet = new ScmFileSet(getWorkingCopy());
    ChangeLogScmResult firstResult = provider.changeLog(getScmRepository(), fileSet, null, null, 0, (ScmBranch) null, null);
    assertTrue(firstResult.getProviderMessage() + ": " + firstResult.getCommandLine() + "\n" + firstResult.getCommandOutput(), firstResult.isSuccess());
    // for svn, cvs, git, the repo get recreated for each test and therefore initial changelog size is 1
    // for SCM like perforce, it is not possible to recreate the repo, therefor the size will be greater then 1
    int firstLogSize = firstResult.getChangeLog().getChangeSets().size();
    assertTrue("Unexpected initial log size", firstLogSize >= 1);
    // Make a timestamp that we know are after initial revision but before the second
    // Current time
    Date timeBeforeSecond = new Date();
    // pause a couple seconds... [SCM-244]
    Thread.sleep(2000);
    // Make a change to the readme.txt and commit the change
    this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
    ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
    CheckInScmResult checkInResult = provider.checkIn(getScmRepository(), fileSet, COMMIT_MSG);
    assertTrue("Unable to checkin changes to the repository", checkInResult.isSuccess());
    ChangeLogScmResult secondResult = provider.changeLog(getScmRepository(), fileSet, (ScmVersion) null, null);
    assertTrue(secondResult.getProviderMessage(), secondResult.isSuccess());
    assertEquals(firstLogSize + 1, secondResult.getChangeLog().getChangeSets().size());
    // Now only retrieve the changelog after timeBeforeSecondChangeLog
    Date currentTime = new Date();
    ChangeLogScmResult thirdResult = provider.changeLog(getScmRepository(), fileSet, timeBeforeSecond, currentTime, 0, new ScmBranch(""));
    // Thorough assert of the last result
    assertTrue(thirdResult.getProviderMessage(), thirdResult.isSuccess());
    assertEquals(1, thirdResult.getChangeLog().getChangeSets().size());
    ChangeSet changeset = thirdResult.getChangeLog().getChangeSets().get(0);
    assertTrue(changeset.getDate().after(timeBeforeSecond));
    assertEquals(COMMIT_MSG, changeset.getComment());
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmBranch(org.apache.maven.scm.ScmBranch) ScmFileSet(org.apache.maven.scm.ScmFileSet) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) ChangeSet(org.apache.maven.scm.ChangeSet) Date(java.util.Date)

Example 5 with ChangeSet

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

the class PerforceChangeLogConsumer method processGetRevision.

/**
 * Most of the relevant info is on the revision line matching the
 * 'pattern' string.
 *
 * @param line A line of text from the perforce log output
 */
private void processGetRevision(String line) {
    if (line.startsWith(FILE_BEGIN_TOKEN)) {
        currentFile = line.substring(repoPath.length() + 1);
        return;
    }
    Matcher matcher = PATTERN.matcher(line);
    if (!matcher.find()) {
        return;
    }
    currentChange = new ChangeSet();
    currentChange.setRevision(matcher.group(1));
    currentChange.setDate(parseDate(matcher.group(3), userDatePattern, PERFORCE_TIMESTAMP_PATTERN));
    currentChange.setAuthor(matcher.group(4));
    status = GET_COMMENT_BEGIN;
}
Also used : Matcher(java.util.regex.Matcher) 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