Search in sources :

Example 1 with Stream

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

the class AccuRevChangeLogCommandTest method testChangeLogToNow.

@Test
public void testChangeLogToNow() throws Exception {
    final ScmFileSet testFileSet = new ScmFileSet(new File(basedir, "project/dir"));
    // start tran (35)
    List<Transaction> startTransaction = Collections.singletonList(new Transaction(35L, new Date(), "sometran", "anyone"));
    when(accurev.history("aStream", "12", null, 1, true, true)).thenReturn(startTransaction);
    // end tran (42)
    List<Transaction> endTransaction = Collections.singletonList(new Transaction(42L, new Date(), "sometran", "anyone"));
    when(accurev.history("aStream", "now", null, 1, true, true)).thenReturn(endTransaction);
    Stream basisStream = new Stream("aStream", 10, "myDepot", 1, "myDepot", getDate(2008, 1, 1), "normal");
    when(accurev.showStream("aStream")).thenReturn(basisStream);
    List<FileDifference> emptyList = Collections.emptyList();
    when(accurev.diff("myStream", "12", "42")).thenReturn(emptyList);
    List<Transaction> noTransactions = Collections.emptyList();
    when(accurev.history("aStream", "13", "42", 0, false, false)).thenReturn(noTransactions);
    AccuRevChangeLogCommand command = new AccuRevChangeLogCommand(getLogger());
    CommandParameters params = new CommandParameters();
    params.setScmVersion(CommandParameter.START_SCM_VERSION, new ScmRevision("aStream/12"));
    assertThat(command.changelog(repo, testFileSet, params), not(nullValue()));
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) Transaction(org.apache.maven.scm.provider.accurev.Transaction) ScmRevision(org.apache.maven.scm.ScmRevision) Stream(org.apache.maven.scm.provider.accurev.Stream) 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) Date(java.util.Date) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 2 with Stream

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

the class StreamsConsumerTest method testname.

@Test
public void testname() throws Exception {
    List<Stream> streams = new ArrayList<Stream>();
    XppStreamConsumer consumer = new StreamsConsumer(new DefaultLog(), streams);
    AccuRevJUnitUtil.consume("/showstreams.xml", consumer);
    assertThat(streams.size(), is(5));
    Stream s = streams.get(2);
    /*
         * <stream name="mvnscm_1275484086_initRepo_ggardner" basis="mvnscm_1275484086_tckTests" basisStreamNumber="2"
         * depotName="mvnscm_1275484086" streamNumber="3" isDynamic="false" type="workspace" startTime="1275484091"
         * hidden="true"/>
         */
    assertThat(s.getBasis(), is("mvnscm_1275484086_tckTests"));
    assertThat(s.getId(), is(3L));
    assertThat(s.getBasisId(), is(2L));
    assertThat(s.getName(), is("mvnscm_1275484086_initRepo_ggardner"));
    assertThat(s.getStartDate(), is(new Date(1275484091L * 1000L)));
    assertThat(s.getStreamType(), is("workspace"));
    assertThat(s.isWorkspace(), is(true));
}
Also used : DefaultLog(org.apache.maven.scm.log.DefaultLog) ArrayList(java.util.ArrayList) Stream(org.apache.maven.scm.provider.accurev.Stream) Date(java.util.Date) Test(org.junit.Test)

Example 3 with Stream

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

the class AccuRevChangeLogCommand method executeAccurevCommand.

@Override
protected ScmResult executeAccurevCommand(AccuRevScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException, AccuRevException {
    // Do we have a supplied branch. If not we default to the URL stream.
    ScmBranch branch = (ScmBranch) parameters.getScmVersion(CommandParameter.BRANCH, null);
    AccuRevVersion branchVersion = repository.getAccuRevVersion(branch);
    String stream = branchVersion.getBasisStream();
    String fromSpec = branchVersion.getTimeSpec();
    String toSpec = "highest";
    // Versions
    ScmVersion startVersion = parameters.getScmVersion(CommandParameter.START_SCM_VERSION, null);
    ScmVersion endVersion = parameters.getScmVersion(CommandParameter.END_SCM_VERSION, null);
    if (startVersion != null && StringUtils.isNotEmpty(startVersion.getName())) {
        AccuRevVersion fromVersion = repository.getAccuRevVersion(startVersion);
        // if no end version supplied then use same basis as startVersion
        AccuRevVersion toVersion = endVersion == null ? new AccuRevVersion(fromVersion.getBasisStream(), "now") : repository.getAccuRevVersion(endVersion);
        if (!StringUtils.equals(fromVersion.getBasisStream(), toVersion.getBasisStream())) {
            throw new AccuRevException("Not able to provide change log between different streams " + fromVersion + "," + toVersion);
        }
        stream = fromVersion.getBasisStream();
        fromSpec = fromVersion.getTimeSpec();
        toSpec = toVersion.getTimeSpec();
    }
    Date startDate = parameters.getDate(CommandParameter.START_DATE, null);
    Date endDate = parameters.getDate(CommandParameter.END_DATE, null);
    int numDays = parameters.getInt(CommandParameter.NUM_DAYS, 0);
    if (numDays > 0) {
        if ((startDate != null || endDate != null)) {
            throw new ScmException("Start or end date cannot be set if num days is set.");
        }
        // Last x days.
        int day = 24 * 60 * 60 * 1000;
        startDate = new Date(System.currentTimeMillis() - (long) numDays * day);
        endDate = new Date(System.currentTimeMillis() + day);
    }
    if (endDate != null && startDate == null) {
        throw new ScmException("The end date is set but the start date isn't.");
    }
    // Date parameters override transaction ids in versions
    if (startDate != null) {
        fromSpec = AccuRevScmProviderRepository.formatTimeSpec(startDate);
    } else if (fromSpec == null) {
        fromSpec = "1";
    }
    // Convert the fromSpec to both a date AND a transaction id by looking up
    // the nearest transaction in the depot.
    Transaction fromTransaction = getDepotTransaction(repository, stream, fromSpec);
    long fromTranId = 1;
    if (fromTransaction != null) {
        // This tran id is less than or equal to the date/tranid we requested.
        fromTranId = fromTransaction.getTranId();
        if (startDate == null) {
            startDate = fromTransaction.getWhen();
        }
    }
    if (endDate != null) {
        toSpec = AccuRevScmProviderRepository.formatTimeSpec(endDate);
    } else if (toSpec == null) {
        toSpec = "highest";
    }
    Transaction toTransaction = getDepotTransaction(repository, stream, toSpec);
    long toTranId = 1;
    if (toTransaction != null) {
        toTranId = toTransaction.getTranId();
        if (endDate == null) {
            endDate = toTransaction.getWhen();
        }
    }
    startVersion = new ScmRevision(repository.getRevision(stream, fromTranId));
    endVersion = new ScmRevision(repository.getRevision(stream, toTranId));
    // TODO Split this method in two here. above to convert params to start and end (stream,tranid,date) and test independantly
    List<Transaction> streamHistory = Collections.emptyList();
    List<Transaction> workspaceHistory = Collections.emptyList();
    List<FileDifference> streamDifferences = Collections.emptyList();
    StringBuilder errorMessage = new StringBuilder();
    AccuRev accurev = repository.getAccuRev();
    Stream changelogStream = accurev.showStream(stream);
    if (changelogStream == null) {
        errorMessage.append("Unknown accurev stream -").append(stream).append(".");
    } else {
        String message = "Changelog on stream " + stream + "(" + changelogStream.getStreamType() + ") from " + fromTranId + " (" + startDate + "), to " + toTranId + " (" + endDate + ")";
        if (startDate != null && startDate.after(endDate) || fromTranId >= toTranId) {
            getLogger().warn("Skipping out of range " + message);
        } else {
            getLogger().info(message);
            // In 4.7.2 and higher we have a diff command that will list all the file differences in a stream
            // and thus can be used to detect upstream changes
            // Unfortunately diff -v -V -t does not work in workspaces.
            Stream diffStream = changelogStream;
            if (changelogStream.isWorkspace()) {
                workspaceHistory = accurev.history(stream, Long.toString(fromTranId + 1), Long.toString(toTranId), 0, false, false);
                if (workspaceHistory == null) {
                    errorMessage.append("history on workspace " + stream + " from " + fromTranId + 1 + " to " + toTranId + " failed.");
                }
                // do the diff/hist on the basis stream instead.
                stream = changelogStream.getBasis();
                diffStream = accurev.showStream(stream);
            }
            if (AccuRevCapability.DIFF_BETWEEN_STREAMS.isSupported(accurev.getClientVersion())) {
                if (startDate.before(diffStream.getStartDate())) {
                    getLogger().warn("Skipping diff of " + stream + " due to start date out of range");
                } else {
                    streamDifferences = accurev.diff(stream, Long.toString(fromTranId), Long.toString(toTranId));
                    if (streamDifferences == null) {
                        errorMessage.append("Diff " + stream + "- " + fromTranId + " to " + toTranId + "failed.");
                    }
                }
            }
            // History needs to start from the transaction after our starting transaction
            streamHistory = accurev.history(stream, Long.toString(fromTranId + 1), Long.toString(toTranId), 0, false, false);
            if (streamHistory == null) {
                errorMessage.append("history on stream " + stream + " from " + fromTranId + 1 + " to " + toTranId + " failed.");
            }
        }
    }
    String errorString = errorMessage.toString();
    if (StringUtils.isBlank(errorString)) {
        ChangeLogSet changeLog = getChangeLog(changelogStream, streamDifferences, streamHistory, workspaceHistory, startDate, endDate);
        changeLog.setEndVersion(endVersion);
        changeLog.setStartVersion(startVersion);
        return new ChangeLogScmResult(accurev.getCommandLines(), changeLog);
    } else {
        return new ChangeLogScmResult(accurev.getCommandLines(), "AccuRev errors: " + errorMessage, accurev.getErrorOutput(), false);
    }
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) AccuRev(org.apache.maven.scm.provider.accurev.AccuRev) ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) AccuRevException(org.apache.maven.scm.provider.accurev.AccuRevException) ScmRevision(org.apache.maven.scm.ScmRevision) Date(java.util.Date) ScmVersion(org.apache.maven.scm.ScmVersion) Transaction(org.apache.maven.scm.provider.accurev.Transaction) Stream(org.apache.maven.scm.provider.accurev.Stream) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) AccuRevVersion(org.apache.maven.scm.provider.accurev.AccuRevVersion) FileDifference(org.apache.maven.scm.provider.accurev.FileDifference)

Example 4 with Stream

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

the class AbstractAccuRevCommandTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    logger = AccuRevJUnitUtil.getLogger(getContainer());
    basedir = getWorkingCopy();
    sequence = inOrder(accurev);
    info = new AccuRevInfo(basedir);
    info.setUser("me");
    when(accurev.getCommandLines()).thenReturn("accurev mock");
    when(accurev.getErrorOutput()).thenReturn("accurev mock error output");
    when(accurev.getClientVersion()).thenReturn("4.9.0");
    when(accurev.showStream("myStream")).thenReturn(new Stream("myStream", 10L, "myDepot", 1L, "myDepot", new Date(), "normal"));
    when(accurev.info(null)).thenReturn(info);
    when(accurev.info(basedir)).thenReturn(info);
    repo.setLogger(getLogger());
    repo.setStreamName("myStream");
    repo.setAccuRev(accurev);
    repo.setProjectPath("/project/dir");
}
Also used : Stream(org.apache.maven.scm.provider.accurev.Stream) InputStream(java.io.InputStream) Date(java.util.Date) AccuRevInfo(org.apache.maven.scm.provider.accurev.AccuRevInfo) Before(org.junit.Before)

Example 5 with Stream

use of org.apache.maven.scm.provider.accurev.Stream 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)

Aggregations

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