Search in sources :

Example 21 with ChangeLogSet

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

Example 22 with ChangeLogSet

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

the class AccuRevChangeLogCommandTest method testWorkspaceChangelog.

@Test
public void testWorkspaceChangelog() throws Exception {
    final ScmFileSet testFileSet = new ScmFileSet(new File(basedir, "project/dir"));
    final Date keepWhen = getDate(2009, 0, 2, 9, 0, 0, null);
    final Date promoteWhen = getDate(2009, 0, 4, 23, 0, 0, null);
    final Date fromDate = getDate(2009, 0, 1, 0, 0, 0, null);
    final Date toDate = getDate(2009, 0, 5, 1, 0, 0, null);
    // start tran (35)
    List<Transaction> startTransaction = Collections.singletonList(new Transaction(35L, fromDate, "sometran", "anyone"));
    when(accurev.history("workspace5", "35", null, 1, true, true)).thenReturn(startTransaction);
    // end tran (42)
    List<Transaction> endTransaction = Collections.singletonList(new Transaction(42L, toDate, "sometran", "anyone"));
    when(accurev.history("workspace5", "42", null, 1, true, true)).thenReturn(endTransaction);
    // Stream hierarchy
    // S2 < S4, S2 < WS3, S4 < WS5, S4 << WS7
    // 
    // Changelog(WS5,35,42) involves
    // -- diff(S4,35,42)
    // -- hist(WS5,36-42)
    // -- hist(S4,36-42)
    // 
    // Promote S4 to S2 - not in diffS4, not in histS4, not in hist WS5 -
    // not in changeset
    // Promote WS3 to S2 - in diffS4, not hist histS4, not in hist WS5 - in
    // "upstream changes"
    // Promote WS5 to S4 - in diffS4, in histS4, not in hist WS5 - not in
    // changeset (real version from WS5)
    // Promote WS7 to S4 - in diffS4, in histS4, not in hist WS5 - in
    // changeset as a promote transaction
    // Keep WS5 - not in diffS4, not in histS4, in histWS5 - in changeset as
    // a keep transaction
    // This workspace is stream 5, attached to basis mystream 5
    Stream workspaceStream = new Stream("workspace5", 5, "stream4", 4, "myDepot", getDate(2008, 10, 1, 10, 0, 0, null), "workspace");
    when(accurev.showStream("workspace5")).thenReturn(workspaceStream);
    Stream basisStream = new Stream("stream4", 4, "myDepot", 1, "myDepot", getDate(2008, 1, 1), "normal");
    when(accurev.showStream("stream4")).thenReturn(basisStream);
    // now we call diff between the tran ids - 35 to 42
    FileDifference diffWS3toS2 = new FileDifference(32L, "/promoted/WS3toS2", "3/2", "/promoted/WS3toS2", "6/1");
    FileDifference diffWS5toS4 = new FileDifference(54L, "/promoted/WS5toS4", "5/3", "/promoted/WS5toS4", "8/1");
    FileDifference diffWS7toS4 = new FileDifference(74L, "/promoted/WS7toS4", "7/12", "/promoted/WS7toS4", "3/13");
    when(accurev.diff("stream4", "35", "42")).thenReturn(Arrays.asList(diffWS3toS2, diffWS5toS4, diffWS7toS4));
    // and we call hist for tranid + 1 to end trand ii
    Transaction promoteWS5toS4 = new Transaction(37L, promoteWhen, "promote", "aUser");
    promoteWS5toS4.setComment("WS5toS4");
    promoteWS5toS4.addVersion(54L, "/./promoted/WS5toS4", "4/5", "5/3", "3/2");
    Transaction promoteWS7toS4 = new Transaction(38L, promoteWhen, "promote", "aUser");
    promoteWS7toS4.setComment("WS7toS4");
    promoteWS7toS4.addVersion(74L, "/./promoted/WS7toS4", "4/11", "7/12", "3/2");
    when(accurev.history("stream4", "36", "42", 0, false, false)).thenReturn(Arrays.asList(promoteWS5toS4, promoteWS7toS4));
    Transaction keepWS5 = new Transaction(39L, keepWhen, "keep", "anOther");
    keepWS5.addVersion(5L, "/./kept/WS5", "5/7", "5/7", "7/21");
    keepWS5.setComment("keepWS5");
    when(accurev.history("workspace5", "36", "42", 0, false, false)).thenReturn(Collections.singletonList(keepWS5));
    AccuRevChangeLogCommand command = new AccuRevChangeLogCommand(getLogger());
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setScmVersion(CommandParameter.START_SCM_VERSION, new ScmRevision("workspace5/35"));
    commandParameters.setScmVersion(CommandParameter.END_SCM_VERSION, new ScmRevision("workspace5/42"));
    ChangeLogScmResult result = command.changelog(repo, testFileSet, commandParameters);
    assertThat(result.isSuccess(), is(true));
    ChangeLogSet changelog = result.getChangeLog();
    assertThat(changelog.getStartVersion().getName(), is("workspace5/35"));
    assertThat(changelog.getEndVersion().getName(), is("workspace5/42"));
    List<ChangeSet> changesets = changelog.getChangeSets();
    assertThat(changesets.size(), is(3));
    for (ChangeSet changeSet : changesets) {
        assertThat(changeSet.getComment(), isOneOf("Upstream changes", "WS7toS4", "keepWS5"));
        if ("Upstream changes".equals(changeSet.getComment())) {
            assertThat(changeSet.getFiles().size(), is(1));
            ChangeFile changeFile = (ChangeFile) changeSet.getFiles().get(0);
            assertThat(changeFile, is(changeFile("/promoted/WS3toS2")));
        }
    }
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) ScmRevision(org.apache.maven.scm.ScmRevision) Date(java.util.Date) Transaction(org.apache.maven.scm.provider.accurev.Transaction) ChangeFile(org.apache.maven.scm.ChangeFile) Stream(org.apache.maven.scm.provider.accurev.Stream) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) FileDifference(org.apache.maven.scm.provider.accurev.FileDifference) CommandParameters(org.apache.maven.scm.CommandParameters) ChangeFile(org.apache.maven.scm.ChangeFile) ChangeFileMatcher.changeFile(org.apache.maven.scm.ChangeFileMatcher.changeFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 23 with ChangeLogSet

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

the class HgChangeLogCommand method executeChangeLogCommand.

private ChangeLogScmResult executeChangeLogCommand(ScmFileSet fileSet, Date startDate, Date endDate, String datePattern, Integer limit) throws ScmException {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    StringBuilder dateInterval = new StringBuilder();
    // TRICK: Mercurial 1.9.3 don't accept 1970-01-01
    dateInterval.append(// From 2. Jan 1970
    dateFormat.format(startDate == null ? new Date(1000L * 60 * 60 * 24) : startDate));
    dateInterval.append(" to ");
    // Upto now
    dateInterval.append(dateFormat.format(endDate == null ? new Date() : endDate));
    List<String> cmd = new ArrayList<String>();
    cmd.addAll(Arrays.asList(HgCommandConstants.LOG_CMD, HgCommandConstants.TEMPLATE_OPTION, HgCommandConstants.TEMPLATE_FORMAT, HgCommandConstants.NO_MERGES_OPTION, HgCommandConstants.DATE_OPTION, dateInterval.toString()));
    if (limit != null && limit > 0) {
        cmd.add(HgCommandConstants.LIMIT_OPTION);
        cmd.add(Integer.toString(limit));
    }
    HgChangeLogConsumer consumer = new HgChangeLogConsumer(getLogger(), datePattern);
    ScmResult result = HgUtils.execute(consumer, getLogger(), fileSet.getBasedir(), cmd.toArray(new String[cmd.size()]));
    List<ChangeSet> logEntries = consumer.getModifications();
    ChangeLogSet changeLogSet = new ChangeLogSet(logEntries, 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) SimpleDateFormat(java.text.SimpleDateFormat) ChangeSet(org.apache.maven.scm.ChangeSet) Date(java.util.Date)

Example 24 with ChangeLogSet

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

the class HgChangeLogCommand method executeChangeLogCommand.

@Override
protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion startVersion, ScmVersion endVersion, String datePattern) throws ScmException {
    StringBuilder revisionInterval = new StringBuilder();
    if (startVersion != null) {
        revisionInterval.append(startVersion.getName());
    }
    revisionInterval.append(":");
    if (endVersion != null) {
        revisionInterval.append(endVersion.getName());
    }
    String[] cmd = new String[] { HgCommandConstants.LOG_CMD, HgCommandConstants.TEMPLATE_OPTION, HgCommandConstants.TEMPLATE_FORMAT, HgCommandConstants.NO_MERGES_OPTION, HgCommandConstants.REVISION_OPTION, revisionInterval.toString() };
    HgChangeLogConsumer consumer = new HgChangeLogConsumer(getLogger(), datePattern);
    ScmResult result = HgUtils.execute(consumer, getLogger(), fileSet.getBasedir(), cmd);
    List<ChangeSet> logEntries = consumer.getModifications();
    Date startDate = null;
    Date endDate = null;
    if (!logEntries.isEmpty()) {
        startDate = logEntries.get(0).getDate();
        endDate = logEntries.get(logEntries.size() - 1).getDate();
    }
    ChangeLogSet changeLogSet = new ChangeLogSet(logEntries, startDate, endDate);
    changeLogSet.setStartVersion(startVersion);
    changeLogSet.setEndVersion(endVersion);
    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) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ChangeSet(org.apache.maven.scm.ChangeSet) Date(java.util.Date)

Example 25 with ChangeLogSet

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

the class Sandbox method getChangeLog.

/**
 * Executes the 'si rlog' command to generate a list of changed revision found between startDate and endDate
 *
 * @param startDate The date range for the beginning of the operation
 * @param endDate   The date range for the end of the operation
 * @return ChangeLogSet containing a list of changes grouped by Change Pacakge ID
 * @throws APIException
 */
public ChangeLogSet getChangeLog(Date startDate, Date endDate) throws APIException {
    // Initialize our return object
    ChangeLogSet changeLog = new ChangeLogSet(startDate, endDate);
    // By default we're going to group-by change package
    // Non change package changes will be lumped into one big Change Set
    Hashtable<String, ChangeSet> changeSetHash = new Hashtable<String, ChangeSet>();
    // Lets prepare our si rlog command for execution
    Command siRlog = new Command(Command.SI, "rlog");
    siRlog.addOption(new Option("recurse"));
    MultiValue rFilter = new MultiValue(":");
    rFilter.add("daterange");
    rFilter.add("'" + RLOG_DATEFORMAT.format(startDate) + "'-'" + RLOG_DATEFORMAT.format(endDate) + "'");
    siRlog.addOption(new Option("rfilter", rFilter));
    siRlog.addOption(new Option("cwd", sandboxDir));
    // Execute the si rlog command
    Response response = api.runCommand(siRlog);
    for (WorkItemIterator wit = response.getWorkItems(); wit.hasNext(); ) {
        WorkItem wi = wit.next();
        String memberName = wi.getContext();
        // We're going to have to do a little dance to get the correct server file name
        memberName = memberName.substring(0, memberName.lastIndexOf('/'));
        memberName = memberName + '/' + wi.getId();
        memberName = memberName.replace('\\', '/');
        // Now lets get the revisions for this file
        Field revisionsFld = wi.getField("revisions");
        if (null != revisionsFld && revisionsFld.getDataType().equals(Field.ITEM_LIST_TYPE) && null != revisionsFld.getList()) {
            @SuppressWarnings("unchecked") List<Item> revList = revisionsFld.getList();
            for (Iterator<Item> lit = revList.iterator(); lit.hasNext(); ) {
                Item revisionItem = lit.next();
                String revision = revisionItem.getId();
                String author = revisionItem.getField("author").getItem().getId();
                // Attempt to get the full name, if available
                try {
                    author = revisionItem.getField("author").getItem().getField("fullname").getValueAsString();
                } catch (NullPointerException npe) {
                /* ignore */
                }
                String cpid = ":none";
                // Attempt to get the cpid for this revision
                try {
                    cpid = revisionItem.getField("cpid").getItem().getId();
                } catch (NullPointerException npe) {
                /* ignore */
                }
                // Get the Change Package summary for this revision
                String comment = cpid + ": " + revisionItem.getField("cpsummary").getValueAsString();
                // Get the date associated with this revision
                Date date = revisionItem.getField("date").getDateTime();
                // Lets create our ChangeFile based on the information we've gathered so far
                ChangeFile changeFile = new ChangeFile(memberName, revision);
                // Check to see if we already have a ChangeSet grouping for this revision
                ChangeSet changeSet = changeSetHash.get(cpid);
                if (null != changeSet) {
                    // Set the date of the ChangeSet to the oldest entry
                    if (changeSet.getDate().after(date)) {
                        changeSet.setDate(date);
                    }
                    // Add the new ChangeFile
                    changeSet.addFile(changeFile);
                    // Update the changeSetHash
                    changeSetHash.put(cpid, changeSet);
                } else // Create a new ChangeSet grouping and add the ChangeFile
                {
                    List<ChangeFile> changeFileList = new ArrayList<ChangeFile>();
                    changeFileList.add(changeFile);
                    changeSet = new ChangeSet(date, comment, author, changeFileList);
                    // Update the changeSetHash with an initial entry for the cpid
                    changeSetHash.put(cpid, changeSet);
                }
            }
        }
    }
    // Update the Change Log with the Change Sets
    List<ChangeSet> changeSetList = new ArrayList<ChangeSet>();
    changeSetList.addAll(changeSetHash.values());
    changeLog.setChangeSets(changeSetList);
    return changeLog;
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) WorkItemIterator(com.mks.api.response.WorkItemIterator) WorkItem(com.mks.api.response.WorkItem) Date(java.util.Date) Response(com.mks.api.response.Response) Field(com.mks.api.response.Field) WorkItem(com.mks.api.response.WorkItem) Item(com.mks.api.response.Item) Command(com.mks.api.Command) ChangeFile(org.apache.maven.scm.ChangeFile) Option(com.mks.api.Option) ChangeSet(org.apache.maven.scm.ChangeSet) MultiValue(com.mks.api.MultiValue)

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