use of com.mks.api.response.APIException 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.APIException 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.APIException in project maven-scm by apache.
the class Sandbox method create.
/**
* Creates a new Sandbox in the sandboxDir specified
*
* @return true if the operation is successful; false otherwise
* @throws APIException
*/
public boolean create() throws APIException {
File project = new File(siProject.getProjectName());
File sandboxpj = new File(sandboxDir + fs + project.getName());
// Check to see if the sandbox file already exists and its OK to use
api.getLogger().debug("Sandbox Project File: " + sandboxpj.getAbsolutePath());
if (sandboxpj.isFile()) {
// Validate this sandbox
if (isValidSandbox(sandboxpj.getAbsolutePath())) {
api.getLogger().debug("Reusing existing Sandbox in " + sandboxDir + " for project " + siProject.getConfigurationPath());
return true;
} else {
api.getLogger().error("An invalid Sandbox exists in " + sandboxDir + ". Please provide a different location!");
return false;
}
} else // Create a new sandbox in the location specified
{
api.getLogger().debug("Creating Sandbox in " + sandboxDir + " for project " + siProject.getConfigurationPath());
try {
Command cmd = new Command(Command.SI, "createsandbox");
cmd.addOption(new Option("recurse"));
cmd.addOption(new Option("nopopulate"));
cmd.addOption(new Option("project", siProject.getConfigurationPath()));
cmd.addOption(new Option("cwd", sandboxDir));
api.runCommand(cmd);
} catch (APIException aex) {
// Check to see if this exception is due an existing sandbox registry entry
ExceptionHandler eh = new ExceptionHandler(aex);
if (eh.getMessage().indexOf("There is already a registered entry") > 0) {
// This will re-validate the sandbox, if Maven blew away the old directory
return create();
} else {
throw aex;
}
}
return true;
}
}
use of com.mks.api.response.APIException 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.APIException 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;
}
Aggregations