Search in sources :

Example 6 with WorkItem

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

the class Project method createDevPath.

/**
 * Creates a Development Path (project branch) for the MKS Integrity SCM Project
 *
 * @param devPath Development Path Name
 * @return MKS API Response object
 * @throws APIException
 */
public Response createDevPath(String devPath) throws APIException {
    // First we need to obtain a checkpoint from the current configuration (normal or variant)
    String chkpt = projectRevision;
    if (!isBuild()) {
        Response chkptRes = checkpoint("Pre-checkpoint for development path " + devPath, devPath + " Baseline");
        WorkItem wi = chkptRes.getWorkItem(fullConfigSyntax);
        chkpt = wi.getResult().getField("resultant").getItem().getId();
    }
    // Now lets setup the create development path command
    api.getLogger().debug("Creating development path '" + devPath + "' for project " + projectName + " at revision '" + chkpt + "'");
    Command siCreateDevPath = new Command(Command.SI, "createdevpath");
    siCreateDevPath.addOption(new Option("devpath", devPath));
    // Set the project name
    siCreateDevPath.addOption(new Option("project", projectName));
    // Set the checkpoint we want to create the development path from
    siCreateDevPath.addOption(new Option("projectRevision", chkpt));
    // Run the create development path command
    return api.runCommand(siCreateDevPath);
}
Also used : Response(com.mks.api.response.Response) Command(com.mks.api.Command) Option(com.mks.api.Option) WorkItem(com.mks.api.response.WorkItem)

Example 7 with WorkItem

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

the class Project method listFiles.

/**
 * Parses the output from the si viewproject command to get a list of members
 *
 * @param workspaceDir The current workspace directory, which is required for an export
 * @return The list of Member objects for this project
 * @throws APIException
 */
public List<Member> listFiles(String workspaceDir) throws APIException {
    // Re-initialize the member list for this project
    List<Member> memberList = new ArrayList<Member>();
    // Initialize the project config hash
    Hashtable<String, String> pjConfigHash = new Hashtable<String, String>();
    // Add the mapping for this project
    pjConfigHash.put(projectName, fullConfigSyntax);
    // Compute the project root directory
    String projectRoot = projectName.substring(0, projectName.lastIndexOf('/'));
    // Now, lets parse this project
    Command siViewProjectCmd = new Command(Command.SI, "viewproject");
    siViewProjectCmd.addOption(new Option("recurse"));
    siViewProjectCmd.addOption(new Option("project", fullConfigSyntax));
    MultiValue mvFields = new MultiValue(",");
    mvFields.add("name");
    mvFields.add("context");
    mvFields.add("memberrev");
    mvFields.add("membertimestamp");
    mvFields.add("memberdescription");
    siViewProjectCmd.addOption(new Option("fields", mvFields));
    api.getLogger().info("Preparing to execute si viewproject for " + fullConfigSyntax);
    Response viewRes = api.runCommand(siViewProjectCmd);
    // Iterate through the list of members returned by the API
    WorkItemIterator wit = viewRes.getWorkItems();
    while (wit.hasNext()) {
        WorkItem wi = wit.next();
        if (wi.getModelType().equals(SIModelTypeName.SI_SUBPROJECT)) {
            // Save the configuration path for the current subproject, using the canonical path name
            pjConfigHash.put(wi.getField("name").getValueAsString(), wi.getId());
        } else if (wi.getModelType().equals(SIModelTypeName.MEMBER)) {
            // Figure out this member's parent project's canonical path name
            String parentProject = wi.getField("parent").getValueAsString();
            // Instantiate our Integrity CM Member object
            Member iCMMember = new Member(wi, pjConfigHash.get(parentProject), projectRoot, workspaceDir);
            // Add this to the full list of members in this project
            memberList.add(iCMMember);
        } else {
            api.getLogger().warn("View project output contains an invalid model type: " + wi.getModelType());
        }
    }
    // Sort the files list...
    Collections.sort(memberList, FILES_ORDER);
    return memberList;
}
Also used : Response(com.mks.api.response.Response) Command(com.mks.api.Command) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Option(com.mks.api.Option) WorkItemIterator(com.mks.api.response.WorkItemIterator) WorkItem(com.mks.api.response.WorkItem) MultiValue(com.mks.api.MultiValue)

Example 8 with WorkItem

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

the class Sandbox method getChangeLog.

/**
 * Executes the 'si rlog' command to generate a list of changed revision found between startDate and endDate
 *
 * @param startDate The date range for the beginning of the operation
 * @param endDate   The date range for the end of the operation
 * @return ChangeLogSet containing a list of changes grouped by Change Pacakge ID
 * @throws APIException
 */
public ChangeLogSet getChangeLog(Date startDate, Date endDate) throws APIException {
    // Initialize our return object
    ChangeLogSet changeLog = new ChangeLogSet(startDate, endDate);
    // By default we're going to group-by change package
    // Non change package changes will be lumped into one big Change Set
    Hashtable<String, ChangeSet> changeSetHash = new Hashtable<String, ChangeSet>();
    // Lets prepare our si rlog command for execution
    Command siRlog = new Command(Command.SI, "rlog");
    siRlog.addOption(new Option("recurse"));
    MultiValue rFilter = new MultiValue(":");
    rFilter.add("daterange");
    rFilter.add("'" + RLOG_DATEFORMAT.format(startDate) + "'-'" + RLOG_DATEFORMAT.format(endDate) + "'");
    siRlog.addOption(new Option("rfilter", rFilter));
    siRlog.addOption(new Option("cwd", sandboxDir));
    // Execute the si rlog command
    Response response = api.runCommand(siRlog);
    for (WorkItemIterator wit = response.getWorkItems(); wit.hasNext(); ) {
        WorkItem wi = wit.next();
        String memberName = wi.getContext();
        // We're going to have to do a little dance to get the correct server file name
        memberName = memberName.substring(0, memberName.lastIndexOf('/'));
        memberName = memberName + '/' + wi.getId();
        memberName = memberName.replace('\\', '/');
        // Now lets get the revisions for this file
        Field revisionsFld = wi.getField("revisions");
        if (null != revisionsFld && revisionsFld.getDataType().equals(Field.ITEM_LIST_TYPE) && null != revisionsFld.getList()) {
            @SuppressWarnings("unchecked") List<Item> revList = revisionsFld.getList();
            for (Iterator<Item> lit = revList.iterator(); lit.hasNext(); ) {
                Item revisionItem = lit.next();
                String revision = revisionItem.getId();
                String author = revisionItem.getField("author").getItem().getId();
                // Attempt to get the full name, if available
                try {
                    author = revisionItem.getField("author").getItem().getField("fullname").getValueAsString();
                } catch (NullPointerException npe) {
                /* ignore */
                }
                String cpid = ":none";
                // Attempt to get the cpid for this revision
                try {
                    cpid = revisionItem.getField("cpid").getItem().getId();
                } catch (NullPointerException npe) {
                /* ignore */
                }
                // Get the Change Package summary for this revision
                String comment = cpid + ": " + revisionItem.getField("cpsummary").getValueAsString();
                // Get the date associated with this revision
                Date date = revisionItem.getField("date").getDateTime();
                // Lets create our ChangeFile based on the information we've gathered so far
                ChangeFile changeFile = new ChangeFile(memberName, revision);
                // Check to see if we already have a ChangeSet grouping for this revision
                ChangeSet changeSet = changeSetHash.get(cpid);
                if (null != changeSet) {
                    // Set the date of the ChangeSet to the oldest entry
                    if (changeSet.getDate().after(date)) {
                        changeSet.setDate(date);
                    }
                    // Add the new ChangeFile
                    changeSet.addFile(changeFile);
                    // Update the changeSetHash
                    changeSetHash.put(cpid, changeSet);
                } else // Create a new ChangeSet grouping and add the ChangeFile
                {
                    List<ChangeFile> changeFileList = new ArrayList<ChangeFile>();
                    changeFileList.add(changeFile);
                    changeSet = new ChangeSet(date, comment, author, changeFileList);
                    // Update the changeSetHash with an initial entry for the cpid
                    changeSetHash.put(cpid, changeSet);
                }
            }
        }
    }
    // Update the Change Log with the Change Sets
    List<ChangeSet> changeSetList = new ArrayList<ChangeSet>();
    changeSetList.addAll(changeSetHash.values());
    changeLog.setChangeSets(changeSetList);
    return changeLog;
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) WorkItemIterator(com.mks.api.response.WorkItemIterator) WorkItem(com.mks.api.response.WorkItem) Date(java.util.Date) Response(com.mks.api.response.Response) Field(com.mks.api.response.Field) WorkItem(com.mks.api.response.WorkItem) Item(com.mks.api.response.Item) Command(com.mks.api.Command) ChangeFile(org.apache.maven.scm.ChangeFile) Option(com.mks.api.Option) ChangeSet(org.apache.maven.scm.ChangeSet) MultiValue(com.mks.api.MultiValue)

Example 9 with WorkItem

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

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

WorkItem (com.mks.api.response.WorkItem)10 Response (com.mks.api.response.Response)8 APIException (com.mks.api.response.APIException)6 WorkItemIterator (com.mks.api.response.WorkItemIterator)6 ArrayList (java.util.ArrayList)6 Command (com.mks.api.Command)5 Option (com.mks.api.Option)5 ScmFile (org.apache.maven.scm.ScmFile)4 ExceptionHandler (org.apache.maven.scm.provider.integrity.ExceptionHandler)4 IntegrityScmProviderRepository (org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository)4 MultiValue (com.mks.api.MultiValue)3 File (java.io.File)3 ChangeFile (org.apache.maven.scm.ChangeFile)3 Sandbox (org.apache.maven.scm.provider.integrity.Sandbox)3 Item (com.mks.api.response.Item)2 Result (com.mks.api.response.Result)2 Hashtable (java.util.Hashtable)2 Field (com.mks.api.response.Field)1 Date (java.util.Date)1 ChangeSet (org.apache.maven.scm.ChangeSet)1