Search in sources :

Example 1 with WorkItemIterator

use of com.mks.api.response.WorkItemIterator 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 WorkItemIterator

use of com.mks.api.response.WorkItemIterator 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 WorkItemIterator

use of com.mks.api.response.WorkItemIterator 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 4 with WorkItemIterator

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

the class IntegrityCheckOutCommand method executeCheckOutCommand.

/**
 * Overridden function that performs a checkout (resynchronize) operation against an MKS Source Project
 * This function ignores the scmVerion and recursive arguments passed into this function as while there is
 * a suitable equivalent to checkout/resynchronize by label/revision, it doesn't make sense for the way
 * Maven seems to want to execute this command.  Hence we will create/resynchronize a sandbox, which will
 * be recursive in nature.  If the user chooses to checkout a specific versioned configuration (checkpoint),
 * then that information will be contained in the Configuration Path obtained from the
 * IntegrityScmProviderRepository
 */
@Override
public CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, boolean recursive, boolean shallow) throws ScmException {
    CheckOutScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    try {
        getLogger().info("Attempting to checkout source for project " + iRepo.getProject().getConfigurationPath());
        String checkoutDir = System.getProperty("checkoutDirectory");
        // Override the sandbox definition, if a checkout directory is specified for this command
        Sandbox siSandbox;
        if (null != checkoutDir && checkoutDir.length() > 0) {
            siSandbox = new Sandbox(iRepo.getAPISession(), iRepo.getProject(), checkoutDir);
            iRepo.setSandbox(siSandbox);
        } else {
            siSandbox = iRepo.getSandbox();
        }
        getLogger().info("Sandbox location is " + siSandbox.getSandboxDir());
        // Now attempt to create the sandbox, if it doesn't already exist
        if (siSandbox.create()) {
            // Resynchronize the new or previously created sandbox
            Response res = siSandbox.resync();
            // Lets output what we got from running this command
            WorkItemIterator wit = res.getWorkItems();
            while (wit.hasNext()) {
                WorkItem wi = wit.next();
                if (wi.getModelType().equals(SIModelTypeName.MEMBER)) {
                    Result message = wi.getResult();
                    getLogger().debug(wi.getDisplayId() + " " + (null != message ? message.getMessage() : ""));
                }
            }
            int exitCode = res.getExitCode();
            boolean success = (exitCode == 0 ? true : false);
            result = new CheckOutScmResult(res.getCommandString(), "", "Exit Code: " + exitCode, success);
        } else {
            result = new CheckOutScmResult("si createsandbox", "Failed to create sandbox!", "", false);
        }
    } catch (APIException aex) {
        ExceptionHandler eh = new ExceptionHandler(aex);
        getLogger().error("MKS API Exception: " + eh.getMessage());
        getLogger().info(eh.getCommand() + " exited with return code " + eh.getExitCode());
        result = new CheckOutScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    }
    return result;
}
Also used : Response(com.mks.api.response.Response) ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) APIException(com.mks.api.response.APIException) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) WorkItemIterator(com.mks.api.response.WorkItemIterator) WorkItem(com.mks.api.response.WorkItem) Sandbox(org.apache.maven.scm.provider.integrity.Sandbox) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) Result(com.mks.api.response.Result)

Example 5 with WorkItemIterator

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

the class Project method listFiles.

/**
 * Parses the output from the si viewproject command to get a list of members
 *
 * @param workspaceDir The current workspace directory, which is required for an export
 * @return The list of Member objects for this project
 * @throws APIException
 */
public List<Member> listFiles(String workspaceDir) throws APIException {
    // Re-initialize the member list for this project
    List<Member> memberList = new ArrayList<Member>();
    // Initialize the project config hash
    Hashtable<String, String> pjConfigHash = new Hashtable<String, String>();
    // Add the mapping for this project
    pjConfigHash.put(projectName, fullConfigSyntax);
    // Compute the project root directory
    String projectRoot = projectName.substring(0, projectName.lastIndexOf('/'));
    // Now, lets parse this project
    Command siViewProjectCmd = new Command(Command.SI, "viewproject");
    siViewProjectCmd.addOption(new Option("recurse"));
    siViewProjectCmd.addOption(new Option("project", fullConfigSyntax));
    MultiValue mvFields = new MultiValue(",");
    mvFields.add("name");
    mvFields.add("context");
    mvFields.add("memberrev");
    mvFields.add("membertimestamp");
    mvFields.add("memberdescription");
    siViewProjectCmd.addOption(new Option("fields", mvFields));
    api.getLogger().info("Preparing to execute si viewproject for " + fullConfigSyntax);
    Response viewRes = api.runCommand(siViewProjectCmd);
    // Iterate through the list of members returned by the API
    WorkItemIterator wit = viewRes.getWorkItems();
    while (wit.hasNext()) {
        WorkItem wi = wit.next();
        if (wi.getModelType().equals(SIModelTypeName.SI_SUBPROJECT)) {
            // Save the configuration path for the current subproject, using the canonical path name
            pjConfigHash.put(wi.getField("name").getValueAsString(), wi.getId());
        } else if (wi.getModelType().equals(SIModelTypeName.MEMBER)) {
            // Figure out this member's parent project's canonical path name
            String parentProject = wi.getField("parent").getValueAsString();
            // Instantiate our Integrity CM Member object
            Member iCMMember = new Member(wi, pjConfigHash.get(parentProject), projectRoot, workspaceDir);
            // Add this to the full list of members in this project
            memberList.add(iCMMember);
        } else {
            api.getLogger().warn("View project output contains an invalid model type: " + wi.getModelType());
        }
    }
    // Sort the files list...
    Collections.sort(memberList, FILES_ORDER);
    return memberList;
}
Also used : Response(com.mks.api.response.Response) Command(com.mks.api.Command) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Option(com.mks.api.Option) WorkItemIterator(com.mks.api.response.WorkItemIterator) WorkItem(com.mks.api.response.WorkItem) MultiValue(com.mks.api.MultiValue)

Aggregations

Response (com.mks.api.response.Response)7 WorkItemIterator (com.mks.api.response.WorkItemIterator)7 WorkItem (com.mks.api.response.WorkItem)6 Command (com.mks.api.Command)5 Option (com.mks.api.Option)5 ArrayList (java.util.ArrayList)5 MultiValue (com.mks.api.MultiValue)3 APIException (com.mks.api.response.APIException)3 ScmFile (org.apache.maven.scm.ScmFile)3 Item (com.mks.api.response.Item)2 Result (com.mks.api.response.Result)2 Hashtable (java.util.Hashtable)2 ChangeFile (org.apache.maven.scm.ChangeFile)2 ExceptionHandler (org.apache.maven.scm.provider.integrity.ExceptionHandler)2 Sandbox (org.apache.maven.scm.provider.integrity.Sandbox)2 IntegrityScmProviderRepository (org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository)2 Field (com.mks.api.response.Field)1 File (java.io.File)1 Date (java.util.Date)1 ChangeSet (org.apache.maven.scm.ChangeSet)1