Search in sources :

Example 36 with ChangeSet

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

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

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

the class CvsChangeLogConsumer method processGetFile.

/**
 * Process the current input line in the Get File state.
 *
 * @param line a line of text from the cvs log output
 */
private void processGetFile(String line) {
    if (line.startsWith(START_FILE)) {
        setCurrentChange(new ChangeSet());
        setCurrentFile(new ChangeFile(line.substring(START_FILE.length(), line.length())));
        setStatus(GET_REVISION);
    }
}
Also used : ChangeFile(org.apache.maven.scm.ChangeFile) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 39 with ChangeSet

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

the class CvsChangeLogConsumer method processGetComment.

/**
 * Process the current input line in the Get Comment state.
 *
 * @param line a line of text from the cvs log output
 */
private void processGetComment(String line) {
    if (line.startsWith(START_REVISION)) {
        // add entry, and set state to get revision
        addEntry(getCurrentChange(), getCurrentFile());
        // new change log entry
        setCurrentChange(new ChangeSet());
        // same file name, but different rev
        setCurrentFile(new ChangeFile(getCurrentFile().getName()));
        setStatus(GET_REVISION);
    } else if (line.startsWith(END_FILE)) {
        addEntry(getCurrentChange(), getCurrentFile());
        setStatus(GET_FILE);
    } else {
        // keep gathering comments
        getCurrentChange().setComment(getCurrentChange().getComment() + line + "\n");
    }
}
Also used : ChangeFile(org.apache.maven.scm.ChangeFile) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 40 with ChangeSet

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

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