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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations