Class AbstractJaxbMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
AbstractJavaGeneratorMojo
,AbstractXsdGeneratorMojo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.sonatype.plexus.build.incremental.BuildContext
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.static final Pattern
Pattern matching strings containing whitespace (or consisting only of whitespace).private String
Defines the encoding used by XJC (for generating Java Source files) and schemagen (for generating XSDs).private org.apache.maven.plugin.MojoExecution
Note that the execution parameter will be injected ONLY if this plugin is executed as part of a maven standard lifecycle - as opposed to directly invoked with a direct invocation.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 String
A Locale definition to create and set the system (default) Locale when the XJB or SchemaGen tools executes.static final String
Platform-independent newline control string.private static final String
static final String
Standard name of the package-info.java file which may contain JAXB annotations and Package JavaDoc.private org.apache.maven.project.MavenProject
The injected Maven project.protected File
The directory where the staleFile is found.static final String
Standard name of the generated JAXB episode file.Standard excludes Filters for all Java generator Mojos.private static final String[]
private static final String[]
private static final String
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
addResource
(org.apache.maven.model.Resource resource) Adds the supplied Resource to the project using the appropriate scope (i.e.final void
execute()
protected final org.sonatype.plexus.build.incremental.BuildContext
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.Retrieves the configured List of paths from which this AbstractJaxbMojo and its internal toolset (XJC or SchemaGen) should read bytecode classes.protected final String
getEncoding
(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 File
getEpisodeFile
(String episodeFileName) Retrieves a File to the JAXB Episode (which is normally written during the XJC process).org.apache.maven.plugin.MojoExecution
private <T> T
getInjectedObject
(T objectOrNull, String objectName) protected abstract File
Retrieves the directory where the generated files should be written to.protected final org.apache.maven.project.MavenProject
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 final File
Acquires the staleFile for this executionprotected abstract String
Retrieves the last name part of the stale file.protected abstract boolean
protected final String[]
logAndReturnToolArguments
(String[] arguments, String toolName) private void
protected void
Prints out the system properties to the Maven Log at Debug level.protected abstract boolean
Implement this method to perform this Mojo's execution.protected abstract boolean
Implement this method to check if this AbstractJaxbMojo should skip executing altogether.private void
protected void
warnAboutIncorrectPluginConfiguration
(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.
-
RELEVANT_GROUPIDS
-
OWN_ARTIFACT_ID
- See Also:
-
SYSTEM_FILE_ENCODING_PROPERTY
- See Also:
-
STANDARD_EXCLUDE_SUFFIXES
-
STANDARD_PRELOADED_CLASSES
-
buildContext
@Component private org.sonatype.plexus.build.incremental.BuildContext 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. -
project
@Parameter(defaultValue="${project}", readonly=true) private org.apache.maven.project.MavenProject projectThe injected Maven project. -
execution
@Parameter(defaultValue="${mojoExecution}", readonly=true) private org.apache.maven.plugin.MojoExecution executionNote that the execution parameter will be injected ONLY if this plugin is executed as part of a maven standard lifecycle - as opposed to directly invoked with a direct invocation. When firing this mojo directly (i.e.mvn xjc:something
ormvn schemagen:something
), theexecution
object will not be injected. -
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
-
encoding
Defines the encoding used by XJC (for generating Java Source files) and schemagen (for generating XSDs). The corresponding argument parameter for XJC and SchemaGen is:
encoding
.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.sourceEncoding
is defined, use its value. - Otherwise use the value from the system property
file.encoding
.
- Since:
- 2.0
- See Also:
-
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,SE
orfr
. 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.MyCoolEnvironmentFacetImplementation
class 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.MojoExecutionException
org.apache.maven.plugin.MojoFailureException
-
shouldExecutionBeSkipped
protected abstract boolean shouldExecutionBeSkipped()Implement this method to check if this AbstractJaxbMojo should skip executing altogether.- Returns:
true
to indicate that this AbstractJaxbMojo should bail out of its execute method.
-
isReGenerationRequired
protected abstract boolean isReGenerationRequired()- Returns:
true
to indicate that this AbstractJaxbMojo should be run since its generated files were either stale or not present, andfalse
otherwise.
-
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:
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
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.sourceEncoding
is 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
-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.- 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.
-
logPluginAndJaxbDependencyInfo
private void logPluginAndJaxbDependencyInfo() -
getInjectedObject
-
updateStaleFileTimestamp
private void updateStaleFileTimestamp() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
logSystemPropertiesAndBasedir
protected void logSystemPropertiesAndBasedir()Prints out the system properties to the Maven Log at Debug level.
-