Search in sources :

Example 1 with Response

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

the class APISession method runCommand.

/**
 * This function executes a generic API Command
 *
 * @param cmd MKS API Command Object representing an API command
 * @return MKS API Response Object
 * @throws APIException
 */
public Response runCommand(Command cmd) throws APIException {
    CmdRunner cmdRunner = session.createCmdRunner();
    cmdRunner.setDefaultHostname(hostName);
    cmdRunner.setDefaultPort(port);
    cmdRunner.setDefaultUsername(userName);
    if (null != password && password.length() > 0) {
        cmdRunner.setDefaultPassword(password);
    }
    Response res = cmdRunner.execute(cmd);
    logger.debug(res.getCommandString() + " returned exit code " + res.getExitCode());
    cmdRunner.release();
    return res;
}
Also used : CmdRunner(com.mks.api.CmdRunner) Response(com.mks.api.response.Response)

Example 2 with Response

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

the class APISession method runCommandAs.

/**
 * This function executes a generic API Command impersonating another user
 *
 * @param cmd             MKS API Command Object representing a API command
 * @param impersonateUser The user to impersonate
 * @return MKS API Response Object
 * @throws APIException
 */
public Response runCommandAs(Command cmd, String impersonateUser) throws APIException {
    CmdRunner cmdRunner = session.createCmdRunner();
    cmdRunner.setDefaultHostname(hostName);
    cmdRunner.setDefaultPort(port);
    cmdRunner.setDefaultUsername(userName);
    if (null != password && password.length() > 0) {
        cmdRunner.setDefaultPassword(password);
    }
    cmdRunner.setDefaultImpersonationUser(impersonateUser);
    Response res = cmdRunner.execute(cmd);
    logger.debug(res.getCommandString() + " returned exit code " + res.getExitCode());
    cmdRunner.release();
    return res;
}
Also used : CmdRunner(com.mks.api.CmdRunner) Response(com.mks.api.response.Response)

Example 3 with Response

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

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

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

Aggregations

Response (com.mks.api.response.Response)22 APIException (com.mks.api.response.APIException)13 ExceptionHandler (org.apache.maven.scm.provider.integrity.ExceptionHandler)11 IntegrityScmProviderRepository (org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository)11 Command (com.mks.api.Command)9 Option (com.mks.api.Option)8 WorkItem (com.mks.api.response.WorkItem)8 Sandbox (org.apache.maven.scm.provider.integrity.Sandbox)8 WorkItemIterator (com.mks.api.response.WorkItemIterator)7 ArrayList (java.util.ArrayList)7 ScmException (org.apache.maven.scm.ScmException)5 File (java.io.File)4 ScmFile (org.apache.maven.scm.ScmFile)4 ScmResult (org.apache.maven.scm.ScmResult)4 CmdRunner (com.mks.api.CmdRunner)3 MultiValue (com.mks.api.MultiValue)3 Project (org.apache.maven.scm.provider.integrity.Project)3 Item (com.mks.api.response.Item)2 Result (com.mks.api.response.Result)2 Hashtable (java.util.Hashtable)2