use of org.apache.maven.scm.provider.integrity.ExceptionHandler 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 org.apache.maven.scm.provider.integrity.ExceptionHandler 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 org.apache.maven.scm.provider.integrity.ExceptionHandler 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 org.apache.maven.scm.provider.integrity.ExceptionHandler in project maven-scm by apache.
the class IntegrityExportCommand method executeExportCommand.
/**
* {@inheritDoc}
*/
@Override
public ExportScmResult executeExportCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, String outputDirectory) throws ScmException {
// First lets figure out where we need to export files to...
String exportDir = outputDirectory;
exportDir = ((null != exportDir && exportDir.length() > 0) ? exportDir : fileSet.getBasedir().getAbsolutePath());
// Let the user know where we're going to be exporting the files...
getLogger().info("Attempting to export files to " + exportDir);
ExportScmResult result;
IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
try {
// Lets set our overall export success flag
boolean exportSuccess = true;
// Perform a fresh checkout of each file in the member list...
List<Member> projectMembers = iRepo.getProject().listFiles(exportDir);
// Initialize the list of files we actually exported...
List<ScmFile> scmFileList = new ArrayList<ScmFile>();
for (Iterator<Member> it = projectMembers.iterator(); it.hasNext(); ) {
Member siMember = it.next();
try {
getLogger().info("Attempting to export file: " + siMember.getTargetFilePath() + " at revision " + siMember.getRevision());
siMember.checkout(iRepo.getAPISession());
scmFileList.add(new ScmFile(siMember.getTargetFilePath(), ScmFileStatus.UNKNOWN));
} catch (APIException ae) {
exportSuccess = false;
ExceptionHandler eh = new ExceptionHandler(ae);
getLogger().error("MKS API Exception: " + eh.getMessage());
getLogger().debug(eh.getCommand() + " exited with return code " + eh.getExitCode());
}
}
// Lets advice the user that we've checked out all the members
getLogger().info("Exported " + scmFileList.size() + " files out of a total of " + projectMembers.size() + " files!");
if (exportSuccess) {
result = new ExportScmResult("si co", scmFileList);
} else {
result = new ExportScmResult("si co", "Failed to export all files!", "", exportSuccess);
}
} 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 ExportScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
}
return result;
}
use of org.apache.maven.scm.provider.integrity.ExceptionHandler in project maven-scm by apache.
the class IntegrityLockCommand method executeLockCommand.
/**
* {@inheritDoc}
*/
@Override
public ScmResult executeLockCommand(ScmProviderRepository repository, File workingDirectory, String filename) throws ScmException {
getLogger().info("Attempting to lock file: " + filename);
if (null == filename || filename.length() == 0) {
throw new ScmException("A single filename is required to execute the lock command!");
}
ScmResult result;
IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
try {
Sandbox siSandbox = iRepo.getSandbox();
File memberFile = new File(workingDirectory.getAbsoluteFile() + File.separator + filename);
Response res = siSandbox.lock(memberFile, filename);
int exitCode = res.getExitCode();
boolean success = (exitCode == 0 ? true : false);
result = new ScmResult(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 ScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
}
return result;
}
Aggregations