Search in sources :

Example 1 with ChangeLogCommand

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

the class AbstractUpdateCommand method executeCommand.

/**
 * {@inheritDoc}
 */
public ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    ScmVersion scmVersion = parameters.getScmVersion(CommandParameter.SCM_VERSION, null);
    boolean runChangelog = Boolean.valueOf(parameters.getString(CommandParameter.RUN_CHANGELOG_WITH_UPDATE, "true")).booleanValue();
    UpdateScmResult updateScmResult = executeUpdateCommand(repository, fileSet, scmVersion);
    List<ScmFile> filesList = updateScmResult.getUpdatedFiles();
    if (!runChangelog) {
        return updateScmResult;
    }
    ChangeLogCommand changeLogCmd = getChangeLogCommand();
    if (filesList != null && filesList.size() > 0 && changeLogCmd != null) {
        ChangeLogScmResult changeLogScmResult = (ChangeLogScmResult) changeLogCmd.executeCommand(repository, fileSet, parameters);
        List<ChangeSet> changes = new ArrayList<ChangeSet>();
        ChangeLogSet changeLogSet = changeLogScmResult.getChangeLog();
        if (changeLogSet != null) {
            Date startDate = null;
            try {
                startDate = parameters.getDate(CommandParameter.START_DATE);
            } catch (ScmException e) {
            // Do nothing, startDate isn't define.
            }
            for (ChangeSet change : changeLogSet.getChangeSets()) {
                if (startDate != null && change.getDate() != null) {
                    if (startDate.after(change.getDate())) {
                        continue;
                    }
                }
                for (ScmFile currentFile : filesList) {
                    if (change.containsFilename(currentFile.getPath())) {
                        changes.add(change);
                        break;
                    }
                }
            }
        }
        updateScmResult.setChanges(changes);
    }
    return updateScmResult;
}
Also used : ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) ArrayList(java.util.ArrayList) Date(java.util.Date) ScmVersion(org.apache.maven.scm.ScmVersion) ScmFile(org.apache.maven.scm.ScmFile) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ChangeLogCommand(org.apache.maven.scm.command.changelog.ChangeLogCommand) ChangeSet(org.apache.maven.scm.ChangeSet)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ChangeSet (org.apache.maven.scm.ChangeSet)1 ScmException (org.apache.maven.scm.ScmException)1 ScmFile (org.apache.maven.scm.ScmFile)1 ScmVersion (org.apache.maven.scm.ScmVersion)1 ChangeLogCommand (org.apache.maven.scm.command.changelog.ChangeLogCommand)1 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)1 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)1