use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.
the class MavenScmCli method checkOut.
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
private void checkOut(ScmRepository scmRepository, File workingDirectory, ScmVersion version) throws ScmException {
if (workingDirectory.exists()) {
System.err.println("The working directory already exist: '" + workingDirectory.getAbsolutePath() + "'.");
return;
}
if (!workingDirectory.mkdirs()) {
System.err.println("Error while making the working directory: '" + workingDirectory.getAbsolutePath() + "'.");
return;
}
CheckOutScmResult result = scmManager.checkOut(scmRepository, new ScmFileSet(workingDirectory), version);
if (!result.isSuccess()) {
showError(result);
return;
}
List<ScmFile> checkedOutFiles = result.getCheckedOutFiles();
System.out.println("Checked out these files: ");
for (ScmFile file : checkedOutFiles) {
System.out.println(" " + file.getPath());
}
}
use of org.apache.maven.scm.command.checkout.CheckOutScmResult 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.command.checkout.CheckOutScmResult in project maven-scm by apache.
the class CheckInCommandTckTest method testCheckInCommandPartialFileset.
public void testCheckInCommandPartialFileset() throws Exception {
// Make sure that the correct files was checked out
File fooJava = new File(getWorkingCopy(), "src/main/java/Foo.java");
File barJava = new File(getWorkingCopy(), "src/main/java/Bar.java");
File readmeTxt = new File(getWorkingCopy(), "readme.txt");
assertFalse("check Foo.java doesn't yet exist", fooJava.canRead());
assertFalse("check Bar.java doesn't yet exist", barJava.canRead());
assertTrue("check can read readme.txt", readmeTxt.canRead());
// Change the files
createFooJava(fooJava);
createBarJava(barJava);
changeReadmeTxt(readmeTxt);
AddScmResult addResult = getScmManager().getProviderByUrl(getScmUrl()).add(getScmRepository(), new ScmFileSet(getWorkingCopy(), "src/main/java/Foo.java", null));
assertResultIsSuccess(addResult);
CheckInScmResult result = getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy(), "**/Foo.java", null), "Commit message");
assertResultIsSuccess(result);
List<ScmFile> files = result.getCheckedInFiles();
assertNotNull(files);
assertEquals(1, files.size());
ScmFile file1 = files.get(0);
assertEquals(ScmFileStatus.CHECKED_IN, file1.getStatus());
assertPath("/test-repo/check-in/Foo.java", file1.getPath());
CheckOutScmResult checkoutResult = getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()));
assertResultIsSuccess(checkoutResult);
fooJava = new File(getAssertionCopy(), "src/main/java/Foo.java");
barJava = new File(getAssertionCopy(), "src/main/java/Bar.java");
readmeTxt = new File(getAssertionCopy(), "readme.txt");
assertTrue("check can read Foo.java", fooJava.canRead());
assertFalse("check Bar.java doesn't exist", barJava.canRead());
assertTrue("check can read readme.txt", readmeTxt.canRead());
assertEquals("check readme.txt contents", "/readme.txt", FileUtils.fileRead(readmeTxt));
}
use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.
the class TagCommandTckTest method testTagCommandTest.
public void testTagCommandTest() throws Exception {
String tag = getTagName();
@SuppressWarnings("deprecation") TagScmResult tagResult = getScmManager().getProviderByUrl(getScmUrl()).tag(getScmRepository(), new ScmFileSet(getWorkingCopy()), tag);
assertResultIsSuccess(tagResult);
// see https://issues.apache.org/jira/browse/SCM-754
// assertEquals( "check all 4 files tagged", 4, tagResult.getTaggedFiles().size() );
File readmeTxt = new File(getWorkingCopy(), "readme.txt");
assertEquals("check readme.txt contents", "/readme.txt", FileUtils.fileRead(readmeTxt));
this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
changeReadmeTxt(readmeTxt);
CheckInScmResult checkinResult = getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy()), "commit message");
assertResultIsSuccess(checkinResult);
CheckOutScmResult checkoutResult = getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()));
assertResultIsSuccess(checkoutResult);
readmeTxt = new File(getAssertionCopy(), "readme.txt");
assertEquals("check readme.txt contents", "changed file", FileUtils.fileRead(readmeTxt));
deleteDirectory(getAssertionCopy());
assertFalse("check previous assertion copy deleted", getAssertionCopy().exists());
checkoutResult = getScmManager().getProviderByUrl(getScmUrl()).checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()), new ScmTag(tag));
assertResultIsSuccess(checkoutResult);
assertEquals("check readme.txt contents is from tagged version", "/readme.txt", FileUtils.fileRead(readmeTxt));
}
use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.
the class CheckOutCommandTckTest method testCheckOutCommandTest.
public void testCheckOutCommandTest() throws Exception {
deleteDirectory(getWorkingCopy());
CheckOutScmResult result = checkOut(getWorkingCopy(), getScmRepository());
assertResultIsSuccess(result);
List<ScmFile> checkedOutFiles = result.getCheckedOutFiles();
if (checkedOutFiles.size() != 4) {
SortedSet<ScmFile> files = new TreeSet<ScmFile>(checkedOutFiles);
int i = 0;
for (Iterator<ScmFile> it = files.iterator(); it.hasNext(); i++) {
ScmFile scmFile = it.next();
System.out.println("" + i + ": " + scmFile);
}
fail("Expected 4 files in the updated files list, was " + checkedOutFiles.size());
}
}
Aggregations