Search in sources :

Example 1 with ScmRevision

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

the class AccuRevCheckOutCommandTest method testCheckoutToVersionExistingWorkspace.

@Test
public void testCheckoutToVersionExistingWorkspace() throws Exception {
    // Set the info result to return a workspace that already exists
    info.setWorkSpace("someOldStream_someUser");
    info.setBasis("myStream");
    info.setTop(basedir.getAbsolutePath());
    List<File> emptyList = Collections.emptyList();
    when(accurev.pop(basedir, null)).thenReturn(emptyList);
    List<File> updatedFiles = Collections.singletonList(new File("updated/file"));
    when(accurev.update(basedir, "12")).thenReturn(updatedFiles);
    AccuRevCheckOutCommand command = new AccuRevCheckOutCommand(getLogger());
    CommandParameters parameters = new CommandParameters();
    parameters.setScmVersion(CommandParameter.SCM_VERSION, new ScmRevision("myStream/12"));
    CheckOutScmResult result = command.checkout(repo, new ScmFileSet(basedir), parameters);
    verify(accurev).pop(basedir, null);
    assertThat(result.isSuccess(), is(true));
    assertThat(result.getCheckedOutFiles().size(), is(1));
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmRevision(org.apache.maven.scm.ScmRevision) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) CommandParameters(org.apache.maven.scm.CommandParameters) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFileMatcher.assertHasScmFile(org.apache.maven.scm.ScmFileMatcher.assertHasScmFile) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 2 with ScmRevision

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

use of org.apache.maven.scm.ScmRevision 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 ScmRevision

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

the class AccuRevScmProvider method update.

@Override
protected UpdateScmResult update(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    AccuRevScmProviderRepository accurevRepo = (AccuRevScmProviderRepository) repository;
    AccuRevUpdateCommand command = new AccuRevUpdateCommand(getLogger());
    UpdateScmResult result = command.update(repository, fileSet, parameters);
    if (result.isSuccess() && parameters.getBoolean(CommandParameter.RUN_CHANGELOG_WITH_UPDATE)) {
        AccuRevUpdateScmResult accuRevResult = (AccuRevUpdateScmResult) result;
        ScmRevision fromRevision = new ScmRevision(accuRevResult.getFromRevision());
        ScmRevision toRevision = new ScmRevision(accuRevResult.getToRevision());
        parameters.setScmVersion(CommandParameter.START_SCM_VERSION, fromRevision);
        parameters.setScmVersion(CommandParameter.END_SCM_VERSION, toRevision);
        AccuRevVersion startVersion = accurevRepo.getAccuRevVersion(fromRevision);
        AccuRevVersion endVersion = accurevRepo.getAccuRevVersion(toRevision);
        if (startVersion.getBasisStream().equals(endVersion.getBasisStream())) {
            ChangeLogScmResult changeLogResult = changelog(repository, fileSet, parameters);
            if (changeLogResult.isSuccess()) {
                result.setChanges(changeLogResult.getChangeLog().getChangeSets());
            } else {
                getLogger().warn("Changelog from " + fromRevision + " to " + toRevision + " failed");
            }
        } else {
            String comment = "Cross stream update result from " + startVersion + " to " + endVersion;
            String author = "";
            List<ScmFile> files = result.getUpdatedFiles();
            List<ChangeFile> changeFiles = new ArrayList<ChangeFile>(files.size());
            for (ScmFile scmFile : files) {
                changeFiles.add(new ChangeFile(scmFile.getPath()));
            }
            ChangeSet dummyChangeSet = new ChangeSet(new Date(), comment, author, changeFiles);
            // different streams invalidates the change log, insert a dummy change instead.
            List<ChangeSet> changeSets = Collections.singletonList(dummyChangeSet);
            result.setChanges(changeSets);
        }
    }
    return result;
}
Also used : AccuRevUpdateScmResult(org.apache.maven.scm.provider.accurev.command.update.AccuRevUpdateScmResult) ScmRevision(org.apache.maven.scm.ScmRevision) AccuRevUpdateScmResult(org.apache.maven.scm.provider.accurev.command.update.AccuRevUpdateScmResult) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ArrayList(java.util.ArrayList) Date(java.util.Date) ScmFile(org.apache.maven.scm.ScmFile) AccuRevUpdateCommand(org.apache.maven.scm.provider.accurev.command.update.AccuRevUpdateCommand) ChangeFile(org.apache.maven.scm.ChangeFile) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 5 with ScmRevision

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

the class AbstractScmProvider method diff.

/**
 * {@inheritDoc}
 *
 * @deprecated
 */
public DiffScmResult diff(ScmRepository repository, ScmFileSet fileSet, String startRevision, String endRevision) throws ScmException {
    ScmVersion startVersion = null;
    ScmVersion endVersion = null;
    if (StringUtils.isNotEmpty(startRevision)) {
        startVersion = new ScmRevision(startRevision);
    }
    if (StringUtils.isNotEmpty(endRevision)) {
        endVersion = new ScmRevision(endRevision);
    }
    return diff(repository, fileSet, startVersion, endVersion);
}
Also used : ScmRevision(org.apache.maven.scm.ScmRevision) ScmVersion(org.apache.maven.scm.ScmVersion)

Aggregations

ScmRevision (org.apache.maven.scm.ScmRevision)28 File (java.io.File)12 ScmFileSet (org.apache.maven.scm.ScmFileSet)12 Commandline (org.codehaus.plexus.util.cli.Commandline)10 Date (java.util.Date)5 CommandParameters (org.apache.maven.scm.CommandParameters)5 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)5 Test (org.junit.Test)5 ChangeFile (org.apache.maven.scm.ChangeFile)4 ScmException (org.apache.maven.scm.ScmException)4 ScmFile (org.apache.maven.scm.ScmFile)4 ScmVersion (org.apache.maven.scm.ScmVersion)4 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)4 ScmRepository (org.apache.maven.scm.repository.ScmRepository)4 ChangeFileMatcher.changeFile (org.apache.maven.scm.ChangeFileMatcher.changeFile)3 ScmBranch (org.apache.maven.scm.ScmBranch)3 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)3 FileDifference (org.apache.maven.scm.provider.accurev.FileDifference)3 Stream (org.apache.maven.scm.provider.accurev.Stream)3 Transaction (org.apache.maven.scm.provider.accurev.Transaction)3