Class AbstractJavaGeneratorMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.codehaus.mojo.jaxb2.AbstractJaxbMojo
-
- org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
TestXjcMojo
,XjcMojo
public abstract class AbstractJavaGeneratorMojo extends AbstractJaxbMojo
Abstract superclass for Mojos generating Java source or binaries from XML schema(s) by invoking the JAXB XJC binding compiler. Most of the Configuration options for the AbstractJavaGeneratorMojo are set or copied to the XJC directly; refer to their documentation in the JAXB Reference Implementation site.
- Author:
- Lennart Jörelid
- See Also:
- The JAXB Reference Implementation
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
addGeneratedAnnotation
Corresponding XJC parameter:mark-generated
.protected List<String>
arguments
Deprecated.This should be removed in the 2.0+ release, as all arguments should be handled by other parameters.protected File
catalog
Corresponding XJC parameter:catalog
.protected boolean
clearOutputDir
Removes all files from the output directory before running XJC.protected String
episodeFileName
Corresponding XJC parameter:episode
.protected boolean
extension
Corresponding XJC parameter:extension
.protected boolean
externalEntityProcessing
If set totrue
, the system propertyenableExternalEntityProcessing
is set for the duration of the Java generation by this plugin, permitting DTD sources to use external entity URIs such asfile://
.protected boolean
failOnNoSchemas
Fails the Mojo execution if no XSDs/schemas are found.protected boolean
generateEpisode
Deprecated.protected boolean
laxSchemaValidation
Corresponding XJC parameter:nv
.protected boolean
noGeneratedHeaderComments
Corresponding XJC parameter:no-header
.protected boolean
noPackageLevelAnnotations
Corresponding XJC parameter:npa
.protected String
packageName
Corresponding XJC parameter:p
.protected boolean
quiet
Corresponding XJC parameter:quiet
.protected boolean
readOnly
Corresponding XJC parameter:readOnly
.protected org.apache.maven.settings.Settings
settings
Sets the HTTP/HTTPS proxy to be used by the XJC, on the format[user[:password]@]proxyHost[:proxyPort]
.protected SourceContentType
sourceType
Defines the content type of sources for the XJC.protected String
target
Corresponding XJC parameter:target
.protected boolean
verbose
Corresponding XJC parameter:verbose
.protected String
xsdPathWithinArtifact
If provided, this parameter indicates that the XSDs used by XJC to generate Java code should be copied into the resulting artifact of this project (the JAR, WAR or whichever artifact type is generated).-
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 AbstractJavaGeneratorMojo()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
addGeneratedSourcesToProjectSourceRoot()
Adds any directories containing the generated XJC classes to the appropriate Project compilation sources; eitherTestCompileSourceRoot
orCompileSourceRoot
depending on the exact Mojo implementation of this AbstractJavaGeneratorMojo.protected abstract List<URL>
getSources()
Override this method to acquire a List holding all URLs to the JAXB sources for which this AbstractJavaGeneratorMojo should generate Java files.protected abstract List<File>
getSourceXJBs()
Override this method to retrieve a list of Files to all XJB files for which this AbstractJavaGeneratorMojo should generate Java files.protected boolean
isReGenerationRequired()
Java generation is required if any of the file products is outdated/stale.protected boolean
performExecution()
Implement this method to perform this Mojo's execution.-
Methods inherited from class org.codehaus.mojo.jaxb2.AbstractJaxbMojo
addResource, execute, getBuildContext, getClasspath, getEncoding, getEpisodeFile, getExecution, getOutputDirectory, getProject, getStaleFile, getStaleFileName, logAndReturnToolArguments, logSystemPropertiesAndBasedir, shouldExecutionBeSkipped, warnAboutIncorrectPluginConfiguration
-
-
-
-
Field Detail
-
catalog
@Parameter protected File catalog
Corresponding XJC parameter:
catalog
.Specify catalog files to resolve external entity references. Supports TR9401, XCatalog, and OASIS XML Catalog format.
-
generateEpisode
@Deprecated @Parameter(defaultValue="true") protected boolean generateEpisode
Deprecated.Deprecated - will be removed in a future releaseFrom plugin version 2.4, this parameter will not be used. Instead, episode files are generated by default with all JAXB operations.
Starting with plugin version 2.4, use the parameter
episodeFileName
to provide a custom name of the generated episode File (or rely on the standard file nameAbstractJaxbMojo.STANDARD_EPISODE_FILENAME
).- Since:
- 2.0
-
episodeFileName
@Parameter protected String episodeFileName
Corresponding XJC parameter:
episode
.Generate an episode file with the supplied name from this XJC compilation, so that other schemas that rely on this schema can be compiled later and rely on classes that are generated from this compilation. The generated episode file is simply a JAXB customization file (but with vendor extensions), normally known as a binding file with the suffix
.xjb
.If the
episodeFileName
parameter is not given, the episode file name is synthesized on the form"episode_" + executionID + ".xjb"
- typically something like episode_my_xjc.xjb, but it depends on the actual ID given in the execution element:<executions> <execution> <id>my_xjc</id> <goals> <goal>xjc</goal> </goals> </execution> </executions>
- Since:
- 2.4
- See Also:
AbstractJaxbMojo.STANDARD_EPISODE_FILENAME
-
settings
@Parameter(defaultValue="${settings}", readonly=true) protected org.apache.maven.settings.Settings settings
Sets the HTTP/HTTPS proxy to be used by the XJC, on the format
[user[:password]@]proxyHost[:proxyPort]
. All information is retrieved from the active proxy within the standard maven settings file.
-
sourceType
@Parameter(defaultValue="XmlSchema") protected SourceContentType sourceType
Defines the content type of sources for the XJC. To simplify usage of the JAXB2 maven plugin, all source files are assumed to have the same type of content.
This parameter replaces the previous multiple-choice boolean configuration options for the jaxb2-maven-plugin (i.e. dtd, xmlschema, relaxng, relaxng-compact, wsdl), and corresponds to setting one of those flags as an XJC argument.
- Since:
- 2.0
-
noPackageLevelAnnotations
@Parameter(defaultValue="false") protected boolean noPackageLevelAnnotations
Corresponding XJC parameter:
npa
.Suppress the generation of package level annotations into
package-info.java
. Using this switch causes the generated code to internalize those annotations into the other generated classes.- Since:
- 2.0
-
noGeneratedHeaderComments
@Parameter(defaultValue="false") protected boolean noGeneratedHeaderComments
Corresponding XJC parameter:
no-header
.Suppress the generation of a file header comment that includes some note and timestamp. Using this makes the generated code more diff-friendly.
- Since:
- 2.0
-
addGeneratedAnnotation
@Parameter(defaultValue="false") protected boolean addGeneratedAnnotation
Corresponding XJC parameter:
mark-generated
.This feature causes all of the generated code to have
@Generated
annotation.- Since:
- 2.0
-
laxSchemaValidation
@Parameter(defaultValue="false") protected boolean laxSchemaValidation
Corresponding XJC parameter:
nv
.By default, the XJC binding compiler performs strict validation of the source schema before processing it. Use this option to disable strict schema validation. This does not mean that the binding compiler will not perform any validation, it simply means that it will perform less-strict validation.
- Since:
- 2.0
-
quiet
@Parameter(defaultValue="false") protected boolean quiet
Corresponding XJC parameter:
quiet
.Suppress compiler output, such as progress information and warnings.
-
verbose
@Parameter(property="xjc.verbose", defaultValue="false") protected boolean verbose
Corresponding XJC parameter:
verbose
.Tells XJC to be extra verbose, such as printing informational messages or displaying stack traces.
-
extension
@Parameter(defaultValue="true") protected boolean extension
Corresponding XJC parameter:
extension
.By default, the XJC binding compiler strictly enforces the rules outlined in the Compatibility chapter of the JAXB Specification. Appendix E.2 defines a set of W3C XML Schema features that are not completely supported by JAXB v1.0. In some cases, you may be allowed to use them in the "-extension" mode enabled by this switch. In the default (strict) mode, you are also limited to using only the binding customizations defined in the specification.
-
failOnNoSchemas
@Parameter(defaultValue="true") protected boolean failOnNoSchemas
Fails the Mojo execution if no XSDs/schemas are found.- Since:
- 1.3
-
clearOutputDir
@Parameter(defaultValue="true") protected boolean clearOutputDir
Removes all files from the output directory before running XJC.
-
readOnly
@Parameter(defaultValue="false") protected boolean readOnly
Corresponding XJC parameter:
readOnly
.By default, the XJC binding compiler does not write-protect the Java source files it generates. Use this option to force the XJC binding compiler to mark the generated Java sources read-only.
- Since:
- 2.0
-
arguments
@Parameter(property="xjc.arguments") protected List<String> arguments
Deprecated.This should be removed in the 2.0+ release, as all arguments should be handled by other parameters.List of ordered extra arguments to the XJC command. Each extra argument is interpreted as a word, intended to be copied verbatim to the XJC argument list with spaces in between:
<configuration> ... <arguments> <argument>-Xfluent-api</argument> <argument>somefile</argument> </arguments> </configuration>
The arguments configured above yields the following extra arguments to the XJC command:
-Xfluent-api -episode somefile
- Since:
- 2.0
-
packageName
@Parameter protected String packageName
Corresponding XJC parameter:
p
.The package under which the source files will be generated. Quoting the XJC documentation: "Specifying a target package via this command-line option overrides any binding customization for package name and the default package name algorithm defined in the specification".
-
target
@Parameter protected String target
Corresponding XJC parameter:
target
.Permitted values:
"2.0"
and"2.1"
. Avoid generating code that relies on JAXB newer than the version given. This will allow the generated code to run with JAXB 2.0 runtime (such as JavaSE 6.)- Since:
- 1.3
-
xsdPathWithinArtifact
@Parameter protected String xsdPathWithinArtifact
If provided, this parameter indicates that the XSDs used by XJC to generate Java code should be copied into the resulting artifact of this project (the JAR, WAR or whichever artifact type is generated). The value of the
xsdPathWithinArtifact
parameter is the relative path within the artifact where all source XSDs are copied to (hence the name "XSD Path Within Artifact").The target directory is created within the artifact if it does not already exist. If the
xsdPathWithinArtifact
parameter is not given, the XSDs used to generate Java code are not included within the project's artifact.Example:Adding the sample configuration below would copy all source XSDs to the given directory within the resulting JAR (and/or test-JAR). If the directory
META-INF/jaxb/xsd
does not exist, it will be created.<configuration> ... <xsdPathWithinArtifact>META-INF/jaxb/xsd</xsdPathWithinArtifact> </configuration>
Note: This parameter was previously called
includeSchemasOutputPath
in the 1.x versions of this plugin, but was renamed and re-documented for improved usability and clarity.- Since:
- 2.0
-
externalEntityProcessing
@Parameter(defaultValue="false") protected boolean externalEntityProcessing
If set to
true
, the system propertyenableExternalEntityProcessing
is set for the duration of the Java generation by this plugin, permitting DTD sources to use external entity URIs such asfile://
. Typically, this is used in conjunction with thesourceType
similar to the configuration snippet below where DTDs are used as sourceType and read from thesrc/main/dtd
directory. This implies afile://
URI.<configuration> ... <sourceType>dtd</sourceType> <sources> <source>src/main/dtd</source> </sources> <externalEntityProcessing>true</externalEntityProcessing> </configuration>
- Since:
- 2.4
-
-
Method Detail
-
isReGenerationRequired
protected boolean isReGenerationRequired()
Java generation is required if any of the file products is outdated/stale.
- Specified by:
isReGenerationRequired
in classAbstractJaxbMojo
- Returns:
true
to indicate that this AbstractJaxbMojo should be run since its generated files were either stale or not present, andfalse
otherwise.
-
performExecution
protected boolean performExecution() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
Implement this method to perform this Mojo's execution. This method will only be called if
!shouldExecutionBeSkipped() && isReGenerationRequired()
.- Specified by:
performExecution
in classAbstractJaxbMojo
- Returns:
true
if the timestamp of the stale file should be updated.- Throws:
org.apache.maven.plugin.MojoExecutionException
- if an unexpected problem occurs. Throwing this exception causes a "BUILD ERROR" message to be displayed.org.apache.maven.plugin.MojoFailureException
- if an expected problem (such as a compilation failure) occurs. Throwing this exception causes a "BUILD FAILURE" message to be displayed.
-
getSources
protected abstract List<URL> getSources()
Override this method to acquire a List holding all URLs to the JAXB sources for which this AbstractJavaGeneratorMojo should generate Java files. Sources are assumed to be in the form given by thesourceType
value.- Specified by:
getSources
in classAbstractJaxbMojo
- Returns:
- A non-null List holding URLs to sources for the XJC generation.
- See Also:
sourceType
-
getSourceXJBs
protected abstract List<File> getSourceXJBs()
Override this method to retrieve a list of Files to all XJB files for which this AbstractJavaGeneratorMojo should generate Java files.- Returns:
- A non-null List holding binding files.
-
addGeneratedSourcesToProjectSourceRoot
protected abstract void addGeneratedSourcesToProjectSourceRoot()
Adds any directories containing the generated XJC classes to the appropriate Project compilation sources; eitherTestCompileSourceRoot
orCompileSourceRoot
depending on the exact Mojo implementation of this AbstractJavaGeneratorMojo.
-
-