Search in sources :

Example 16 with APIException

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

the class IntegrityUnEditCommand method executeUnEditCommand.

/**
 * {@inheritDoc}
 */
@Override
public UnEditScmResult executeUnEditCommand(ScmProviderRepository repository, ScmFileSet fileSet) throws ScmException {
    getLogger().info("Attempting to revert members in sandbox " + fileSet.getBasedir().getAbsolutePath());
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    UnEditScmResult result;
    try {
        Sandbox siSandbox = iRepo.getSandbox();
        Response res = siSandbox.revertMembers();
        int exitCode = res.getExitCode();
        boolean success = (exitCode == 0 ? true : false);
        result = new UnEditScmResult(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 UnEditScmResult(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) UnEditScmResult(org.apache.maven.scm.command.unedit.UnEditScmResult) Sandbox(org.apache.maven.scm.provider.integrity.Sandbox)

Example 17 with APIException

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

Example 18 with APIException

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

the class IntegrityLoginCommand method executeLoginCommand.

/**
 * {@inheritDoc}
 */
@Override
public LoginScmResult executeLoginCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params) throws ScmException {
    getLogger().info("Attempting to connect with the MKS Integrity Server");
    LoginScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    APISession api = iRepo.getAPISession();
    try {
        // First we will establish a connection to the MKS Integrity Server
        Response res = api.connect(iRepo.getHost(), iRepo.getPort(), iRepo.getUser(), iRepo.getPassword());
        int exitCode = res.getExitCode();
        boolean success = (exitCode == 0 ? true : false);
        result = new LoginScmResult(res.getCommandString(), "", "Exit Code: " + exitCode, success);
        // Next we will prepare the Project and Sandbox for the other commands
        Project siProject = new Project(api, iRepo.getConfigruationPath());
        Sandbox siSandbox = new Sandbox(api, siProject, fileSet.getBasedir().getAbsolutePath());
        iRepo.setProject(siProject);
        iRepo.setSandbox(siSandbox);
    } 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 LoginScmResult(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) Project(org.apache.maven.scm.provider.integrity.Project) APIException(com.mks.api.response.APIException) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) LoginScmResult(org.apache.maven.scm.command.login.LoginScmResult) APISession(org.apache.maven.scm.provider.integrity.APISession) Sandbox(org.apache.maven.scm.provider.integrity.Sandbox)

Example 19 with APIException

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

the class IntegrityRemoveCommand method executeRemoveCommand.

/**
 * {@inheritDoc}
 */
@Override
public RemoveScmResult executeRemoveCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message) throws ScmException {
    getLogger().info("Attempting to un-register sandbox in directory " + fileSet.getBasedir().getAbsolutePath());
    RemoveScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    try {
        Sandbox siSandbox = iRepo.getSandbox();
        Response res = siSandbox.drop();
        int exitCode = res.getExitCode();
        boolean success = (exitCode == 0 ? true : false);
        result = new RemoveScmResult(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 RemoveScmResult(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) RemoveScmResult(org.apache.maven.scm.command.remove.RemoveScmResult) Sandbox(org.apache.maven.scm.provider.integrity.Sandbox)

Example 20 with APIException

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

the class IntegrityTagCommand method executeTagCommand.

/**
 * {@inheritDoc}
 */
@Override
public TagScmResult executeTagCommand(ScmProviderRepository repository, ScmFileSet fileSet, String tagName, ScmTagParameters scmTagParameters) throws ScmException {
    getLogger().info("Attempting to checkpoint project associated with sandbox " + fileSet.getBasedir().getAbsolutePath());
    TagScmResult result;
    String message = scmTagParameters.getMessage();
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    try {
        // First validate the checkpoint label string by evaluating the groovy script
        String chkptLabel = evalGroovyExpression(tagName);
        Project.validateTag(chkptLabel);
        String msg = ((null == message || message.length() == 0) ? System.getProperty("message") : message);
        // Get information about the Project
        Project siProject = iRepo.getProject();
        // Ensure this is not a build project configuration
        if (!siProject.isBuild()) {
            Response res = siProject.checkpoint(msg, chkptLabel);
            int exitCode = res.getExitCode();
            boolean success = (exitCode == 0 ? true : false);
            WorkItem wi = res.getWorkItem(siProject.getConfigurationPath());
            String chkpt = wi.getResult().getField("resultant").getItem().getId();
            getLogger().info("Successfully checkpointed project " + siProject.getConfigurationPath() + " with label '" + chkptLabel + "', new revision is " + chkpt);
            result = new TagScmResult(res.getCommandString(), wi.getResult().getMessage(), "Exit Code: " + exitCode, success);
        } else {
            getLogger().error("Cannot checkpoint a build project configuration: " + siProject.getConfigurationPath() + "!");
            result = new TagScmResult("si checkpoint", "Cannot checkpoint a build project configuration!", "", false);
        }
    } catch (CompilationFailedException cfe) {
        getLogger().error("Groovy Compilation Exception: " + cfe.getMessage());
        result = new TagScmResult("si checkpoint", cfe.getMessage(), "", 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 TagScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    } catch (Exception e) {
        getLogger().error("Failed to checkpoint project! " + e.getMessage());
        result = new TagScmResult("si checkpoint", 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) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) WorkItem(com.mks.api.response.WorkItem) ScmException(org.apache.maven.scm.ScmException) APIException(com.mks.api.response.APIException) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException)

Aggregations

APIException (com.mks.api.response.APIException)20 ExceptionHandler (org.apache.maven.scm.provider.integrity.ExceptionHandler)15 IntegrityScmProviderRepository (org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository)15 Response (com.mks.api.response.Response)13 Sandbox (org.apache.maven.scm.provider.integrity.Sandbox)9 ArrayList (java.util.ArrayList)8 ScmFile (org.apache.maven.scm.ScmFile)8 File (java.io.File)7 ScmResult (org.apache.maven.scm.ScmResult)7 WorkItem (com.mks.api.response.WorkItem)6 ScmException (org.apache.maven.scm.ScmException)6 Command (com.mks.api.Command)3 Option (com.mks.api.Option)3 WorkItemIterator (com.mks.api.response.WorkItemIterator)3 ChangeFile (org.apache.maven.scm.ChangeFile)3 Project (org.apache.maven.scm.provider.integrity.Project)3 Result (com.mks.api.response.Result)2 Member (org.apache.maven.scm.provider.integrity.Member)2 BranchScmResult (org.apache.maven.scm.command.branch.BranchScmResult)1 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)1