Search in sources :

Example 6 with ScmManager

use of org.apache.maven.scm.manager.ScmManager in project maven-scm by apache.

the class CvsCheckoutCommandTest method testCheckOutWithoutTag.

/**
 * @todo move this test to the TCK.
 */
public void testCheckOutWithoutTag() throws Exception {
    if (!isSystemCmd(CvsScmTestUtils.CVS_COMMAND_LINE)) {
        System.err.println("'" + CvsScmTestUtils.CVS_COMMAND_LINE + "' is not a system command. Ignored " + getName() + ".");
        return;
    }
    ScmManager scmManager = getScmManager();
    CheckOutScmResult result = scmManager.checkOut(getScmRepository(), getScmFileSet());
    if (!result.isSuccess()) {
        fail(result.getProviderMessage() + "\n" + result.getCommandOutput() + "\n" + result.getCommandLine());
    }
    List<ScmFile> files = result.getCheckedOutFiles();
    assertNotNull(files);
    assertEquals(3, files.size());
    assertCheckedOutFile(files, 0, "/Foo.java", ScmFileStatus.UPDATED);
    assertCheckedOutFile(files, 1, "/Readme.txt", ScmFileStatus.UPDATED);
    assertCheckedOutFile(files, 2, "/src/java/org/apache/maven/MavenUtils.java", ScmFileStatus.UPDATED);
}
Also used : ScmManager(org.apache.maven.scm.manager.ScmManager) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) ScmFile(org.apache.maven.scm.ScmFile)

Example 7 with ScmManager

use of org.apache.maven.scm.manager.ScmManager in project maven-scm by apache.

the class CvsUpdateCommandTest method testCvsUpdate.

/**
 * @todo merge into tck
 */
public void testCvsUpdate() throws Exception {
    FileWriter writer = null;
    try {
        if (!isSystemCmd(CvsScmTestUtils.CVS_COMMAND_LINE)) {
            System.err.println("'" + CvsScmTestUtils.CVS_COMMAND_LINE + "' is not a system command. Ignored " + getName() + ".");
            return;
        }
        ScmManager scmManager = getScmManager();
        String scmUrl = CvsScmTestUtils.getScmUrl(repository, getModule());
        // Check out the repo to a working directory where files will be modified and committed
        String arguments = "-f -d " + repository.getAbsolutePath() + " " + "co -d " + workingDirectory.getName() + " " + getModule();
        CvsScmTestUtils.executeCVS(workingDirectory.getParentFile(), arguments);
        // Check out the repo to a assertion directory where the command will be used
        arguments = "-f -d " + repository.getAbsolutePath() + " " + "co -d " + assertionDirectory.getName() + " " + getModule();
        CvsScmTestUtils.executeCVS(assertionDirectory.getParentFile(), arguments);
        // A new check out should return 0 updated files.
        ScmRepository scmRepository = scmManager.makeScmRepository(scmUrl);
        UpdateScmResult result = scmManager.update(scmRepository, new ScmFileSet(assertionDirectory));
        assertNotNull(result);
        if (!result.isSuccess()) {
            System.out.println("result.providerMessage: " + result.getProviderMessage());
            System.out.println("result.commandOutput: " + result.getCommandOutput());
            fail("Command failed");
        }
        assertNull(result.getProviderMessage());
        assertNull(result.getCommandOutput());
        assertNotNull(result.getUpdatedFiles());
        assertEquals(0, result.getUpdatedFiles().size());
        // Modifing a file
        File fooJava = new File(workingDirectory, "Foo.java");
        String content = FileUtils.fileRead(fooJava);
        writer = new FileWriter(fooJava);
        writer.write(content + System.getProperty("line.separator"));
        writer.write("extra line");
        writer.close();
        // Adding a new file
        writer = new FileWriter(new File(workingDirectory, "New.txt"));
        writer.write("new file");
        writer.close();
        arguments = "-f -d " + repository.getAbsolutePath() + " add New.txt";
        CvsScmTestUtils.executeCVS(workingDirectory, arguments);
        // Committing
        arguments = "-f -d " + repository.getAbsolutePath() + " commit -m .";
        CvsScmTestUtils.executeCVS(workingDirectory, arguments);
        // Check the updated files
        result = scmManager.update(scmRepository, new ScmFileSet(assertionDirectory));
        assertNotNull(result);
        if (!result.isSuccess()) {
            System.out.println("result.providerMessage: " + result.getProviderMessage());
            System.out.println("result.commandOutput: " + result.getCommandOutput());
            fail("Command failed");
        }
        assertNull(result.getProviderMessage());
        assertNull(result.getCommandOutput());
        assertNotNull(result.getUpdatedFiles());
        assertEquals(2, result.getUpdatedFiles().size());
        ScmFile file1 = result.getUpdatedFiles().get(0);
        assertPath("Foo.java", file1.getPath());
        assertEquals(ScmFileStatus.UPDATED, file1.getStatus());
        ScmFile file2 = result.getUpdatedFiles().get(1);
        assertPath("New.txt", file2.getPath());
        assertEquals(ScmFileStatus.UPDATED, file2.getStatus());
    } finally {
        IOUtil.close(writer);
    }
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) FileWriter(java.io.FileWriter) ScmManager(org.apache.maven.scm.manager.ScmManager) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 8 with ScmManager

use of org.apache.maven.scm.manager.ScmManager in project maven-scm by apache.

the class BlameCommandTckTest method testBlameCommand.

public void testBlameCommand() throws Exception {
    ScmRepository repository = getScmRepository();
    ScmManager manager = getScmManager();
    ScmProvider provider = manager.getProviderByRepository(getScmRepository());
    ScmFileSet fileSet = new ScmFileSet(getWorkingCopy());
    BlameScmResult result;
    BlameLine line;
    // === readme.txt ===
    BlameScmRequest blameScmRequest = new BlameScmRequest(repository, fileSet);
    blameScmRequest.setFilename("readme.txt");
    // result = manager.blame( repository, fileSet, "readme.txt" );
    result = manager.blame(blameScmRequest);
    assertNotNull("The command returned a null result.", result);
    assertResultIsSuccess(result);
    assertEquals("Expected 1 line in blame", 1, result.getLines().size());
    line = result.getLines().get(0);
    String initialRevision = line.getRevision();
    // Make a timestamp that we know are after initial revision but before the second
    // Current time
    Date timeBeforeSecond = new Date();
    // pause a couple seconds...
    Thread.sleep(2000);
    // Make a change to the readme.txt and commit the change
    this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
    ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
    CheckInScmResult checkInResult = provider.checkIn(getScmRepository(), fileSet, COMMIT_MSG);
    assertTrue("Unable to checkin changes to the repository", checkInResult.isSuccess());
    result = manager.blame(repository, fileSet, "readme.txt");
    // pause a couple seconds...
    Thread.sleep(2000);
    // Current time
    Date timeAfterSecond = new Date();
    assertNotNull("The command returned a null result.", result);
    assertResultIsSuccess(result);
    assertEquals("Expected 1 line in blame", 1, result.getLines().size());
    line = result.getLines().get(0);
    assertNotNull("Expected not null author", line.getAuthor());
    assertNotNull("Expected not null revision", line.getRevision());
    assertNotNull("Expected not null date", line.getDate());
    assertTrue("Expected another revision", !initialRevision.equals(line.getRevision()));
    if (isTestDateTime()) {
        assertDateBetween(timeBeforeSecond, timeAfterSecond, line.getDate());
    }
    // === pom.xml ===
    result = manager.blame(repository, fileSet, "pom.xml");
    assertNotNull("The command returned a null result.", result);
    assertResultIsSuccess(result);
    verifyResult(result);
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) BlameLine(org.apache.maven.scm.command.blame.BlameLine) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) BlameScmRequest(org.apache.maven.scm.command.blame.BlameScmRequest) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) ScmManager(org.apache.maven.scm.manager.ScmManager) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) Date(java.util.Date)

Example 9 with ScmManager

use of org.apache.maven.scm.manager.ScmManager in project plugin-compat-tester by jenkinsci.

the class ExampleMultiParent method action.

/*
     * No check implementation is required because transformedPlugins
     * returns your specific list.
     */
/**
 * Point to the shared location.  Check if this needs to be downloaded.
 */
public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception {
    PluginCompatTesterConfig config = (PluginCompatTesterConfig) moreInfo.get("config");
    Plugin currentPlugin = (Plugin) moreInfo.get("plugin");
    // Determine if we need to run the download; only run for first identified plugin in the series
    if (firstRun) {
        System.out.println("Preparing for Multimodule checkout.");
        // Checkout to the parent directory. All other processes will be on the child directory
        File parentPath = new File(config.workDirectory.getAbsolutePath() + "/" + parentName);
        System.out.println("Checking out from SCM connection URL : " + parentUrl + " (" + parentName + "-" + currentPlugin.version + ")");
        ScmManager scmManager = SCMManagerFactory.getInstance().createScmManager();
        ScmRepository repository = scmManager.makeScmRepository(parentUrl);
        CheckOutScmResult result = scmManager.checkOut(repository, new ScmFileSet(parentPath), new ScmTag(parentName + "-" + currentPlugin.version));
        if (!result.isSuccess()) {
            throw new RuntimeException(result.getProviderMessage() + "||" + result.getCommandOutput());
        }
    }
    // Checkout already happened, don't run through again
    moreInfo.put("runCheckout", false);
    firstRun = false;
    // Change the "download"" directory; after download, it's simply used for reference
    File childPath = new File(config.workDirectory.getAbsolutePath() + "/" + parentName + "/" + currentPlugin.name);
    moreInfo.put("checkoutDir", childPath);
    return moreInfo;
}
Also used : PluginCompatTesterConfig(org.jenkins.tools.test.model.PluginCompatTesterConfig) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmTag(org.apache.maven.scm.ScmTag) ScmManager(org.apache.maven.scm.manager.ScmManager) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) File(java.io.File) Plugin(hudson.model.UpdateSite.Plugin)

Example 10 with ScmManager

use of org.apache.maven.scm.manager.ScmManager in project plugin-compat-tester by jenkinsci.

the class PluginCompatTester method cloneFromSCM.

private void cloneFromSCM(String connectionUrl, String name, String version, File checkoutDirectory) throws ComponentLookupException, ScmException {
    System.out.println("Checking out from SCM connection URL : " + connectionUrl + " (" + name + "-" + version + ")");
    ScmManager scmManager = SCMManagerFactory.getInstance().createScmManager();
    ScmRepository repository = scmManager.makeScmRepository(connectionUrl);
    CheckOutScmResult result = scmManager.checkOut(repository, new ScmFileSet(checkoutDirectory), new ScmTag(name + "-" + version));
    if (!result.isSuccess()) {
        throw new RuntimeException(result.getProviderMessage() + " || " + result.getCommandOutput());
    }
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmTag(org.apache.maven.scm.ScmTag) ScmManager(org.apache.maven.scm.manager.ScmManager) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult)

Aggregations

ScmManager (org.apache.maven.scm.manager.ScmManager)11 ScmFileSet (org.apache.maven.scm.ScmFileSet)8 ScmRepository (org.apache.maven.scm.repository.ScmRepository)8 File (java.io.File)7 ScmFile (org.apache.maven.scm.ScmFile)6 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)5 Date (java.util.Date)3 ScmTag (org.apache.maven.scm.ScmTag)3 UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)3 PluginCompatTesterConfig (org.jenkins.tools.test.model.PluginCompatTesterConfig)2 UpdateSite (hudson.model.UpdateSite)1 Plugin (hudson.model.UpdateSite.Plugin)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 Reader (java.io.Reader)1 ChangeSet (org.apache.maven.scm.ChangeSet)1 BlameLine (org.apache.maven.scm.command.blame.BlameLine)1 BlameScmRequest (org.apache.maven.scm.command.blame.BlameScmRequest)1 BlameScmResult (org.apache.maven.scm.command.blame.BlameScmResult)1 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)1