Search in sources :

Example 16 with Option

use of com.mks.api.Option in project maven-scm by apache.

the class Sandbox method dropMember.

/**
 * Executes a 'si drop' command using the relativeName for the member name
 *
 * @param memberFile   Full path to the member's current sandbox location
 * @param relativeName Relative path from the nearest subproject or project
 * @return MKS API Response object
 * @throws APIException
 */
private Response dropMember(File memberFile, String relativeName) throws APIException {
    // Setup the drop command
    api.getLogger().info("Dropping member " + memberFile.getAbsolutePath());
    Command siDrop = new Command(Command.SI, "drop");
    siDrop.addOption(new Option("cwd", memberFile.getParentFile().getAbsolutePath()));
    siDrop.addOption(new Option("noconfirm"));
    siDrop.addOption(new Option("cpid", cpid));
    siDrop.addOption(new Option("delete"));
    siDrop.addSelection(relativeName);
    return api.runCommand(siDrop);
}
Also used : Command(com.mks.api.Command) Option(com.mks.api.Option)

Example 17 with Option

use of com.mks.api.Option in project maven-scm by apache.

the class Sandbox method revertMembers.

/**
 * Executes a 'si revert' command to roll back changes to all files in the Sandbox directory
 *
 * @return MKS API Response object
 * @throws APIException
 */
public Response revertMembers() throws APIException {
    api.getLogger().debug("Reverting changes in sandbox " + sandboxDir + " for project " + siProject.getConfigurationPath());
    Command cmd = new Command(Command.SI, "revert");
    cmd.addOption(new Option("recurse"));
    cmd.addOption(new Option("cwd", sandboxDir));
    return api.runCommand(cmd);
}
Also used : Command(com.mks.api.Command) Option(com.mks.api.Option)

Example 18 with Option

use of com.mks.api.Option in project maven-scm by apache.

the class Sandbox method createSubproject.

/**
 * Creates one subproject per directory, as required.
 *
 * @param dirPath A relative path structure of folders
 * @return Response containing the result for the created subproject
 * @throws APIException
 */
public Response createSubproject(String dirPath) throws APIException {
    // Setup the create subproject command
    api.getLogger().debug("Creating subprojects for: " + dirPath + "/project.pj");
    Command siCreateSubproject = new Command(Command.SI, "createsubproject");
    siCreateSubproject.addOption(new Option("cpid", cpid));
    siCreateSubproject.addOption(new Option("createSubprojects"));
    siCreateSubproject.addOption(new Option("cwd", sandboxDir));
    siCreateSubproject.addSelection(dirPath + "/project.pj");
    // Execute the create subproject command
    return api.runCommand(siCreateSubproject);
}
Also used : Command(com.mks.api.Command) Option(com.mks.api.Option)

Example 19 with Option

use of com.mks.api.Option 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)

Example 20 with Option

use of com.mks.api.Option in project maven-scm by apache.

the class Sandbox method lock.

/**
 * Executes a 'si lock' command using the relativeName of the file
 *
 * @param memberFile   Full path to the member's current sandbox location
 * @param relativeName Relative path from the nearest subproject or project
 * @return MKS API Response object
 * @throws APIException
 */
public Response lock(File memberFile, String relativeName) throws APIException {
    // Setup the lock command
    api.getLogger().debug("Locking member: " + memberFile.getAbsolutePath());
    Command siLock = new Command(Command.SI, "lock");
    siLock.addOption(new Option("revision", ":member"));
    siLock.addOption(new Option("cpid", cpid));
    siLock.addOption(new Option("cwd", memberFile.getParentFile().getAbsolutePath()));
    siLock.addSelection(relativeName);
    // Execute the lock command
    return api.runCommand(siLock);
}
Also used : Command(com.mks.api.Command) Option(com.mks.api.Option)

Aggregations

Command (com.mks.api.Command)20 Option (com.mks.api.Option)20 Response (com.mks.api.response.Response)8 WorkItem (com.mks.api.response.WorkItem)5 WorkItemIterator (com.mks.api.response.WorkItemIterator)5 ArrayList (java.util.ArrayList)4 ChangeFile (org.apache.maven.scm.ChangeFile)4 ScmFile (org.apache.maven.scm.ScmFile)4 MultiValue (com.mks.api.MultiValue)3 APIException (com.mks.api.response.APIException)3 File (java.io.File)3 Item (com.mks.api.response.Item)2 Hashtable (java.util.Hashtable)2 FileOption (com.mks.api.FileOption)1 Field (com.mks.api.response.Field)1 Date (java.util.Date)1 ChangeSet (org.apache.maven.scm.ChangeSet)1 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)1