Author: vsiveton
Date: Tue Jun 17 14:01:28 2008
New Revision: 668827

URL: http://svn.apache.org/viewvc?rev=668827&view=rev
Log:
o bumped to p-u 1.5.4-snap
o bumped to maven 2.0.4 as prerequisite and dependencies
o fixed encoding in the generated doap file
o replaced ASF header in the generated doap file with a generated notice
o added a new utility class with static methods

Added:
    
maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
   (with props)
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

Modified: maven/plugins/trunk/maven-doap-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/pom.xml?rev=668827&r1=668826&r2=668827&view=diff
==============================================================================
--- maven/plugins/trunk/maven-doap-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-doap-plugin/pom.xml Tue Jun 17 14:01:28 2008
@@ -36,7 +36,7 @@
   <description>Plugins which generate a DOAP file from information in a 
POM.</description>
 
   <prerequisites>
-    <maven>2.0.1</maven>
+    <maven>2.0.4</maven>
   </prerequisites>
 
   <issueManagement>
@@ -45,20 +45,23 @@
   </issueManagement>
 
   <dependencies>
+    <!-- Maven -->
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-project</artifactId>
-      <version>2.0</version>
+      <version>2.0.4</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
-      <version>2.0</version>
+      <version>2.0.4</version>
     </dependency>
+
+    <!-- misc -->
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
-      <version>1.1</version>
+      <version>1.5.4-SNAPSHOT</version>
     </dependency>
   </dependencies>
 </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=668827&r1=668826&r2=668827&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
 Tue Jun 17 14:01:28 2008
@@ -19,23 +19,21 @@
  * under the License.
  */
 
+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.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.WriterFactory;
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
 import org.codehaus.plexus.util.xml.XMLWriter;
 
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.Writer;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Iterator;
-
 /**
  * Generate a Description of a Project (DOAP) file from the information found 
in a POM.
  *
@@ -47,8 +45,6 @@
 public class DoapMojo
     extends AbstractMojo
 {
-    public static final String RDF_RESOURCE = "rdf:resource";
-
     /**
      * The POM from which information will be extracted to create a DOAP file.
      *
@@ -80,8 +76,6 @@
      */
     private String language;
 
-    private XMLWriter w;
-
     /**
      * [EMAIL PROTECTED]
      */
@@ -92,115 +86,79 @@
         // setup pretty print xml writer
         // 
----------------------------------------------------------------------------
 
-        Writer writer;
-
+        Writer w;
         try
         {
-            writer = new FileWriter( doapFile );
+            w = WriterFactory.newXmlWriter( doapFile );
         }
         catch ( IOException e )
         {
             throw new MojoExecutionException( "Error creating DOAP file.", e );
         }
 
-        PrintWriter pw = new PrintWriter( writer );
-
-        w = new PrettyPrintXMLWriter( pw );
+        XMLWriter writer = new PrettyPrintXMLWriter( w, 
project.getModel().getModelEncoding(), null );
 
         // 
----------------------------------------------------------------------------
         // Convert POM to DOAP
         // 
----------------------------------------------------------------------------
 
-        // Grab year for the license.
-        SimpleDateFormat format = new SimpleDateFormat( "yyyy" );
-        String year = format.format( new Date() );
-
-        pw.println( "<!--" );
-        pw.println( "  ~ Copyright " + year + " The Apache Software 
Foundation." );
-        pw.println( "  ~" );
-        pw.println( "  ~ Licensed under the Apache License, Version 2.0 (the 
\"License\");" );
-        pw.println( "  ~ you may not use this file except in compliance with 
the License." );
-        pw.println( "  ~ You may obtain a copy of the License at" );
-        pw.println( "  ~" );
-        pw.println( "  ~      http://www.apache.org/licenses/LICENSE-2.0"; );
-        pw.println( "  ~" );
-        pw.println( "  ~ Unless required by applicable law or agreed to in 
writing, software" );
-        pw.println( "  ~ distributed under the License is distributed on an 
\"AS IS\" BASIS," );
-        pw.println( "  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
express or implied." );
-        pw.println( "  ~ See the License for the specific language governing 
permissions and" );
-        pw.println( "  ~ limitations under the License." );
-        pw.println( "--> " );
+        DoapUtil.writeHeader( writer );
 
         // Heading
-        w.startElement( "rdf:RDF" );
-        w.addAttribute( "xml:lang", "en" );
-        w.addAttribute( "xmlns", "http://usefulinc.com/ns/doap#"; );
-        w.addAttribute( "xmlns:rdf", 
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"; );
-        w.addAttribute( "xmlns:asfext", 
"http://projects.apache.org/ns/asfext#"; );
-        w.addAttribute( "xmlns:foaf", "http://xmlns.com/foaf/0.1/"; );
+        writer.startElement( "rdf:RDF" );
+        writer.addAttribute( "xml:lang", "en" );
+        writer.addAttribute( "xmlns", "http://usefulinc.com/ns/doap#"; );
+        writer.addAttribute( "xmlns:rdf", 
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"; );
+        writer.addAttribute( "xmlns:asfext", 
"http://projects.apache.org/ns/asfext#"; );
+        writer.addAttribute( "xmlns:foaf", "http://xmlns.com/foaf/0.1/"; );
 
         // Project
-        w.startElement( "Project" );
-        w.addAttribute( "rdf:about", "http://Maven.rdf.apache.org/"; );
-        element( "created", project.getInceptionYear() );
+        writer.startElement( "Project" );
+        writer.addAttribute( "rdf:about", "http://Maven.rdf.apache.org/"; );
+        DoapUtil.writeElement( writer, "created", project.getInceptionYear() );
 
         if ( project.getLicenses().size() > 0 )
         {
             //TODO: how to map to usefulinc site, or if this is necessary, the 
OSI page might
             //      be more appropriate.
-            rdfResourceElement( "license", ((License) 
project.getLicenses().get( 0 )).getUrl() );
+            DoapUtil.writeRdfResourceElement( writer, "license", ((License) 
project.getLicenses().get( 0 )).getUrl() );
         }
 
-        element( "name", project.getName() );
-        rdfResourceElement( "homepage", project.getUrl() );
-        rdfResourceElement( "asfext:pmc", project.getUrl() );
-        element( "shortdesc", project.getDescription() );
-        element( "description", project.getDescription() );
+        DoapUtil.writeElement( writer, "name", project.getName() );
+        DoapUtil.writeRdfResourceElement( writer, "homepage", project.getUrl() 
);
+        DoapUtil.writeRdfResourceElement( writer, "asfext:pmc", 
project.getUrl() );
+        DoapUtil.writeElement( writer, "shortdesc", project.getDescription() );
+        DoapUtil.writeElement( writer, "description", project.getDescription() 
);
 
         if ( project.getIssueManagement() != null )
         {
-            rdfResourceElement( "bug-database", 
project.getIssueManagement().getUrl() );
+            DoapUtil.writeRdfResourceElement( writer, "bug-database", 
project.getIssueManagement().getUrl() );
         }
-        rdfResourceElement( "mailing-list", composeUrl( project.getUrl() , 
"/mail-lists.html" ) );
-        rdfResourceElement( "download-page", composeUrl( project.getUrl() , 
"/download.html" ) );
-        element( "programming-language", language );
+        DoapUtil.writeRdfResourceElement( writer, "mailing-list", composeUrl( 
project.getUrl() , "/mail-lists.html" ) );
+        DoapUtil.writeRdfResourceElement( writer, "download-page", composeUrl( 
project.getUrl() , "/download.html" ) );
+        DoapUtil.writeElement( writer, "programming-language", language );
         //TODO: how to lookup category, map it, or just declare it.
-        rdfResourceElement( "category", "http://projects.apache.org/category/"; 
+ category );
+        DoapUtil.writeRdfResourceElement( writer, "category", 
"http://projects.apache.org/category/"; + category );
 
         // Releases
         publishReleases();
 
         // SCM
-        publishSourceRepository();
+        publishSourceRepository( writer );
 
         // Developers
-        publishMaintainers();
+        publishMaintainers( writer );
 
-        w.endElement();
-        w.endElement();
-
-        pw.close();
-    }
+        writer.endElement();
+        writer.endElement();
 
-    private void element( String name,
-                          String value )
-    {
-        if ( value != null )
+        try
         {
-            w.startElement( name );
-            w.writeText( value );
-            w.endElement();
+            w.close();
         }
-    }
-
-    private void rdfResourceElement( String name,
-                                     String value )
-    {
-        if ( value != null )
+        catch ( IOException e )
         {
-            w.startElement( name );
-            w.addAttribute( RDF_RESOURCE, value );
-            w.endElement();
+            throw new MojoExecutionException( "Error when closing the 
writer.", e );
         }
     }
 
@@ -209,7 +167,7 @@
     {
     }
 
-    private void publishSourceRepository()
+    private void publishSourceRepository( XMLWriter w )
     {
         //<repository>
         //  <SVNRepository>
@@ -225,14 +183,14 @@
 
         w.startElement( "repository" );
         w.startElement( "SVNRepository" );
-        rdfResourceElement( "location", 
project.getScm().getConnection().substring( 8 ) );
-        rdfResourceElement( "browse", project.getScm().getUrl() );
+        DoapUtil.writeRdfResourceElement( w, "location", 
project.getScm().getConnection().substring( 8 ) );
+        DoapUtil.writeRdfResourceElement( w, "browse", 
project.getScm().getUrl() );
         w.endElement();
         w.endElement();
 
     }
 
-    private void publishMaintainers()
+    private void publishMaintainers( XMLWriter w )
     {
         //<maintainer>
         //  <foaf:Person>
@@ -255,7 +213,7 @@
             w.startElement( "foaf:name" );
             w.writeText( d.getName() );
             w.endElement();
-            rdfResourceElement( "foaf:mbox", "mailto:"; + d.getEmail() );
+            DoapUtil.writeRdfResourceElement( w, "foaf:mbox", "mailto:"; + 
d.getEmail() );
             w.endElement();
             w.endElement();
         }
@@ -275,9 +233,7 @@
         {
             return base + path.substring( 1 );
         }
-        else
-        {
-            return base + path;
-        }
+
+        return base + path;
     }
 }

Added: 
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=668827&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
 (added)
+++ 
maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
 Tue Jun 17 14:01:28 2008
@@ -0,0 +1,109 @@
+package org.apache.maven.plugin.doap;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.XMLWriter;
+import org.codehaus.plexus.util.xml.XmlWriterUtil;
+
+/**
+ * Utility class for DOAP mojo.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class DoapUtil
+{
+    private static final String RDF_RESOURCE = "rdf:resource";
+
+    /**
+     * Write comments in the DOAP file header
+     *
+     * @param writer not null
+     */
+    public static void writeHeader( XMLWriter writer )
+    {
+        XmlWriterUtil.writeLineBreak( writer );
+
+        XmlWriterUtil.writeCommentLineBreak( writer );
+        XmlWriterUtil.writeComment( writer, StringUtils.repeat( "=", 21 ) + " 
- DO NOT EDIT THIS FILE! - "
+            + StringUtils.repeat( "=", 21 ) );
+        XmlWriterUtil.writeCommentLineBreak( writer );
+        XmlWriterUtil.writeComment( writer, " " );
+        XmlWriterUtil.writeComment( writer, "Any modifications will be 
overwritten." );
+        XmlWriterUtil.writeComment( writer, " " );
+        DateFormat dateFormat = DateFormat.getDateTimeInstance( 
DateFormat.SHORT, DateFormat.SHORT, Locale.US );
+        XmlWriterUtil.writeComment( writer, "Generated by Maven Doap Plugin on 
"
+            + dateFormat.format( new Date( System.currentTimeMillis() ) ) );
+        XmlWriterUtil.writeComment( writer, "See: 
http://maven.apache.org/plugins/maven-doap-plugin/"; );
+        XmlWriterUtil.writeComment( writer, " " );
+        XmlWriterUtil.writeCommentLineBreak( writer );
+
+        XmlWriterUtil.writeLineBreak( writer );
+    }
+
+    /**
+     * @param writer not null
+     * @param name not null
+     * @param value not null
+     * @throws IllegalArgumentException if name is null or empty
+     */
+    public static void writeElement( XMLWriter writer, String name, String 
value )
+        throws IllegalArgumentException
+    {
+        if ( StringUtils.isEmpty( name ) )
+        {
+            throw new IllegalArgumentException( "name should be defined" );
+        }
+
+        if ( value != null )
+        {
+            writer.startElement( name );
+            writer.writeText( value );
+            writer.endElement();
+        }
+    }
+
+    /**
+     * @param writer not null
+     * @param name not null
+     * @param value not null
+     * @throws IllegalArgumentException if name is null or empty
+     */
+    public static void writeRdfResourceElement( XMLWriter writer, String name, 
String value )
+        throws IllegalArgumentException
+    {
+        if ( StringUtils.isEmpty( name ) )
+        {
+            throw new IllegalArgumentException( "name should be defined" );
+        }
+
+        if ( value != null )
+        {
+            writer.startElement( name );
+            writer.addAttribute( RDF_RESOURCE, value );
+            writer.endElement();
+        }
+    }
+}

Propchange: 
maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision


Reply via email to