public abstract class AbstractJaxbMojo
extends org.apache.maven.plugin.AbstractMojo
Modifier and Type | Field and Description |
---|---|
static Pattern |
CONTAINS_WHITESPACE
Pattern matching strings containing whitespace (or consisting only of whitespace).
|
protected List<EnvironmentFacet> |
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.
|
protected String |
locale
A Locale definition to create and set the system (default) Locale when the XJB or SchemaGen tools executes.
|
static String |
NEWLINE
Platform-independent newline control string.
|
static String |
PACKAGE_INFO_FILENAME
Standard name of the package-info.java file which may contain
JAXB annotations and Package JavaDoc.
|
protected File |
staleFileDirectory
The directory where the staleFile is found.
|
static String |
STANDARD_EPISODE_FILENAME
Standard name of the generated JAXB episode file.
|
static List<Filter<File>> |
STANDARD_EXCLUDE_FILTERS
Standard excludes Filters for all Java generator Mojos.
|
Constructor and Description |
---|
AbstractJaxbMojo() |
Modifier and Type | Method and Description |
---|---|
void |
execute() |
protected 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.
|
protected abstract List<String> |
getClasspath()
Retrieves the configured List of paths from which this AbstractJaxbMojo and its internal toolset
(XJC or SchemaGen) should read bytecode classes.
|
protected String |
getEncoding(boolean warnIfConfiguredEncodingDiffersFromFileEncoding)
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.
|
protected File |
getEpisodeFile(String customEpisodeFileName)
Retrieves the JAXB episode File, and ensures that the parent directory where it exists is created.
|
org.apache.maven.plugin.MojoExecution |
getExecution() |
protected abstract File |
getOutputDirectory()
Retrieves the directory where the generated files should be written to.
|
protected org.apache.maven.project.MavenProject |
getProject() |
protected abstract List<URL> |
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).
|
protected File |
getStaleFile()
Acquires the staleFile for this execution
|
protected abstract String |
getStaleFileName()
Retrieves the last name part of the stale file.
|
protected abstract boolean |
isReGenerationRequired() |
protected String[] |
logAndReturnToolArguments(String[] arguments,
String toolName) |
protected void |
logSystemPropertiesAndBasedir()
Prints out the system properties to the Maven Log at Debug level.
|
protected abstract boolean |
performExecution()
Implement this method to perform this Mojo's execution.
|
protected abstract boolean |
shouldExecutionBeSkipped()
Implement this method to check if this AbstractJaxbMojo should skip executing altogether.
|
protected void |
warnAboutIncorrectPluginConfiguration(String propertyName,
String description)
Convenience method to invoke when some plugin configuration is incorrect.
|
public static final String STANDARD_EPISODE_FILENAME
public static final String PACKAGE_INFO_FILENAME
public static final String NEWLINE
public static final Pattern CONTAINS_WHITESPACE
public static final List<Filter<File>> STANDARD_EXCLUDE_FILTERS
@Parameter(defaultValue="${project.build.directory}/jaxb2", readonly=true, required=true) protected File staleFileDirectory
The 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.
@Parameter(required=false) protected String 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 as sv,SE
or fr
. Refer to
org.codehaus.mojo.jaxb2.shared.environment.locale.LocaleFacet.createFor(String, Log)
for further
information.
Example (assigns french locale):
<configuration>
<locale>fr</locale>
</configuration>
LocaleFacet.createFor(String, Log)
,
Locale.getAvailableLocales()
@Parameter(required=false) protected List<EnvironmentFacet> 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
, its setup()
method is called before the
XJC or SchemaGen tools are executed to setup some facet of their Execution environment. Correspondingly, the
restore()
method in your org.acme.MyCoolEnvironmentFacetImplementation
class is invoked after
the XJC or SchemaGen execution terminates.
<configuration>
...
<extraFacets>
<extraFacet implementation="org.acme.MyCoolEnvironmentFacetImplementation" />
</extraFacets>
...
</configuration>
EnvironmentFacet
,
ToolExecutionEnvironment.add(EnvironmentFacet)
protected final org.sonatype.plexus.build.incremental.BuildContext getBuildContext()
protected final org.apache.maven.project.MavenProject getProject()
public org.apache.maven.plugin.MojoExecution getExecution()
public final void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureException
protected abstract boolean shouldExecutionBeSkipped()
true
to indicate that this AbstractJaxbMojo should bail out of its execute method.protected abstract boolean isReGenerationRequired()
true
to indicate that this AbstractJaxbMojo should be run since its generated files were
either stale or not present, and false
otherwise.protected abstract 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()
.
true
if the timestamp of the stale file should be updated.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.protected abstract List<URL> getSources()
protected abstract File getOutputDirectory()
protected abstract List<String> getClasspath() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
- if the classpath could not be retrieved.protected void warnAboutIncorrectPluginConfiguration(String propertyName, String description)
propertyName
- The name of the problematic property.description
- The problem description.protected final String[] logAndReturnToolArguments(String[] arguments, String toolName)
arguments
- The final arguments to be passed to a JAXB tool (XJC or SchemaGen).toolName
- The name of the tool.protected abstract String getStaleFileName()
"." + getExecution().getExecutionId()
before this staleFileName.protected final File getStaleFile()
protected final String getEncoding(boolean warnIfConfiguredEncodingDiffersFromFileEncoding)
The algorithm for finding the encoding to use is as follows (where the first non-null value found is used for encoding):
project.build.sourceEncoding
is defined, use its value.file.encoding
.warnIfConfiguredEncodingDiffersFromFileEncoding
- Defines if the configured encoding is not equal to the
system property file.encoding
, emit a warning
on the Maven Log (implies that the Maven log has to be
warnEnabled).encoding
protected File getEpisodeFile(String customEpisodeFileName) throws org.apache.maven.plugin.MojoExecutionException
customEpisodeFileName
- null
to 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.org.apache.maven.plugin.MojoExecutionException
- if the parent directory of the episode file could not be created.protected void logSystemPropertiesAndBasedir()
Copyright © 2005–2015 MojoHaus. All rights reserved.