Search in sources :

Example 6 with Response

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

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

the class Sandbox method hasMemberChanged.

/**
 * Executes a 'si diff' command to see if the working file has actually changed.  Even though the
 * working file delta might be true, that doesn't always mean the file has actually changed.
 *
 * @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
 */
private boolean hasMemberChanged(File memberFile, String relativeName) {
    // Setup the differences command
    Command siDiff = new Command(Command.SI, "diff");
    siDiff.addOption(new Option("cwd", memberFile.getParentFile().getAbsolutePath()));
    siDiff.addSelection(relativeName);
    try {
        // Run the diff command...
        Response res = api.runCommand(siDiff);
        try {
            // Return the changed flag...
            return res.getWorkItems().next().getResult().getField("resultant").getItem().getField("different").getBoolean().booleanValue();
        } catch (NullPointerException npe) {
            api.getLogger().warn("Couldn't figure out differences for file: " + memberFile.getAbsolutePath());
            api.getLogger().warn("Null value found along response object for WorkItem/Result/Field/Item/Field.getBoolean()");
            api.getLogger().warn("Proceeding with the assumption that the file has changed!");
        }
    } catch (APIException aex) {
        ExceptionHandler eh = new ExceptionHandler(aex);
        api.getLogger().warn("Couldn't figure out differences for file: " + memberFile.getAbsolutePath());
        api.getLogger().warn(eh.getMessage());
        api.getLogger().warn("Proceeding with the assumption that the file has changed!");
        api.getLogger().debug(eh.getCommand() + " completed with exit Code " + eh.getExitCode());
    }
    return true;
}
Also used : Response(com.mks.api.response.Response) APIException(com.mks.api.response.APIException) Command(com.mks.api.Command) Option(com.mks.api.Option)

Example 8 with Response

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

the class IntegrityBranchCommand method executeBranchCommand.

/**
 * {@inheritDoc}
 */
@Override
public BranchScmResult executeBranchCommand(ScmProviderRepository repository, ScmFileSet fileSet, String branchName, String message) throws ScmException {
    BranchScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    Project siProject = iRepo.getProject();
    getLogger().info("Attempting to branch project " + siProject.getProjectName() + " using branch name '" + branchName + "'");
    try {
        Project.validateTag(branchName);
        Response res = siProject.createDevPath(branchName);
        int exitCode = res.getExitCode();
        boolean success = (exitCode == 0 ? true : false);
        ScmResult scmResult = new ScmResult(res.getCommandString(), "", "Exit Code: " + exitCode, success);
        result = new BranchScmResult(new ArrayList<ScmFile>(), scmResult);
    } 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 BranchScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    } catch (Exception e) {
        getLogger().error("Failed to checkpoint project! " + e.getMessage());
        result = new BranchScmResult("si createdevpath", e.getMessage(), "", false);
    }
    return result;
}
Also used : Response(com.mks.api.response.Response) ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) Project(org.apache.maven.scm.provider.integrity.Project) APIException(com.mks.api.response.APIException) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) ScmResult(org.apache.maven.scm.ScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) ArrayList(java.util.ArrayList) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) ScmException(org.apache.maven.scm.ScmException) APIException(com.mks.api.response.APIException)

Example 9 with Response

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

the class IntegrityEditCommand method executeEditCommand.

/**
 * {@inheritDoc}
 */
@Override
public EditScmResult executeEditCommand(ScmProviderRepository repository, ScmFileSet fileSet) throws ScmException {
    getLogger().info("Attempting make files writeable in Sandbox " + fileSet.getBasedir().getAbsolutePath());
    EditScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    try {
        Sandbox siSandbox = iRepo.getSandbox();
        Response res = siSandbox.makeWriteable();
        int exitCode = res.getExitCode();
        boolean success = (exitCode == 0 ? true : false);
        result = new EditScmResult(res.getCommandString(), "", "Exit Code: " + exitCode, success);
    } 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 EditScmResult(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) EditScmResult(org.apache.maven.scm.command.edit.EditScmResult) Sandbox(org.apache.maven.scm.provider.integrity.Sandbox)

Example 10 with Response

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

Aggregations

Response (com.mks.api.response.Response)22 APIException (com.mks.api.response.APIException)13 ExceptionHandler (org.apache.maven.scm.provider.integrity.ExceptionHandler)11 IntegrityScmProviderRepository (org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository)11 Command (com.mks.api.Command)9 Option (com.mks.api.Option)8 WorkItem (com.mks.api.response.WorkItem)8 Sandbox (org.apache.maven.scm.provider.integrity.Sandbox)8 WorkItemIterator (com.mks.api.response.WorkItemIterator)7 ArrayList (java.util.ArrayList)7 ScmException (org.apache.maven.scm.ScmException)5 File (java.io.File)4 ScmFile (org.apache.maven.scm.ScmFile)4 ScmResult (org.apache.maven.scm.ScmResult)4 CmdRunner (com.mks.api.CmdRunner)3 MultiValue (com.mks.api.MultiValue)3 Project (org.apache.maven.scm.provider.integrity.Project)3 Item (com.mks.api.response.Item)2 Result (com.mks.api.response.Result)2 Hashtable (java.util.Hashtable)2