Search in sources :

Example 1 with ChangeLogSet

use of org.apache.maven.scm.command.changelog.ChangeLogSet in project maven-scm by apache.

the class BazaarChangeLogCommand method executeChangeLogCommand.

private ChangeLogScmResult executeChangeLogCommand(ScmFileSet fileSet, Date startDate, Date endDate, String datePattern, Integer limit) throws ScmException {
    List<String> cmd = new ArrayList<String>();
    cmd.addAll(Arrays.asList(BazaarConstants.LOG_CMD, BazaarConstants.VERBOSE_OPTION));
    if (limit != null && limit > 0) {
        cmd.add(BazaarConstants.LIMIT_OPTION);
        cmd.add(Integer.toString(limit));
    }
    BazaarChangeLogConsumer consumer = new BazaarChangeLogConsumer(getLogger(), datePattern);
    ScmResult result = BazaarUtils.execute(consumer, getLogger(), fileSet.getBasedir(), cmd.toArray(new String[cmd.size()]));
    List<ChangeSet> logEntries = consumer.getModifications();
    List<ChangeSet> inRangeAndValid = new ArrayList<ChangeSet>();
    // From 1. Jan 1970
    startDate = startDate == null ? new Date(0) : startDate;
    // Upto now
    endDate = endDate == null ? new Date() : endDate;
    for (ChangeSet change : logEntries) {
        if (change.getFiles().size() > 0) {
            if (!change.getDate().before(startDate) && !change.getDate().after(endDate)) {
                inRangeAndValid.add(change);
            }
        }
    }
    ChangeLogSet changeLogSet = new ChangeLogSet(inRangeAndValid, startDate, endDate);
    return new ChangeLogScmResult(changeLogSet, result);
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) ScmResult(org.apache.maven.scm.ScmResult) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ArrayList(java.util.ArrayList) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ChangeSet(org.apache.maven.scm.ChangeSet) Date(java.util.Date)

Example 2 with ChangeLogSet

use of org.apache.maven.scm.command.changelog.ChangeLogSet in project maven-scm by apache.

the class PerforceChangeLogCommand method executeChangeLogCommand.

protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern, ScmVersion startVersion, ScmVersion endVersion) throws ScmException {
    PerforceScmProviderRepository p4repo = (PerforceScmProviderRepository) repo;
    String clientspec = PerforceScmProvider.getClientspecName(getLogger(), p4repo, fileSet.getBasedir());
    Commandline cl = createCommandLine(p4repo, fileSet.getBasedir(), clientspec, null, startDate, endDate, startVersion, endVersion);
    String location = PerforceScmProvider.getRepoPath(getLogger(), p4repo, fileSet.getBasedir());
    PerforceChangesConsumer consumer = new PerforceChangesConsumer(getLogger());
    try {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
        }
        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
        int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
        if (exitCode != 0) {
            String cmdLine = CommandLineUtils.toString(cl.getCommandline());
            StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
            msg.append('\n');
            msg.append("Command line was:" + cmdLine);
            throw new CommandLineException(msg.toString());
        }
    } catch (CommandLineException e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("CommandLineException " + e.getMessage(), e);
        }
    }
    List<String> changes = consumer.getChanges();
    cl = PerforceScmProvider.createP4Command(p4repo, fileSet.getBasedir());
    cl.createArg().setValue("describe");
    cl.createArg().setValue("-s");
    for (String change : changes) {
        cl.createArg().setValue(change);
    }
    PerforceDescribeConsumer describeConsumer = new PerforceDescribeConsumer(location, datePattern, getLogger());
    try {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
        }
        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
        int exitCode = CommandLineUtils.executeCommandLine(cl, describeConsumer, err);
        if (exitCode != 0) {
            String cmdLine = CommandLineUtils.toString(cl.getCommandline());
            StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
            msg.append('\n');
            msg.append("Command line was:" + cmdLine);
            throw new CommandLineException(msg.toString());
        }
    } catch (CommandLineException e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("CommandLineException " + e.getMessage(), e);
        }
    }
    ChangeLogSet cls = new ChangeLogSet(describeConsumer.getModifications(), null, null);
    cls.setStartVersion(startVersion);
    cls.setEndVersion(endVersion);
    return new ChangeLogScmResult(cl.toString(), cls);
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) PerforceScmProviderRepository(org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository)

Example 3 with ChangeLogSet

use of org.apache.maven.scm.command.changelog.ChangeLogSet in project maven-scm by apache.

the class ClearCaseChangeLogCommand method executeChangeLogCommand.

// ----------------------------------------------------------------------
// AbstractChangeLogCommand Implementation
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executing changelog command...");
    }
    Commandline cl = createCommandLine(fileSet.getBasedir(), branch, startDate);
    ClearCaseChangeLogConsumer consumer = new ClearCaseChangeLogConsumer(getLogger(), datePattern);
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    try {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString());
        }
        exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing cvs command.", ex);
    }
    if (exitCode != 0) {
        return new ChangeLogScmResult(cl.toString(), "The cleartool command failed.", stderr.getOutput(), false);
    }
    return new ChangeLogScmResult(cl.toString(), new ChangeLogSet(consumer.getModifications(), startDate, endDate));
}
Also used : ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 4 with ChangeLogSet

use of org.apache.maven.scm.command.changelog.ChangeLogSet in project maven-scm by apache.

the class CvsExeChangeLogCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected ChangeLogScmResult executeCvsCommand(Commandline cl, Date startDate, Date endDate, ScmVersion startVersion, ScmVersion endVersion, String datePattern) throws ScmException {
    CvsChangeLogConsumer consumer = new CvsChangeLogConsumer(getLogger(), datePattern);
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing cvs command.", ex);
    }
    if (exitCode != 0) {
        return new ChangeLogScmResult(cl.toString(), "The cvs command failed.", stderr.getOutput(), false);
    }
    ChangeLogSet changeLogSet = new ChangeLogSet(consumer.getModifications(), startDate, endDate);
    changeLogSet.setStartVersion(startVersion);
    changeLogSet.setEndVersion(endVersion);
    return new ChangeLogScmResult(cl.toString(), changeLogSet);
}
Also used : CvsChangeLogConsumer(org.apache.maven.scm.provider.cvslib.command.changelog.CvsChangeLogConsumer) ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 5 with ChangeLogSet

use of org.apache.maven.scm.command.changelog.ChangeLogSet in project maven-scm by apache.

the class CvsJavaChangeLogCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected ChangeLogScmResult executeCvsCommand(Commandline cl, Date startDate, Date endDate, ScmVersion startVersion, ScmVersion endVersion, String datePattern) throws ScmException {
    CvsLogListener logListener = new CvsLogListener();
    CvsChangeLogConsumer consumer = new CvsChangeLogConsumer(getLogger(), datePattern);
    try {
        boolean isSuccess = CvsConnection.processCommand(cl.getArguments(), cl.getWorkingDirectory().getAbsolutePath(), logListener, getLogger());
        if (!isSuccess) {
            return new ChangeLogScmResult(cl.toString(), "The cvs command failed.", logListener.getStderr().toString(), false);
        }
        BufferedReader stream = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(logListener.getStdout().toString().getBytes())));
        String line;
        while ((line = stream.readLine()) != null) {
            consumer.consumeLine(line);
        }
    } catch (Exception e) {
        e.printStackTrace();
        return new ChangeLogScmResult(cl.toString(), "The cvs command failed.", logListener.getStdout().toString(), false);
    }
    ChangeLogSet changeLogSet = new ChangeLogSet(consumer.getModifications(), startDate, endDate);
    changeLogSet.setStartVersion(startVersion);
    changeLogSet.setEndVersion(endVersion);
    return new ChangeLogScmResult(cl.toString(), changeLogSet);
}
Also used : CvsChangeLogConsumer(org.apache.maven.scm.provider.cvslib.command.changelog.CvsChangeLogConsumer) CvsLogListener(org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsLogListener) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ScmException(org.apache.maven.scm.ScmException)

Aggregations

ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)34 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)22 ChangeSet (org.apache.maven.scm.ChangeSet)16 ScmException (org.apache.maven.scm.ScmException)14 ArrayList (java.util.ArrayList)13 Date (java.util.Date)9 ChangeFile (org.apache.maven.scm.ChangeFile)7 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)7 Commandline (org.codehaus.plexus.util.cli.Commandline)6 File (java.io.File)4 IOException (java.io.IOException)4 SimpleDateFormat (java.text.SimpleDateFormat)4 ScmVersion (org.apache.maven.scm.ScmVersion)4 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 ScmBranch (org.apache.maven.scm.ScmBranch)3 ScmResult (org.apache.maven.scm.ScmResult)3 ScmRevision (org.apache.maven.scm.ScmRevision)3 FileDifference (org.apache.maven.scm.provider.accurev.FileDifference)3 BufferedReader (java.io.BufferedReader)2