Search in sources :

Example 1 with Option

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

the class Sandbox method getChangeList.

/**
 * Executes a 'si viewsandbox' and parses the output for changed or dropped working files
 *
 * @return A list of MKS API Response WorkItem objects representing the changes in the Sandbox
 * @throws APIException
 */
public List<WorkItem> getChangeList() throws APIException {
    // Store a list of files that were changed/removed to the repository
    List<WorkItem> changedFiles = new ArrayList<WorkItem>();
    // Setup the view sandbox command to figure out what has changed...
    Command siViewSandbox = new Command(Command.SI, "viewsandbox");
    // Create the --fields option
    MultiValue mv = new MultiValue(",");
    mv.add("name");
    mv.add("context");
    mv.add("wfdelta");
    mv.add("memberarchive");
    siViewSandbox.addOption(new Option("fields", mv));
    siViewSandbox.addOption(new Option("recurse"));
    siViewSandbox.addOption(new Option("noincludeDropped"));
    siViewSandbox.addOption(new Option("filterSubs"));
    siViewSandbox.addOption(new Option("cwd", sandboxDir));
    // Run the view sandbox command
    Response r = api.runCommand(siViewSandbox);
    // Check-in all changed files, drop all members with missing working files
    for (WorkItemIterator wit = r.getWorkItems(); wit.hasNext(); ) {
        WorkItem wi = wit.next();
        api.getLogger().debug("Inspecting file: " + wi.getField("name").getValueAsString());
        if (wi.getModelType().equals(SIModelTypeName.MEMBER)) {
            Item wfdeltaItem = (Item) wi.getField("wfdelta").getValue();
            // Proceed with this entry only if it is an actual working file delta
            if (isDelta(wfdeltaItem)) {
                File memberFile = new File(wi.getField("name").getValueAsString());
                if (hasWorkingFile(wfdeltaItem)) {
                    // Only report on files that have actually changed...
                    if (hasMemberChanged(memberFile, wi.getId())) {
                        changedFiles.add(wi);
                    }
                } else {
                    // Also report on dropped files
                    changedFiles.add(wi);
                }
            }
        }
    }
    return changedFiles;
}
Also used : Response(com.mks.api.response.Response) WorkItem(com.mks.api.response.WorkItem) Item(com.mks.api.response.Item) Command(com.mks.api.Command) ArrayList(java.util.ArrayList) Option(com.mks.api.Option) WorkItemIterator(com.mks.api.response.WorkItemIterator) WorkItem(com.mks.api.response.WorkItem) ChangeFile(org.apache.maven.scm.ChangeFile) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) MultiValue(com.mks.api.MultiValue)

Example 2 with Option

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

the class Sandbox method getNewMembers.

/**
 * Executes a 'si viewnonmembers' command filtering the results using the exclude and include lists
 *
 * @param exclude Pattern containing the exclude file list
 * @param include Pattern containing the include file list
 * @return List of ScmFile objects representing the new files in the Sandbox
 * @throws APIException
 */
public List<ScmFile> getNewMembers(String exclude, String include) throws APIException {
    // Store a list of files that were added to the repository
    List<ScmFile> filesAdded = new ArrayList<ScmFile>();
    Command siViewNonMem = new Command(Command.SI, "viewnonmembers");
    siViewNonMem.addOption(new Option("recurse"));
    if (null != exclude && exclude.length() > 0) {
        siViewNonMem.addOption(new Option("exclude", exclude));
    }
    if (null != include && include.length() > 0) {
        siViewNonMem.addOption(new Option("include", include));
    }
    siViewNonMem.addOption(new Option("noincludeFormers"));
    siViewNonMem.addOption(new Option("cwd", sandboxDir));
    Response response = api.runCommand(siViewNonMem);
    for (WorkItemIterator wit = response.getWorkItems(); wit.hasNext(); ) {
        filesAdded.add(new ScmFile(wit.next().getField("absolutepath").getValueAsString(), ScmFileStatus.ADDED));
    }
    return filesAdded;
}
Also used : Response(com.mks.api.response.Response) Command(com.mks.api.Command) ArrayList(java.util.ArrayList) Option(com.mks.api.Option) WorkItemIterator(com.mks.api.response.WorkItemIterator) ScmFile(org.apache.maven.scm.ScmFile)

Example 3 with Option

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

the class Sandbox method checkin.

/**
 * Executes a 'si ci' command using the relativeName for the member name and message for the description
 *
 * @param memberFile   Full path to the member's current sandbox location
 * @param relativeName Relative path from the nearest subproject or project
 * @param message      Description for checking in the new update
 * @return MKS API Response object
 * @throws APIException
 */
private Response checkin(File memberFile, String relativeName, String message) throws APIException {
    // Setup the check-in command
    api.getLogger().info("Checking in member:  " + memberFile.getAbsolutePath());
    Command sici = new Command(Command.SI, "ci");
    sici.addOption(new Option("cpid", cpid));
    if (null != message && message.length() > 0) {
        sici.addOption(new Option("description", message));
    }
    sici.addOption(new Option("cwd", memberFile.getParentFile().getAbsolutePath()));
    sici.addSelection(relativeName);
    return api.runCommand(sici);
}
Also used : Command(com.mks.api.Command) Option(com.mks.api.Option)

Example 4 with Option

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

the class Sandbox method isValidSandbox.

/**
 * Attempts to figure out if the current sandbox already exists and is valid
 *
 * @param sandbox The client-side fully qualified path to the sandbox pj
 * @return true/false depending on whether or not this location has a valid sandbox
 * @throws APIException
 */
private boolean isValidSandbox(String sandbox) throws APIException {
    Command cmd = new Command(Command.SI, "sandboxinfo");
    cmd.addOption(new Option("sandbox", sandbox));
    api.getLogger().debug("Validating existing sandbox: " + sandbox);
    Response res = api.runCommand(cmd);
    WorkItemIterator wit = res.getWorkItems();
    try {
        WorkItem wi = wit.next();
        return wi.getField("fullConfigSyntax").getValueAsString().equalsIgnoreCase(siProject.getConfigurationPath());
    } catch (APIException aex) {
        ExceptionHandler eh = new ExceptionHandler(aex);
        api.getLogger().error("MKS API Exception: " + eh.getMessage());
        api.getLogger().debug(eh.getCommand() + " completed with exit code " + eh.getExitCode());
        return false;
    }
}
Also used : Response(com.mks.api.response.Response) APIException(com.mks.api.response.APIException) Command(com.mks.api.Command) Option(com.mks.api.Option) WorkItemIterator(com.mks.api.response.WorkItemIterator) WorkItem(com.mks.api.response.WorkItem)

Example 5 with Option

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

the class Sandbox method makeWriteable.

/**
 * Executes a 'si makewritable' command to allow edits to all files in the Sandbox directory
 *
 * @return MKS API Response object
 * @throws APIException
 */
public Response makeWriteable() throws APIException {
    api.getLogger().debug("Setting files to writeable in " + sandboxDir + " for project " + siProject.getConfigurationPath());
    Command cmd = new Command(Command.SI, "makewritable");
    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)

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