Search in sources :

Example 1 with AccuRev

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

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

the class AccuRevCheckOutCommand method extractSource.

@Override
protected List<File> extractSource(AccuRevScmProviderRepository repository, File basedir, AccuRevVersion version) throws AccuRevException {
    AccuRev accuRev = repository.getAccuRev();
    AccuRevInfo info = accuRev.info(basedir);
    List<File> extractedFiles = new ArrayList<File>();
    String basisStream = version.getBasisStream();
    String transactionId = version.getTimeSpec();
    boolean success = true;
    if (info.isWorkSpace()) {
        if (!repository.isWorkSpaceTop(info)) {
            throw new AccuRevException(String.format("Can't checkout to %s, " + "a subdirectory of existing workspace %s", basedir, info.getWorkSpace()));
        }
        // workspace exists at this basedir already.
        if (!basisStream.equals(info.getBasis())) {
            // different basis, reparent.
            success = accuRev.chws(basedir, info.getWorkSpace(), basisStream);
        }
        if (success) {
            // repopulate everything in the workspace.
            // note we do NOT want -t here, we just fill in any missing files
            // to the current transaction watermark...
            // the update later on will get the extra files
            List<File> poppedFiles = accuRev.pop(basedir, null);
            if (poppedFiles != null) {
                extractedFiles.addAll(poppedFiles);
            } else {
                success = false;
            }
        }
    } else {
        // not a workspace, make one...
        // TODO set incl rules to only include the projectPath
        // TODO somehow set provider message (via throw exception?
        // if basisStream is null
        String workSpaceName = getWorkSpaceName(basedir, basisStream);
        success = accuRev.mkws(basisStream, workSpaceName, basedir);
        // Even though a new workspace starts with "0" as the high water mark
        // it can't be updated to anything less than its own mkstream transaction
        // now is close enough since even if something does sneak inbetween we
        // were just lucky that it didn't happen before...
        transactionId = "now";
        if (success) {
            getLogger().info("Created workspace " + workSpaceName);
        }
    }
    if (success) {
        List<File> updatedFiles = accuRev.update(basedir, transactionId);
        if (updatedFiles != null) {
            extractedFiles.addAll(updatedFiles);
        } else {
            success = false;
        }
    }
    return success ? extractedFiles : null;
}
Also used : AccuRev(org.apache.maven.scm.provider.accurev.AccuRev) AccuRevException(org.apache.maven.scm.provider.accurev.AccuRevException) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) AccuRevInfo(org.apache.maven.scm.provider.accurev.AccuRevInfo)

Example 3 with AccuRev

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

the class AccuRevStatusCommand method executeAccurevCommand.

@Override
protected ScmResult executeAccurevCommand(AccuRevScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException, AccuRevException {
    AccuRev accuRev = repository.getAccuRev();
    File basedir = fileSet.getBasedir();
    List<File> elements = fileSet.getFileList();
    List<File> defunctElements = accuRev.stat(basedir, elements, AccuRevStat.DEFUNCT);
    if (defunctElements == null) {
        return error(accuRev, "Failed retrieving defunct elements");
    }
    List<File> keptElements = accuRev.stat(basedir, elements, AccuRevStat.KEPT);
    // Defunct elements are also listed as kept (AccuRev 4.7.1), exclude those here.
    if (keptElements == null) {
        return error(accuRev, "Failed retrieving kept elements");
    }
    List<File> modOrAddedElements = new ArrayList<File>();
    for (File file : keptElements) {
        if (!defunctElements.contains(file)) {
            modOrAddedElements.add(file);
        }
    }
    List<File> modifiedElements = accuRev.stat(basedir, elements, AccuRevStat.MODIFIED);
    if (modifiedElements == null) {
        return error(accuRev, "Failed retrieving modified elements");
    }
    modOrAddedElements.addAll(modifiedElements);
    CategorisedElements catElems = accuRev.statBackingStream(basedir, modOrAddedElements);
    if (catElems == null) {
        return error(accuRev, "Failed stat backing stream to split modified and added elements");
    }
    modifiedElements = catElems.getMemberElements();
    List<File> addedElements;
    if (AccuRevCapability.STAT_ADDED_NOT_PROMOTED_BUG.isSupported(accuRev.getClientVersion())) {
        modOrAddedElements.removeAll(modifiedElements);
        addedElements = modOrAddedElements;
    } else {
        addedElements = catElems.getNonMemberElements();
    }
    List<File> missingElements = accuRev.stat(basedir, elements, AccuRevStat.MISSING);
    if (missingElements == null) {
        return error(accuRev, "Failed retrieving missing elements");
    }
    List<File> externalElements = accuRev.stat(basedir, elements, AccuRevStat.EXTERNAL);
    if (externalElements == null) {
        return error(accuRev, "Failed retrieving external elements");
    }
    List<ScmFile> resultFiles = getScmFiles(defunctElements, ScmFileStatus.DELETED);
    resultFiles.addAll(getScmFiles(modifiedElements, ScmFileStatus.MODIFIED));
    resultFiles.addAll(getScmFiles(addedElements, ScmFileStatus.ADDED));
    resultFiles.addAll(getScmFiles(missingElements, ScmFileStatus.MISSING));
    resultFiles.addAll(getScmFiles(externalElements, ScmFileStatus.UNKNOWN));
    return new StatusScmResult(accuRev.getCommandLines(), resultFiles);
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) AccuRev(org.apache.maven.scm.provider.accurev.AccuRev) ArrayList(java.util.ArrayList) CategorisedElements(org.apache.maven.scm.provider.accurev.CategorisedElements) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 4 with AccuRev

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

the class AccuRevRemoveCommand method executeAccurevCommand.

@Override
protected ScmResult executeAccurevCommand(AccuRevScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException, AccuRevException {
    AccuRev accuRev = repository.getAccuRev();
    String message = parameters.getString(CommandParameter.MESSAGE, "");
    File basedir = fileSet.getBasedir();
    List<File> relativeFiles = fileSet.getFileList();
    final List<File> removedFiles = accuRev.defunct(basedir, relativeFiles, message);
    if (removedFiles != null) {
        List<ScmFile> resultFiles = getScmFiles(removedFiles, ScmFileStatus.DELETED);
        return new RemoveScmResult(accuRev.getCommandLines(), resultFiles);
    } else {
        return new RemoveScmResult(accuRev.getCommandLines(), "AccuRev Error", accuRev.getErrorOutput(), false);
    }
}
Also used : AccuRev(org.apache.maven.scm.provider.accurev.AccuRev) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) RemoveScmResult(org.apache.maven.scm.command.remove.RemoveScmResult) ScmFile(org.apache.maven.scm.ScmFile)

Example 5 with AccuRev

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

the class AccuRevTagCommand method executeAccurevCommand.

@Override
protected ScmResult executeAccurevCommand(AccuRevScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException, AccuRevException {
    AccuRev accuRev = repository.getAccuRev();
    String snapshotName = parameters.getString(CommandParameter.TAG_NAME);
    snapshotName = repository.getSnapshotName(snapshotName);
    File basedir = fileSet.getBasedir();
    boolean success = true;
    AccuRevInfo info = accuRev.info(basedir);
    List<File> taggedFiles = null;
    success = accuRev.mksnap(snapshotName, info.getBasis());
    if (success) {
        taggedFiles = accuRev.statTag(snapshotName);
    }
    if (success && taggedFiles != null) {
        return new TagScmResult(accuRev.getCommandLines(), getScmFiles(taggedFiles, ScmFileStatus.TAGGED));
    } else {
        return new TagScmResult(accuRev.getCommandLines(), "AccuRev error", accuRev.getErrorOutput(), false);
    }
}
Also used : AccuRev(org.apache.maven.scm.provider.accurev.AccuRev) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) File(java.io.File) AccuRevInfo(org.apache.maven.scm.provider.accurev.AccuRevInfo)

Aggregations

AccuRev (org.apache.maven.scm.provider.accurev.AccuRev)11 File (java.io.File)9 AccuRevInfo (org.apache.maven.scm.provider.accurev.AccuRevInfo)6 ScmFile (org.apache.maven.scm.ScmFile)5 AccuRevException (org.apache.maven.scm.provider.accurev.AccuRevException)4 ArrayList (java.util.ArrayList)2 ScmException (org.apache.maven.scm.ScmException)2 ScmVersion (org.apache.maven.scm.ScmVersion)2 AccuRevVersion (org.apache.maven.scm.provider.accurev.AccuRevVersion)2 Date (java.util.Date)1 ScmBranch (org.apache.maven.scm.ScmBranch)1 ScmRevision (org.apache.maven.scm.ScmRevision)1 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)1 BlameLine (org.apache.maven.scm.command.blame.BlameLine)1 BlameScmResult (org.apache.maven.scm.command.blame.BlameScmResult)1 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)1 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)1 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)1 LoginScmResult (org.apache.maven.scm.command.login.LoginScmResult)1 RemoveScmResult (org.apache.maven.scm.command.remove.RemoveScmResult)1