maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r669454 - in /maven/plugins/trunk/maven-doap-plugin: pom.xml src/main/java/org/apache/maven/plugin/doap/DoapMojo.java src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
Date Thu, 19 Jun 2008 11:43:20 GMT
Author: vsiveton
Date: Thu Jun 19 04:43:19 2008
New Revision: 669454

URL: http://svn.apache.org/viewvc?rev=669454&view=rev
Log:
MDOAP-6: Support more repositories

o added SCM (CVS+SVN) dependencies 
o updated code to handle different DOAP tags

Modified:
    maven/plugins/trunk/maven-doap-plugin/pom.xml
    maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
    maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java

Modified: maven/plugins/trunk/maven-doap-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/pom.xml?rev=669454&r1=669453&r2=669454&view=diff
==============================================================================
--- maven/plugins/trunk/maven-doap-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-doap-plugin/pom.xml Thu Jun 19 04:43:19 2008
@@ -44,6 +44,12 @@
     <url>http://jira.codehaus.org/browse/MDOAP</url>
   </issueManagement>
 
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-doap-plugin/</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-doap-plugin/</developerConnection>
+    <url>http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/</url>
+  </scm>
+
   <dependencies>
     <!-- Maven -->
     <dependency>
@@ -57,6 +63,43 @@
       <version>2.0.6</version>
     </dependency>
 
+    <!-- scm -->
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-api</artifactId>
+      <version>${scmVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-manager-plexus</artifactId>
+      <version>${scmVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-provider-svn-commons</artifactId>
+      <version>${scmVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-provider-svnexe</artifactId>
+      <version>${scmVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-provider-cvs-commons</artifactId>
+      <version>${scmVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-provider-cvsexe</artifactId>
+      <version>${scmVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-provider-cvsjava</artifactId>
+      <version>${scmVersion}</version>
+    </dependency>
+
     <!-- misc -->
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
@@ -64,4 +107,8 @@
       <version>1.5.4</version>
     </dependency>
   </dependencies>
+
+  <properties>
+    <scmVersion>1.0</scmVersion>
+  </properties>
 </project>

Modified: maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java?rev=669454&r1=669453&r2=669454&view=diff
==============================================================================
--- maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
(original)
+++ maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
Thu Jun 19 04:43:19 2008
@@ -21,18 +21,26 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.io.Writer;
 import java.util.Iterator;
 
 import org.apache.maven.model.Developer;
 import org.apache.maven.model.License;
+import org.apache.maven.model.Scm;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.scm.manager.NoSuchScmProviderException;
+import org.apache.maven.scm.manager.ScmManager;
+import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
+import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.WriterFactory;
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
 import org.codehaus.plexus.util.xml.XMLWriter;
+import org.codehaus.plexus.util.xml.XmlWriterUtil;
 
 /**
  * Generate a Description of a Project (DOAP) file from the information found in a POM.
@@ -77,6 +85,16 @@
     private String language;
 
     /**
+     * Maven SCM Manager.
+     *
+     * @parameter expression="${component.org.apache.maven.scm.manager.ScmManager}"
+     * @required
+     * @readonly
+     * @since 1.0
+     */
+    protected ScmManager scmManager;
+
+    /**
      * {@inheritDoc}
      */
     public void execute()
@@ -144,7 +162,7 @@
         publishReleases();
 
         // SCM
-        publishSourceRepository( writer );
+        writeSourceRepositories( writer );
 
         // Developers
         publishMaintainers( writer );
@@ -167,27 +185,101 @@
     {
     }
 
-    private void publishSourceRepository( XMLWriter w )
+    /**
+     * Write all DOAP repositories.
+     *
+     * @param writer
+     */
+    private void writeSourceRepositories( XMLWriter writer )
     {
-        //<repository>
-        //  <SVNRepository>
-        //    <location rdf:resource="http://svn.apache.org/repos/asf/maven/components/trunk/"/>
-        //    <browse rdf:resource="http://svn.apache.org/viewcvs.cgi/maven/components/trunk/"/>
-        //  </SVNRepository>
-        //</repository>
-
-        if ( project.getScm() == null )
+        Scm scm = project.getScm();
+        if ( scm == null )
         {
             return;
         }
 
-        w.startElement( "repository" );
-        w.startElement( "SVNRepository" );
-        DoapUtil.writeRdfResourceElement( w, "location", project.getScm().getConnection().substring(
8 ) );
-        DoapUtil.writeRdfResourceElement( w, "browse", project.getScm().getUrl() );
-        w.endElement();
-        w.endElement();
+        XmlWriterUtil.writeLineBreak( writer );
+        XmlWriterUtil.writeCommentText( writer, "Anonymous Connection", 2 );
+        String anonymousConnection = scm.getConnection();
+        writeSourceRepository( writer, anonymousConnection );
+
+        XmlWriterUtil.writeLineBreak( writer );
+        XmlWriterUtil.writeCommentText( writer, "Developer Connection", 2 );
+        String developerConnection = scm.getDeveloperConnection();
+        writeSourceRepository( writer, developerConnection );
+    }
 
+    /**
+     * Write a DOAP repository, for instance:
+     * <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 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, String connection )
+    {
+        ScmRepository repository = getScmRepository( connection );
+
+        writer.startElement( "repository" );
+
+        if ( isScmSystem( repository, "cvs" ) )
+        {
+            // http://usefulinc.com/ns/doap#CVSRepository
+            writer.startElement( "CVSRepository" );
+
+            CvsScmProviderRepository cvsRepo =
+                (CvsScmProviderRepository) repository.getProviderRepository();
+
+            // http://usefulinc.com/ns/doap#anon-root
+            DoapUtil.writeElement( writer, "anon-root", cvsRepo.getCvsRoot() );
+            // http://usefulinc.com/ns/doap#module
+            DoapUtil.writeElement( writer, "module", cvsRepo.getModule() );
+        }
+        else if ( isScmSystem( repository, "svn" ) )
+        {
+            // http://usefulinc.com/ns/doap#SVNRepository
+            writer.startElement( "SVNRepository" );
+
+            SvnScmProviderRepository svnRepo =
+                (SvnScmProviderRepository) repository.getProviderRepository();
+
+            // http://usefulinc.com/ns/doap#location
+            DoapUtil.writeRdfResourceElement( writer, "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.
+             */
+            writer.startElement( "Repository" );
+
+            if ( connection.length() < 4 )
+            {
+                throw new IllegalArgumentException( "The source repository connection is
too short." );
+            }
+
+            // http://usefulinc.com/ns/doap#location
+            DoapUtil.writeRdfResourceElement( writer, "location", connection.substring( 4
) );
+        }
+
+        // http://usefulinc.com/ns/doap#browse
+        DoapUtil.writeRdfResourceElement( writer, "browse", project.getScm().getUrl() );
+
+        writer.endElement(); // CVSRepository || SVNRepository || Repository
+        writer.endElement(); // repository
     }
 
     private void publishMaintainers( XMLWriter w )
@@ -236,4 +328,63 @@
 
         return base + path;
     }
+
+    /**
+     * Return a <code>SCM repository</code> defined by a given url
+     *
+     * @param scmUrl an SCM URL
+     * @return a valid SCM repository or null
+     */
+    public ScmRepository getScmRepository( String scmUrl )
+    {
+        ScmRepository repo = null;
+        if ( !StringUtils.isEmpty( scmUrl ) )
+        {
+            try
+            {
+                repo = scmManager.makeScmRepository( scmUrl );
+            }
+            catch ( NoSuchScmProviderException e )
+            {
+                if ( getLog().isDebugEnabled() )
+                {
+                    getLog().debug( e.getMessage(), e );
+                }
+            }
+            catch ( ScmRepositoryException e )
+            {
+                if ( getLog().isDebugEnabled() )
+                {
+                    getLog().debug( e.getMessage(), e );
+                }
+            }
+        }
+        return repo;
+    }
+
+    /**
+     * Convenience method that return true is the defined <code>SCM repository</code>
is a known provider.
+     * <p>
+     * Actually, we fully support Clearcase, CVS, Perforce, Starteam, SVN by the maven-scm-providers
component.
+     * </p>
+     *
+     * @param scmRepository a SCM repository
+     * @param scmProvider a SCM provider name
+     * @return true if the provider of the given SCM repository is equal to the given scm
provider.
+     * @see <a href="http://svn.apache.org/repos/asf/maven/scm/trunk/maven-scm-providers/">maven-scm-providers</a>
+     */
+    private static boolean isScmSystem( ScmRepository scmRepository, String scmProvider )
+    {
+        if ( StringUtils.isEmpty( scmProvider ) )
+        {
+            return false;
+        }
+
+        if ( scmRepository != null && scmProvider.equalsIgnoreCase( scmRepository.getProvider()
) )
+        {
+            return true;
+        }
+
+        return false;
+    }
 }

Modified: maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java?rev=669454&r1=669453&r2=669454&view=diff
==============================================================================
--- maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
(original)
+++ maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
Thu Jun 19 04:43:19 2008
@@ -66,7 +66,7 @@
     /**
      * @param writer not null
      * @param name not null
-     * @param value not null
+     * @param value could be null. In this case, the element is not written.
      * @throws IllegalArgumentException if name is null or empty
      */
     public static void writeElement( XMLWriter writer, String name, String value )
@@ -88,7 +88,7 @@
     /**
      * @param writer not null
      * @param name not null
-     * @param value not null
+     * @param value could be null. In this case, the element is not written.
      * @throws IllegalArgumentException if name is null or empty
      */
     public static void writeRdfResourceElement( XMLWriter writer, String name, String value
)



Mime
View raw message