use of com.mks.api.response.WorkItem 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.WorkItem in project maven-scm by apache.
the class Sandbox method checkInUpdates.
/**
* Wrapper function to check-in all changes and drop members associated with missing working files
*
* @param message Description for the changes
* @return
*/
public List<ScmFile> checkInUpdates(String message) {
// Re-initialize the overall ciSuccess to be true for now
ciSuccess = true;
// Store a list of files that were changed/removed to the repository
List<ScmFile> changedFiles = new ArrayList<ScmFile>();
api.getLogger().debug("Looking for changed and dropped members in sandbox dir: " + sandboxDir);
try {
// Let the list of changed files
List<WorkItem> changeList = getChangeList();
// Check-in all changed files, drop all members with missing working files
for (Iterator<WorkItem> wit = changeList.iterator(); wit.hasNext(); ) {
try {
WorkItem wi = wit.next();
File memberFile = new File(wi.getField("name").getValueAsString());
// Check-in files that have actually changed...
if (hasWorkingFile((Item) wi.getField("wfdelta").getValue())) {
// Lock each member as you go...
lock(memberFile, wi.getId());
// Commit the changes...
checkin(memberFile, wi.getId(), message);
// Update the changed file list
changedFiles.add(new ScmFile(memberFile.getAbsolutePath(), ScmFileStatus.CHECKED_IN));
} else {
// Drop the member if there is no working file
dropMember(memberFile, wi.getId());
// Update the changed file list
changedFiles.add(new ScmFile(memberFile.getAbsolutePath(), ScmFileStatus.DELETED));
}
} catch (APIException aex) {
// Set the ciSuccess to false, since we ran into a problem
ciSuccess = false;
ExceptionHandler eh = new ExceptionHandler(aex);
api.getLogger().error("MKS API Exception: " + eh.getMessage());
api.getLogger().debug(eh.getCommand() + " completed with exit Code " + eh.getExitCode());
}
}
} catch (APIException aex) {
// Set the ciSuccess to false, since we ran into a problem
ciSuccess = false;
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 changedFiles;
}
use of com.mks.api.response.WorkItem 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.WorkItem 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;
}
use of com.mks.api.response.WorkItem in project maven-scm by apache.
the class IntegrityStatusCommand method executeStatusCommand.
/**
* {@inheritDoc}
*/
@Override
public StatusScmResult executeStatusCommand(ScmProviderRepository repository, ScmFileSet fileSet) throws ScmException {
StatusScmResult result;
IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
getLogger().info("Status of files changed in sandbox " + fileSet.getBasedir().getAbsolutePath());
try {
// Initialize the list of ScmFile objects for the StatusScmResult
List<ScmFile> scmFileList = new ArrayList<ScmFile>();
// Get a listing for all the changes in the sandbox
Sandbox siSandbox = iRepo.getSandbox();
// Get the excludes and includes list from the configuration
String excludes = Sandbox.formatFilePatterns(fileSet.getExcludes());
String includes = Sandbox.formatFilePatterns(fileSet.getIncludes());
// Get the new members found in the sandbox
List<ScmFile> newMemberList = siSandbox.getNewMembers(excludes, includes);
// Update the scmFileList with our updates
scmFileList.addAll(newMemberList);
// Get the changed/dropped members from the sandbox
List<WorkItem> changeList = siSandbox.getChangeList();
for (Iterator<WorkItem> wit = changeList.iterator(); wit.hasNext(); ) {
WorkItem wi = wit.next();
File memberFile = new File(wi.getField("name").getValueAsString());
// Separate the changes into files that have been updated and deleted files
if (siSandbox.hasWorkingFile((Item) wi.getField("wfdelta").getValue())) {
scmFileList.add(new ScmFile(memberFile.getAbsolutePath(), ScmFileStatus.UPDATED));
} else {
scmFileList.add(new ScmFile(memberFile.getAbsolutePath(), ScmFileStatus.DELETED));
}
}
if (scmFileList.size() == 0) {
getLogger().info("No local changes found!");
}
result = new StatusScmResult(scmFileList, new ScmResult("si viewsandbox", "", "", true));
} catch (APIException aex) {
ExceptionHandler eh = new ExceptionHandler(aex);
getLogger().error("MKS API Exception: " + eh.getMessage());
getLogger().debug(eh.getCommand() + " exited with return code " + eh.getExitCode());
result = new StatusScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
}
return result;
}
Aggregations