use of com.mks.api.Command in project maven-scm by apache.
the class Sandbox method makeWriteable.
/**
* Executes a 'si makewritable' command to allow edits to all files in the Sandbox directory
*
* @return MKS API Response object
* @throws APIException
*/
public Response makeWriteable() throws APIException {
api.getLogger().debug("Setting files to writeable in " + sandboxDir + " for project " + siProject.getConfigurationPath());
Command cmd = new Command(Command.SI, "makewritable");
cmd.addOption(new Option("recurse"));
cmd.addOption(new Option("cwd", sandboxDir));
return api.runCommand(cmd);
}
use of com.mks.api.Command in project maven-scm by apache.
the class Sandbox method add.
/**
* Executes a 'si add' command using the message for the description
*
* @param memberFile Full path to the new member's location
* @param message Description for the new member's archive
* @return MKS API Response object
* @throws APIException
*/
private Response add(File memberFile, String message) throws APIException {
// Setup the add command
api.getLogger().info("Adding member: " + memberFile.getAbsolutePath());
Command siAdd = new Command(Command.SI, "add");
siAdd.addOption(new Option("onExistingArchive", "sharearchive"));
siAdd.addOption(new Option("cpid", cpid));
if (null != message && message.length() > 0) {
siAdd.addOption(new Option("description", message));
}
siAdd.addOption(new Option("cwd", memberFile.getParentFile().getAbsolutePath()));
siAdd.addSelection(memberFile.getName());
return api.runCommand(siAdd);
}
use of com.mks.api.Command in project maven-scm by apache.
the class Sandbox method resync.
/**
* Resynchronizes an existing Sandbox
* Assumes that the create() call has already been made to validate this sandbox
*
* @throws APIException
*/
public Response resync() throws APIException {
api.getLogger().debug("Resynchronizing Sandbox in " + sandboxDir + " for project " + siProject.getConfigurationPath());
Command cmd = new Command(Command.SI, "resync");
cmd.addOption(new Option("recurse"));
cmd.addOption(new Option("populate"));
cmd.addOption(new Option("cwd", sandboxDir));
return api.runCommand(cmd);
}
use of com.mks.api.Command 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.Command 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;
}
Aggregations