Search in sources :

Example 11 with ChangeSet

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

the class HgUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion tag) throws ScmException {
    File workingDir = fileSet.getBasedir();
    String[] updateCmd;
    // Update branch
    if (repo.isPushChanges()) {
        updateCmd = new String[] { HgCommandConstants.PULL_CMD, HgCommandConstants.REVISION_OPTION, tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip" };
    } else {
        updateCmd = new String[] { HgCommandConstants.UPDATE_CMD, tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip", HgCommandConstants.CLEAN_OPTION };
    }
    ScmResult updateResult = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, updateCmd);
    if (!updateResult.isSuccess()) {
        return new UpdateScmResult(null, null, updateResult);
    }
    // Find changes from last revision
    int currentRevision = HgUtils.getCurrentRevisionNumber(getLogger(), workingDir);
    int previousRevision = currentRevision - 1;
    String[] diffCmd = new String[] { HgCommandConstants.DIFF_CMD, HgCommandConstants.REVISION_OPTION, "" + previousRevision };
    HgDiffConsumer diffConsumer = new HgDiffConsumer(getLogger(), workingDir);
    ScmResult diffResult = HgUtils.execute(diffConsumer, getLogger(), workingDir, diffCmd);
    // Now translate between diff and update file status
    List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
    List<CharSequence> changes = new ArrayList<CharSequence>();
    List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
    Map<String, CharSequence> diffChanges = diffConsumer.getDifferences();
    for (ScmFile file : diffFiles) {
        changes.add(diffChanges.get(file.getPath()));
        if (file.getStatus() == ScmFileStatus.MODIFIED) {
            updatedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.PATCHED));
        } else {
            updatedFiles.add(file);
        }
    }
    if (repo.isPushChanges()) {
        String[] hgUpdateCmd = new String[] { HgCommandConstants.UPDATE_CMD };
        HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, hgUpdateCmd);
    }
    return new UpdateScmResultWithRevision(updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf(currentRevision), diffResult);
}
Also used : UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ScmResult(org.apache.maven.scm.ScmResult) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) HgDiffConsumer(org.apache.maven.scm.provider.hg.command.diff.HgDiffConsumer) HgConsumer(org.apache.maven.scm.provider.hg.command.HgConsumer) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 12 with ChangeSet

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

the class HgChangeLogConsumer method doConsume.

/**
 * {@inheritDoc}
 */
public void doConsume(ScmFileStatus status, String line) {
    String tmpLine;
    // new changeset
    if (line.startsWith(REVNO_TAG)) {
        // Init a new changeset
        currentChange = new ChangeSet();
        currentChange.setFiles(new ArrayList<ChangeFile>(0));
        logEntries.add(currentChange);
        // parse revision
        tmpLine = line.substring(REVNO_TAG.length()).trim();
        currentRevision = tmpLine.substring(tmpLine.indexOf(':') + 1);
        currentChange.setRevision(currentRevision);
    } else if (line.startsWith(BRANCH_TAG)) {
        tmpLine = line.substring(BRANCH_TAG.length()).trim();
        currentBranch = tmpLine;
    } else if (line.startsWith(AUTHOR_TAG)) {
        tmpLine = line.substring(AUTHOR_TAG.length()).trim();
        currentChange.setAuthor(tmpLine);
    } else if (line.startsWith(TIME_STAMP_TOKEN)) {
        tmpLine = line.substring(TIME_STAMP_TOKEN.length()).trim();
        Date date = parseDate(tmpLine, userDatePattern, TIME_PATTERN, Locale.ENGLISH);
        currentChange.setDate(date);
    } else if (line.startsWith(TAG_TAG)) {
        tmpLine = line.substring(TAG_TAG.length()).trim();
        currentTag = tmpLine;
    } else if (line.startsWith(FILES_TOKEN)) {
        tmpLine = line.substring(FILES_TOKEN.length()).trim();
        String[] files = tmpLine.split(" ");
        for (int i = 0; i < files.length; i++) {
            String file = files[i];
            ChangeFile changeFile = new ChangeFile(file, currentRevision);
            currentChange.addFile(changeFile);
        }
    } else if (line.startsWith(MESSAGE_TOKEN)) {
        currentChange.setComment("");
    } else {
        StringBuilder comment = new StringBuilder(currentChange.getComment());
        comment.append(line);
        comment.append('\n');
        currentChange.setComment(comment.toString());
    }
}
Also used : ChangeFile(org.apache.maven.scm.ChangeFile) ChangeSet(org.apache.maven.scm.ChangeSet) Date(java.util.Date)

Example 13 with ChangeSet

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

the class CvsChangeLogConsumer method getModifications.

public List<ChangeSet> getModifications() {
    Collections.sort(entries, new Comparator<ChangeSet>() {

        public int compare(ChangeSet set1, ChangeSet set2) {
            return set1.getDate().compareTo(set2.getDate());
        }
    });
    List<ChangeSet> fixedModifications = new ArrayList<ChangeSet>();
    ChangeSet currentEntry = null;
    for (Iterator<ChangeSet> entryIterator = entries.iterator(); entryIterator.hasNext(); ) {
        ChangeSet entry = (ChangeSet) entryIterator.next();
        if (currentEntry == null) {
            currentEntry = entry;
        } else if (areEqual(currentEntry, entry)) {
            currentEntry.addFile((ChangeFile) entry.getFiles().get(0));
        } else {
            fixedModifications.add(currentEntry);
            currentEntry = entry;
        }
    }
    if (currentEntry != null) {
        fixedModifications.add(currentEntry);
    }
    return fixedModifications;
}
Also used : ChangeFile(org.apache.maven.scm.ChangeFile) ArrayList(java.util.ArrayList) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 14 with ChangeSet

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

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

Aggregations

ChangeSet (org.apache.maven.scm.ChangeSet)62 ChangeFile (org.apache.maven.scm.ChangeFile)34 ArrayList (java.util.ArrayList)21 Date (java.util.Date)18 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)16 File (java.io.File)15 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)15 Matcher (java.util.regex.Matcher)8 ScmException (org.apache.maven.scm.ScmException)8 BufferedReader (java.io.BufferedReader)7 SimpleDateFormat (java.text.SimpleDateFormat)7 ScmFile (org.apache.maven.scm.ScmFile)6 ScmFileSet (org.apache.maven.scm.ScmFileSet)5 ScmResult (org.apache.maven.scm.ScmResult)5 DefaultLog (org.apache.maven.scm.log.DefaultLog)5 FileReader (java.io.FileReader)4 List (java.util.List)4 ScmFileStatus (org.apache.maven.scm.ScmFileStatus)4 FileInputStream (java.io.FileInputStream)3 InputStreamReader (java.io.InputStreamReader)3