Search in sources :

Example 16 with CheckOutScmResult

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());
    }
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) ScmFile(org.apache.maven.scm.ScmFile)

Example 17 with CheckOutScmResult

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;
}
Also used : Response(com.mks.api.response.Response) ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) APIException(com.mks.api.response.APIException) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) WorkItemIterator(com.mks.api.response.WorkItemIterator) WorkItem(com.mks.api.response.WorkItem) Sandbox(org.apache.maven.scm.provider.integrity.Sandbox) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) Result(com.mks.api.response.Result)

Example 18 with CheckOutScmResult

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));
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) ScmFile(org.apache.maven.scm.ScmFile)

Example 19 with CheckOutScmResult

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));
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmTag(org.apache.maven.scm.ScmTag) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) File(java.io.File) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult)

Example 20 with CheckOutScmResult

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());
    }
}
Also used : TreeSet(java.util.TreeSet) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) ScmFile(org.apache.maven.scm.ScmFile)

Aggregations

CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)57 File (java.io.File)24 ScmFileSet (org.apache.maven.scm.ScmFileSet)20 ScmFile (org.apache.maven.scm.ScmFile)14 ScmException (org.apache.maven.scm.ScmException)11 ScmTag (org.apache.maven.scm.ScmTag)9 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)9 Commandline (org.codehaus.plexus.util.cli.Commandline)8 Test (org.junit.Test)8 CommandParameters (org.apache.maven.scm.CommandParameters)7 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)7 IOException (java.io.IOException)6 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)6 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)6 ScmManager (org.apache.maven.scm.manager.ScmManager)5 ScmRepository (org.apache.maven.scm.repository.ScmRepository)5 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)5 ArrayList (java.util.ArrayList)4 ScmResult (org.apache.maven.scm.ScmResult)4 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)3