use of com.mks.api.response.Response 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;
}
}
use of com.mks.api.response.Response 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;
}
use of com.mks.api.response.Response 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;
}
use of com.mks.api.response.Response in project maven-scm by apache.
the class IntegrityEditCommand method executeEditCommand.
/**
* {@inheritDoc}
*/
@Override
public EditScmResult executeEditCommand(ScmProviderRepository repository, ScmFileSet fileSet) throws ScmException {
getLogger().info("Attempting make files writeable in Sandbox " + fileSet.getBasedir().getAbsolutePath());
EditScmResult result;
IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
try {
Sandbox siSandbox = iRepo.getSandbox();
Response res = siSandbox.makeWriteable();
int exitCode = res.getExitCode();
boolean success = (exitCode == 0 ? true : false);
result = new EditScmResult(res.getCommandString(), "", "Exit Code: " + exitCode, success);
} 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 EditScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
}
return result;
}
use of com.mks.api.response.Response in project maven-scm by apache.
the class IntegrityCheckOutCommand method executeCheckOutCommand.
/**
* Overridden function that performs a checkout (resynchronize) operation against an MKS Source Project
* This function ignores the scmVerion and recursive arguments passed into this function as while there is
* a suitable equivalent to checkout/resynchronize by label/revision, it doesn't make sense for the way
* Maven seems to want to execute this command. Hence we will create/resynchronize a sandbox, which will
* be recursive in nature. If the user chooses to checkout a specific versioned configuration (checkpoint),
* then that information will be contained in the Configuration Path obtained from the
* IntegrityScmProviderRepository
*/
@Override
public CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, boolean recursive, boolean shallow) throws ScmException {
CheckOutScmResult result;
IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
try {
getLogger().info("Attempting to checkout source for project " + iRepo.getProject().getConfigurationPath());
String checkoutDir = System.getProperty("checkoutDirectory");
// Override the sandbox definition, if a checkout directory is specified for this command
Sandbox siSandbox;
if (null != checkoutDir && checkoutDir.length() > 0) {
siSandbox = new Sandbox(iRepo.getAPISession(), iRepo.getProject(), checkoutDir);
iRepo.setSandbox(siSandbox);
} else {
siSandbox = iRepo.getSandbox();
}
getLogger().info("Sandbox location is " + siSandbox.getSandboxDir());
// Now attempt to create the sandbox, if it doesn't already exist
if (siSandbox.create()) {
// Resynchronize the new or previously created sandbox
Response res = siSandbox.resync();
// Lets output what we got from running this command
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() : ""));
}
}
int exitCode = res.getExitCode();
boolean success = (exitCode == 0 ? true : false);
result = new CheckOutScmResult(res.getCommandString(), "", "Exit Code: " + exitCode, success);
} else {
result = new CheckOutScmResult("si createsandbox", "Failed to create sandbox!", "", 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 CheckOutScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
}
return result;
}
Aggregations