Search in sources :

Example 6 with APIException

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

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

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

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

Example 10 with APIException

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

the class IntegrityMkdirCommand method executeMkdirCommand.

/**
 * Creates a subproject in the Integrity repository.
 * <br>However, since the subproject automatically creates a folder in
 * the local sandbox, the createInLocal argument will be ignored
 */
@Override
public MkdirScmResult executeMkdirCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean createInLocal) throws ScmException {
    String dirPath = "";
    Iterator<File> fit = fileSet.getFileList().iterator();
    if (fit.hasNext()) {
        dirPath = fit.next().getPath().replace('\\', '/');
    }
    if (null == dirPath || dirPath.length() == 0) {
        throw new ScmException("A relative directory path is required to execute this command!");
    }
    getLogger().info("Creating subprojects one per directory, as required for " + dirPath);
    MkdirScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    try {
        Response res = iRepo.getSandbox().createSubproject(dirPath);
        String subProject = res.getWorkItems().next().getResult().getField("resultant").getItem().getDisplayId();
        List<ScmFile> createdDirs = new ArrayList<ScmFile>();
        createdDirs.add(new ScmFile(subProject, ScmFileStatus.ADDED));
        int exitCode = res.getExitCode();
        boolean success = (exitCode == 0 ? true : false);
        getLogger().info("Successfully created subproject " + subProject);
        result = new MkdirScmResult(createdDirs, 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 MkdirScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    }
    return result;
}
Also used : ScmException(org.apache.maven.scm.ScmException) MkdirScmResult(org.apache.maven.scm.command.mkdir.MkdirScmResult) ScmResult(org.apache.maven.scm.ScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) Response(com.mks.api.response.Response) ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) APIException(com.mks.api.response.APIException) MkdirScmResult(org.apache.maven.scm.command.mkdir.MkdirScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

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