Author: vsiveton
Date: Fri Dec 10 10:32:41 2010
New Revision: 1044272
URL: http://svn.apache.org/viewvc?rev=1044272&view=rev
Log:
MDOAP-27: Generated files aren't useable with Jena
o added validate parameter
Added:
maven/plugins/trunk/maven-doap-plugin/src/test/resources/generated-doap-1.0.rdf
(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
maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java
maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/asf-doap-configuration/asf-doap-configuration-plugin-config.xml
maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml
Modified: maven/plugins/trunk/maven-doap-plugin/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/pom.xml?rev=1044272&r1=1044271&r2=1044272&view=diff
==============================================================================
--- maven/plugins/trunk/maven-doap-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-doap-plugin/pom.xml Fri Dec 10 10:32:41 2010
@@ -49,6 +49,13 @@ under the License.
<url>http://jira.codehaus.org/browse/MDOAP</url>
</issueManagement>
+ <repositories>
+ <repository>
+ <id>jena</id>
+ <url>http://openjena.org/repo/</url>
+ </repository>
+ </repositories>
+
<properties>
<scmVersion>1.0</scmVersion>
</properties>
@@ -120,6 +127,11 @@ under the License.
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>com.hp.hpl.jena</groupId>
+ <artifactId>jena</artifactId>
+ <version>2.6.3</version>
+ </dependency>
<!-- test -->
<dependency>
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=1044272&r1=1044271&r2=1044272&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
Fri Dec 10 10:32:41 2010
@@ -282,6 +282,14 @@ public class DoapMojo
*/
private String about;
+ /**
+ * Flag to validate the generated DOAP.
+ *
+ * @parameter default-value="true"
+ * @since 1.1
+ */
+ private boolean validate;
+
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
@@ -416,6 +424,20 @@ public class DoapMojo
{
throw new MojoExecutionException( "Error when closing the
writer.", e );
}
+
+ if ( validate )
+ {
+ List errors = DoapUtil.validate( doapFile );
+ if ( !errors.isEmpty() )
+ {
+ for ( int i = 0; i < errors.size(); i++ )
+ {
+ getLog().error( errors.get( i ).toString() );
+ }
+
+ throw new MojoExecutionException( "Error parsing the generated
doap file, see above." );
+ }
+ }
}
// ----------------------------------------------------------------------
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=1044272&r1=1044271&r2=1044272&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
Fri Dec 10 10:32:41 2010
@@ -19,6 +19,8 @@ package org.apache.maven.plugin.doap;
* under the License.
*/
+import java.io.File;
+import java.net.MalformedURLException;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -35,6 +37,11 @@ import org.codehaus.plexus.util.StringUt
import org.codehaus.plexus.util.xml.XMLWriter;
import org.codehaus.plexus.util.xml.XmlWriterUtil;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.RDFReader;
+import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
+
/**
* Utility class for DOAP mojo.
*
@@ -220,6 +227,45 @@ public class DoapUtil
return (List) filterDevelopersOrContributorsByDoapRoles( i18n,
developersOrContributors ).get( "unknowns" );
}
+ /**
+ * Validate the given DOAP file.
+ *
+ * @param doapFile not null and should exists.
+ * @return an empty list if the DOAP file is valid, otherwise a list of
errors.
+ * @since 1.1
+ */
+ public static List validate( File doapFile )
+ {
+ if ( doapFile == null || !doapFile.isFile() )
+ {
+ throw new IllegalArgumentException( "The DOAP file should exist" );
+ }
+
+ Model model = ModelFactory.createDefaultModel();
+ RDFReader r = model.getReader( "RDF/XML" );
+ r.setProperty( "error-mode", "strict-error" );
+ final List errors = new ArrayList();
+ r.setErrorHandler( new RDFDefaultErrorHandler()
+ {
+ /** {...@inheritdoc} */
+ public void error( Exception e )
+ {
+ errors.add( e.getMessage() );
+ }
+ } );
+
+ try
+ {
+ r.read( model, doapFile.toURI().toURL().toString() );
+ }
+ catch ( MalformedURLException e )
+ {
+ // ignored
+ }
+
+ return errors;
+ }
+
// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
Modified:
maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java?rev=1044272&r1=1044271&r2=1044272&view=diff
==============================================================================
---
maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java
(original)
+++
maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java
Fri Dec 10 10:32:41 2010
@@ -19,6 +19,7 @@ package org.apache.maven.plugin.doap;
* under the License.
*/
+import java.io.File;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
@@ -170,4 +171,17 @@ public class DoapUtilTest
assertTrue( DoapUtil.getDevelopersOrContributorsWithTranslatorRole(
i18n, developersOrContributors ).isEmpty() );
assertFalse( DoapUtil.getDevelopersOrContributorsWithUnknownRole(
i18n, developersOrContributors ).isEmpty() );
}
+
+ /**
+ * Test method for:
+ * {...@link DoapUtil#validate(java.io.File)}
+ *
+ * @throws Exception if any
+ */
+ public void testValidate()
+ throws Exception
+ {
+ File doapFile = new File( getBasedir(),
"src/test/resources/generated-doap-1.0.rdf" );
+ assertFalse( DoapUtil.validate( doapFile ).isEmpty() );
+ }
}
Added:
maven/plugins/trunk/maven-doap-plugin/src/test/resources/generated-doap-1.0.rdf
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/test/resources/generated-doap-1.0.rdf?rev=1044272&view=auto
==============================================================================
---
maven/plugins/trunk/maven-doap-plugin/src/test/resources/generated-doap-1.0.rdf
(added)
+++
maven/plugins/trunk/maven-doap-plugin/src/test/resources/generated-doap-1.0.rdf
Fri Dec 10 10:32:41 2010
@@ -0,0 +1,47 @@
+
+<!-- ====================================================================== -->
+<!-- ===================== - DO NOT EDIT THIS FILE! - ===================== -->
+<!-- ====================================================================== -->
+<!-- -->
+<!-- Any modifications will be overwritten. -->
+<!-- -->
+<!-- Generated by Maven Doap Plugin on 12/10/10 4:53 AM -->
+<!-- See: http://maven.apache.org/plugins/maven-doap-plugin/ -->
+<!-- -->
+<!-- ====================================================================== -->
+
+<rdf:RDF xml:lang="en" xmlns="http://usefulinc.com/ns/doap#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
+ <Project rdf:about="http://maven.apache.org/plugins/maven-doap-plugin/tests">
+
+ <!--
====================================================================== -->
+ <!-- A name of something.
-->
+ <!--
====================================================================== -->
+
+ <name rdf:resource="Maven DOAP Plugin Test"/>
+
+ <!--
====================================================================== -->
+ <!-- Plain text description of a project, of 2-4 sentences in length.
-->
+ <!--
====================================================================== -->
+
+ <description xml:lang="en">Test the DOAP plugin</description>
+ <shortdesc xml:lang="en">Test the DOAP plugin</shortdesc>
+
+ <!--
====================================================================== -->
+ <!-- URL of a project's homepage, associated with exactly one project.
-->
+ <!--
====================================================================== -->
+
+ <homepage
rdf:resource="http://maven.apache.org/plugins/maven-doap-plugin/tests"/>
+
+ <!--
====================================================================== -->
+ <!-- Programming language.
-->
+ <!--
====================================================================== -->
+
+ <programming-language rdf:resource="java"/>
+
+ <!--
====================================================================== -->
+ <!-- Download page.
-->
+ <!--
====================================================================== -->
+
+ <download-page
rdf:resource="http://maven.apache.org/plugins/maven-doap-plugin/tests/download.html"/>
+ </Project>
+</rdf:RDF>
\ No newline at end of file
Propchange:
maven/plugins/trunk/maven-doap-plugin/src/test/resources/generated-doap-1.0.rdf
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-doap-plugin/src/test/resources/generated-doap-1.0.rdf
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified:
maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/asf-doap-configuration/asf-doap-configuration-plugin-config.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/asf-doap-configuration/asf-doap-configuration-plugin-config.xml?rev=1044272&r1=1044271&r2=1044272&view=diff
==============================================================================
---
maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/asf-doap-configuration/asf-doap-configuration-plugin-config.xml
(original)
+++
maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/asf-doap-configuration/asf-doap-configuration-plugin-config.xml
Fri Dec 10 10:32:41 2010
@@ -57,6 +57,7 @@ under the License.
<localRepository>${localRepository}</localRepository>
<doapFile>target/test/unit/asf-doap-configuration/asf-doap-configuration.rdf</doapFile>
<lang>en</lang>
+ <validate>true</validate>
<doapOptions>
<programmingLanguage>java</programmingLanguage>
Modified:
maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml?rev=1044272&r1=1044271&r2=1044272&view=diff
==============================================================================
---
maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml
(original)
+++
maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml
Fri Dec 10 10:32:41 2010
@@ -57,6 +57,7 @@ under the License.
<localRepository>${localRepository}</localRepository>
<doapFile>target/test/unit/doap-configuration/doap-configuration.rdf</doapFile>
<lang>en</lang>
+ <validate>true</validate>
<doapOptions>
<programmingLanguage>java</programmingLanguage>