Search in sources :

Example 1 with AccuRevCommandLine

use of org.apache.maven.scm.provider.accurev.cli.AccuRevCommandLine 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 AccuRevCommandLine

use of org.apache.maven.scm.provider.accurev.cli.AccuRevCommandLine in project maven-scm by apache.

the class AccuRevScmProvider method makeProviderScmRepository.

/**
 * The basic url parsing approach is to be as loose as possible. If you specify as per the docs you'll get what you
 * expect. If you do something else the result is undefined. Don't use "/" "\" or "@" as the delimiter,
 */
public ScmProviderRepository makeProviderScmRepository(String scmSpecificUrl, char delimiter) throws ScmRepositoryException {
    List<String> validationMessages = new ArrayList<String>();
    String[] tokens = StringUtils.split(scmSpecificUrl, Character.toString(delimiter));
    // [[user][/pass]@host[:port]][:stream][:\project\dir]
    String basisStream = null;
    String projectPath = null;
    int port = AccuRev.DEFAULT_PORT;
    String host = null;
    String user = null;
    String password = null;
    Map<String, String> properties = new HashMap<String, String>();
    properties.put(TAG_FORMAT_PROPERTY, AccuRevScmProviderRepository.DEFAULT_TAG_FORMAT);
    properties.put(ACCUREV_EXECUTABLE_PROPERTY, AccuRev.DEFAULT_ACCUREV_EXECUTABLE);
    fillSystemProperties(properties);
    int i = 0;
    while (i < tokens.length) {
        int at = tokens[i].indexOf('@');
        // prefer "/", better not have a "/" or a "\\" in your password.
        int slash = tokens[i].indexOf('/');
        slash = slash < 0 ? tokens[i].indexOf('\\') : slash;
        int qMark = tokens[i].indexOf('?');
        if (qMark == 0) {
            QuotedPropertyParser.parse(tokens[i].substring(1), properties);
        } else if (slash == 0) {
            // this is the project path
            projectPath = tokens[i].substring(1);
            break;
        } else if ((slash > 0 || (at >= 0)) && host == null && user == null) {
            // user/pass@host
            int len = tokens[i].length();
            if (at >= 0 && len > at) {
                // everything after the "@"
                host = tokens[i].substring(at + 1);
            }
            if (slash > 0) {
                // user up to /
                user = tokens[i].substring(0, slash);
                // pass between / and @
                password = tokens[i].substring(slash + 1, at < 0 ? len : at);
            } else {
                // no /, user from beginning to @
                user = tokens[i].substring(0, at < 0 ? len : at);
            }
        } else if (host != null && tokens[i].matches("^[0-9]+$")) {
            // only valid entry with all digits is the port specification.
            port = Integer.parseInt(tokens[i]);
        } else {
            basisStream = tokens[i];
        }
        i++;
    }
    if (i < tokens.length) {
        validationMessages.add("Unknown tokens in URL " + scmSpecificUrl);
    }
    AccuRevScmProviderRepository repo = new AccuRevScmProviderRepository();
    repo.setLogger(getLogger());
    if (!StringUtils.isEmpty(user)) {
        repo.setUser(user);
    }
    if (!StringUtils.isEmpty(password)) {
        repo.setPassword(password);
    }
    if (!StringUtils.isEmpty(basisStream)) {
        repo.setStreamName(basisStream);
    }
    if (!StringUtils.isEmpty(projectPath)) {
        repo.setProjectPath(projectPath);
    }
    if (!StringUtils.isEmpty(host)) {
        repo.setHost(host);
    }
    repo.setPort(port);
    repo.setTagFormat(properties.get(TAG_FORMAT_PROPERTY));
    AccuRevCommandLine accuRev = new AccuRevCommandLine(host, port);
    accuRev.setLogger(getLogger());
    accuRev.setExecutable(properties.get(ACCUREV_EXECUTABLE_PROPERTY));
    repo.setAccuRev(accuRev);
    return repo;
}
Also used : HashMap(java.util.HashMap) AccuRevCommandLine(org.apache.maven.scm.provider.accurev.cli.AccuRevCommandLine) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)2 AccuRevCommandLine (org.apache.maven.scm.provider.accurev.cli.AccuRevCommandLine)2 File (java.io.File)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 ChangeSet (org.apache.maven.scm.ChangeSet)1 ScmBranch (org.apache.maven.scm.ScmBranch)1 ScmFileSet (org.apache.maven.scm.ScmFileSet)1 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)1 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)1 ScmProvider (org.apache.maven.scm.provider.ScmProvider)1 ScmRepository (org.apache.maven.scm.repository.ScmRepository)1 ChangeLogCommandTckTest (org.apache.maven.scm.tck.command.changelog.ChangeLogCommandTckTest)1 Test (org.junit.Test)1