Search in sources :

Example 1 with Command

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

the class APISession method connect.

/**
 * Establishes a connection with the MKS Integrity Server
 *
 * @param host    Hostname or IP address for the MKS Integrity Server
 * @param portNum Port number for the MKS Integrity Server
 * @param user    Username to connect to the MKS Integrity Server
 * @param paswd   Password for the User connecting to the server
 * @throws APIException
 */
public Response connect(String host, int portNum, String user, String paswd) throws APIException {
    // Initialize our termination flag...
    terminated = false;
    // Create a local integration point
    ip = IntegrationPointFactory.getInstance().createLocalIntegrationPoint(MAJOR_VERSION, MINOR_VERSION);
    // Set the flag to automatically start the MKS Integrity Client, if not running
    ip.setAutoStartIntegrityClient(true);
    // Use a common session, which means we don't have to manage the password
    if (null != paswd && paswd.length() > 0) {
        logger.info("Creating session for " + user + "/" + StringUtils.repeat("*", paswd.length()));
        session = ip.createSession(user, paswd);
        logger.info("Attempting to establish connection using " + user + "@" + host + ":" + portNum);
    } else {
        logger.info("Using a common session.  Connection information is obtained from client preferences");
        session = ip.getCommonSession();
    }
    // Test the connection to the MKS Integrity Server
    Command ping = new Command(Command.SI, "connect");
    CmdRunner cmdRunner = session.createCmdRunner();
    // Initialize the command runner with valid connection information
    if (null != host && host.length() > 0) {
        cmdRunner.setDefaultHostname(host);
    }
    if (portNum > 0) {
        cmdRunner.setDefaultPort(portNum);
    }
    if (null != user && user.length() > 0) {
        cmdRunner.setDefaultUsername(user);
    }
    if (null != paswd && paswd.length() > 0) {
        cmdRunner.setDefaultPassword(paswd);
    }
    // Execute the connection
    Response res = cmdRunner.execute(ping);
    logger.debug(res.getCommandString() + " returned exit code " + res.getExitCode());
    // Initialize class variables based on the connection information
    hostName = res.getConnectionHostname();
    port = res.getConnectionPort();
    userName = res.getConnectionUsername();
    password = paswd;
    cmdRunner.release();
    logger.info("Successfully established connection " + userName + "@" + hostName + ":" + port);
    return res;
}
Also used : CmdRunner(com.mks.api.CmdRunner) Response(com.mks.api.response.Response) Command(com.mks.api.Command)

Example 2 with Command

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

the class Sandbox method getChangeList.

/**
 * Executes a 'si viewsandbox' and parses the output for changed or dropped working files
 *
 * @return A list of MKS API Response WorkItem objects representing the changes in the Sandbox
 * @throws APIException
 */
public List<WorkItem> getChangeList() throws APIException {
    // Store a list of files that were changed/removed to the repository
    List<WorkItem> changedFiles = new ArrayList<WorkItem>();
    // Setup the view sandbox command to figure out what has changed...
    Command siViewSandbox = new Command(Command.SI, "viewsandbox");
    // Create the --fields option
    MultiValue mv = new MultiValue(",");
    mv.add("name");
    mv.add("context");
    mv.add("wfdelta");
    mv.add("memberarchive");
    siViewSandbox.addOption(new Option("fields", mv));
    siViewSandbox.addOption(new Option("recurse"));
    siViewSandbox.addOption(new Option("noincludeDropped"));
    siViewSandbox.addOption(new Option("filterSubs"));
    siViewSandbox.addOption(new Option("cwd", sandboxDir));
    // Run the view sandbox command
    Response r = api.runCommand(siViewSandbox);
    // Check-in all changed files, drop all members with missing working files
    for (WorkItemIterator wit = r.getWorkItems(); wit.hasNext(); ) {
        WorkItem wi = wit.next();
        api.getLogger().debug("Inspecting file: " + wi.getField("name").getValueAsString());
        if (wi.getModelType().equals(SIModelTypeName.MEMBER)) {
            Item wfdeltaItem = (Item) wi.getField("wfdelta").getValue();
            // Proceed with this entry only if it is an actual working file delta
            if (isDelta(wfdeltaItem)) {
                File memberFile = new File(wi.getField("name").getValueAsString());
                if (hasWorkingFile(wfdeltaItem)) {
                    // Only report on files that have actually changed...
                    if (hasMemberChanged(memberFile, wi.getId())) {
                        changedFiles.add(wi);
                    }
                } else {
                    // Also report on dropped files
                    changedFiles.add(wi);
                }
            }
        }
    }
    return changedFiles;
}
Also used : Response(com.mks.api.response.Response) WorkItem(com.mks.api.response.WorkItem) Item(com.mks.api.response.Item) Command(com.mks.api.Command) ArrayList(java.util.ArrayList) Option(com.mks.api.Option) WorkItemIterator(com.mks.api.response.WorkItemIterator) WorkItem(com.mks.api.response.WorkItem) ChangeFile(org.apache.maven.scm.ChangeFile) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) MultiValue(com.mks.api.MultiValue)

Example 3 with Command

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

the class Sandbox method getNewMembers.

/**
 * Executes a 'si viewnonmembers' command filtering the results using the exclude and include lists
 *
 * @param exclude Pattern containing the exclude file list
 * @param include Pattern containing the include file list
 * @return List of ScmFile objects representing the new files in the Sandbox
 * @throws APIException
 */
public List<ScmFile> getNewMembers(String exclude, String include) throws APIException {
    // Store a list of files that were added to the repository
    List<ScmFile> filesAdded = new ArrayList<ScmFile>();
    Command siViewNonMem = new Command(Command.SI, "viewnonmembers");
    siViewNonMem.addOption(new Option("recurse"));
    if (null != exclude && exclude.length() > 0) {
        siViewNonMem.addOption(new Option("exclude", exclude));
    }
    if (null != include && include.length() > 0) {
        siViewNonMem.addOption(new Option("include", include));
    }
    siViewNonMem.addOption(new Option("noincludeFormers"));
    siViewNonMem.addOption(new Option("cwd", sandboxDir));
    Response response = api.runCommand(siViewNonMem);
    for (WorkItemIterator wit = response.getWorkItems(); wit.hasNext(); ) {
        filesAdded.add(new ScmFile(wit.next().getField("absolutepath").getValueAsString(), ScmFileStatus.ADDED));
    }
    return filesAdded;
}
Also used : Response(com.mks.api.response.Response) Command(com.mks.api.Command) ArrayList(java.util.ArrayList) Option(com.mks.api.Option) WorkItemIterator(com.mks.api.response.WorkItemIterator) ScmFile(org.apache.maven.scm.ScmFile)

Example 4 with Command

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

the class Sandbox method checkin.

/**
 * Executes a 'si ci' command using the relativeName for the member name and message for the description
 *
 * @param memberFile   Full path to the member's current sandbox location
 * @param relativeName Relative path from the nearest subproject or project
 * @param message      Description for checking in the new update
 * @return MKS API Response object
 * @throws APIException
 */
private Response checkin(File memberFile, String relativeName, String message) throws APIException {
    // Setup the check-in command
    api.getLogger().info("Checking in member:  " + memberFile.getAbsolutePath());
    Command sici = new Command(Command.SI, "ci");
    sici.addOption(new Option("cpid", cpid));
    if (null != message && message.length() > 0) {
        sici.addOption(new Option("description", message));
    }
    sici.addOption(new Option("cwd", memberFile.getParentFile().getAbsolutePath()));
    sici.addSelection(relativeName);
    return api.runCommand(sici);
}
Also used : Command(com.mks.api.Command) Option(com.mks.api.Option)

Example 5 with Command

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

Aggregations

Command (com.mks.api.Command)21 Option (com.mks.api.Option)20 Response (com.mks.api.response.Response)9 WorkItem (com.mks.api.response.WorkItem)5 WorkItemIterator (com.mks.api.response.WorkItemIterator)5 ArrayList (java.util.ArrayList)4 ChangeFile (org.apache.maven.scm.ChangeFile)4 ScmFile (org.apache.maven.scm.ScmFile)4 MultiValue (com.mks.api.MultiValue)3 APIException (com.mks.api.response.APIException)3 File (java.io.File)3 Item (com.mks.api.response.Item)2 Hashtable (java.util.Hashtable)2 CmdRunner (com.mks.api.CmdRunner)1 FileOption (com.mks.api.FileOption)1 Field (com.mks.api.response.Field)1 Date (java.util.Date)1 ChangeSet (org.apache.maven.scm.ChangeSet)1 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)1