Search in sources :

Example 1 with ScmRepository

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

the class ChangeLogReport method getScmRepository.

public ScmRepository getScmRepository() throws ScmException {
    ScmRepository repository;
    try {
        repository = manager.makeScmRepository(getConnection());
        ScmProviderRepository providerRepo = repository.getProviderRepository();
        if (!StringUtils.isEmpty(username)) {
            providerRepo.setUser(username);
        }
        if (!StringUtils.isEmpty(password)) {
            providerRepo.setPassword(password);
        }
        if (repository.getProviderRepository() instanceof ScmProviderRepositoryWithHost) {
            ScmProviderRepositoryWithHost repo = (ScmProviderRepositoryWithHost) repository.getProviderRepository();
            loadInfosFromSettings(repo);
            if (!StringUtils.isEmpty(username)) {
                repo.setUser(username);
            }
            if (!StringUtils.isEmpty(password)) {
                repo.setPassword(password);
            }
            if (!StringUtils.isEmpty(privateKey)) {
                repo.setPrivateKey(privateKey);
            }
            if (!StringUtils.isEmpty(passphrase)) {
                repo.setPassphrase(passphrase);
            }
        }
        if (!StringUtils.isEmpty(tagBase) && repository.getProvider().equals("svn")) {
            SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) repository.getProviderRepository();
            svnRepo.setTagBase(tagBase);
        }
    } catch (Exception e) {
        throw new ScmException("Can't load the scm provider.", e);
    }
    return repository;
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmException(org.apache.maven.scm.ScmException) ScmProviderRepositoryWithHost(org.apache.maven.scm.provider.ScmProviderRepositoryWithHost) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) ScmProviderRepository(org.apache.maven.scm.provider.ScmProviderRepository) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) ScmException(org.apache.maven.scm.ScmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MavenReportException(org.apache.maven.reporting.MavenReportException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 2 with ScmRepository

use of org.apache.maven.scm.repository.ScmRepository 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 3 with ScmRepository

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

the class DoapMojo method writeSourceRepository.

/**
     * Write a DOAP repository, for instance:
     * <p/>
     * <pre>
     *   &lt;repository&gt;
     *     &lt;SVNRepository&gt;
     *       &lt;location rdf:resource="http://svn.apache.org/repos/asf/maven/components/trunk/"/&gt;
     *       &lt;browse rdf:resource="http://svn.apache.org/viewcvs.cgi/maven/components/trunk/"/&gt;
     *     &lt;/SVNRepository&gt;
     *   &lt;/repository&gt;
     * </pre>
     *
     * @param writer     not null
     * @param project    the Maven project, not null
     * @param connection not null
     * @see <a href="http://usefulinc.com/ns/doap#Repository">http://usefulinc.com/ns/doap#Repository</a>
     * @see <a href="http://usefulinc.com/ns/doap#CVSRepository">http://usefulinc.com/ns/doap#CVSRepository</a>
     * @see <a href="http://usefulinc.com/ns/doap#SVNRepository">http://usefulinc.com/ns/doap#SVNRepository</a>
     */
private void writeSourceRepository(XMLWriter writer, MavenProject project, String connection) {
    ScmRepository repository = getScmRepository(connection);
    DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "repository");
    if (isScmSystem(repository, "cvs")) {
        DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "CVSRepository");
        CvsScmProviderRepository cvsRepo = (CvsScmProviderRepository) repository.getProviderRepository();
        DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "anon-root", cvsRepo.getCvsRoot());
        DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "module", cvsRepo.getModule());
    } else if (isScmSystem(repository, "svn")) {
        DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "SVNRepository");
        SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) repository.getProviderRepository();
        DoapUtil.writeRdfResourceElement(writer, doapOptions.getXmlnsPrefix(), "location", svnRepo.getUrl());
    } else {
        /*
             * Supported DOAP repositories actually unsupported by SCM: BitKeeper
             * (http://usefulinc.com/ns/doap#BKRepository) Arch (http://usefulinc.com/ns/doap#ArchRepository) Other SCM
             * repos are unsupported by DOAP.
             */
        DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "Repository");
        if (connection.length() < 4) {
            throw new IllegalArgumentException("The source repository connection is too short.");
        }
        DoapUtil.writeRdfResourceElement(writer, doapOptions.getXmlnsPrefix(), "location", connection.substring(4));
    }
    DoapUtil.writeRdfResourceElement(writer, doapOptions.getXmlnsPrefix(), "browse", project.getScm().getUrl());
    // CVSRepository || SVNRepository || Repository
    writer.endElement();
    // repository
    writer.endElement();
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) CvsScmProviderRepository(org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)

Aggregations

ScmRepository (org.apache.maven.scm.repository.ScmRepository)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2 ScmException (org.apache.maven.scm.ScmException)2 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 ScmBranch (org.apache.maven.scm.ScmBranch)1 ScmFileSet (org.apache.maven.scm.ScmFileSet)1 ScmRevision (org.apache.maven.scm.ScmRevision)1 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)1 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)1 ScmProvider (org.apache.maven.scm.provider.ScmProvider)1 ScmProviderRepository (org.apache.maven.scm.provider.ScmProviderRepository)1 ScmProviderRepositoryWithHost (org.apache.maven.scm.provider.ScmProviderRepositoryWithHost)1 CvsScmProviderRepository (org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository)1