Search in sources :

Example 1 with APIException

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

the class Sandbox method checkInUpdates.

/**
 * Wrapper function to check-in all changes and drop members associated with missing working files
 *
 * @param message Description for the changes
 * @return
 */
public List<ScmFile> checkInUpdates(String message) {
    // Re-initialize the overall ciSuccess to be true for now
    ciSuccess = true;
    // Store a list of files that were changed/removed to the repository
    List<ScmFile> changedFiles = new ArrayList<ScmFile>();
    api.getLogger().debug("Looking for changed and dropped members in sandbox dir: " + sandboxDir);
    try {
        // Let the list of changed files
        List<WorkItem> changeList = getChangeList();
        // Check-in all changed files, drop all members with missing working files
        for (Iterator<WorkItem> wit = changeList.iterator(); wit.hasNext(); ) {
            try {
                WorkItem wi = wit.next();
                File memberFile = new File(wi.getField("name").getValueAsString());
                // Check-in files that have actually changed...
                if (hasWorkingFile((Item) wi.getField("wfdelta").getValue())) {
                    // Lock each member as you go...
                    lock(memberFile, wi.getId());
                    // Commit the changes...
                    checkin(memberFile, wi.getId(), message);
                    // Update the changed file list
                    changedFiles.add(new ScmFile(memberFile.getAbsolutePath(), ScmFileStatus.CHECKED_IN));
                } else {
                    // Drop the member if there is no working file
                    dropMember(memberFile, wi.getId());
                    // Update the changed file list
                    changedFiles.add(new ScmFile(memberFile.getAbsolutePath(), ScmFileStatus.DELETED));
                }
            } catch (APIException aex) {
                // Set the ciSuccess to false, since we ran into a problem
                ciSuccess = false;
                ExceptionHandler eh = new ExceptionHandler(aex);
                api.getLogger().error("MKS API Exception: " + eh.getMessage());
                api.getLogger().debug(eh.getCommand() + " completed with exit Code " + eh.getExitCode());
            }
        }
    } catch (APIException aex) {
        // Set the ciSuccess to false, since we ran into a problem
        ciSuccess = false;
        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 changedFiles;
}
Also used : APIException(com.mks.api.response.APIException) ArrayList(java.util.ArrayList) WorkItem(com.mks.api.response.WorkItem) ChangeFile(org.apache.maven.scm.ChangeFile) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 2 with APIException

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

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

the class Sandbox method create.

/**
 * Creates a new Sandbox in the sandboxDir specified
 *
 * @return true if the operation is successful; false otherwise
 * @throws APIException
 */
public boolean create() throws APIException {
    File project = new File(siProject.getProjectName());
    File sandboxpj = new File(sandboxDir + fs + project.getName());
    // Check to see if the sandbox file already exists and its OK to use
    api.getLogger().debug("Sandbox Project File: " + sandboxpj.getAbsolutePath());
    if (sandboxpj.isFile()) {
        // Validate this sandbox
        if (isValidSandbox(sandboxpj.getAbsolutePath())) {
            api.getLogger().debug("Reusing existing Sandbox in " + sandboxDir + " for project " + siProject.getConfigurationPath());
            return true;
        } else {
            api.getLogger().error("An invalid Sandbox exists in " + sandboxDir + ". Please provide a different location!");
            return false;
        }
    } else // Create a new sandbox in the location specified
    {
        api.getLogger().debug("Creating Sandbox in " + sandboxDir + " for project " + siProject.getConfigurationPath());
        try {
            Command cmd = new Command(Command.SI, "createsandbox");
            cmd.addOption(new Option("recurse"));
            cmd.addOption(new Option("nopopulate"));
            cmd.addOption(new Option("project", siProject.getConfigurationPath()));
            cmd.addOption(new Option("cwd", sandboxDir));
            api.runCommand(cmd);
        } catch (APIException aex) {
            // Check to see if this exception is due an existing sandbox registry entry
            ExceptionHandler eh = new ExceptionHandler(aex);
            if (eh.getMessage().indexOf("There is already a registered entry") > 0) {
                // This will re-validate the sandbox, if Maven blew away the old directory
                return create();
            } else {
                throw aex;
            }
        }
        return true;
    }
}
Also used : APIException(com.mks.api.response.APIException) Command(com.mks.api.Command) Option(com.mks.api.Option) ChangeFile(org.apache.maven.scm.ChangeFile) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Example 4 with APIException

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

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

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