You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ij...@apache.org on 2013/10/28 15:26:27 UTC
svn commit: r1536365 [6/6] - in /jena/trunk/jena-maven-tools: ./ demo/
demo/src/ demo/src/main/ demo/src/main/vocabs/ src/ src/it/
src/it/schemagen-integration-0/ src/it/schemagen-integration-0/src/
src/it/schemagen-integration-0/src/main/ src/it/schem...
Added: jena/trunk/jena-maven-tools/src/main/java/org/openjena/tools/schemagen/SchemagenMojo.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/main/java/org/openjena/tools/schemagen/SchemagenMojo.java?rev=1536365&view=auto
==============================================================================
--- jena/trunk/jena-maven-tools/src/main/java/org/openjena/tools/schemagen/SchemagenMojo.java (added)
+++ jena/trunk/jena-maven-tools/src/main/java/org/openjena/tools/schemagen/SchemagenMojo.java Mon Oct 28 14:26:25 2013
@@ -0,0 +1,348 @@
+/*****************************************************************************
+ * File: SchemagenMojo.java
+ * Project: schemagen
+ * Created: 22 Mar 2010
+ * By: ian
+ *
+ * Copyright (c) 2010-11 Epimorphics Ltd. See LICENSE file for license terms.
+ *****************************************************************************/
+
+// Package
+///////////////
+
+package org.openjena.tools.schemagen;
+
+
+// Imports
+///////////////
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import jena.schemagen;
+import jena.schemagen.SchemagenOptions.OPT;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.DirectoryScanner;
+
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.ResourceFactory;
+
+
+/**
+ * <p>Maven plugin to execute Jena schemagen as part of a Jena-based
+ * project build cycle
+ * </p>
+ *
+ * @author Ian Dickinson, Epimorphics (mailto:ian@epimorphics.com)
+ *
+ * Maven Mojo options
+ * @goal translate
+ * @phase generate-sources
+*/
+public class SchemagenMojo
+ extends AbstractMojo
+{
+ /***********************************/
+ /* Constants */
+ /***********************************/
+
+ /** Default output location */
+ public static final String GENERATED_SOURCES = File.separator + "generated-sources";
+
+ /** Default pattern for includes */
+
+ /** Name of default options element */
+ public static final String DEFAULT_OPTIONS_ELEM = "default";
+
+ /***********************************/
+ /* Static variables */
+ /***********************************/
+
+ /**
+ * Target directory
+ * @parameter property="project.build.directory"
+ */
+ private static String projectBuildDir;
+
+ /** Return the value of <code>${project.build.directory}</code> */
+ public static String getProjectBuildDir() {
+ return projectBuildDir;
+ }
+
+ /***********************************/
+ /* Instance variables */
+ /***********************************/
+
+ /**
+ * Array of file patterns to include in processing
+ * @parameter alias="includes"
+ */
+ private String[] includes = new String[0];
+
+ /**
+ * Array of file patterns to exclude from processing
+ * @parameter alias="excludes"
+ */
+ private String[] excludes = new String[0];
+
+ /**
+ * Options for individual files
+ * @parameter alias="fileOptions"
+ */
+ private List<Source> fileOptions;
+
+ /**
+ * The current base directory of the project
+ * @parameter property="basedir"
+ */
+ private File baseDir;
+
+ /** The default options object, if any */
+ private SchemagenOptions defaultOptions;
+
+ /** Map of source options, indexed by name */
+ private Map<String, SchemagenOptions> optIndex = new HashMap<String, SchemagenOptions>();
+
+ /***********************************/
+ /* Constructors */
+ /***********************************/
+
+ /***********************************/
+ /* External signature methods */
+ /***********************************/
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ // set the default defaults
+ defaultOptions = new SchemagenOptions.DefaultSchemagenOptions();
+
+ getLog().info( "Starting schemagen execute() ...");
+
+ // next process the various options specs
+ if( fileOptions != null ){
+ for (Source p: fileOptions) {
+ if (p.isDefaultOptions()) {
+ handleDefaultOptions( p );
+ }
+ else {
+ handleOption( p );
+ }
+ }
+ }
+
+ if( defaultOptions == null ){
+ handleDefaultOptions( new Source() );
+ }
+
+ // then the files themselves
+ for (String fileName: matchFileNames()) {
+ processFile( fileName );
+ }
+ }
+
+ /**
+ * Return a list of the file names to be processed by schemagen. These are
+ * determined by processing the Ant style paths given in the <code>includes</code>
+ * and <code>excludes</code> parameters.
+ *
+ * @return Non-null but possibly empty list of files to process, sorted into lexical order
+ */
+ protected List<String> matchFileNames() {
+ DirectoryScanner ds = new DirectoryScanner();
+ ds.setExcludes( excludes );
+ ds.setIncludes( includes );
+ ds.setBasedir( getBaseDir() );
+ ds.scan();
+
+ List<String> files = new ArrayList<String>( Arrays.asList( ds.getIncludedFiles() ) );
+ Collections.sort( files );
+
+ //add http includes
+ for( String include : includes ){
+ if( include.startsWith("http:") || include.startsWith("https:")){
+ files.add( include );
+ }
+ }
+ return files;
+ }
+
+
+ /**
+ * Return the default options structure, or null
+ * @return The default options
+ */
+ protected SchemagenOptions getDefaultOptions() {
+ return defaultOptions;
+ }
+
+ /**
+ * Handle the default options by creating a default options object and assigning
+ * the options values from the given source object.
+ * @param defOptionsSource The source object containing the default options
+ */
+ protected void handleDefaultOptions( Source defOptionsSource ) {
+ if (defaultOptions != null) {
+ defOptionsSource.setParent( defaultOptions );
+ }
+ defaultOptions = defOptionsSource;
+ }
+
+ /**
+ * Process the given options specification for one of the input files
+ * by attaching the default options and indexing.
+ *
+ * @param optionSpec Specification of the options for a given file
+ */
+ protected void handleOption( Source optionSpec ) {
+ if (optionSpec.getFileName() != null) {
+ optionSpec.setParent( getDefaultOptions() );
+ optIndex.put( optionSpec.getFileName(), optionSpec );
+ }
+ else {
+ getLog().info( "ignoring <source> element because the fileName is not specified" );
+ }
+ }
+
+ /**
+ * Delegate the processing of the given file to schemagen itself
+ * @param fileName
+ */
+ protected void processFile( String fileName )
+ throws MojoExecutionException
+ {
+ //fix windows paths
+ if( File.separator.equals("\\") ){
+ fileName = fileName.replaceAll( "\\\\", "/" );
+ }
+
+ getLog().info( "processFile with " + fileName );
+ getLog().info( optIndex.keySet().toString() );
+ SchemagenOptions so = optIndex.get( fileName );
+ getLog().info( "so = " + so );
+
+ // if we have no options carrier for this file, we create one to contain
+ // the name of the input file, and link it to the defaults
+ String soFileName;
+ if (so == null) {
+ so = new Source();
+ soFileName = fileName;
+ so.setParent( getDefaultOptions() );
+ } else {
+ soFileName = so.getOption( OPT.INPUT ).asLiteral().getString();
+ }
+
+ getLog().info( "input before adjustment: " + soFileName );
+
+ boolean relative = !(soFileName.startsWith( "http:" ) || soFileName.startsWith( "https:" )
+ || soFileName.startsWith( "file:" ));
+ getLog().info( "relative = " + relative );
+ getLog().info( "baseDir = " + baseDir );
+ getLog().info( "getBaseDir() = " + getBaseDir() );
+ soFileName = relative ? "file:" + baseDir + File.separator + soFileName : soFileName;
+ getLog().info( "input after adjustment: " + soFileName );
+ Resource input = ResourceFactory.createResource( soFileName );
+ so.setOption( OPT.INPUT, input );
+
+ getLog().info( "about to call run(): " );
+ ensureTargetDirectory( so );
+ new SchemagenAdapter().run( so );
+ }
+
+
+ /***********************************/
+ /* Internal implementation methods */
+ /***********************************/
+
+ public void setExcludes( String[] excludes ) {
+ this.excludes = excludes;
+ }
+
+ public void setIncludes( String[] includes ) {
+ this.includes = includes;
+ }
+
+ /**
+ * Append the given string to the array of included file patterns
+ * @param incl File pattern string to append to <code>this.includes</code>
+ */
+ public void addIncludes( String incl ) {
+ String[] incls = new String[this.includes.length + 1];
+ int i = 0;
+ for (String s: this.includes) {
+ incls[i++] = s;
+ }
+ incls[i] = incl;
+
+ this.includes = incls;
+ }
+
+ /**
+ * Append the given string to the array of excluded file patterns
+ * @param excl File pattern string to append to <code>this.excludes</code>
+ */
+ public void addExcludes( String excl ) {
+ String[] excls = new String[this.excludes.length + 1];
+ int i = 0;
+ for (String s: this.excludes) {
+ excls[i++] = s;
+ }
+ excls[i] = excl;
+ this.excludes = excls;
+ }
+
+ /**
+ * Return the base directory for the plugin, which should be supplied
+ * by plexus, but if not we default to the current working directory.
+ *
+ * @return The base directory as a file
+ */
+ protected File getBaseDir() {
+ return (baseDir == null) ? new File(".").getAbsoluteFile() : baseDir;
+ }
+
+ /**
+ * Ensure that the output directory exists
+ */
+ protected void ensureTargetDirectory( SchemagenOptions so )
+ throws MojoExecutionException
+ {
+ File gs = new File( so.getOutputOption() );
+
+ if (!gs.exists()) {
+ gs.mkdirs();
+ }
+ else if (!gs.isDirectory()) {
+ getLog().error( "The output location is not a directory: " + gs.getPath() );
+ throw new MojoExecutionException( "Already exists as file: " + gs.getPath() );
+ }
+ else if (!gs.canWrite()) {
+ getLog().error( "Output directory exists but is not writable: " + gs.getPath() );
+ throw new MojoExecutionException( "Not writable: " + gs.getPath() );
+ }
+ }
+
+
+ /***********************************/
+ /* Inner classes */
+ /***********************************/
+
+ /**
+ * Adapter class to invoke the schemagen tool with a given set of options
+ */
+ protected class SchemagenAdapter
+ extends schemagen
+ {
+ public void run( SchemagenOptions options ) {
+ go( options );
+ }
+ }
+}
+
Added: jena/trunk/jena-maven-tools/src/main/java/org/openjena/tools/schemagen/SchemagenOptions.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/main/java/org/openjena/tools/schemagen/SchemagenOptions.java?rev=1536365&view=auto
==============================================================================
--- jena/trunk/jena-maven-tools/src/main/java/org/openjena/tools/schemagen/SchemagenOptions.java (added)
+++ jena/trunk/jena-maven-tools/src/main/java/org/openjena/tools/schemagen/SchemagenOptions.java Mon Oct 28 14:26:25 2013
@@ -0,0 +1,257 @@
+/*****************************************************************************
+ * File: SchemagenOptions.java
+ * Project: schemagen
+ * Created: 2 Apr 2010
+ * By: ian
+ *
+ * Copyright (c) 2010-11 Epimorphics Ltd. See LICENSE file for license terms.
+ *****************************************************************************/
+
+// Package
+///////////////
+
+package org.openjena.tools.schemagen;
+
+
+// Imports
+///////////////
+
+import java.util.*;
+
+import jena.schemagen;
+import jena.schemagen.OptionDefinition;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.rdf.model.*;
+
+
+/**
+ * <p>An extension to the option class built in to {@link schemagen}, in which we
+ * allow a two-level defaults hierarchy. Each option is tested against the local
+ * object. If the result is <code>true</code> or non-null, or if the object has
+ * no parent options object, then the result stands. Otherwise, the option value
+ * is delegated to the parent. This allows us to specify global defaults for an
+ * entire group of files to be processed with maven, while still allowing each
+ * file to have its own local options.
+ * </p>
+ *
+ * @author Ian Dickinson, Epimorphics (mailto:ian@epimorphics.com)
+*/
+public class SchemagenOptions
+ extends schemagen.SchemagenOptionsImpl
+{
+ /***********************************/
+ /* Constants */
+ /***********************************/
+
+ /***********************************/
+ /* Static variables */
+ /***********************************/
+
+ @SuppressWarnings( value = "unused" )
+ private static final Logger log = LoggerFactory.getLogger( SchemagenOptions.class );
+
+ /***********************************/
+ /* Instance variables */
+ /***********************************/
+
+ /** The parent options for this options instance */
+ private SchemagenOptions parent;
+
+ /***********************************/
+ /* Constructors */
+ /***********************************/
+
+ public SchemagenOptions() {
+ super( new String[]{} );
+ }
+
+ /***********************************/
+ /* External signature methods */
+ /***********************************/
+
+ /**
+ * Set the parent options object for this object
+ * @param parent Parent options object, or null
+ */
+ protected void setParent( SchemagenOptions parent ) {
+ this.parent = parent;
+ }
+
+ /**
+ * Return the parent options object, or null
+ * @return The parent options object if defined
+ */
+ public SchemagenOptions getParent() {
+ return parent;
+ }
+
+ /**
+ * Return true if this options object has a parent
+ * @return True if parent is defined
+ */
+ public boolean hasParent() {
+ return getParent() != null;
+ }
+
+ /**
+ * Get the value of the given option, as a string. If the option is not defined
+ * locally, return the value of the same option of the parent, if the parent
+ * is non-null. Otherwise, return <code>null</code>
+ * @param option The name of the option to retrieve
+ * @return The value of the option as a string, or null if the option is not defined. If
+ * the parent is non-null and the option is not defined, delegate the <code>getOption</code>
+ * to the parent.
+ * @return The string value of the option, or null
+ */
+ public String getStringOption( OPT option ) {
+ String v = getStringValue( option );
+ return (v != null) ? v : (parent != null ? parent.getStringOption( option ) : null);
+ }
+
+ /**
+ * Get the value of the given option, as an RDF node. If the option is not defined
+ * locally, return the value of the same option of the parent, if the parent
+ * is non-null. Otherwise, return <code>null</code>
+ * @param option The name of the option to retrieve
+ * @return The value of the option as an RDFNode, or null if the option is not defined. If
+ * the parent is non-null and the option is not defined, delegate the <code>getOption</code>
+ * to the parent.
+ * @return The RDFnode value of the option, or null
+ */
+ public RDFNode getOption( OPT option ) {
+ RDFNode v = getValue( option );
+ return (v != null) ? v : (parent != null ? parent.getOption( option ) : null);
+ }
+
+ /**
+ * Set the value of the given option in the local options list
+ * @param optionName The option to set, as a string value
+ * @param value
+ */
+ public void setOption( String optionName, String value ) {
+ setOption( asOption( optionName ), value );
+ }
+
+ /**
+ * Set the value of the given option in the local options list
+ * @param option The option to set
+ * @param value The string value of the option
+ */
+ public void setOption( OPT option, String value ) {
+ OptionDefinition od = getOpt( option );
+ getConfigRoot().addProperty( od.getDeclarationProperty(), value );
+ }
+
+ /**
+ * Set the value of the given option in the local options list
+ * @param option The option to set
+ * @param value The Boolean value of the option
+ */
+ public void setOption( OPT option, boolean value ) {
+ OptionDefinition od = getOpt( option );
+ getConfigRoot().addProperty( od.getDeclarationProperty(), ResourceFactory.createTypedLiteral( value ) );
+ }
+
+ /**
+ * Set the value of the given option in the local options list
+ * @param option The option to set
+ * @param value The Resource value of the option
+ */
+ public void setOption( OPT option, Resource value ) {
+ OptionDefinition od = getOpt( option );
+ getConfigRoot().addProperty( od.getDeclarationProperty(), value );
+ }
+
+ /***********************************/
+ /* Internal implementation methods */
+ /***********************************/
+
+ protected OPT asOption( String optString ) {
+ return OPT.valueOf( optString );
+ }
+
+ /**
+ * Return true if the given option is set to true, either locally or
+ * in the parent options object.
+ */
+ @Override
+ protected boolean isTrue( OPT option ) {
+ return super.isTrue( option ) || (hasParent() && getParent().isTrue( option ));
+ }
+
+ /**
+ * Return true if the given option has a value, either locally or
+ * in the parent options object.
+ */
+ @Override
+ protected boolean hasValue( OPT option ) {
+ return super.hasValue( option ) || (hasParent() && getParent().hasValue( option ));
+ }
+
+ /**
+ * Return the value of the option or null, , either locally or
+ * from the parent options object.
+ */
+ @Override
+ protected RDFNode getValue( OPT option ) {
+ RDFNode v = super.getValue( option );
+ return (v == null && hasParent()) ? getParent().getValue( option ) : v;
+ }
+
+ /**
+ * Return the value of the option or null, , either locally or
+ * from the parent options object.
+ */
+ @Override
+ protected String getStringValue( OPT option ) {
+ String v = super.getStringValue( option );
+ return (v == null && hasParent()) ? getParent().getStringValue( option ) : v;
+ }
+
+ /**
+ * Return true if the given option has a resource value, either locally or
+ * in the parent options object.
+ */
+ @Override
+ protected boolean hasResourceValue( OPT option ) {
+ return super.hasResourceValue( option ) || (hasParent() && getParent().hasResourceValue( option ));
+ }
+
+ /**
+ * Return the value of the option or null, , either locally or
+ * from the parent options object.
+ */
+ @Override
+ protected Resource getResource( OPT option ) {
+ Resource r = super.getResource( option );
+ return (r == null && hasParent()) ? getParent().getResource( option ) : r;
+ }
+
+ /**
+ * Return all values for the given options as Strings, either locally or
+ * from the parent options object.
+ */
+ @Override
+ protected List<String> getAllValues( OPT option ) {
+ List<String> l = super.getAllValues( option );
+ return (l.isEmpty() && hasParent()) ? getParent().getAllValues( option ) : l;
+ }
+
+ /***********************************/
+ /* Inner class definitions */
+ /***********************************/
+
+ /**
+ * Default options for schemagen if no other options are specified
+ */
+ public static class DefaultSchemagenOptions
+ extends SchemagenOptions
+ {
+ public DefaultSchemagenOptions() {
+ setOption( OPT.OUTPUT, SchemagenMojo.getProjectBuildDir() + SchemagenMojo.GENERATED_SOURCES );
+ }
+ }
+}
\ No newline at end of file
Added: jena/trunk/jena-maven-tools/src/main/java/org/openjena/tools/schemagen/Source.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/main/java/org/openjena/tools/schemagen/Source.java?rev=1536365&view=auto
==============================================================================
--- jena/trunk/jena-maven-tools/src/main/java/org/openjena/tools/schemagen/Source.java (added)
+++ jena/trunk/jena-maven-tools/src/main/java/org/openjena/tools/schemagen/Source.java Mon Oct 28 14:26:25 2013
@@ -0,0 +1,265 @@
+/*****************************************************************************
+ * File: Source.java
+ * Project: schemagen
+ * Created: 24 Mar 2010
+ * By: ian
+ *
+ * Copyright (c) 2010-11 Epimorphics Ltd. See LICENSE file for license terms.
+ *****************************************************************************/
+
+// Package
+///////////////
+
+package org.openjena.tools.schemagen;
+
+
+
+// Imports
+///////////////
+
+
+/**
+ * <p>Simple container object to hold the per-source configuration
+ * values from the <code>pom.xml</code>.</p>
+ *
+ * @author Ian Dickinson, Epimorphics (mailto:ian@epimorphics.com)
+ */
+public class Source
+ extends SchemagenOptions
+{
+ /***********************************/
+ /* Constants */
+ /***********************************/
+
+ /***********************************/
+ /* Static variables */
+ /***********************************/
+
+
+ /***********************************/
+ /* Instance variables */
+ /***********************************/
+
+ /***********************************/
+ /* Constructors */
+ /***********************************/
+
+ /***********************************/
+ /* External signature methods */
+ /***********************************/
+
+ public String getFileName() {
+ return getStringOption( OPT.INPUT );
+ }
+
+ /** @parameter expr="config-file" */
+ public void setConfigFile( String arg ) {
+ setOption( OPT.CONFIG_FILE, arg );
+ }
+
+ /** @parameter expr="no-comments" */
+ public void setNoComments( String arg ) {
+ setOption( OPT.NO_COMMENTS, trueArg( arg ) );
+ }
+
+ /** @parameter expr="input" */
+ public void setInput( String arg ) {
+ setOption( OPT.INPUT, arg );
+ }
+
+ /** @parameter expr="lang-daml" */
+ public void setLangDaml( String arg ) {
+ setOption( OPT.LANG_DAML, trueArg( arg ) );
+ }
+
+ /** @parameter expr="lang-owl" */
+ public void setLangOwl( String arg ) {
+ setOption( OPT.LANG_OWL, trueArg( arg ) );
+ }
+
+ /** @parameter expr="lang-rdfs" */
+ public void setLangRdfs( String arg ) {
+ setOption( OPT.LANG_RDFS, trueArg( arg ) );
+ }
+
+ /** @parameter expr="output" */
+ public void setOutput( String arg ) {
+ setOption( OPT.OUTPUT, arg );
+ }
+
+ /** @parameter expr="header" */
+ public void setHeader( String arg ) {
+ setOption( OPT.HEADER, arg );
+ }
+
+ /** @parameter expr="footer" */
+ public void setFooter( String arg ) {
+ setOption( OPT.FOOTER, arg );
+ }
+
+ /** @parameter expr="root" */
+ public void setRoot( String arg ) {
+ setOption( OPT.ROOT, arg );
+ }
+
+ /** @parameter expr="marker" */
+ public void setMarker( String arg ) {
+ setOption( OPT.MARKER, arg );
+ }
+
+ /** @parameter expr="package-name" */
+ public void setPackageName( String arg ) {
+ setOption( OPT.PACKAGENAME, arg );
+ }
+
+ /** @parameter expr="ontology" */
+ public void setOntology( String arg ) {
+ setOption( OPT.ONTOLOGY, trueArg( arg ) );
+ }
+
+ /** @parameter expr="classname" */
+ public void setClassName( String arg ) {
+ setOption( OPT.CLASSNAME, arg );
+ }
+
+ /** @parameter expr="classdec" */
+ public void setClassDec( String arg ) {
+ setOption( OPT.CLASSDEC, arg );
+ }
+
+ /** @parameter expr="namespace" */
+ public void setNamespace( String arg ) {
+ setOption( OPT.NAMESPACE, arg );
+ }
+
+ /** @parameter expr="declarations" */
+ public void setDeclarations( String arg ) {
+ setOption( OPT.DECLARATIONS, arg );
+ }
+
+ /** @parameter expr="property-section" */
+ public void setPropertySection( String arg ) {
+ setOption( OPT.PROPERTY_SECTION, arg );
+ }
+
+ /** @parameter expr="class-section" */
+ public void setClassSection( String arg ) {
+ setOption( OPT.CLASS_SECTION, arg );
+ }
+
+ /** @parameter expr="individuals-section" */
+ public void setIndividualsSection( String arg ) {
+ setOption( OPT.INDIVIDUALS_SECTION, arg );
+ }
+
+ /** @parameter expr="noproperties" */
+ public void setNoProperties( String arg ) {
+ setOption( OPT.NOPROPERTIES, trueArg( arg ) );
+ }
+
+ /** @parameter expr="noclasses" */
+ public void setNoClasses( String arg ) {
+ setOption( OPT.NOCLASSES, trueArg( arg ) );
+ }
+
+ /** @parameter expr="noindividuals" */
+ public void setNoIndividuals( String arg ) {
+ setOption( OPT.NOINDIVIDUALS, trueArg( arg ) );
+ }
+
+ /** @parameter expr="noheader" */
+ public void setNoHeader( String arg ) {
+ setOption( OPT.NOHEADER, trueArg( arg ) );
+ }
+
+ /** @parameter expr="prop-template" */
+ public void setPropTemplate( String arg ) {
+ setOption( OPT.PROP_TEMPLATE, arg );
+ }
+
+ /** @parameter expr="classttemplate" */
+ public void setClassTemplate( String arg ) {
+ setOption( OPT.CLASS_TEMPLATE, arg );
+ }
+
+ /** @parameter expr="individualttemplate" */
+ public void setIndividualTemplate( String arg ) {
+ setOption( OPT.INDIVIDUAL_TEMPLATE, arg );
+ }
+
+ /** @parameter expr="uc-names" */
+ public void setUcNames( String arg ) {
+ setOption( OPT.UC_NAMES, trueArg( arg ) );
+ }
+
+ /** @parameter expr="include" */
+ public void setInclude( String arg ) {
+ setOption( OPT.INCLUDE, arg );
+ }
+
+ /** @parameter expr="classname-suffix" */
+ public void setClassNameSuffix( String arg ) {
+ setOption( OPT.CLASSNAME_SUFFIX, arg );
+ }
+
+ /** @parameter expr="encoding" */
+ public void setEncoding( String arg ) {
+ setOption( OPT.ENCODING, arg );
+ }
+
+ /** @parameter expr="help" */
+ public void setHelp( String arg ) {
+ setOption( OPT.HELP, trueArg( arg ) );
+ }
+
+ /** @parameter expr="dos" */
+ public void setDos( String arg ) {
+ setOption( OPT.DOS, trueArg( arg ) );
+ }
+
+ /** @parameter expr="use-inf" */
+ public void setUseInf( String arg ) {
+ setOption( OPT.USE_INF, trueArg( arg ) );
+ }
+
+ /** @parameter expr="strict-individuals" */
+ public void setStrictIndividuals( String arg ) {
+ setOption( OPT.STRICT_INDIVIDUALS, trueArg( arg ) );
+ }
+
+ /** @parameter expr="include-source" */
+ public void setIncludeSource( String arg ) {
+ setOption( OPT.INCLUDE_SOURCE, trueArg( arg ) );
+ }
+
+ /** @parameter expr="no-strict" */
+ public void setNoStrict( String arg ) {
+ setOption( OPT.NO_STRICT, trueArg( arg ) );
+ }
+
+
+ /**
+ * Return true if this source actually represents the default options
+ * element
+ *
+ * @return True for the default options
+ */
+ public boolean isDefaultOptions() {
+ return getFileName().equals( SchemagenMojo.DEFAULT_OPTIONS_ELEM );
+ }
+
+
+ /***********************************/
+ /* Internal implementation methods */
+ /***********************************/
+
+ private boolean trueArg( String arg ) {
+ return !"false".equals( arg );
+ }
+
+ /***********************************/
+ /* Inner class definitions */
+ /***********************************/
+
+}
+
Added: jena/trunk/jena-maven-tools/src/site/apt/configuration.apt
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/site/apt/configuration.apt?rev=1536365&view=auto
==============================================================================
--- jena/trunk/jena-maven-tools/src/site/apt/configuration.apt (added)
+++ jena/trunk/jena-maven-tools/src/site/apt/configuration.apt Mon Oct 28 14:26:25 2013
@@ -0,0 +1,81 @@
+Schemagen Maven plugin - configuration options
+
+ The following options can be set in the <<<pom.xml>>> to configure the
+ behaviour of the schemagen plugin.
+
+*----------*--------------+----------------+
+ XML config element | <<<jena.schemagen.SchemagenOptions.OPT>>> value | description
+*---*---+---+
+classdec | <<<j.s.S.OPT.CLASSDEC>>> | Additional decoration for class header (such as implements)
+*---*---+---+
+classname | <<<j.s.S.OPT.CLASSNAME>>> | The name of the generated class
+*---*---+---+
+classname-suffix | <<<j.s.S.OPT.CLASSNAME_SUFFIX>>> | Option for adding a suffix to the generated class name, e.g. <<<Vocab>>>
+*---*---+---+
+class-section | <<<j.s.S.OPT.CLASS_SECTION>>> | Text of section declaration for classes section
+*---*---+---+
+classttemplate | <<<j.s.S.OPT.CLASS_TEMPLATE>>> | Template for writing out class declarations
+*----------*--------------+----------------+
+config-file | <<<j.s.S.OPT.CONFIG_FILE>>> | Select an alternative config file
+*---*---+---+
+declarations | <<<j.s.S.OPT.DECLARATIONS>>> | Additional declarations to add at the top of the class
+*---*---+---+
+dos | <<<j.s.S.OPT.DOS>>> | Option to generate an output file with DOS (\r\n) line endings. Default is Unix line endings.
+*---*---+---+
+encoding | <<<j.s.S.OPT.ENCODING>>> | Option for the encoding syntax (RDF/XML, Turtle, etc) of the input file
+*---*---+---+
+footer | <<<j.s.S.OPT.FOOTER>>> | Text to use for the file footer
+*---*---+---+
+header | <<<j.s.S.OPT.HEADER>>> | Text to use for the file header
+*---*---+---+
+include | <<<j.s.S.OPT.INCLUDE>>> | Other namespace URI's to include in the generated Java constants
+*---*---+---+
+include-source | <<<j.s.S.OPT.INCLUDE_SOURCE>>> | Option to include the ontology source code in the generated file
+*---*---+---+
+individuals-section | <<<j.s.S.OPT.INDIVIDUALS_SECTION>>> | Text of section declaration for individuals section
+*---*---+---+
+individualttemplate | <<<j.s.S.OPT.INDIVIDUAL_TEMPLATE>>> | Template for writing out individual declarations
+*---*---+---+
+input | <<<j.s.S.OPT.INPUT>>> | Specify the URL of the input document
+*---*---+---+
+lang-daml | <<<j.s.S.OPT.LANG_DAML>>> |Specify that the language of the source is DAML+OIL
+*---*---+---+
+lang-owl | <<<j.s.S.OPT.LANG_OWL>>> |Specify that the language of the source is OWL (the default)
+*---*---+---+
+lang-rdfs | <<<j.s.S.OPT.LANG_RDFS>>> | Specify that the language of the source is RDFS
+*---*---+---+
+marker | <<<j.s.S.OPT.MARKER>>> | Specify the marker string for substitutions
+*---*---+---+
+namespace | <<<j.s.S.OPT.NAMESPACE>>> | The namespace URI for the vocabulary
+*---*---+---+
+no-comments | <<<j.s.S.OPT.NO_COMMENTS>>> | Turn off all comment output
+*---*---+---+
+noclasses | <<<j.s.S.OPT.NOCLASSES>>> | If true, don't include classes in the Java class
+*---*---+---+
+noheader | <<<j.s.S.OPT.NOHEADER>>> | If true, suppress the file header comment
+*---*---+---+
+noindividuals | <<<j.s.S.OPT.NOINDIVIDUALS>>> | If true, don't include individuals in the Java class
+*---*---+---+
+noproperties | <<<j.s.S.OPT.NOPROPERTIES>>> | If true, don't include properties in the Java class
+*---*---+---+
+no-strict | <<<j.s.S.OPT.NO_STRICT>>> | Option to turn off strict checking in .as()
+*---*---+---+
+ontology | <<<j.s.S.OPT.ONTOLOGY>>> | Use ontology terms in preference to vanilla RDF
+*---*---+---+
+output | <<<j.s.S.OPT.OUTPUT>>> | The name of the file that will be generated; overrides the default name taken from the class
+*---*---+---+
+package-name | <<<j.s.S.OPT.PACKAGENAME>>> | Specify the Java package name that classes will be created in
+*---*---+---+
+property-section | <<<j.s.S.OPT.PROPERTY_SECTION>>> | Text of section declaration for properties section
+*---*---+---+
+prop-template | <<<j.s.S.OPT.PROP_TEMPLATE>>> | Template for writing out property declarations
+*---*---+---+
+root | <<<j.s.S.OPT.ROOT>>> | Specify the uri of the configuration root node (not used in Maven plugin)
+*---*---+---+
+strict-individuals | <<<j.s.S.OPT.STRICT_INDIVIDUALS>>> | Option to exclude instances of classes in the allowed namespaces, where the individuals themselves are in other namespaces
+*---*---+---+
+uc-names | <<<j.s.S.OPT.UC_NAMES>>> | Option for mapping constant names to uppercase
+*---*---+---+
+use-inf | <<<j.s.S.OPT.USE_INF>>> | Option to generate to force the model to perform inference, off by default.
+*---*---+---+
+
Added: jena/trunk/jena-maven-tools/src/site/apt/index.apt.vm
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/site/apt/index.apt.vm?rev=1536365&view=auto
==============================================================================
--- jena/trunk/jena-maven-tools/src/site/apt/index.apt.vm (added)
+++ jena/trunk/jena-maven-tools/src/site/apt/index.apt.vm Mon Oct 28 14:26:25 2013
@@ -0,0 +1,118 @@
+Schemagen plugin for Maven
+
+ Ian Dickinson, i.j.dickinson@gmail.com\
+ 2010-03-28
+
+ This plugin allows Java source files containing the concepts from
+an ontology as Java constants to be generated directly from the
+RDF source file. The Jena
+{{{http://jena.sourceforge.net/how-to/schemagen.html}schemagen}} tool
+exists to do this job;
+this project is simply a wrapper to allow Jena's schemagen to be
+run as a Maven plugin.
+
+* Basic principles
+
+ The plugin is controlled through parameters in the <<<configuration>>> section
+ of the project <<<pom.xml>>>. The files to include are specified by an
+ <<<includes>>> element, which defaults to <<<src/main/vocabs/*>>>. Files may
+ be excluded from processing by a pattern specified in an <<<excludes>>> element.
+
+ Schemagen has a large number of options for each vocabulary generated. These options
+ allow users to control what gets generated in the Java file, where the output is
+ sent to, and how the Java file is formatted. All of schemagen's options are available
+ through the plugin.
+
+ While schemagen itself is optimised for processing one vocabulary file into one
+ Java source file, the Maven schemagen plugin is typically used to process a number
+ of files. By default, this will be all files in the path <<<src/main/vocab>>>. In
+ this scenario, where the plugin is processing more than one file during one generation
+ phase, it would be tedious and non-scalable to specify individual schemagen options
+ for each file that matches the <<<includes>>> pattern. Consequently, the plugin allows
+ default configuration settings to be set once, and subsequently overridden, where
+ necessary, by per-file options.
+
+ Within the <<<configuration>>> XML element of the <<<pom.xml>>>, a list of input
+ source options is given by the nested element <<<fileOptions>>>. Each child element of the
+ <<<fileOptions>>> list is a <<<source>>> element, corresponding to a single source
+ input file. However, the reserved file name <<<default>>> corresponds to default
+ schemagen options that are applied to all of the vocabulary files specified by the
+ combination of <<<includes>>> and <<<excludes>>> parameter values.
+
+* Example configurations
+
+ The following complete <<<pom.xml>>> configuration will process all <<<*.ttl>>> files
+ in <<<src/main/vocabs>>>, and put them all of the generated output
+ into the Java package <<<org.example.test>>>:
+
+--------------------------------
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.openjena.tools</groupId>
+ <artifactId>schemagen-example</artifactId>
+ <packaging>jar</packaging>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>schemagen-example</name>
+ <url>http://maven.apache.org</url>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.openjena.tools</groupId>
+ <artifactId>schemagen</artifactId>
+ <version>${version}</version>
+ <configuration>
+ <includes>
+ <include>src/main/vocabs/*.ttl</include>
+ </includes>
+ <fileOptions>
+ <source>
+ <input>default</input>
+ <package-name>org.example.test</package-name>
+ </source>
+ </fileOptions>
+ </configuration>
+ <executions>
+ <execution>
+ <id>schemagen</id>
+ <goals>
+ <goal>translate</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.openjena.tools</groupId>
+ <artifactId>schemagen</artifactId>
+ <version>${version}</version>
+ <type>maven-plugin</type>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+ </project>
+--------------------------------
+
+ The following partial configuration shows how to pass additional schemagen configuration options,
+ and how to specify an option for one file that does not apply to the default selection:
+
+--------------------------------
+ <configuration>
+ <includes>
+ <include>src/main/vocabs/*.ttl</include>
+ </includes>
+ <fileOptions>
+ <source>
+ <input>default</input>
+ <package-name>org.example.test</package-name>
+ </source>
+ <source>
+ <!-- Test2.java (only) will contain OntModel declarations -->
+ <input>src/main/vocabs/test2.ttl</input>
+ <ontology>true</ontology>
+ </source>
+ </fileOptions>
+ </configuration>
+--------------------------------
Added: jena/trunk/jena-maven-tools/src/site/resources/images/jena-logo-small.png
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/site/resources/images/jena-logo-small.png?rev=1536365&view=auto
==============================================================================
Binary file - no diff available.
Propchange: jena/trunk/jena-maven-tools/src/site/resources/images/jena-logo-small.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: jena/trunk/jena-maven-tools/src/site/resources/images/schemagen-logo-small.png
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/site/resources/images/schemagen-logo-small.png?rev=1536365&view=auto
==============================================================================
Binary file - no diff available.
Propchange: jena/trunk/jena-maven-tools/src/site/resources/images/schemagen-logo-small.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: jena/trunk/jena-maven-tools/src/site/site.xml
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/site/site.xml?rev=1536365&view=auto
==============================================================================
--- jena/trunk/jena-maven-tools/src/site/site.xml (added)
+++ jena/trunk/jena-maven-tools/src/site/site.xml Mon Oct 28 14:26:25 2013
@@ -0,0 +1,15 @@
+<project name="Jena Schemagen Maven Plugin">
+ <bannerLeft>
+ <name>Jena</name>
+ <src>images/schemagen-logo-small.png</src>
+ <href>#</href>
+ </bannerLeft>
+ <body>
+ <menu name="Jena Schemagen Plugin">
+ <item name="Overview" href="index.html" />
+ <item name="Configuration" href="configuration.html" />
+ </menu>
+
+ <menu ref="reports" />
+ </body>
+</project>
\ No newline at end of file
Added: jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SchemagenMojoTest.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SchemagenMojoTest.java?rev=1536365&view=auto
==============================================================================
--- jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SchemagenMojoTest.java (added)
+++ jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SchemagenMojoTest.java Mon Oct 28 14:26:25 2013
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * File: SchemagenMojoTest.java
+ * Project: schemagen
+ * Created: 22 Mar 2010
+ * By: ian
+ *
+ * Copyright (c) 2010-11 Epimorphics Ltd. See LICENSE file for license terms.
+ *****************************************************************************/
+
+// Package
+///////////////
+
+package org.openjena.tools.schemagen;
+
+// Imports
+///////////////
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.List;
+
+import org.junit.Test;
+import org.openjena.tools.schemagen.SchemagenMojo;
+
+/**
+ * <p>Unit tests for {@link SchemagenMojo}</p>
+ *
+ * @author ian
+ */
+public class SchemagenMojoTest {
+
+ @Test
+ public void testMatchFileNames0() {
+ SchemagenMojo sm = new SchemagenMojo();
+
+ List<String> s = sm.matchFileNames();
+ assertNotNull(s);
+ assertTrue( s.isEmpty() );
+ }
+
+ @Test
+ public void testMatchFileNames1() {
+ SchemagenMojo sm = new SchemagenMojo();
+ String f = "src/test/resources/test1/test1.ttl";
+ sm.addIncludes( f );
+ List<String> s = sm.matchFileNames();
+ assertNotNull(s);
+ assertEquals( 1, s.size() );
+ assertEquals( new File(f), new File(s.get(0)) );
+ }
+
+ @Test
+ public void testMatchFileNames2() {
+ SchemagenMojo sm = new SchemagenMojo();
+ String f = "src/test/resources/test1/*.ttl";
+ sm.addIncludes( f );
+ List<String> s = sm.matchFileNames();
+ assertNotNull(s);
+ assertEquals( 2, s.size() );
+ assertTrue( s.get(0).endsWith( "test1.ttl" ));
+ assertTrue( s.get(1).endsWith( "test2.ttl" ));
+ }
+
+ @Test
+ public void testMatchFileNames3() {
+ SchemagenMojo sm = new SchemagenMojo();
+ String f = "src/test/resources/test1/*.ttl";
+ sm.addIncludes( f );
+ sm.addExcludes( "src/test/resources/test1/test1.ttl" );
+
+ List<String> s = sm.matchFileNames();
+ assertNotNull(s);
+ assertEquals( 1, s.size() );
+ assertTrue( s.get(0).endsWith( "test2.ttl" ));
+ }
+
+
+}
Added: jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SchemagenOptionsTest.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SchemagenOptionsTest.java?rev=1536365&view=auto
==============================================================================
--- jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SchemagenOptionsTest.java (added)
+++ jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SchemagenOptionsTest.java Mon Oct 28 14:26:25 2013
@@ -0,0 +1,371 @@
+/*****************************************************************************
+ * File: SchemagenOptionsTest.java
+ * Project: schemagen
+ * Created: 2 May 2010
+ * By: ian
+ *
+ * Copyright (c) 2010-11 Epimorphics Ltd. See LICENSE file for license terms.
+ *****************************************************************************/
+
+// Package
+///////////////
+
+package org.openjena.tools.schemagen;
+
+
+// Imports
+///////////////
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import jena.schemagen.SchemagenOptions.OPT;
+
+import org.junit.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.ResourceFactory;
+
+/**
+ * <p>Unit tests for {@link SchemagenOptions}</p>
+ *
+ * @author ian
+ */
+public class SchemagenOptionsTest
+{
+ /***********************************/
+ /* Constants */
+ /***********************************/
+
+ /***********************************/
+ /* Static variables */
+ /***********************************/
+
+ @SuppressWarnings( value = "unused" )
+ private static final Logger log = LoggerFactory.getLogger( SchemagenOptionsTest.class );
+
+ /***********************************/
+ /* Instance variables */
+ /***********************************/
+
+ /***********************************/
+ /* Constructors */
+ /***********************************/
+
+ /***********************************/
+ /* External signature methods */
+ /***********************************/
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ //
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.SchemagenOptions#getParent()}.
+ */
+ @Test
+ public void testGetParent() {
+ SchemagenOptions so = new SchemagenOptions();
+ assertNull( so.getParent() );
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.SchemagenOptions#setParent(org.openjena.tools.schemagen.SchemagenOptions)}.
+ */
+ @Test
+ public void testSetParent() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ assertSame( so1, so0.getParent() );
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.SchemagenOptions#hasParent()}.
+ */
+ @Test
+ public void testHasParent() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ assertTrue( so0.hasParent() );
+ assertFalse( so1.hasParent() );
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.SchemagenOptions#getOption(jena.schemagen.SchemagenOptions.OPT)}.
+ */
+ @Test
+ public void testGetOption0() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ assertNull( so0.getOption( OPT.CLASS_SECTION ));
+ }
+
+ @Test
+ public void testGetOption1() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ assertNull( so0.getOption( OPT.CLASS_SECTION ));
+ }
+
+ @Test
+ public void testGetOption2() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ so0.setOption( OPT.CLASS_SECTION, "test123" );
+ assertEquals( "test123", so0.getOption( OPT.CLASS_SECTION ).asLiteral().getString() );
+ }
+
+ @Test
+ public void testGetOption3() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ so0.setOption( OPT.CLASS_SECTION, "test123" );
+ assertEquals( "test123", so0.getOption( OPT.CLASS_SECTION ).asLiteral().getString() );
+ }
+
+ @Test
+ public void testGetOption4() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ so1.setOption( OPT.CLASS_SECTION, "test123" );
+ assertEquals( "test123", so0.getOption( OPT.CLASS_SECTION ).asLiteral().getString());
+ }
+
+ @Test
+ public void testGetOption5() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ so0.setOption( OPT.CLASS_SECTION, "test.child" );
+ so1.setOption( OPT.CLASS_SECTION, "test.parent" );
+ assertEquals( "test.child", so0.getOption( OPT.CLASS_SECTION ).asLiteral().getString());
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.SchemagenOptions#setOption(java.lang.String, java.lang.String)}.
+ */
+ @Test
+ public void testSetOptionStringString() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ so0.setOption( "CLASS_SECTION", "test123" );
+ assertEquals( "test123", so0.getOption( OPT.CLASS_SECTION ).asLiteral().getString() );
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.SchemagenOptions#asOption(java.lang.String)}.
+ */
+ @Test
+ public void testAsOption() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ assertSame( OPT.DOS, so0.asOption( "DOS" ));
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.SchemagenOptions#isTrue(jena.schemagen.SchemagenOptions.OPT)}.
+ */
+ @Test
+ public void testIsTrueOPT0() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ assertFalse( so0.isTrue( OPT.DOS ));
+ }
+
+ @Test
+ public void testIsTrueOPT1() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ so0.setOption( OPT.DOS, true );
+ assertTrue( so0.isTrue( OPT.DOS ));
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.SchemagenOptions#hasValue(jena.schemagen.SchemagenOptions.OPT)}.
+ */
+ @Test
+ public void testHasValueOPT0() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ assertFalse( so0.hasValue( OPT.CLASS_SECTION ));
+ }
+
+ @Test
+ public void testHasValueOPT1() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ so0.setOption( OPT.CLASS_SECTION, "foo" );
+ assertTrue( so0.hasValue( OPT.CLASS_SECTION ));
+ }
+
+ @Test
+ public void testHasValueOPT2() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ so1.setOption( OPT.CLASS_SECTION, "foo" );
+ assertTrue( so0.hasValue( OPT.CLASS_SECTION ));
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.SchemagenOptions#getValue(jena.schemagen.SchemagenOptions.OPT)}.
+ */
+ @Test
+ public void testGetValueOPT0() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ assertNull( so0.getValue( OPT.CLASS_SECTION ));
+ }
+
+ @Test
+ public void testGetValueOPT1() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ so0.setOption( OPT.CLASS_SECTION, "foo" );
+ assertEquals( "foo", so0.getValue( OPT.CLASS_SECTION ).asLiteral().getString() );
+ }
+
+ @Test
+ public void testGetValueOPT2() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ so1.setOption( OPT.CLASS_SECTION, "foo" );
+ assertEquals( "foo", so0.getValue( OPT.CLASS_SECTION ).asLiteral().getString() );
+ }
+
+ @Test
+ public void testGetValueOPT3() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ so1.setOption( OPT.CLASS_SECTION, "foo" );
+ so0.setOption( OPT.CLASS_SECTION, "bar" );
+ assertEquals( "bar", so0.getValue( OPT.CLASS_SECTION ).asLiteral().getString() );
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.SchemagenOptions#hasResourceValue(jena.schemagen.SchemagenOptions.OPT)}.
+ */
+ @Test
+ public void testHasResourceValueOPT0() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ assertFalse( so0.hasResourceValue( OPT.ROOT ));
+ }
+
+ @Test
+ public void testHasResourceValueOPT1() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ Resource r = ResourceFactory.createResource( "http://example.org/foo" );
+ so0.setOption( OPT.ROOT, r );
+ assertTrue( so0.hasResourceValue( OPT.ROOT ));
+ }
+
+ @Test
+ public void testHasResourceValueOPT2() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ Resource r = ResourceFactory.createResource( "http://example.org/foo" );
+ so1.setOption( OPT.ROOT, r );
+ assertTrue( so0.hasResourceValue( OPT.ROOT ));
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.SchemagenOptions#getResource(jena.schemagen.SchemagenOptions.OPT)}.
+ */
+ @Test
+ public void testGetResourceOPT0() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ assertNull( so0.getResource( OPT.ROOT ));
+ }
+
+ @Test
+ public void testGetResourceValueOPT1() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ Resource r = ResourceFactory.createResource( "http://example.org/foo" );
+ so0.setOption( OPT.ROOT, r );
+ assertEquals( r, so0.getResource( OPT.ROOT ));
+ }
+
+ @Test
+ public void testGetResourceValueOPT2() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ Resource r = ResourceFactory.createResource( "http://example.org/foo" );
+ so1.setOption( OPT.ROOT, r );
+ assertEquals( r, so0.getResource( OPT.ROOT ));
+ }
+
+ @Test
+ public void testGetResourceValueOPT3() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ Resource r0 = ResourceFactory.createResource( "http://example.org/foo" );
+ Resource r1 = ResourceFactory.createResource( "http://example.org/bar" );
+ so0.setOption( OPT.ROOT, r0 );
+ so1.setOption( OPT.ROOT, r1 );
+ assertEquals( r0, so0.getResource( OPT.ROOT ));
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.SchemagenOptions#getAllValues(jena.schemagen.SchemagenOptions.OPT)}.
+ */
+ @Test
+ public void testGetAllValuesOPT0() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ List<String> l = so0.getAllValues( OPT.INCLUDE );
+ assertNotNull( l );
+ assertTrue( l.isEmpty() );
+ }
+
+ @Test
+ public void testGetAllValuesOPT1() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ so0.setOption( OPT.INCLUDE, "foo" );
+ List<String> l = so0.getAllValues( OPT.INCLUDE );
+ assertNotNull( l );
+ assertEquals( 1, l.size() );
+ assertTrue( l.contains( "foo" ));
+ }
+
+ @Test
+ public void testGetAllValuesOPT2() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ so0.setOption( OPT.INCLUDE, "foo" );
+ so0.setOption( OPT.INCLUDE, "bar" );
+ List<String> l = so0.getAllValues( OPT.INCLUDE );
+ assertNotNull( l );
+ assertEquals( 2, l.size() );
+ assertTrue( l.contains( "foo" ));
+ assertTrue( l.contains( "bar" ));
+ }
+
+ @Test
+ public void testGetAllValuesOPT3() {
+ SchemagenOptions so0 = new SchemagenOptions();
+ SchemagenOptions so1 = new SchemagenOptions();
+ so0.setParent( so1 );
+ so1.setOption( OPT.INCLUDE, "foo" );
+ so1.setOption( OPT.INCLUDE, "bar" );
+ List<String> l = so0.getAllValues( OPT.INCLUDE );
+ assertNotNull( l );
+ assertEquals( 2, l.size() );
+ assertTrue( l.contains( "foo" ));
+ assertTrue( l.contains( "bar" ));
+ }
+
+ /***********************************/
+ /* Internal implementation methods */
+ /***********************************/
+
+ /***********************************/
+ /* Inner class definitions */
+ /***********************************/
+
+}
+
Added: jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SourceParameterTest.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SourceParameterTest.java?rev=1536365&view=auto
==============================================================================
--- jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SourceParameterTest.java (added)
+++ jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SourceParameterTest.java Mon Oct 28 14:26:25 2013
@@ -0,0 +1,349 @@
+/*****************************************************************************
+ * File: SourceTest.java
+ * Project: schemagen
+ * Created: 10 May 2010
+ * By: ian
+ *
+ * Copyright (c) 2010-11 Epimorphics Ltd. See LICENSE file for license terms.
+ *****************************************************************************/
+
+// Package
+///////////////
+
+package org.openjena.tools.schemagen;
+
+
+// Imports
+///////////////
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import jena.schemagen.SchemagenOptions.OPT;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <p>This test checks basic coverage of the options from schemagen: if more options are added,
+ * without updating the option setters, this test should give a compile warning in @{@link #setParamValue(Source)}</p>
+ *
+ * @author Ian Dickinson, Epimorphics (mailto:ian@epimorphics.com)
+ */
+@RunWith( Parameterized.class )
+public class SourceParameterTest
+{
+ /***********************************/
+ /* Constants */
+ /***********************************/
+
+ /** Test parameters are formed from the schemagen options
+ **/
+ @Parameters
+ public static Collection<Object[]> testParameters() {
+ Collection<Object[]> params = new ArrayList<Object[]>();
+
+ for (OPT opt: OPT.values()) {
+ Object[] par = new Object[2];
+ par[0] = opt;
+ par[1] = opt.name();
+
+ params.add( par );
+ }
+
+ return params;
+ }
+
+
+ /***********************************/
+ /* Static variables */
+ /***********************************/
+
+ @SuppressWarnings( value = "unused" )
+ private static final Logger log = LoggerFactory.getLogger( SourceParameterTest.class );
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ //
+ }
+
+ /***********************************/
+ /* Instance variables */
+ /***********************************/
+
+ private OPT option;
+ private String optionName;
+ private Object expected;
+
+ /***********************************/
+ /* Constructors */
+ /***********************************/
+
+ public SourceParameterTest( OPT paramVal, String paramName ) {
+ option = paramVal;
+ optionName = paramName;
+ }
+
+ /***********************************/
+ /* External signature methods */
+ /***********************************/
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.Source#getFileName()}.
+ */
+ @Test
+ public void testGetOption() {
+ Source s = new Source();
+ setParamValue( s );
+ assertEquals( optionName, expected, s.getOption( option ).asLiteral().getValue() );
+ }
+
+
+ /***********************************/
+ /* Internal implementation methods */
+ /***********************************/
+
+ protected void setParamValue( Source s ) {
+ switch (option) {
+ case INPUT:
+ s.setInput( optionName );
+
+ expected = optionName;
+ break;
+
+ case CLASS_SECTION:
+ s.setClassSection( optionName );
+
+ expected = optionName;
+ break;
+
+ case CLASSDEC:
+ s.setClassDec( optionName );
+
+ expected = optionName;
+ break;
+
+ case CLASSNAME:
+ s.setClassName( optionName );
+
+ expected = optionName;
+ break;
+
+ case CLASSNAME_SUFFIX:
+ s.setClassNameSuffix( optionName );
+
+ expected = optionName;
+ break;
+
+ case CLASS_TEMPLATE:
+ s.setClassTemplate( optionName );
+
+ expected = optionName;
+ break;
+
+ case CONFIG_FILE:
+ s.setConfigFile( optionName );
+
+ expected = optionName;
+ break;
+
+ case DECLARATIONS:
+ s.setDeclarations( optionName );
+
+ expected = optionName;
+ break;
+
+ case ENCODING:
+ s.setEncoding( optionName );
+
+ expected = optionName;
+ break;
+
+ case FOOTER:
+ s.setFooter( optionName );
+
+ expected = optionName;
+ break;
+
+ case HEADER:
+ s.setHeader( optionName );
+
+ expected = optionName;
+ break;
+
+ case INCLUDE:
+ s.setInclude( optionName );
+
+ expected = optionName;
+ break;
+
+ case INDIVIDUALS_SECTION:
+ s.setIndividualsSection( optionName );
+
+ expected = optionName;
+ break;
+
+ case INDIVIDUAL_TEMPLATE:
+ s.setIndividualTemplate( optionName );
+
+ expected = optionName;
+ break;
+
+ case MARKER:
+ s.setMarker( optionName );
+
+ expected = optionName;
+ break;
+
+ case NAMESPACE:
+ s.setNamespace( optionName );
+
+ expected = optionName;
+ break;
+
+ case OUTPUT:
+ s.setOutput( optionName );
+
+ expected = optionName;
+ break;
+
+ case PACKAGENAME:
+ s.setPackageName( optionName );
+
+ expected = optionName;
+ break;
+
+ case PROPERTY_SECTION:
+ s.setPropertySection( optionName );
+
+ expected = optionName;
+ break;
+
+ case PROP_TEMPLATE:
+ s.setPropTemplate( optionName );
+
+ expected = optionName;
+ break;
+
+ case ROOT:
+ s.setRoot( optionName );
+
+ expected = optionName;
+ break;
+
+ // Boolean options
+ case DOS:
+ s.setDos( optionName );
+
+ expected = true;
+ break;
+
+ case HELP:
+ s.setHelp( optionName );
+
+ expected = true;
+ break;
+
+ case INCLUDE_SOURCE:
+ s.setIncludeSource( optionName );
+
+ expected = true;
+ break;
+
+ case LANG_DAML:
+ s.setLangDaml( optionName );
+
+ expected = true;
+ break;
+
+ case LANG_OWL:
+ s.setLangOwl( optionName );
+
+ expected = true;
+ break;
+
+ case LANG_RDFS:
+ s.setLangRdfs( optionName );
+
+ expected = true;
+ break;
+
+ case NOCLASSES:
+ s.setNoClasses( optionName );
+
+ expected = true;
+ break;
+
+ case NOHEADER:
+ s.setNoHeader( optionName );
+
+ expected = true;
+ break;
+
+ case NOINDIVIDUALS:
+ s.setNoIndividuals( optionName );
+
+ expected = true;
+ break;
+
+ case NOPROPERTIES:
+ s.setNoProperties( optionName );
+
+ expected = true;
+ break;
+
+ case NO_COMMENTS:
+ s.setNoComments( optionName );
+
+ expected = true;
+ break;
+
+ case NO_STRICT:
+ s.setNoStrict( optionName );
+
+ expected = true;
+ break;
+
+ case ONTOLOGY:
+ s.setOntology( optionName );
+
+ expected = true;
+ break;
+
+ case STRICT_INDIVIDUALS:
+ s.setStrictIndividuals( optionName );
+
+ expected = true;
+ break;
+
+ case UC_NAMES:
+ s.setUcNames( optionName );
+
+ expected = true;
+ break;
+
+ case USE_INF:
+ s.setUseInf( optionName );
+
+ expected = true;
+ break;
+
+ }
+ }
+
+ /***********************************/
+ /* Inner class definitions */
+ /***********************************/
+
+}
+
Added: jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SourceTest.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SourceTest.java?rev=1536365&view=auto
==============================================================================
--- jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SourceTest.java (added)
+++ jena/trunk/jena-maven-tools/src/test/java/org/openjena/tools/schemagen/SourceTest.java Mon Oct 28 14:26:25 2013
@@ -0,0 +1,118 @@
+/*****************************************************************************
+ * File: SourceTest.java
+ * Project: schemagen
+ * Created: 18 May 2010
+ * By: ian
+ *
+ * Copyright (c) 2010-11 Epimorphics Ltd. See LICENSE file for license terms.
+ *****************************************************************************/
+
+// Package
+///////////////
+
+package org.openjena.tools.schemagen;
+
+
+// Imports
+///////////////
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import jena.schemagen.SchemagenOptions.OPT;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <p>Additional unit test cases for {@link Source}, in addition
+ * to parameter coverage tests in {@link SourceParameterTest}. </p>
+ *
+ * @author Ian Dickinson, Epimorphics (mailto:ian@epimorphics.com)
+ */
+public class SourceTest
+{
+ /***********************************/
+ /* Constants */
+ /***********************************/
+
+ /***********************************/
+ /* Static variables */
+ /***********************************/
+
+ @SuppressWarnings( value = "unused" )
+ private static final Logger log = LoggerFactory.getLogger( SourceTest.class );
+
+ /***********************************/
+ /* Instance variables */
+ /***********************************/
+
+ /***********************************/
+ /* Constructors */
+ /***********************************/
+
+ /***********************************/
+ /* External signature methods */
+ /***********************************/
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ //
+ }
+
+ /**
+ * Test method for {@link org.openjena.tools.schemagen.Source#setInput(java.lang.String)}.
+ */
+ @Test
+ public void testSetInput0() {
+ Source s = new Source();
+ List<String> values = s.getAllValues( OPT.INPUT );
+ assertListMatch( new String[] {}, new String[] {}, 0, values );
+ }
+
+ @Test
+ public void testSetInput1() {
+ Source s = new Source();
+ s.setInput( "__file1" );
+ List<String> values = s.getAllValues( OPT.INPUT );
+ assertListMatch( new String[] {"__file1"}, new String[] {}, 1, values );
+ }
+
+ @Test
+ public void testSetInput2() {
+ Source s = new Source();
+ s.setInput( "__file1" );
+ s.setInput( "__file2" );
+ List<String> values = s.getAllValues( OPT.INPUT );
+ assertListMatch( new String[] {"__file1", "__file2"}, new String[] {}, 2, values );
+ }
+
+ /***********************************/
+ /* Internal implementation methods */
+ /***********************************/
+
+ protected void assertListMatch( String[] positives, String[] negatives, int expectedLen, List<String> values ) {
+ assertEquals( expectedLen, values.size() );
+
+ for (String match: positives) {
+ assertTrue( "Should contain " + match, values.contains( match ) );
+ }
+
+ for (String match: negatives) {
+ assertFalse( "Should not contain " + match, values.contains( match ) );
+ }
+ }
+
+
+ /***********************************/
+ /* Inner class definitions */
+ /***********************************/
+
+}
+
Added: jena/trunk/jena-maven-tools/src/test/resources/test1/test1.ttl
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/test/resources/test1/test1.ttl?rev=1536365&view=auto
==============================================================================
--- jena/trunk/jena-maven-tools/src/test/resources/test1/test1.ttl (added)
+++ jena/trunk/jena-maven-tools/src/test/resources/test1/test1.ttl Mon Oct 28 14:26:25 2013
@@ -0,0 +1,10 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix eg: <http://www.epimorphics.com/vocabularies/example#> .
+@prefix : <http://www.epimorphics.com/vocabularies/example#> .
+
+:Clzz a rdfs:Class.
+
+:a a :Clzz.
\ No newline at end of file
Added: jena/trunk/jena-maven-tools/src/test/resources/test1/test2.ttl
URL: http://svn.apache.org/viewvc/jena/trunk/jena-maven-tools/src/test/resources/test1/test2.ttl?rev=1536365&view=auto
==============================================================================
(empty)