Class SchemaGenerationMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.codehaus.mojo.jaxb2.AbstractJaxbMojo
-
- org.codehaus.mojo.jaxb2.schemageneration.AbstractXsdGeneratorMojo
-
- org.codehaus.mojo.jaxb2.schemageneration.SchemaGenerationMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
@Mojo(name="schemagen", defaultPhase=GENERATE_RESOURCES, requiresDependencyResolution=COMPILE, threadSafe=true) public class SchemaGenerationMojo extends AbstractXsdGeneratorMojo
Mojo that creates XML schema(s) from compile-scope Java sources or binaries by invoking the JAXB SchemaGenerator. This implementation is tailored to use the JAXB Reference Implementation from project Kenai.
Note that the SchemaGenerationMojo was completely re-implemented for the 2.x versions. Its configuration semantics and parameter set is not necessarily backwards compatible with the 1.x plugin versions. If you are upgrading from version 1.x of the plugin, read the documentation carefully.
- See Also:
- The JAXB Reference Implementation
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.File
outputDirectory
The directory where the generated XML Schema file(s) will be placed, after all transformations are done.private java.util.List<Filter<java.io.File>>
schemaSourceExcludeFilters
Parameter holding a List of Filters, used to match all files under thesources
directories which should not be considered SchemaGenerator source files.private java.util.List<java.lang.String>
sources
Parameter holding List of paths to files and/or directories which should be recursively searched for Java source files.static java.lang.String
STALE_FILENAME
The last part of the stale fileName for this SchemaGenerationMojo.static java.util.List<Filter<java.io.File>>
STANDARD_SOURCE_EXCLUDE_FILTERS
Default exclude file name suffixes for sources, used unless overridden by an explicit configuration in thesourceExcludeSuffixes
parameter.private java.io.File
workDirectory
The directory where theschemagen
tool will output XSDs, episode files - and intermediary bytecode files.-
Fields inherited from class org.codehaus.mojo.jaxb2.schemageneration.AbstractXsdGeneratorMojo
CLASS_INCLUDE_FILTERS, clearOutputDir, createJavaDocAnnotations, episodeFileName, generateEpisode, javaDocRenderer, SCHEMAGEN_EMITTED_FILENAME, STANDARD_BYTECODE_EXCLUDE_FILTERS, STANDARD_JAVADOC_RENDERER, SYSTEM_TOOLS_CLASSLOADER_PACKAGES
-
Fields inherited from class org.codehaus.mojo.jaxb2.AbstractJaxbMojo
CONTAINS_WHITESPACE, extraFacets, locale, NEWLINE, PACKAGE_INFO_FILENAME, staleFileDirectory, STANDARD_EPISODE_FILENAME, STANDARD_EXCLUDE_FILTERS
-
-
Constructor Summary
Constructors Constructor Description SchemaGenerationMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addResource(org.apache.maven.model.Resource resource)
Adds the supplied Resource to the project using the appropriate scope (i.e.protected java.util.List<java.lang.String>
getClasspath()
Retrieves the configured List of paths from which this AbstractJaxbMojo and its internal toolset (XJC or SchemaGen) should read bytecode classes.protected java.util.List<java.net.URL>
getCompiledClassNames()
Finds a List containing URLs to compiled bytecode files within this Compilation Unit.protected java.io.File
getOutputDirectory()
Retrieves the directory where the generated files should be written to.protected java.util.List<java.net.URL>
getSources()
Override this method to acquire a List holding all URLs to the SchemaGen Java sources for which this AbstractXsdGeneratorMojo should generate Xml Schema Descriptor files.protected java.lang.String
getStaleFileName()
Retrieves the last name part of the stale file.protected java.io.File
getWorkDirectory()
-
Methods inherited from class org.codehaus.mojo.jaxb2.schemageneration.AbstractXsdGeneratorMojo
isReGenerationRequired, performExecution, shouldExecutionBeSkipped
-
Methods inherited from class org.codehaus.mojo.jaxb2.AbstractJaxbMojo
execute, getBuildContext, getEncoding, getEpisodeFile, getExecution, getProject, getStaleFile, logAndReturnToolArguments, logSystemPropertiesAndBasedir, warnAboutIncorrectPluginConfiguration
-
-
-
-
Field Detail
-
STALE_FILENAME
public static final java.lang.String STALE_FILENAME
The last part of the stale fileName for this SchemaGenerationMojo.- See Also:
- Constant Field Values
-
STANDARD_SOURCE_EXCLUDE_FILTERS
public static final java.util.List<Filter<java.io.File>> STANDARD_SOURCE_EXCLUDE_FILTERS
Default exclude file name suffixes for sources, used unless overridden by an explicit configuration in the
sourceExcludeSuffixes
parameter. The default values are found as follows:final List<Filter<File>> srcTemp = new ArrayList<Filter<File>>(); srcTemp.addAll(AbstractJaxbMojo.STANDARD_EXCLUDE_FILTERS); srcTemp.add(new PatternFileFilter(Arrays.asList("\\.xjb", "\\.xsd", "\\.properties"), true)); STANDARD_SOURCE_EXCLUDE_FILTERS = Collections.unmodifiableList(srcTemp);
-
sources
@Parameter(required=false) private java.util.List<java.lang.String> sources
Parameter holding List of paths to files and/or directories which should be recursively searched for Java source files. Only files or directories that actually exist will be included (in the case of files) or recursively searched for source files to include (in the case of directories or JARs). Configure using standard Maven structure for Lists:
<configuration> ... <sources> <source>/a/full/absolute/path/to/a/SourceFile.java</source> <source>target/some/sourceJar.jar</source> <source>src/main/java</source> </sources> </configuration>
Note: if configured, the sources parameters replace the default value, which is a List containing the paths to the directories defined by
getProject().getCompileSourceRoots()
.- Since:
- 2.0
-
schemaSourceExcludeFilters
@Parameter(required=false) private java.util.List<Filter<java.io.File>> schemaSourceExcludeFilters
Parameter holding a List of Filters, used to match all files under the
sources
directories which should not be considered SchemaGenerator source files. (The filters identify files to exclude, and hence this parameter is calledschemaSourceExcludeFilters
). If a file under any of the source directories matches at least one of the Filters supplied in theschemaSourceExcludeFilters
, it is not considered an XJC source file, and therefore excluded from processing.If not explicitly provided, the Mojo uses the value within
STANDARD_SOURCE_EXCLUDE_FILTERS
. The algorithm for finding XJC sources is as follows:- Find all files given in the sources List. Any Directories provided are searched for files recursively.
- Exclude any found files matching any of the supplied
schemaSourceExcludeFilters
List. - The remaining Files are submitted for processing by the XJC tool.
Example: The following configuration would exclude any sources whose names end with
.txt
or.foo
:<configuration> ... <schemaSourceExcludeFilters> <filter implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter"> <patterns> <pattern>\.txt</pattern> <pattern>\.foo</pattern> </patterns> </filter> </schemaSourceExcludeFilters> </configuration>
Note that inner workings of the Dependency Injection mechanism used by Maven Plugins (i.e. the DI from the Plexus container) requires that the full class name to the Filter implementation should be supplied for each filter, as is illustrated in the sample above. This is true also if you implement custom Filters.
- Since:
- 2.0
- See Also:
STANDARD_SOURCE_EXCLUDE_FILTERS
,PatternFileFilter
,AbstractPatternFilter
,AbstractFilter
-
outputDirectory
@Parameter(defaultValue="${project.build.directory}/generated-resources/schemagen", required=true) private java.io.File outputDirectory
The directory where the generated XML Schema file(s) will be placed, after all transformations are done.
-
workDirectory
@Parameter(defaultValue="${project.build.directory}/schemagen-work/compile_scope", required=true) private java.io.File workDirectory
The directory where the
schemagen
tool will output XSDs, episode files - and intermediary bytecode files. From this directory the XSDs and the episode file (but not the bytecode files) will be copied to the outputDirectory for further processing.- See Also:
outputDirectory
-
-
Method Detail
-
getCompiledClassNames
protected java.util.List<java.net.URL> getCompiledClassNames()
Finds a List containing URLs to compiled bytecode files within this Compilation Unit. Typically this equals the resolved files under the project's build directories, plus any JAR artifacts found on the classpath.- Specified by:
getCompiledClassNames
in classAbstractXsdGeneratorMojo
- Returns:
- A non-null List containing URLs to bytecode files within this compilation unit. Typically this equals the resolved files under the project's build directories, plus any JAR artifacts found on the classpath.
-
getSources
protected java.util.List<java.net.URL> getSources()
Override this method to acquire a List holding all URLs to the SchemaGen Java sources for which this AbstractXsdGeneratorMojo should generate Xml Schema Descriptor files.- Specified by:
getSources
in classAbstractXsdGeneratorMojo
- Returns:
- A non-null List holding URLs to sources for the XSD generation.
-
getOutputDirectory
protected java.io.File getOutputDirectory()
Retrieves the directory where the generated files should be written to.- Specified by:
getOutputDirectory
in classAbstractJaxbMojo
- Returns:
- the directory where the generated files should be written to.
-
getClasspath
protected java.util.List<java.lang.String> getClasspath() throws org.apache.maven.plugin.MojoExecutionException
Retrieves the configured List of paths from which this AbstractJaxbMojo and its internal toolset (XJC or SchemaGen) should read bytecode classes.- Specified by:
getClasspath
in classAbstractJaxbMojo
- Returns:
- the configured List of paths from which this AbstractJaxbMojo and its internal toolset (XJC or SchemaGen) should read classes.
- Throws:
org.apache.maven.plugin.MojoExecutionException
- if the classpath could not be retrieved.
-
getStaleFileName
protected java.lang.String getStaleFileName()
Retrieves the last name part of the stale file. The full name of the stale file will be generated by pre-pending"." + getExecution().getExecutionId()
before this staleFileName.- Specified by:
getStaleFileName
in classAbstractJaxbMojo
- Returns:
- The name of the stale file used by this AbstractJavaGeneratorMojo to detect staleness amongst its generated files.
-
getWorkDirectory
protected java.io.File getWorkDirectory()
- Specified by:
getWorkDirectory
in classAbstractXsdGeneratorMojo
- Returns:
- The working directory to which the SchemaGenerator should initially copy all its generated files, including bytecode files, compiled from java sources.
-
addResource
protected void addResource(org.apache.maven.model.Resource resource)
Adds the supplied Resource to the project using the appropriate scope (i.e. resource or testResource) depending on the exact implementation of this AbstractJaxbMojo.- Specified by:
addResource
in classAbstractJaxbMojo
- Parameters:
resource
- The resource to add.
-
-