Class AbstractJaxbMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
AbstractJavaGeneratorMojo,AbstractXsdGeneratorMojo
- Author:
- Lennart Jörelid
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternPattern matching strings containing whitespace (or consisting only of whitespace).protected List<EnvironmentFacet> Defines a set of extra EnvironmentFacet instances which are used to further configure the ToolExecutionEnvironment used by this plugin to fire XJC or SchemaGen.protected StringA Locale definition to create and set the system (default) Locale when the XJB or SchemaGen tools executes.static final StringPlatform-independent newline control string.static final StringStandard name of the package-info.java file which may contain JAXB annotations and Package JavaDoc.protected FileThe directory where the staleFile is found.static final StringStandard name of the generated JAXB episode file.Standard excludes Filters for all Java generator Mojos.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract 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 abstract voidaddResource(org.apache.maven.model.Resource resource) Adds the supplied Resource to the project using the appropriate scope (i.e.final voidexecute()protected final org.sonatype.plexus.build.incremental.BuildContextThe Plexus BuildContext is used to identify files or directories modified since last build, implying functionality used to define if java generation must be performed again.Retrieves the configured List of paths from which this AbstractJaxbMojo and its internal toolset (XJC or SchemaGen) should read bytecode classes.protected final StringgetEncoding(boolean warnIfPlatformEncoding) The algorithm for finding the encoding to use is as follows (where the first non-null value found is used for encoding):protected FilegetEpisodeFile(String episodeFileName) Retrieves a File to the JAXB Episode (which is normally written during the XJC process).org.apache.maven.plugin.MojoExecutionprotected abstract FileRetrieves the directory where the generated files should be written to.protected final org.apache.maven.project.MavenProjectOverride this method to acquire a List holding all URLs to the sources which this AbstractJaxbMojo should use to produce its output (XSDs files for AbstractXsdGeneratorMojos and Java Source Code for AbstractJavaGeneratorMojos).protected final FileAcquires the staleFile for this executionprotected abstract StringRetrieves the last name part of the stale file.protected abstract booleanprotected final String[]logAndReturnToolArguments(String[] arguments, String toolName) protected voidPrints out the system properties to the Maven Log at Debug level.protected abstract booleanImplement this method to perform this Mojo's execution.protected abstract booleanImplement this method to check if this AbstractJaxbMojo should skip executing altogether.protected voidwarnAboutIncorrectPluginConfiguration(String propertyName, String description) Convenience method to invoke when some plugin configuration is incorrect.Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
STANDARD_EPISODE_FILENAME
Standard name of the generated JAXB episode file.- See Also:
-
PACKAGE_INFO_FILENAME
Standard name of the package-info.java file which may contain JAXB annotations and Package JavaDoc.- See Also:
-
NEWLINE
Platform-independent newline control string. -
CONTAINS_WHITESPACE
Pattern matching strings containing whitespace (or consisting only of whitespace). -
STANDARD_EXCLUDE_FILTERS
Standard excludes Filters for all Java generator Mojos. The List is unmodifiable, and contains Filters on the following form:
// The standard exclude filters contain simple, exclude pattern filters. final List<Filter<File>> tmp = new ArrayList<Filter<File>>(); tmp.add(new PatternFileFilter(Arrays.asList({"README.*", "\\.xml", "\\.txt"}), true)); tmp.add(new FileFilterAdapter(new FileFilter() { @Override public boolean accept(final File aFileOrDir) { // Check sanity if (aFileOrDir == null) { return false; } final String name = aFileOrDir.getName(); // Ignore hidden files and CVS directories return name.startsWith(".") || (aFileOrDir.isDirectory() && name.equals("CVS")); } }));Note! Since the plugin is currently developed in jdk 1.7-compliant code, we cannot use lambdas within Filters just yet.
-
staleFileDirectory
@Parameter(defaultValue="${project.build.directory}/jaxb2", readonly=true, required=true) protected File staleFileDirectoryThe directory where the staleFile is found. The staleFile assists in determining if re-generation of JAXB build products is required.
While it is permitted to re-define the staleFileDirectory, it is recommended to keep it below the
${project.build.directory}, to ensure that JAXB code or XSD re-generation occurs after cleaning the project.- Since:
- 2.0
-
locale
A Locale definition to create and set the system (default) Locale when the XJB or SchemaGen tools executes. The Locale will be reset to its default value after the execution of XJC or SchemaGen is complete.
The configuration parameter must be supplied on the form
language[,country[,variant]], such assv,SEorfr. Refer toorg.codehaus.mojo.jaxb2.shared.environment.locale.LocaleFacet.createFor(String, Log)for further information.Example (assigns french locale):
<configuration> <locale>fr</locale> </configuration>- Since:
- 2.2
- See Also:
-
extraFacets
Defines a set of extra EnvironmentFacet instances which are used to further configure the ToolExecutionEnvironment used by this plugin to fire XJC or SchemaGen.
Example: If you implement the EnvironmentFacet interface in the class
org.acme.MyCoolEnvironmentFacetImplementation, itssetup()method is called before the XJC or SchemaGen tools are executed to setup some facet of their Execution environment. Correspondingly, therestore()method in yourorg.acme.MyCoolEnvironmentFacetImplementationclass is invoked after the XJC or SchemaGen execution terminates.<configuration> ... <extraFacets> <extraFacet implementation="org.acme.MyCoolEnvironmentFacetImplementation" /> </extraFacets> ... </configuration>- Since:
- 2.2
- See Also:
-
-
Constructor Details
-
AbstractJaxbMojo
public AbstractJaxbMojo()
-
-
Method Details
-
addResource
protected abstract 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.- Parameters:
resource- The resource to add.
-
getBuildContext
protected final org.sonatype.plexus.build.incremental.BuildContext getBuildContext()The Plexus BuildContext is used to identify files or directories modified since last build, implying functionality used to define if java generation must be performed again.- Returns:
- the active Plexus BuildContext.
-
getProject
protected final org.apache.maven.project.MavenProject getProject()- Returns:
- The active MavenProject.
-
getExecution
public org.apache.maven.plugin.MojoExecution getExecution()- Returns:
- The active MojoExecution.
-
execute
public final void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
addGeneratedSourcesToProjectSourceRoot
protected abstract void addGeneratedSourcesToProjectSourceRoot(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. -
shouldExecutionBeSkipped
protected abstract boolean shouldExecutionBeSkipped()Implement this method to check if this AbstractJaxbMojo should skip executing altogether.- Returns:
trueto indicate that this AbstractJaxbMojo should bail out of its execute method.
-
isReGenerationRequired
protected abstract boolean isReGenerationRequired()- Returns:
trueto indicate that this AbstractJaxbMojo should be run since its generated files were either stale or not present, andfalseotherwise.
-
performExecution
protected abstract boolean performExecution() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionImplement this method to perform this Mojo's execution. This method will only be called if
!shouldExecutionBeSkipped() && isReGenerationRequired().- Returns:
trueif 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
Override this method to acquire a List holding all URLs to the sources which this AbstractJaxbMojo should use to produce its output (XSDs files for AbstractXsdGeneratorMojos and Java Source Code for AbstractJavaGeneratorMojos).- Returns:
- A non-null List holding URLs to sources used by this AbstractJaxbMojo to produce its output.
-
getOutputDirectory
Retrieves the directory where the generated files should be written to.- Returns:
- the directory where the generated files should be written to.
-
getClasspath
protected abstract List<String> getClasspath() throws org.apache.maven.plugin.MojoExecutionExceptionRetrieves the configured List of paths from which this AbstractJaxbMojo and its internal toolset (XJC or SchemaGen) should read bytecode classes.- 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.
-
warnAboutIncorrectPluginConfiguration
Convenience method to invoke when some plugin configuration is incorrect. Will output the problem as a warning with some degree of log formatting.- Parameters:
propertyName- The name of the problematic property.description- The problem description.
-
logAndReturnToolArguments
- Parameters:
arguments- The final arguments to be passed to a JAXB tool (XJC or SchemaGen).toolName- The name of the tool.- Returns:
- the arguments, untouched.
-
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.- Returns:
- The name of the stale file used by this AbstractJavaGeneratorMojo to detect staleness amongst its generated files.
-
getStaleFile
Acquires the staleFile for this execution- Returns:
- the staleFile (used to define where) for this execution
-
getEncoding
The algorithm for finding the encoding to use is as follows (where the first non-null value found is used for encoding):
- If the configuration property is explicitly given within the plugin's configuration, use that value.
- If the Maven property
project.build.sourceEncodingis defined, use its value. - Otherwise use the value from the system property
file.encoding.
- Parameters:
warnIfPlatformEncoding- Defines if a warning should be logged if encoding is not configured but the platform encoding (system propertyfile.encoding) is used- Returns:
- The encoding to be used by this AbstractJaxbMojo and its tools.
- See Also:
-
getEpisodeFile
protected File getEpisodeFile(String episodeFileName) throws org.apache.maven.plugin.MojoExecutionException Retrieves a File to the JAXB Episode (which is normally written during the XJC process). Moreover, ensures that the parent directory of that File is created, to enable writing the File.- Parameters:
episodeFileName-nullto indicate that the standard episode file name ("sun-jaxb.episode") should be used, and otherwise a non-empty name which should be used as the episode file name.- Returns:
- A non-null File where the JAXB episode file should be written.
- Throws:
org.apache.maven.plugin.MojoExecutionException- if the parent directory of the episode file could not be created.
-
logSystemPropertiesAndBasedir
protected void logSystemPropertiesAndBasedir()Prints out the system properties to the Maven Log at Debug level.
-