Class XjcMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Mojo that creates compile-scope Java source or binaries from XML schema(s) by invoking the JAXB XJC binding compiler. This implementation is tailored to use the JAXB Reference Implementation from project Kenai.
Note that the XjcMojo 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.
- Author:
- Lennart Jörelid
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe last part of the stale fileName for this XjcMojo.static final StringStandard directory path (relative to basedir) searched recursively for source files (typically XSDs), unless overridden by ansourcesconfiguration element.Default exclude Filters for sources, used unless overridden by an explicit configuration in thexjcSourceExcludeFiltersparameter.static final StringStandard directory path (relative to basedir) searched recursively for XJB files, unless overridden by anxjbSourcesconfiguration element.Default List of exclude Filters for XJB files, unless overridden by providing an explicit configuration in thexjbExcludeSuffixesparameter.Fields inherited from class AbstractJavaGeneratorMojo
addGeneratedAnnotation, arguments, autoNameResolution, catalog, clearOutputDir, episodeFileName, extension, externalEntityProcessing, failOnNoSchemas, generateEpisode, laxSchemaValidation, noGeneratedHeaderComments, noPackageLevelAnnotations, packageName, plugins, quiet, readOnly, settings, sourceType, target, verbose, xsdPathWithinArtifactFields inherited from class AbstractJaxbMojo
CONTAINS_WHITESPACE, extraFacets, locale, NEWLINE, PACKAGE_INFO_FILENAME, staleFileDirectory, STANDARD_EPISODE_FILENAME, STANDARD_EXCLUDE_FILTERSFields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddGeneratedSourcesToProjectSourceRoot(String canonicalPathToOutputDirectory) Adds any directories containing the generated XJC classes to the appropriate Project compilation sources; eitherTestCompileSourceRootorCompileSourceRootdepending on the exact Mojo implementation of this AbstractJavaGeneratorMojo.protected voidaddResource(org.apache.maven.model.Resource resource) Adds the supplied Resource to the project using the appropriate scope (i.e.Retrieves the configured List of paths from which this AbstractJaxbMojo and its internal toolset (XJC or SchemaGen) should read bytecode classes.protected FileRetrieves the directory where the generated files should be written to.Override this method to acquire a List holding all URLs to the JAXB sources for which this AbstractJavaGeneratorMojo should generate Java files.Override this method to retrieve a list of Files to all XJB files for which this AbstractJavaGeneratorMojo should generate Java files.protected StringRetrieves the last name part of the stale file.protected FileresolveCatalog(File catalogFile) Optionally pre-processes the supplied catalogFilebefore it is passed to XJC.protected booleanImplement this method to check if this AbstractJaxbMojo should skip executing altogether.Methods inherited from class AbstractJavaGeneratorMojo
getXjcArguments, isReGenerationRequired, performExecutionMethods inherited from class AbstractJaxbMojo
execute, getBuildContext, getEncoding, getEpisodeFile, getExecution, getProject, getStaleFile, logAndReturnToolArguments, logSystemPropertiesAndBasedir, validateOutputDirectory, warnAboutIncorrectPluginConfigurationMethods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
STALE_FILENAME
The last part of the stale fileName for this XjcMojo.- See Also:
-
STANDARD_SOURCE_DIRECTORY
Standard directory path (relative to basedir) searched recursively for source files (typically XSDs), unless overridden by an
sourcesconfiguration element.- See Also:
-
STANDARD_SOURCE_EXCLUDE_FILTERS
Default exclude Filters for sources, used unless overridden by an explicit configuration in the
xjcSourceExcludeFiltersparameter. The default values are found as follows:final List<Filter<File>> xsdTemp = new ArrayList<Filter<File>>(); xsdTemp.addAll(AbstractJaxbMojo.STANDARD_EXCLUDE_FILTERS); xsdTemp.add(new PatternFileFilter(Arrays.asList("\\.xjb"), true)); STANDARD_SOURCE_EXCLUDE_FILTERS = Collections.unmodifiableList(xsdTemp);- See Also:
-
STANDARD_XJB_DIRECTORY
Standard directory path (relative to basedir) searched recursively for XJB files, unless overridden by an
xjbSourcesconfiguration element. As explained in the JAXB specification, XJB files (JAXB Xml Binding files) are used to configure parts of the Java source generation.- See Also:
-
STANDARD_XJB_EXCLUDE_FILTERS
Default List of exclude Filters for XJB files, unless overridden by providing an explicit configuration in the
xjbExcludeSuffixesparameter. The default values are found as follows:final List<Filter<File>> xjbTemp = new ArrayList<Filter<File>>(); xjbTemp.addAll(AbstractJaxbMojo.STANDARD_EXCLUDE_FILTERS); xjbTemp.add(new PatternFileFilter(Arrays.asList("\\.xsd"), true)); STANDARD_XJB_EXCLUDE_FILTERS = Collections.unmodifiableList(xjbTemp);- See Also:
-
-
Constructor Details
-
XjcMojo
public XjcMojo()
-
-
Method Details
-
shouldExecutionBeSkipped
protected boolean shouldExecutionBeSkipped()Implement this method to check if this AbstractJaxbMojo should skip executing altogether.- Specified by:
shouldExecutionBeSkippedin classAbstractJaxbMojo- Returns:
trueto indicate that this AbstractJaxbMojo should bail out of its execute method.
-
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 thesourceTypevalue.- Specified by:
getSourcesin classAbstractJavaGeneratorMojo- Returns:
- A non-null List holding URLs to sources for the XJC generation.
- See Also:
-
getSourceXJBs
Override this method to retrieve a list of Files to all XJB files for which this AbstractJavaGeneratorMojo should generate Java files.- Specified by:
getSourceXJBsin classAbstractJavaGeneratorMojo- Returns:
- A non-null List holding binding files.
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
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:
getStaleFileNamein classAbstractJaxbMojo- Returns:
- The name of the stale file used by this AbstractJavaGeneratorMojo to detect staleness amongst its generated files.
-
getOutputDirectory
Retrieves the directory where the generated files should be written to.- Specified by:
getOutputDirectoryin classAbstractJaxbMojo- Returns:
- the directory where the generated files should be written to.
-
getClasspath
Retrieves the configured List of paths from which this AbstractJaxbMojo and its internal toolset (XJC or SchemaGen) should read bytecode classes.- Specified by:
getClasspathin 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.
-
addGeneratedSourcesToProjectSourceRoot
Adds any directories containing the generated XJC classes to the appropriate Project compilation sources; eitherTestCompileSourceRootorCompileSourceRootdepending on the exact Mojo implementation of this AbstractJavaGeneratorMojo.- Specified by:
addGeneratedSourcesToProjectSourceRootin classAbstractJaxbMojo
-
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:
addResourcein classAbstractJaxbMojo- Parameters:
resource- The resource to add.
-
resolveCatalog
protected File resolveCatalog(File catalogFile) throws org.apache.maven.plugin.MojoExecutionException Optionally pre-processes the supplied catalogFilebefore it is passed to XJC.The default implementation returns
catalogFileunchanged. Subclasses (such asXjcMojo) can override this method to resolvemaven:URIs in the catalog to concretejar:file://URLs, allowing XJC to consume XSD resources packaged inside Maven dependency JARs without manual unpacking.If the supplied catalog file contains
maven:groupId:artifactId:type:classifier!/pathURIs, this override resolves each of them to ajar:file://URL pointing into the corresponding artifact in the local Maven repository, then writes a pre-processed copy of the catalog to${project.build.directory}/jaxb2/resolved-<name>and returns that file to XJC.If the catalog contains no
maven:URIs the original file is returned unchanged.This allows users to reference XSD files packaged inside dependency JARs from a catalog:
REWRITE_SYSTEM "http://example.com/common.xsd" "maven:com.example:shared-schemas:jar:!/schemas/common.xsd"- Overrides:
resolveCatalogin classAbstractJavaGeneratorMojo- Parameters:
catalogFile- the catalog file as configured by the user; nevernull- Returns:
- the catalog file to pass to XJC — either
catalogFileas-is, or a rewritten copy written to the build directory - Throws:
org.apache.maven.plugin.MojoExecutionException- if catalog pre-processing fails- Since:
- 4.1.1
- See Also:
-