Search in sources :

Example 6 with Transaction

use of org.apache.maven.scm.provider.accurev.Transaction in project maven-scm by apache.

the class AccurevUpdateCommandTest method testUpdateWithChangeLog.

@Test
public void testUpdateWithChangeLog() throws Exception {
    final WorkSpace wsBefore = new WorkSpace("theWorkSpace", 123);
    Map<String, WorkSpace> workspaces = Collections.singletonMap("theWorkSpace", wsBefore);
    when(accurev.showWorkSpaces()).thenReturn(workspaces);
    List<File> emptyList = Collections.emptyList();
    when(accurev.update(eq(basedir), any(String.class))).thenReturn(emptyList);
    final Date currentDate = new Date();
    List<Transaction> transactions = Collections.singletonList(new Transaction(197L, currentDate, "type", "user"));
    when(accurev.history(any(String.class), any(String.class), any(String.class), eq(1), eq(true), eq(true))).thenReturn(transactions);
    AccuRevUpdateCommand command = new AccuRevUpdateCommand(getLogger());
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setString(CommandParameter.RUN_CHANGELOG_WITH_UPDATE, Boolean.toString(true));
    UpdateScmResult result = command.update(repo, testFileSet, commandParameters);
    assertThat(result.isSuccess(), is(true));
    assertThat(result, IsInstanceOf.instanceOf(AccuRevUpdateScmResult.class));
    AccuRevUpdateScmResult accuRevResult = (AccuRevUpdateScmResult) result;
    assertThat(accuRevResult.getFromRevision(), is("theWorkSpace/123"));
    assertThat(accuRevResult.getToRevision(), is("theWorkSpace/197"));
}
Also used : WorkSpace(org.apache.maven.scm.provider.accurev.WorkSpace) Transaction(org.apache.maven.scm.provider.accurev.Transaction) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) CommandParameters(org.apache.maven.scm.CommandParameters) File(java.io.File) ScmFileMatcher.assertHasScmFile(org.apache.maven.scm.ScmFileMatcher.assertHasScmFile) Date(java.util.Date) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 7 with Transaction

use of org.apache.maven.scm.provider.accurev.Transaction in project maven-scm by apache.

the class AccuRevChangeLogCommandTest method testWorkspaceChangelog.

@Test
public void testWorkspaceChangelog() throws Exception {
    final ScmFileSet testFileSet = new ScmFileSet(new File(basedir, "project/dir"));
    final Date keepWhen = getDate(2009, 0, 2, 9, 0, 0, null);
    final Date promoteWhen = getDate(2009, 0, 4, 23, 0, 0, null);
    final Date fromDate = getDate(2009, 0, 1, 0, 0, 0, null);
    final Date toDate = getDate(2009, 0, 5, 1, 0, 0, null);
    // start tran (35)
    List<Transaction> startTransaction = Collections.singletonList(new Transaction(35L, fromDate, "sometran", "anyone"));
    when(accurev.history("workspace5", "35", null, 1, true, true)).thenReturn(startTransaction);
    // end tran (42)
    List<Transaction> endTransaction = Collections.singletonList(new Transaction(42L, toDate, "sometran", "anyone"));
    when(accurev.history("workspace5", "42", null, 1, true, true)).thenReturn(endTransaction);
    // Stream hierarchy
    // S2 < S4, S2 < WS3, S4 < WS5, S4 << WS7
    // 
    // Changelog(WS5,35,42) involves
    // -- diff(S4,35,42)
    // -- hist(WS5,36-42)
    // -- hist(S4,36-42)
    // 
    // Promote S4 to S2 - not in diffS4, not in histS4, not in hist WS5 -
    // not in changeset
    // Promote WS3 to S2 - in diffS4, not hist histS4, not in hist WS5 - in
    // "upstream changes"
    // Promote WS5 to S4 - in diffS4, in histS4, not in hist WS5 - not in
    // changeset (real version from WS5)
    // Promote WS7 to S4 - in diffS4, in histS4, not in hist WS5 - in
    // changeset as a promote transaction
    // Keep WS5 - not in diffS4, not in histS4, in histWS5 - in changeset as
    // a keep transaction
    // This workspace is stream 5, attached to basis mystream 5
    Stream workspaceStream = new Stream("workspace5", 5, "stream4", 4, "myDepot", getDate(2008, 10, 1, 10, 0, 0, null), "workspace");
    when(accurev.showStream("workspace5")).thenReturn(workspaceStream);
    Stream basisStream = new Stream("stream4", 4, "myDepot", 1, "myDepot", getDate(2008, 1, 1), "normal");
    when(accurev.showStream("stream4")).thenReturn(basisStream);
    // now we call diff between the tran ids - 35 to 42
    FileDifference diffWS3toS2 = new FileDifference(32L, "/promoted/WS3toS2", "3/2", "/promoted/WS3toS2", "6/1");
    FileDifference diffWS5toS4 = new FileDifference(54L, "/promoted/WS5toS4", "5/3", "/promoted/WS5toS4", "8/1");
    FileDifference diffWS7toS4 = new FileDifference(74L, "/promoted/WS7toS4", "7/12", "/promoted/WS7toS4", "3/13");
    when(accurev.diff("stream4", "35", "42")).thenReturn(Arrays.asList(diffWS3toS2, diffWS5toS4, diffWS7toS4));
    // and we call hist for tranid + 1 to end trand ii
    Transaction promoteWS5toS4 = new Transaction(37L, promoteWhen, "promote", "aUser");
    promoteWS5toS4.setComment("WS5toS4");
    promoteWS5toS4.addVersion(54L, "/./promoted/WS5toS4", "4/5", "5/3", "3/2");
    Transaction promoteWS7toS4 = new Transaction(38L, promoteWhen, "promote", "aUser");
    promoteWS7toS4.setComment("WS7toS4");
    promoteWS7toS4.addVersion(74L, "/./promoted/WS7toS4", "4/11", "7/12", "3/2");
    when(accurev.history("stream4", "36", "42", 0, false, false)).thenReturn(Arrays.asList(promoteWS5toS4, promoteWS7toS4));
    Transaction keepWS5 = new Transaction(39L, keepWhen, "keep", "anOther");
    keepWS5.addVersion(5L, "/./kept/WS5", "5/7", "5/7", "7/21");
    keepWS5.setComment("keepWS5");
    when(accurev.history("workspace5", "36", "42", 0, false, false)).thenReturn(Collections.singletonList(keepWS5));
    AccuRevChangeLogCommand command = new AccuRevChangeLogCommand(getLogger());
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setScmVersion(CommandParameter.START_SCM_VERSION, new ScmRevision("workspace5/35"));
    commandParameters.setScmVersion(CommandParameter.END_SCM_VERSION, new ScmRevision("workspace5/42"));
    ChangeLogScmResult result = command.changelog(repo, testFileSet, commandParameters);
    assertThat(result.isSuccess(), is(true));
    ChangeLogSet changelog = result.getChangeLog();
    assertThat(changelog.getStartVersion().getName(), is("workspace5/35"));
    assertThat(changelog.getEndVersion().getName(), is("workspace5/42"));
    List<ChangeSet> changesets = changelog.getChangeSets();
    assertThat(changesets.size(), is(3));
    for (ChangeSet changeSet : changesets) {
        assertThat(changeSet.getComment(), isOneOf("Upstream changes", "WS7toS4", "keepWS5"));
        if ("Upstream changes".equals(changeSet.getComment())) {
            assertThat(changeSet.getFiles().size(), is(1));
            ChangeFile changeFile = (ChangeFile) changeSet.getFiles().get(0);
            assertThat(changeFile, is(changeFile("/promoted/WS3toS2")));
        }
    }
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) ScmRevision(org.apache.maven.scm.ScmRevision) 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 8 with Transaction

use of org.apache.maven.scm.provider.accurev.Transaction 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 9 with Transaction

use of org.apache.maven.scm.provider.accurev.Transaction in project maven-scm by apache.

the class AccuRevChangeLogCommand method getChangeLog.

private ChangeLogSet getChangeLog(Stream stream, List<FileDifference> streamDifferences, List<Transaction> streamHistory, List<Transaction> workspaceHistory, Date startDate, Date endDate) {
    // Collect all the "to" versions from the streamDifferences into a Map by element id
    // If that version is seen in the promote/keep history then we move it from the map
    // At the end we create a pseudo ChangeSet for any remaining entries in the map as
    // representing "upstream changes"
    Map<Long, FileDifference> differencesMap = new HashMap<Long, FileDifference>();
    for (FileDifference fileDifference : streamDifferences) {
        differencesMap.put(fileDifference.getElementId(), fileDifference);
    }
    List<Transaction> mergedHistory = new ArrayList<Transaction>(streamHistory);
    // will never match a version
    String streamPrefix = "/";
    mergedHistory.addAll(workspaceHistory);
    streamPrefix = stream.getId() + "/";
    List<ChangeSet> entries = new ArrayList<ChangeSet>(streamHistory.size());
    for (Transaction t : mergedHistory) {
        if ((startDate != null && t.getWhen().before(startDate)) || (endDate != null && t.getWhen().after(endDate))) {
            // This is possible if dates and transactions are mixed in the time spec.
            continue;
        }
        // the history of this stream.
        if ("mkstream".equals(t.getTranType())) {
            continue;
        }
        Collection<Version> versions = t.getVersions();
        List<ChangeFile> files = new ArrayList<ChangeFile>(versions.size());
        for (Version v : versions) {
            // Remove diff representing this promote
            FileDifference difference = differencesMap.get(v.getElementId());
            // TODO: how are defuncts shown in the version history?
            if (difference != null) {
                String newVersionSpec = difference.getNewVersionSpec();
                if (newVersionSpec != null && newVersionSpec.equals(v.getRealSpec())) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("Removing difference for " + v);
                    }
                    differencesMap.remove(v.getElementId());
                }
            }
            // to its basis stream, and is therefore NOT a change
            if (v.getRealSpec().startsWith(streamPrefix) && !v.getVirtualSpec().startsWith(streamPrefix)) {
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Skipping workspace to basis stream promote " + v);
                }
            } else {
                ChangeFile f = new ChangeFile(v.getElementName(), v.getVirtualSpec() + " (" + v.getRealSpec() + ")");
                files.add(f);
            }
        }
        if (versions.isEmpty() || !files.isEmpty()) {
            ChangeSet changeSet = new ChangeSet(t.getWhen(), t.getComment(), t.getAuthor(), files);
            entries.add(changeSet);
        } else {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("All versions removed for " + t);
            }
        }
    }
    // detect these for CI tools like Continuum
    if (!differencesMap.isEmpty()) {
        List<ChangeFile> upstreamFiles = new ArrayList<ChangeFile>();
        for (FileDifference difference : differencesMap.values()) {
            if (difference.getNewVersionSpec() != null) {
                upstreamFiles.add(new ChangeFile(difference.getNewFile().getPath(), difference.getNewVersionSpec()));
            } else {
                // difference is a deletion
                upstreamFiles.add(new ChangeFile(difference.getOldFile().getPath(), null));
            }
        }
        entries.add(new ChangeSet(endDate, "Upstream changes", "various", upstreamFiles));
    }
    return new ChangeLogSet(entries, startDate, endDate);
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Transaction(org.apache.maven.scm.provider.accurev.Transaction) Version(org.apache.maven.scm.provider.accurev.Transaction.Version) AccuRevVersion(org.apache.maven.scm.provider.accurev.AccuRevVersion) ScmVersion(org.apache.maven.scm.ScmVersion) ChangeFile(org.apache.maven.scm.ChangeFile) FileDifference(org.apache.maven.scm.provider.accurev.FileDifference) ChangeSet(org.apache.maven.scm.ChangeSet)

Aggregations

Transaction (org.apache.maven.scm.provider.accurev.Transaction)9 Date (java.util.Date)8 Test (org.junit.Test)6 File (java.io.File)5 ChangeFile (org.apache.maven.scm.ChangeFile)5 CommandParameters (org.apache.maven.scm.CommandParameters)5 FileDifference (org.apache.maven.scm.provider.accurev.FileDifference)5 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)5 ChangeFileMatcher.changeFile (org.apache.maven.scm.ChangeFileMatcher.changeFile)4 ScmFileSet (org.apache.maven.scm.ScmFileSet)4 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)4 Stream (org.apache.maven.scm.provider.accurev.Stream)4 ChangeSet (org.apache.maven.scm.ChangeSet)3 ScmRevision (org.apache.maven.scm.ScmRevision)3 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)3 ArrayList (java.util.ArrayList)2 ScmVersion (org.apache.maven.scm.ScmVersion)2 AccuRevVersion (org.apache.maven.scm.provider.accurev.AccuRevVersion)2 HashMap (java.util.HashMap)1 ScmBranch (org.apache.maven.scm.ScmBranch)1