Search in sources :

Example 1 with ScmBranch

use of org.apache.maven.scm.ScmBranch in project maven-scm by apache.

the class AccuRevChangeLogCommandTckTest method testUpstreamChangesIncludedInChangeLog.

@SuppressWarnings("unchecked")
@Test
public void testUpstreamChangesIncludedInChangeLog() throws Exception {
    AccuRevCommandLine accurev = accurevTckTestUtil.getAccuRevCL();
    // UpdatingCopy is a workspace rooted at a substream
    String workingStream = accurevTckTestUtil.getWorkingStream();
    String subStream = accurevTckTestUtil.getDepotName() + "_sub_stream";
    accurev.mkstream(workingStream, subStream);
    ScmRepository mainRepository = getScmRepository();
    ScmProvider provider = getScmManager().getProviderByRepository(mainRepository);
    // Create a workspace at the updating copy location backed by the substream
    ScmBranch branch = new ScmBranch("sub_stream");
    provider.checkOut(mainRepository, new ScmFileSet(getUpdatingCopy()), branch);
    Thread.sleep(1000);
    ScmFileSet fileSet = new ScmFileSet(getWorkingCopy());
    // Make a timestamp that we know are after initial revision but before the second
    // Current time
    Date timeBeforeUpstreamCheckin = new Date();
    // pause a couple seconds... [SCM-244]
    Thread.sleep(2000);
    // Make a change to the readme.txt and commit the change
    ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
    ScmTestCase.makeFile(getWorkingCopy(), "/src/test/java/Test.java", "changed Test.java");
    CheckInScmResult checkInResult = provider.checkIn(mainRepository, fileSet, "upstream workspace promote");
    assertTrue("Unable to checkin changes to the repository", checkInResult.isSuccess());
    Thread.sleep(2000);
    Date timeBeforeDownstreamCheckin = new Date();
    Thread.sleep(2000);
    ScmFileSet updateFileSet = new ScmFileSet(getUpdatingCopy());
    provider.update(mainRepository, updateFileSet);
    ScmTestCase.makeFile(getUpdatingCopy(), "/pom.xml", "changed pom.xml");
    ScmTestCase.makeFile(getUpdatingCopy(), "/src/test/java/Test.java", "changed again Test.java");
    checkInResult = provider.checkIn(mainRepository, updateFileSet, "downstream workspace promote");
    assertTrue("Unable to checkin changes to the repository", checkInResult.isSuccess());
    Thread.sleep(2000);
    Date timeBeforeDownstreamPromote = new Date();
    List<File> promotedFiles = new ArrayList<File>();
    accurev.promoteStream(subStream, "stream promote", promotedFiles);
    Thread.sleep(2000);
    Date timeEnd = new Date();
    // Changelog beforeUpstreamCheckin to end should contain both upstream and downstream changes. upstream change
    // should NOT include Test.java
    ChangeLogScmResult result = provider.changeLog(mainRepository, fileSet, timeBeforeUpstreamCheckin, timeEnd, 0, branch);
    assertTrue("changelog beforeUpstreamCheckin to end", result.isSuccess());
    List<ChangeSet> changeSets = result.getChangeLog().getChangeSets();
    assertThat(changeSets.size(), is(2));
    assertThat(changeSets, Matchers.<ChangeSet>hasItems(changeSet("Upstream changes", "/readme.txt"), changeSet("downstream workspace promote", "/./pom.xml", "/./src/test/java/Test.java")));
    // Changelog beforeUpstreamCheckin to beforeDownstreamCheckin should include just upstream change including
    // Test.java
    result = provider.changeLog(mainRepository, fileSet, timeBeforeUpstreamCheckin, timeBeforeDownstreamCheckin, 0, branch);
    assertTrue("changelog beforeUpstreamCheckin to beforeDownstreamCheckin", result.isSuccess());
    changeSets = result.getChangeLog().getChangeSets();
    assertThat(changeSets.size(), is(1));
    assertThat(changeSets.get(0), changeSet("Upstream changes", "/readme.txt", "/src/test/java/Test.java"));
    // Changelog beforeDownstreamCheckin to end should include just downstream change
    result = provider.changeLog(mainRepository, fileSet, timeBeforeDownstreamCheckin, timeEnd, 0, branch);
    assertTrue("changelog beforeDownstreamCheckin to end", result.isSuccess());
    changeSets = result.getChangeLog().getChangeSets();
    assertThat(changeSets.size(), is(1));
    assertThat(changeSets.get(0), changeSet("downstream workspace promote", "/./pom.xml", "/./src/test/java/Test.java"));
    // Changelog beforeDownstreamPromote to end should be empty
    result = provider.changeLog(mainRepository, fileSet, timeBeforeDownstreamPromote, timeEnd, 0, branch);
    assertTrue("changelog beforeDownstreamPromote to end", result.isSuccess());
    changeSets = result.getChangeLog().getChangeSets();
    assertThat(changeSets.size(), is(0));
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmBranch(org.apache.maven.scm.ScmBranch) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) AccuRevCommandLine(org.apache.maven.scm.provider.accurev.cli.AccuRevCommandLine) ArrayList(java.util.ArrayList) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) Date(java.util.Date) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet) Test(org.junit.Test) ChangeLogCommandTckTest(org.apache.maven.scm.tck.command.changelog.ChangeLogCommandTckTest)

Example 2 with ScmBranch

use of org.apache.maven.scm.ScmBranch in project maven-scm by apache.

the class ChangeLogCommandTckTest method testChangeLogCommand.

public void testChangeLogCommand() throws Exception {
    Thread.sleep(1000);
    ScmProvider provider = getScmManager().getProviderByRepository(getScmRepository());
    ScmFileSet fileSet = new ScmFileSet(getWorkingCopy());
    ChangeLogScmResult firstResult = provider.changeLog(getScmRepository(), fileSet, null, null, 0, (ScmBranch) null, null);
    assertTrue(firstResult.getProviderMessage() + ": " + firstResult.getCommandLine() + "\n" + firstResult.getCommandOutput(), firstResult.isSuccess());
    // for svn, cvs, git, the repo get recreated for each test and therefore initial changelog size is 1
    // for SCM like perforce, it is not possible to recreate the repo, therefor the size will be greater then 1
    int firstLogSize = firstResult.getChangeLog().getChangeSets().size();
    assertTrue("Unexpected initial log size", firstLogSize >= 1);
    // Make a timestamp that we know are after initial revision but before the second
    // Current time
    Date timeBeforeSecond = new Date();
    // pause a couple seconds... [SCM-244]
    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());
    ChangeLogScmResult secondResult = provider.changeLog(getScmRepository(), fileSet, (ScmVersion) null, null);
    assertTrue(secondResult.getProviderMessage(), secondResult.isSuccess());
    assertEquals(firstLogSize + 1, secondResult.getChangeLog().getChangeSets().size());
    // Now only retrieve the changelog after timeBeforeSecondChangeLog
    Date currentTime = new Date();
    ChangeLogScmResult thirdResult = provider.changeLog(getScmRepository(), fileSet, timeBeforeSecond, currentTime, 0, new ScmBranch(""));
    // Thorough assert of the last result
    assertTrue(thirdResult.getProviderMessage(), thirdResult.isSuccess());
    assertEquals(1, thirdResult.getChangeLog().getChangeSets().size());
    ChangeSet changeset = thirdResult.getChangeLog().getChangeSets().get(0);
    assertTrue(changeset.getDate().after(timeBeforeSecond));
    assertEquals(COMMIT_MSG, changeset.getComment());
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmBranch(org.apache.maven.scm.ScmBranch) ScmFileSet(org.apache.maven.scm.ScmFileSet) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) ChangeSet(org.apache.maven.scm.ChangeSet) Date(java.util.Date)

Example 3 with ScmBranch

use of org.apache.maven.scm.ScmBranch in project maven-scm by apache.

the class SvnTagBranchUtilsTest method testResolveBranchUrl.

private void testResolveBranchUrl(String scmUrl, String branchBase, String branch, String expected) throws Exception {
    SvnScmProviderRepository repository = getSvnRepository(scmUrl);
    if (branchBase != null) {
        repository.setBranchBase(branchBase);
    }
    if (branchBase != null) {
        assertEquals(repository.getBranchBase(), branchBase);
    } else {
        assertEquals(repository.getBranchBase(), SvnTagBranchUtils.resolveBranchBase(repository.getUrl()));
    }
    assertEquals(expected, SvnTagBranchUtils.resolveBranchUrl(repository, new ScmBranch(branch)));
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)

Example 4 with ScmBranch

use of org.apache.maven.scm.ScmBranch in project maven-scm by apache.

the class SvnExeExportCommand method executeExportCommand.

/**
 * {@inheritDoc}
 */
protected ExportScmResult executeExportCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version, String outputDirectory) throws ScmException {
    if (outputDirectory == null) {
        outputDirectory = fileSet.getBasedir().getAbsolutePath();
    }
    SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
    String url = repository.getUrl();
    if (version != null && StringUtils.isNotEmpty(version.getName())) {
        if (version instanceof ScmTag) {
            url = SvnTagBranchUtils.resolveTagUrl(repository, (ScmTag) version);
        } else if (version instanceof ScmBranch) {
            url = SvnTagBranchUtils.resolveBranchUrl(repository, (ScmBranch) version);
        }
    }
    url = SvnCommandUtils.fixUrl(url, repository.getUser());
    Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), version, url, outputDirectory);
    SvnUpdateConsumer consumer = new SvnUpdateConsumer(getLogger(), fileSet.getBasedir());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
        if (cl.getWorkingDirectory() != null && Os.isFamily(Os.FAMILY_WINDOWS)) {
            getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
        }
    }
    int exitCode;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new ExportScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    return new ExportScmResultWithRevision(cl.toString(), consumer.getUpdatedFiles(), String.valueOf(consumer.getRevision()));
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) SvnUpdateConsumer(org.apache.maven.scm.provider.svn.svnexe.command.update.SvnUpdateConsumer) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ScmTag(org.apache.maven.scm.ScmTag) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) ExportScmResult(org.apache.maven.scm.command.export.ExportScmResult) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) ExportScmResultWithRevision(org.apache.maven.scm.command.export.ExportScmResultWithRevision)

Example 5 with ScmBranch

use of org.apache.maven.scm.ScmBranch in project maven-scm by apache.

the class SvnChangeLogCommandTest method testCommandLineWithBranchStartDateOnly.

public void testCommandLineWithBranchStartDateOnly() throws Exception {
    Date startDate = getDate(2003, Calendar.SEPTEMBER, 10, 1, 1, 1, GMT_TIME_ZONE);
    testCommandLine("scm:svn:http://foo.com/svn/trunk", new ScmBranch("my-test-branch"), startDate, null, "svn --non-interactive log -v -r \"{2003-09-10 01:01:01 +0000}:HEAD\" http://foo.com/svn/branches/my-test-branch http://foo.com/svn/trunk");
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) Date(java.util.Date)

Aggregations

ScmBranch (org.apache.maven.scm.ScmBranch)25 Date (java.util.Date)9 ScmException (org.apache.maven.scm.ScmException)9 ScmFileSet (org.apache.maven.scm.ScmFileSet)7 Commandline (org.codehaus.plexus.util.cli.Commandline)7 ScmTag (org.apache.maven.scm.ScmTag)5 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)5 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 ScmVersion (org.apache.maven.scm.ScmVersion)4 ScmProvider (org.apache.maven.scm.provider.ScmProvider)4 File (java.io.File)3 ChangeSet (org.apache.maven.scm.ChangeSet)3 ScmRevision (org.apache.maven.scm.ScmRevision)3 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)3 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)3 ScmRepository (org.apache.maven.scm.repository.ScmRepository)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)2