Search in sources :

Example 11 with ScmBranch

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

the class BranchCommandTckTest method testBranchCommandTest.

public void testBranchCommandTest() throws Exception {
    String branch = getBranch();
    @SuppressWarnings("deprecation") BranchScmResult branchResult = getScmManager().getProviderByUrl(getScmUrl()).branch(getScmRepository(), new ScmFileSet(getWorkingCopy()), branch);
    assertResultIsSuccess(branchResult);
    // see https://issues.apache.org/jira/browse/SCM-754
    // assertEquals( "check all 4 files branched", 4, branchResult.getBranchedFiles().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 ScmBranch(branch));
    assertResultIsSuccess(checkoutResult);
    assertEquals("check readme.txt contents is from branched version", "/readme.txt", FileUtils.fileRead(readmeTxt));
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) ScmFileSet(org.apache.maven.scm.ScmFileSet) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) File(java.io.File) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult)

Example 12 with ScmBranch

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

the class GitCheckOutCommand method createCloneCommand.

/**
 * create a git-clone repository command
 */
private Commandline createCloneCommand(GitScmProviderRepository repository, File workingDirectory, ScmVersion version, boolean shallow) {
    Commandline cl = GitCommandLineUtils.getBaseGitCommandLine(workingDirectory.getParentFile(), "clone");
    if (shallow) {
        cl.createArg().setValue("--depth");
        cl.createArg().setValue("1");
    }
    if (version != null && (version instanceof ScmBranch)) {
        cl.createArg().setValue("--branch");
        cl.createArg().setValue(version.getName());
    }
    cl.createArg().setValue(repository.getFetchUrl());
    cl.createArg().setFile(workingDirectory);
    return cl;
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) Commandline(org.codehaus.plexus.util.cli.Commandline)

Example 13 with ScmBranch

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

the class StarteamDiffCommandTest method testGetCommandLineWithLabels.

public void testGetCommandLineWithLabels() throws Exception {
    ScmFileSet fileSet = new ScmFileSet(getWorkingCopy());
    String workingCopy = StarteamCommandLineUtils.toJavaPath(getWorkingCopy().getPath());
    String starteamUrl = "user:password@host:1234/project/view";
    String mavenUrl = "scm:starteam:" + starteamUrl;
    String expectedCmd = "stcmd diff -x -nologo -stop" + " -p " + starteamUrl + " -fp " + workingCopy + " -is -filter M" + " -vl label1 -vl label2 -eol on";
    testCommandLine(mavenUrl, fileSet, new ScmBranch("label1"), new ScmBranch("label2"), expectedCmd);
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) ScmFileSet(org.apache.maven.scm.ScmFileSet)

Example 14 with ScmBranch

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

the class ChangeLogReport method generateChangeSetsFromSCM.

/**
 * creates a ChangeLog object and then connects to the SCM to generate the changed sets
 *
 * @return changedlogsets generated from the SCM
 * @throws MavenReportException
 */
protected List<ChangeLogSet> generateChangeSetsFromSCM() throws MavenReportException {
    try {
        List<ChangeLogSet> changeSets = new ArrayList<ChangeLogSet>();
        ScmRepository repository = getScmRepository();
        ScmProvider provider = manager.getProviderByRepository(repository);
        ChangeLogScmResult result;
        if ("range".equals(type)) {
            result = provider.changeLog(repository, new ScmFileSet(basedir), null, null, range, (ScmBranch) null, dateFormat);
            checkResult(result);
            changeSets.add(result.getChangeLog());
        } else if ("tag".equals(type)) {
            Iterator<String> tagsIter = tags.iterator();
            String startTag = tagsIter.next();
            String endTag = null;
            if (tagsIter.hasNext()) {
                while (tagsIter.hasNext()) {
                    endTag = tagsIter.next();
                    String endRevision = getRevisionForTag(endTag, repository, provider);
                    String startRevision = getRevisionForTag(startTag, repository, provider);
                    result = provider.changeLog(repository, new ScmFileSet(basedir), new ScmRevision(startRevision), new ScmRevision(endRevision));
                    checkResult(result);
                    result.getChangeLog().setStartVersion(new ScmRevision(startTag));
                    result.getChangeLog().setEndVersion(new ScmRevision(endTag));
                    changeSets.add(result.getChangeLog());
                    startTag = endTag;
                }
            } else {
                String startRevision = getRevisionForTag(startTag, repository, provider);
                String endRevision = getRevisionForTag(endTag, repository, provider);
                result = provider.changeLog(repository, new ScmFileSet(basedir), new ScmRevision(startRevision), new ScmRevision(endRevision));
                checkResult(result);
                result.getChangeLog().setStartVersion(new ScmRevision(startTag));
                result.getChangeLog().setEndVersion(null);
                changeSets.add(result.getChangeLog());
            }
        } else if ("date".equals(type)) {
            Iterator<String> dateIter = dates.iterator();
            String startDate = dateIter.next();
            String endDate = null;
            if (dateIter.hasNext()) {
                while (dateIter.hasNext()) {
                    endDate = dateIter.next();
                    result = provider.changeLog(repository, new ScmFileSet(basedir), parseDate(startDate), parseDate(endDate), 0, (ScmBranch) null);
                    checkResult(result);
                    changeSets.add(result.getChangeLog());
                    startDate = endDate;
                }
            } else {
                result = provider.changeLog(repository, new ScmFileSet(basedir), parseDate(startDate), parseDate(endDate), 0, (ScmBranch) null);
                checkResult(result);
                changeSets.add(result.getChangeLog());
            }
        } else {
            throw new MavenReportException("The type '" + type + "' isn't supported.");
        }
        filter(changeSets);
        return changeSets;
    } catch (ScmException e) {
        throw new MavenReportException("Cannot run changelog command : ", e);
    } catch (MojoExecutionException e) {
        throw new MavenReportException("An error has occurred during changelog command : ", e);
    }
}
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) ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ScmRevision(org.apache.maven.scm.ScmRevision) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 15 with ScmBranch

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

the class AbstractScmPublishMojo method checkinFiles.

/**
 * Check-in content from scm checkout.
 *
 * @throws MojoExecutionException
 */
protected void checkinFiles() throws MojoExecutionException {
    if (skipCheckin) {
        return;
    }
    ScmFileSet updatedFileSet = new ScmFileSet(checkoutDirectory);
    try {
        long start = System.currentTimeMillis();
        CheckInScmResult checkinResult = checkScmResult(scmProvider.checkIn(scmRepository, updatedFileSet, new ScmBranch(scmBranch), checkinComment), "check-in files to SCM");
        logInfo("Checked in %d file(s) to revision %s in %s", checkinResult.getCheckedInFiles().size(), checkinResult.getScmRevision(), DurationFormatUtils.formatPeriod(start, System.currentTimeMillis(), "H' h 'm' m 's' s'"));
    } catch (ScmException e) {
        throw new MojoExecutionException("Failed to perform SCM checkin", e);
    }
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult)

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