Search in sources :

Example 1 with ExceptionHandler

use of org.apache.maven.scm.provider.integrity.ExceptionHandler 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 2 with ExceptionHandler

use of org.apache.maven.scm.provider.integrity.ExceptionHandler 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 3 with ExceptionHandler

use of org.apache.maven.scm.provider.integrity.ExceptionHandler 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 4 with ExceptionHandler

use of org.apache.maven.scm.provider.integrity.ExceptionHandler in project maven-scm by apache.

the class IntegrityExportCommand method executeExportCommand.

/**
 * {@inheritDoc}
 */
@Override
public ExportScmResult executeExportCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, String outputDirectory) throws ScmException {
    // First lets figure out where we need to export files to...
    String exportDir = outputDirectory;
    exportDir = ((null != exportDir && exportDir.length() > 0) ? exportDir : fileSet.getBasedir().getAbsolutePath());
    // Let the user know where we're going to be exporting the files...
    getLogger().info("Attempting to export files to " + exportDir);
    ExportScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    try {
        // Lets set our overall export success flag
        boolean exportSuccess = true;
        // Perform a fresh checkout of each file in the member list...
        List<Member> projectMembers = iRepo.getProject().listFiles(exportDir);
        // Initialize the list of files we actually exported...
        List<ScmFile> scmFileList = new ArrayList<ScmFile>();
        for (Iterator<Member> it = projectMembers.iterator(); it.hasNext(); ) {
            Member siMember = it.next();
            try {
                getLogger().info("Attempting to export file: " + siMember.getTargetFilePath() + " at revision " + siMember.getRevision());
                siMember.checkout(iRepo.getAPISession());
                scmFileList.add(new ScmFile(siMember.getTargetFilePath(), ScmFileStatus.UNKNOWN));
            } catch (APIException ae) {
                exportSuccess = false;
                ExceptionHandler eh = new ExceptionHandler(ae);
                getLogger().error("MKS API Exception: " + eh.getMessage());
                getLogger().debug(eh.getCommand() + " exited with return code " + eh.getExitCode());
            }
        }
        // Lets advice the user that we've checked out all the members
        getLogger().info("Exported " + scmFileList.size() + " files out of a total of " + projectMembers.size() + " files!");
        if (exportSuccess) {
            result = new ExportScmResult("si co", scmFileList);
        } else {
            result = new ExportScmResult("si co", "Failed to export all files!", "", exportSuccess);
        }
    } catch (APIException aex) {
        ExceptionHandler eh = new ExceptionHandler(aex);
        getLogger().error("MKS API Exception: " + eh.getMessage());
        getLogger().debug(eh.getCommand() + " exited with return code " + eh.getExitCode());
        result = new ExportScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    }
    return result;
}
Also used : ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) APIException(com.mks.api.response.APIException) ExportScmResult(org.apache.maven.scm.command.export.ExportScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) ArrayList(java.util.ArrayList) Member(org.apache.maven.scm.provider.integrity.Member) ScmFile(org.apache.maven.scm.ScmFile)

Example 5 with ExceptionHandler

use of org.apache.maven.scm.provider.integrity.ExceptionHandler in project maven-scm by apache.

the class IntegrityLockCommand method executeLockCommand.

/**
 * {@inheritDoc}
 */
@Override
public ScmResult executeLockCommand(ScmProviderRepository repository, File workingDirectory, String filename) throws ScmException {
    getLogger().info("Attempting to lock file: " + filename);
    if (null == filename || filename.length() == 0) {
        throw new ScmException("A single filename is required to execute the lock command!");
    }
    ScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    try {
        Sandbox siSandbox = iRepo.getSandbox();
        File memberFile = new File(workingDirectory.getAbsoluteFile() + File.separator + filename);
        Response res = siSandbox.lock(memberFile, filename);
        int exitCode = res.getExitCode();
        boolean success = (exitCode == 0 ? true : false);
        result = new ScmResult(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 ScmResult(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) ScmException(org.apache.maven.scm.ScmException) APIException(com.mks.api.response.APIException) ScmResult(org.apache.maven.scm.ScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) File(java.io.File) Sandbox(org.apache.maven.scm.provider.integrity.Sandbox)

Aggregations

APIException (com.mks.api.response.APIException)15 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)11 Sandbox (org.apache.maven.scm.provider.integrity.Sandbox)9 ScmResult (org.apache.maven.scm.ScmResult)7 ArrayList (java.util.ArrayList)6 ScmException (org.apache.maven.scm.ScmException)6 ScmFile (org.apache.maven.scm.ScmFile)5 WorkItem (com.mks.api.response.WorkItem)4 File (java.io.File)4 Project (org.apache.maven.scm.provider.integrity.Project)3 Result (com.mks.api.response.Result)2 WorkItemIterator (com.mks.api.response.WorkItemIterator)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 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)1 EditScmResult (org.apache.maven.scm.command.edit.EditScmResult)1 ExportScmResult (org.apache.maven.scm.command.export.ExportScmResult)1