Class TestXjcMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.codehaus.mojo.jaxb2.AbstractJaxbMojo
-
- org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo
-
- org.codehaus.mojo.jaxb2.javageneration.TestXjcMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
@Mojo(name="testXjc", defaultPhase=GENERATE_TEST_SOURCES, requiresDependencyResolution=TEST, threadSafe=false) public class TestXjcMojo extends AbstractJavaGeneratorMojoMojo that creates test-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 TestXjcMojo 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.
- See Also:
- The JAXB Reference Implementation
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.FileoutputDirectoryCorresponding XJC parameter:d.private booleanskipTestXjcIndicate if the XjcMojo execution should be skipped.static java.lang.StringSTALE_FILENAMEThe last part of the stale fileName for this TestXjcMojo.static java.lang.StringSTANDARD_TEST_SOURCE_DIRECTORYStandard directory path (relative to basedir) searched recursively for test source files (typically XSDs), unless overridden by atestSourcesconfiguration element.static java.util.List<Filter<java.io.File>>STANDARD_TEST_SOURCE_EXCLUDE_FILTERSDefault exclude Filters for test sources, used unless overridden by an explicit configuration in thetestSourceExcludeFiltersparameter.static java.lang.StringSTANDARD_TEST_XJB_DIRECTORYStandard directory path (relative to basedir) searched recursively for XJB files, unless overridden by antestXjbSourcesconfiguration element.static java.util.List<Filter<java.io.File>>STANDARD_TEST_XJB_EXCLUDE_FILTERSDefault List of exclude Filters for XJB files, unless overridden by providing an explicit configuration in thetestXjbExcludeFiltersparameter.private java.util.List<Filter<java.io.File>>testSourceExcludeFiltersParameter holding a List of Filters, used to match all files under thetestSourcesdirectories which should not be considered XJC test source files.private java.util.List<java.lang.String>testSourcesParameter holding List of XSD paths to files and/or directories which should be recursively searched for XSD files.private java.util.List<Filter<java.io.File>>testXjbExcludeFiltersParameter holding a List of Filters, used to match all files under thetestXjbSourcesdirectories which should not be considered XJB files.private java.util.List<java.lang.String>testXjbSourcesParameter holding List of XJB Files and/or directories which should be recursively searched for XJB files.-
Fields inherited from class org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo
addGeneratedAnnotation, arguments, catalog, clearOutputDir, episodeFileName, extension, externalEntityProcessing, failOnNoSchemas, generateEpisode, laxSchemaValidation, noGeneratedHeaderComments, noPackageLevelAnnotations, packageName, quiet, readOnly, settings, sourceType, target, verbose, xsdPathWithinArtifact
-
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 TestXjcMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddGeneratedSourcesToProjectSourceRoot()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.protected java.util.List<java.lang.String>getClasspath()Retrieves the configured List of paths from which this AbstractJaxbMojo and its internal toolset (XJC or SchemaGen) should read bytecode classes.protected java.io.FilegetOutputDirectory()Retrieves the directory where the generated files should be written to.protected java.util.List<java.net.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 java.util.List<java.io.File>getSourceXJBs()Override this method to retrieve a list of Files to all XJB files for which this AbstractJavaGeneratorMojo should generate Java files.protected java.lang.StringgetStaleFileName()Retrieves the last name part of the stale file.protected booleanshouldExecutionBeSkipped()Implement this method to check if this AbstractJaxbMojo should skip executing altogether.-
Methods inherited from class org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo
isReGenerationRequired, performExecution
-
Methods inherited from class org.codehaus.mojo.jaxb2.AbstractJaxbMojo
execute, getBuildContext, getEncoding, getEpisodeFile, getExecution, getProject, getStaleFile, logAndReturnToolArguments, logSystemPropertiesAndBasedir, warnAboutIncorrectPluginConfiguration
-
-
-
-
Field Detail
-
STALE_FILENAME
public static final java.lang.String STALE_FILENAME
The last part of the stale fileName for this TestXjcMojo.- See Also:
- Constant Field Values
-
STANDARD_TEST_SOURCE_DIRECTORY
public static final java.lang.String STANDARD_TEST_SOURCE_DIRECTORY
Standard directory path (relative to basedir) searched recursively for test source files (typically XSDs), unless overridden by atestSourcesconfiguration element.- See Also:
- Constant Field Values
-
STANDARD_TEST_SOURCE_EXCLUDE_FILTERS
public static final java.util.List<Filter<java.io.File>> STANDARD_TEST_SOURCE_EXCLUDE_FILTERS
Default exclude Filters for test sources, used unless overridden by an explicit configuration in the
testSourceExcludeFiltersparameter. The default values are found as follows:final List<Filter<File>> xjbTemp = new ArrayList<Filter<File>>(); xjbTemp.addAll(AbstractJaxbMojo.STANDARD_EXCLUDE_FILTERS); xsdTemp.add(new PatternFileFilter(Arrays.asList("\\.xjb"), true)); STANDARD_TEST_SOURCE_EXCLUDE_FILTERS = Collections.unmodifiableList(xsdTemp);
-
STANDARD_TEST_XJB_DIRECTORY
public static final java.lang.String STANDARD_TEST_XJB_DIRECTORY
Standard directory path (relative to basedir) searched recursively for XJB files, unless overridden by an
testXjbSourcesconfiguration 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:
- Constant Field Values
-
STANDARD_TEST_XJB_EXCLUDE_FILTERS
public static final java.util.List<Filter<java.io.File>> STANDARD_TEST_XJB_EXCLUDE_FILTERS
Default List of exclude Filters for XJB files, unless overridden by providing an explicit configuration in the
testXjbExcludeFiltersparameter. 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_TEST_XJB_EXCLUDE_FILTERS = Collections.unmodifiableList(xjbTemp);
-
outputDirectory
@Parameter(defaultValue="${project.build.directory}/generated-test-sources/jaxb", required=true) private java.io.File outputDirectoryCorresponding XJC parameter:
d.The working directory where the generated Java test source files are created.
-
testSources
@Parameter(required=false) private java.util.List<java.lang.String> testSources
Parameter holding List of XSD paths to files and/or directories which should be recursively searched for XSD files. Only files or directories that actually exist will be included (in the case of files) or recursively searched for XSD files to include (in the case of directories). Configure using standard Maven structure for Lists:
<configuration> ... <testSources> <testSource>some/explicit/relative/file.xsd</testSource> <testSource>/another/absolute/path/to/a/specification.xsd</testSource> <testSource>a/directory/holding/xsds</testSource> </testSources> </configuration>- See Also:
STANDARD_TEST_SOURCE_DIRECTORY
-
testXjbSources
@Parameter(required=false) private java.util.List<java.lang.String> testXjbSources
Parameter holding List of XJB Files and/or directories which should be recursively searched for XJB files. Only files or directories that actually exist will be included (in the case of files) or recursively searched for XJB files to include (in the case of directories). JAXB binding files are used to configure parts of the Java source generation. Supply the configuration using the standard Maven structure for configuring plugin Lists:
<configuration> ... <testXjbSources> <testXjbSource>bindings/aBindingConfiguration.xjb</testXjbSource> <testXjbSource>bindings/config/directory</testXjbSource> </testXjbSources> </configuration>- See Also:
STANDARD_TEST_XJB_DIRECTORY
-
testSourceExcludeFilters
@Parameter(required=false) private java.util.List<Filter<java.io.File>> testSourceExcludeFilters
Parameter holding a List of Filters, used to match all files under the
testSourcesdirectories which should not be considered XJC test source files. (The filters identify files to exclude, and hence this parameter is calledtestS§ourceExcludeFilters). If a file under any of the test source directories matches at least one of the Filters supplied in thetestSourceExcludeFilters, it is not considered an XJC source file, and therefore excluded from processing.If not explicitly provided, the Mojo uses the value within
STANDARD_TEST_SOURCE_EXCLUDE_FILTERS. The algorithm for finding XJC test sources is as follows:- Find all files given in the testSources List. Any Directories provided are searched for files recursively.
- Exclude any found files matching any of the supplied
testSourceExcludeFiltersList. - The remaining Files are submitted for processing by the XJC tool.
Example: The following configuration would exclude any sources whose names end with
txtorfoo:<configuration> ... <testSourceExcludeFilters> <suffixFilter impl="org.codehaus.mojo.jaxb2.shared.filters.source.ExclusionRegularExpressionFileFilter">txt</suffixFilter> <suffixFilter impl="org.codehaus.mojo.jaxb2.shared.filters.source.ExclusionRegularExpressionFileFilter">foo</suffixFilter> </testSourceExcludeFilters> </configuration>
-
testXjbExcludeFilters
@Parameter(required=false) private java.util.List<Filter<java.io.File>> testXjbExcludeFilters
Parameter holding a List of Filters, used to match all files under the
testXjbSourcesdirectories which should not be considered XJB files. (The filters identify files to exclude, and hence this parameter is calledtestXjbExcludeFilters). If a file matches at least one of the supplied Filters, it is not considered an XJB file, and therefore excluded from processing.If not explicitly provided, the Mojo uses the value within
STANDARD_TEST_XJB_EXCLUDE_FILTERS.Example: The following configuration would exclude any XJB files whose names end with
xmlorfoo:<configuration> ... <testXjbExcludeFilters> <suffixFilter impl="org.codehaus.mojo.jaxb2.shared.filters.source.ExclusionRegularExpressionFileFilter">xml</suffixFilter> <suffixFilter impl="org.codehaus.mojo.jaxb2.shared.filters.source.ExclusionRegularExpressionFileFilter">foo</suffixFilter> </sourceExcludeFilters> </testXjbExcludeFilters>
-
skipTestXjc
@Parameter(property="xjc.test.skip", defaultValue="false") private boolean skipTestXjcIndicate if the XjcMojo execution should be skipped.
-
-
Method Detail
-
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
protected java.util.List<java.net.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 thesourceTypevalue.- Specified by:
getSourcesin classAbstractJavaGeneratorMojo- Returns:
- A non-null List holding URLs to sources for the XJC generation.
- See Also:
AbstractJavaGeneratorMojo.sourceType
-
getSourceXJBs
protected java.util.List<java.io.File> 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.
-
getStaleFileName
protected java.lang.String 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
protected java.io.File 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
protected java.util.List<java.lang.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.- 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
protected void 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 classAbstractJavaGeneratorMojo
-
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.
-
-