Search in sources :

Example 1 with Result

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

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

the class IntegrityUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
@Override
public UpdateScmResult executeUpdateCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion scmVersion) throws ScmException {
    getLogger().info("Attempting to synchronize sandbox in " + fileSet.getBasedir().getAbsolutePath());
    List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    Sandbox siSandbox = iRepo.getSandbox();
    try {
        // Make sure we've got a valid sandbox, otherwise create it...
        if (siSandbox.create()) {
            Response res = siSandbox.resync();
            // Lets capture what we got from running this resync
            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() : ""));
                    if (null != message && message.getMessage().length() > 0) {
                        updatedFiles.add(new ScmFile(wi.getDisplayId(), message.getMessage().equalsIgnoreCase("removed") ? ScmFileStatus.DELETED : ScmFileStatus.UPDATED));
                    }
                }
            }
            return new UpdateScmResult(res.getCommandString(), updatedFiles);
        } else {
            return new UpdateScmResult("si resync", "Failed to synchronize workspace", "", 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());
        return new UpdateScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    }
}
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) ArrayList(java.util.ArrayList) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) WorkItemIterator(com.mks.api.response.WorkItemIterator) WorkItem(com.mks.api.response.WorkItem) ScmFile(org.apache.maven.scm.ScmFile) Sandbox(org.apache.maven.scm.provider.integrity.Sandbox) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) Result(com.mks.api.response.Result)

Aggregations

APIException (com.mks.api.response.APIException)2 Response (com.mks.api.response.Response)2 Result (com.mks.api.response.Result)2 WorkItem (com.mks.api.response.WorkItem)2 WorkItemIterator (com.mks.api.response.WorkItemIterator)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 ArrayList (java.util.ArrayList)1 ScmFile (org.apache.maven.scm.ScmFile)1 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)1 UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)1