Search in sources :

Example 6 with ScmBranch

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

the class ClearCaseChangeLogCommandTest method testGetCommandLineWithTagAndStartDate.

public void testGetCommandLineWithTagAndStartDate() throws Exception {
    Date startDate = getDate(2003, 8, 10);
    Date endDate = null;
    testCommandLine(new ScmBranch("myBranch"), startDate, endDate, "cleartool lshistory -fmt \"NAME:%En\\nDATE:%Nd\\nCOMM:%-12.12o - %o - %c - Activity: %[activity]p\\nUSER:%u\\nREVI:%Ln\\n\" -recurse -nco -since 10-Sep-2003 -branch myBranch");
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) Date(java.util.Date)

Example 7 with ScmBranch

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

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

the class ChangeLogMojo method execute.

/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException {
    super.execute();
    SimpleDateFormat localFormat = new SimpleDateFormat(userDateFormat);
    try {
        ScmRepository repository = getScmRepository();
        ScmProvider provider = getScmManager().getProviderByRepository(repository);
        ScmVersion startRev = getScmVersion(StringUtils.isEmpty(startScmVersionType) ? "revision" : startScmVersionType, startScmVersion);
        ScmVersion endRev = getScmVersion(StringUtils.isEmpty(endScmVersionType) ? "revision" : endScmVersionType, endScmVersion);
        ChangeLogScmResult result;
        if (startRev != null || endRev != null) {
            result = provider.changeLog(repository, getFileSet(), startRev, endRev, dateFormat);
        } else {
            result = provider.changeLog(repository, getFileSet(), this.parseDate(localFormat, this.startDate), this.parseDate(localFormat, this.endDate), 0, (ScmBranch) getScmVersion(scmVersionType, scmVersion), dateFormat);
        }
        checkResult(result);
        ChangeLogSet changeLogSet = result.getChangeLog();
        for (ChangeSet changeSet : changeLogSet.getChangeSets()) {
            getLog().info(changeSet.toString());
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot run changelog command : ", e);
    } catch (ScmException e) {
        throw new MojoExecutionException("Cannot run changelog command : ", e);
    }
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmBranch(org.apache.maven.scm.ScmBranch) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) ChangeSet(org.apache.maven.scm.ChangeSet) ScmVersion(org.apache.maven.scm.ScmVersion)

Example 9 with ScmBranch

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

the class AbstractChangeLogCommand method executeCommand.

/**
 * {@inheritDoc}
 */
public ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    Date startDate = parameters.getDate(CommandParameter.START_DATE, null);
    Date endDate = parameters.getDate(CommandParameter.END_DATE, null);
    int numDays = parameters.getInt(CommandParameter.NUM_DAYS, 0);
    Integer limit = parameters.getInt(CommandParameter.LIMIT, -1);
    if (limit < 1) {
        limit = null;
    }
    ScmBranch branch = (ScmBranch) parameters.getScmVersion(CommandParameter.BRANCH, null);
    ScmVersion startVersion = parameters.getScmVersion(CommandParameter.START_SCM_VERSION, null);
    ScmVersion endVersion = parameters.getScmVersion(CommandParameter.END_SCM_VERSION, null);
    String datePattern = parameters.getString(CommandParameter.CHANGELOG_DATE_PATTERN, null);
    if (startVersion != null || endVersion != null) {
        return executeChangeLogCommand(repository, fileSet, startVersion, endVersion, datePattern);
    } else {
        if (numDays != 0 && (startDate != null || endDate != null)) {
            throw new ScmException("Start or end date cannot be set if num days is set.");
        }
        if (endDate != null && startDate == null) {
            throw new ScmException("The end date is set but the start date isn't.");
        }
        if (numDays > 0) {
            @SuppressWarnings("checkstyle:magicnumber") int day = 24 * 60 * 60 * 1000;
            startDate = new Date(System.currentTimeMillis() - (long) numDays * day);
            endDate = new Date(System.currentTimeMillis() + (long) day);
        } else if (endDate == null) {
            endDate = new Date();
        }
        return executeChangeLogCommand(repository, fileSet, startDate, endDate, branch, datePattern);
    }
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) ScmException(org.apache.maven.scm.ScmException) Date(java.util.Date) ScmVersion(org.apache.maven.scm.ScmVersion)

Example 10 with ScmBranch

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

the class MavenScmCli method main.

// ----------------------------------------------------------------------
// 
// ----------------------------------------------------------------------
public static void main(String[] args) {
    MavenScmCli cli;
    try {
        cli = new MavenScmCli();
    } catch (Exception ex) {
        System.err.println("Error while starting Maven Scm.");
        ex.printStackTrace(System.err);
        return;
    }
    String scmUrl;
    String command;
    if (args.length != 3) {
        System.err.println("Usage: maven-scm-client <command> <working directory> <scm url> [<scmVersion> [<scmVersionType>]]");
        System.err.println("scmVersion is a branch name/tag name/revision number.");
        System.err.println("scmVersionType can be 'branch', 'tag', 'revision'. " + "The default value is 'revision'.");
        return;
    }
    command = args[0];
    // SCM-641
    File workingDirectory = new File(args[1]).getAbsoluteFile();
    scmUrl = args[2];
    ScmVersion scmVersion = null;
    if (args.length > 3) {
        String version = args[3];
        if (args.length > 4) {
            String type = args[4];
            if ("tag".equals(type)) {
                scmVersion = new ScmTag(version);
            } else if ("branch".equals(type)) {
                scmVersion = new ScmBranch(version);
            } else if ("revision".equals(type)) {
                scmVersion = new ScmRevision(version);
            } else {
                throw new IllegalArgumentException("'" + type + "' version type isn't known.");
            }
        } else {
            scmVersion = new ScmRevision(args[3]);
        }
    }
    cli.execute(scmUrl, command, workingDirectory, scmVersion);
    cli.stop();
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) ScmTag(org.apache.maven.scm.ScmTag) ScmRevision(org.apache.maven.scm.ScmRevision) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmRepositoryException(org.apache.maven.scm.repository.ScmRepositoryException) ScmException(org.apache.maven.scm.ScmException) NoSuchScmProviderException(org.apache.maven.scm.manager.NoSuchScmProviderException) ScmVersion(org.apache.maven.scm.ScmVersion)

Aggregations

ScmBranch (org.apache.maven.scm.ScmBranch)25 Date (java.util.Date)9 ScmException (org.apache.maven.scm.ScmException)9 ScmFileSet (org.apache.maven.scm.ScmFileSet)7 Commandline (org.codehaus.plexus.util.cli.Commandline)7 ScmTag (org.apache.maven.scm.ScmTag)5 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)5 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 ScmVersion (org.apache.maven.scm.ScmVersion)4 ScmProvider (org.apache.maven.scm.provider.ScmProvider)4 File (java.io.File)3 ChangeSet (org.apache.maven.scm.ChangeSet)3 ScmRevision (org.apache.maven.scm.ScmRevision)3 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)3 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)3 ScmRepository (org.apache.maven.scm.repository.ScmRepository)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)2