org.jvnet.jaxb2.maven2
Class XJC2Mojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by org.jvnet.jaxb2.maven2.XJC2Mojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

public class XJC2Mojo
extends org.apache.maven.plugin.AbstractMojo

JAXB 2.x Mojo.

Author:
Aleksei Valikov (valikov@gmx.net)

Nested Class Summary
protected  class XJC2Mojo.JaxbErrorReceiver4Mvn
           
 
Field Summary
protected  java.util.List bindingFiles
          For checking timestamps.
protected  java.util.List schemaFiles
          For checking timestamps.
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
XJC2Mojo()
           
 
Method Summary
protected  void configureCatalogResolver(com.sun.tools.xjc.Options options)
           
 void execute()
          Execute the maven2 mojo to invoke the xjc2 compiler based on any configuration settings.
protected  long findLastModified(java.util.List files, boolean oldest)
           
protected  void gatherDependsFiles(java.util.List inputFiles)
           
protected  java.util.List gatherFiles(java.io.File baseDir, java.lang.String[] includesPattern, java.lang.String[] excludesPattern)
           
protected  void gatherProducesFiles(java.util.List destFiles)
           
static java.lang.String getAllExMsgs(java.lang.Throwable ex, boolean includeExName)
           
static java.lang.String getAllExStackTraces(java.lang.Throwable ex)
           
 java.util.List<java.lang.String> getArgs()
           A list of extra XJC's command-line arguments (items must include the dash '-').
 org.apache.maven.artifact.factory.ArtifactFactory getArtifactFactory()
          Used internally to resolve plugins to their jar files.
protected  java.util.Collection<java.io.File> getArtifactFiles(Artifact[] artifacts, boolean resolveDependencies)
           
 org.apache.maven.artifact.resolver.ArtifactResolver getArtifactResolver()
           
 java.io.File getBindingDirectory()
           The source directory containing the *.xjb binding files.
 java.lang.String[] getBindingExcludes()
          A list of regular expression file search patterns to specify the binding files to be excluded from the bindingIncludes.
 java.lang.String[] getBindingIncludes()
           A list of regular expression file search patterns to specify the binding files to be processed.
 java.io.File getCatalog()
          Specify the catalog file to resolve external entity references (xjc's -catalog option)
 java.lang.String getCatalogResolver()
          Provides the class name of the catalog resolver.
 java.util.List getClasspathElements()
          Project classpath.
 boolean getDebug()
           If 'true', the XJC compiler is set to debug mode (xjc's -debug option)and the 'com.sun.tools.xjc.Options.findServices' property is set, to print any add-on instanciation messages.
 boolean getDisableDefaultExcludes()
          If 'true', maven's default exludes are NOT added to all the excludes lists.
 boolean getEpisode()
           
 java.io.File getEpisodeFile()
           
 java.util.Collection<java.io.File> getEpisodeFiles()
           
 Artifact[] getEpisodes()
           
protected  java.util.List getExcludes(java.util.List origExcludes)
          Modifies input list by adding plexus tools default excludes.
protected  java.lang.String[] getExcludes(java.lang.String[] origExcludes)
           
 boolean getExtension()
          If 'true', the XJC binding compiler will run in the extension mode (xjc's -extension option).
 boolean getForceRegenerate()
          If 'true', no up-to-date check is performed and the XJC always re-generates the sources.
 java.io.File getGenerateDirectory()
           Generated code will be written under this directory.
 java.lang.String getGeneratePackage()
           The generated classes will all be placed under this Java package (xjc's -p option), unless otherwise specified in the schemas.
protected static org.xml.sax.InputSource getInputSource(java.io.File f)
          Converts a File object to an InputSource.
 org.apache.maven.artifact.repository.ArtifactRepository getLocalRepository()
           
 org.apache.maven.project.MavenProjectBuilder getMavenProjectBuilder()
          Artifact factory, needed to download source jars.
 java.lang.String[] getOtherDepends()
          A list of of input files or URLs to consider during the up-to-date.
 Artifact[] getPlugins()
          XJC plugins to be made available to XJC.
 java.util.Collection<java.net.URL> getPluginURLs()
           
 org.apache.maven.project.MavenProject getProject()
           
 boolean getReadOnly()
          If 'true', the generated Java source files are set as read-only (xjc's -readOnly option).
 boolean getRemoveOldOutput()
           If 'true', the [generateDirectory] dir will be deleted before the XJC binding compiler recompiles the source files.
 java.io.File getSchemaDirectory()
          The source directory containing *.xsd schema files.
 java.lang.String[] getSchemaExcludes()
          A list of regular expression file search patterns to specify the schemas to be excluded from the schemaIncludes list.
 java.lang.String[] getSchemaIncludes()
           A list of regular expression file search patterns to specify the schemas to be processed.
 java.lang.String getSchemaLanguage()
          Type of input schema language.
 boolean getStrict()
          If 'true', Perform strict validation of the input schema (xjc's -nv option).
 boolean getVerbose()
           If 'true', the plugin and the XJC compiler are both set to verbose mode (xjc's -verbose option).
protected  java.lang.String getVersionFromDependencies(Artifact artifact, java.util.Set<org.apache.maven.artifact.Artifact> dependencies)
          Returns the version of the artifact as inherited from the dependencies.
 boolean getWriteCode()
          If 'false', the plugin will not write the generated code to disk.
protected static boolean isDefined(java.lang.Object setting, int minimumLength)
          A generic setting validator.
protected  boolean isUpdToDate()
           
protected  void logCalcSettings(java.lang.StringBuffer sb)
          Logs options calculated by mojo parameters.
protected  void logSettings()
          Log the configuration settings.
protected  void logUserSettings(java.lang.StringBuffer sb)
          Logs options defined directly as mojo parameters.
protected static java.lang.String recursiveToString(java.lang.Object setting)
          A generic approach to turning the values inside arrays and collections into toString values.
protected  java.util.Set<org.apache.maven.artifact.Artifact> resolveArtifactDependencies(org.apache.maven.artifact.Artifact artifact)
          This method resolves all transitive dependencies of an artifact.
protected  java.util.Set<org.apache.maven.artifact.Artifact> resolveDependencyArtifacts(org.apache.maven.project.MavenProject theProject)
          This method resolves the dependency artifacts from the project.
protected  void runXJC(com.sun.tools.xjc.Options xjcOpts)
           
 void setArgs(java.util.List<java.lang.String> args)
           
 void setArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory artifactFactory)
           
 void setArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver artifactResolver)
           
 void setBindingDirectory(java.io.File bindingDirectory)
           
 void setBindingExcludes(java.lang.String[] bindingExcludes)
           
 void setBindingIncludes(java.lang.String[] bindingIncludes)
           
 void setCatalog(java.io.File catalog)
           
 void setCatalogResolver(java.lang.String catalogResolver)
           
 void setClasspathElements(java.util.List classpathElements)
           
 void setDebug(boolean debug)
           
 void setDisableDefaultExcludes(boolean disableDefaultExcludes)
           
 void setEpisode(boolean episode)
           
 void setEpisodeFile(java.io.File episodeFile)
           
 void setEpisodes(Artifact[] episodes)
           
 void setExtension(boolean extension)
           
 void setForceRegenerate(boolean forceRegenerate)
           
 void setGenerateDirectory(java.io.File generateDirectory)
           
 void setGeneratePackage(java.lang.String generatePackage)
           
 void setLocalRepository(org.apache.maven.artifact.repository.ArtifactRepository localRepository)
           
 void setMavenProjectBuilder(org.apache.maven.project.MavenProjectBuilder mavenProjectBuilder)
           
 void setOtherDepends(java.lang.String[] otherDepends)
           
 void setPlugins(Artifact[] plugins)
           
 void setProject(org.apache.maven.project.MavenProject project)
           
 void setReadOnly(boolean readOnly)
           
 void setRemoveOldOutput(boolean removeOldOutput)
           
 void setSchemaDirectory(java.io.File schemaDirectory)
           
 void setSchemaExcludes(java.lang.String[] schemaExcludes)
           
 void setSchemaIncludes(java.lang.String[] schemaIncludes)
           
 void setSchemaLanguage(java.lang.String schemaLanguage)
           
 void setStrict(boolean strict)
           
protected  void setupCmdLineArgs(com.sun.tools.xjc.Options xjcOpts)
           
protected  void setupLogging()
          Sets up the verbose and debug mode depending on mvn logging level, and sets up hyperjaxb logging.
protected  com.sun.tools.xjc.Options setupOptions()
          Ensure the any default settings are met and throws exceptions when settings are invalid and also stores the schemas and the bindings files into member vars for calculating timestamps, later.
 void setVerbose(boolean verbose)
           
 void setWriteCode(boolean writeCode)
           
protected  void updateMavenPaths()
          Updates compilePath ans resources.
 
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

schemaFiles

protected java.util.List schemaFiles
For checking timestamps. Modify freely, nothing to do with XJC options.


bindingFiles

protected java.util.List bindingFiles
For checking timestamps. Modify freely, nothing to do with XJC options.

Constructor Detail

XJC2Mojo

public XJC2Mojo()
Method Detail

getVersionFromDependencies

protected java.lang.String getVersionFromDependencies(Artifact artifact,
                                                      java.util.Set<org.apache.maven.artifact.Artifact> dependencies)
Returns the version of the artifact as inherited from the dependencies.

Parameters:
artifact - the artifact for which to return the version.
dependencies - the list of dependencies in which to search for the version.
Returns:
the version of the artifact, or null if dependencies is either null or does not contain the artifact's version.

getArtifactResolver

public org.apache.maven.artifact.resolver.ArtifactResolver getArtifactResolver()

setArtifactResolver

public void setArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver artifactResolver)

getArtifactFactory

public org.apache.maven.artifact.factory.ArtifactFactory getArtifactFactory()
Used internally to resolve plugins to their jar files.


setArtifactFactory

public void setArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory artifactFactory)

getLocalRepository

public org.apache.maven.artifact.repository.ArtifactRepository getLocalRepository()

setLocalRepository

public void setLocalRepository(org.apache.maven.artifact.repository.ArtifactRepository localRepository)

getMavenProjectBuilder

public org.apache.maven.project.MavenProjectBuilder getMavenProjectBuilder()
Artifact factory, needed to download source jars.


setMavenProjectBuilder

public void setMavenProjectBuilder(org.apache.maven.project.MavenProjectBuilder mavenProjectBuilder)

getSchemaLanguage

public java.lang.String getSchemaLanguage()
Type of input schema language. One of: DTD, XMLSCHEMA, RELAXNG, RELAXNG_COMPACT, WSDL, AUTODETECT. If unspecified, it is assumed AUTODETECT.


setSchemaLanguage

public void setSchemaLanguage(java.lang.String schemaLanguage)

getSchemaDirectory

public java.io.File getSchemaDirectory()
The source directory containing *.xsd schema files. Notice that binding files are searched by default in this deriectory.


setSchemaDirectory

public void setSchemaDirectory(java.io.File schemaDirectory)

getSchemaIncludes

public java.lang.String[] getSchemaIncludes()

A list of regular expression file search patterns to specify the schemas to be processed. Searching is based from the root of schemaDirectory.

If left udefined, then all *.xsd files in schemaDirectory will be processed.


setSchemaIncludes

public void setSchemaIncludes(java.lang.String[] schemaIncludes)

getSchemaExcludes

public java.lang.String[] getSchemaExcludes()
A list of regular expression file search patterns to specify the schemas to be excluded from the schemaIncludes list. Searching is based from the root of schemaDirectory.


setSchemaExcludes

public void setSchemaExcludes(java.lang.String[] schemaExcludes)

setBindingDirectory

public void setBindingDirectory(java.io.File bindingDirectory)

getBindingDirectory

public java.io.File getBindingDirectory()

The source directory containing the *.xjb binding files.

If left undefined, then the schemaDirectory is assumed.


getBindingIncludes

public java.lang.String[] getBindingIncludes()

A list of regular expression file search patterns to specify the binding files to be processed. Searching is based from the root of bindingDirectory.

If left undefined, then all *.xjb files in schemaDirectory will be processed.


setBindingIncludes

public void setBindingIncludes(java.lang.String[] bindingIncludes)

getBindingExcludes

public java.lang.String[] getBindingExcludes()
A list of regular expression file search patterns to specify the binding files to be excluded from the bindingIncludes. Searching is based from the root of bindingDirectory.


setBindingExcludes

public void setBindingExcludes(java.lang.String[] bindingExcludes)

getDisableDefaultExcludes

public boolean getDisableDefaultExcludes()
If 'true', maven's default exludes are NOT added to all the excludes lists.


setDisableDefaultExcludes

public void setDisableDefaultExcludes(boolean disableDefaultExcludes)

getCatalog

public java.io.File getCatalog()
Specify the catalog file to resolve external entity references (xjc's -catalog option)

Support TR9401, XCatalog, and OASIS XML Catalog format. See the catalog-resolver sample and this article for details.


setCatalog

public void setCatalog(java.io.File catalog)

getCatalogResolver

public java.lang.String getCatalogResolver()
Provides the class name of the catalog resolver.

Returns:
Class name of the catalog resolver.

setCatalogResolver

public void setCatalogResolver(java.lang.String catalogResolver)

getGeneratePackage

public java.lang.String getGeneratePackage()

The generated classes will all be placed under this Java package (xjc's -p option), unless otherwise specified in the schemas.

If left unspecified, the package will be derived from the schemas only.


setGeneratePackage

public void setGeneratePackage(java.lang.String generatePackage)

getGenerateDirectory

public java.io.File getGenerateDirectory()

Generated code will be written under this directory.

For instance, if you specify generateDirectory="doe/ray" and generatePackage="org.here", then files are generated to doe/ray/org/here.


setGenerateDirectory

public void setGenerateDirectory(java.io.File generateDirectory)

getReadOnly

public boolean getReadOnly()
If 'true', the generated Java source files are set as read-only (xjc's -readOnly option).


setReadOnly

public void setReadOnly(boolean readOnly)

getExtension

public boolean getExtension()
If 'true', the XJC binding compiler will run in the extension mode (xjc's -extension option). Otherwise, it will run in the strict conformance mode.


setExtension

public void setExtension(boolean extension)

getStrict

public boolean getStrict()
If 'true', Perform strict validation of the input schema (xjc's -nv option).


setStrict

public void setStrict(boolean strict)

getWriteCode

public boolean getWriteCode()
If 'false', the plugin will not write the generated code to disk.


setWriteCode

public void setWriteCode(boolean writeCode)

getVerbose

public boolean getVerbose()

If 'true', the plugin and the XJC compiler are both set to verbose mode (xjc's -verbose option).

It is automatically set to 'true' when maven is run in debug mode (mvn's -X option).


setVerbose

public void setVerbose(boolean verbose)

getDebug

public boolean getDebug()

If 'true', the XJC compiler is set to debug mode (xjc's -debug option)and the 'com.sun.tools.xjc.Options.findServices' property is set, to print any add-on instanciation messages.

It is automatically set to 'true' when maven is run in debug mode (mvn's -X option).


setDebug

public void setDebug(boolean debug)

getArgs

public java.util.List<java.lang.String> getArgs()

A list of extra XJC's command-line arguments (items must include the dash '-').

Arguments set here take precedence over other mojo parameters.


setArgs

public void setArgs(java.util.List<java.lang.String> args)

getForceRegenerate

public boolean getForceRegenerate()
If 'true', no up-to-date check is performed and the XJC always re-generates the sources.


setForceRegenerate

public void setForceRegenerate(boolean forceRegenerate)

getRemoveOldOutput

public boolean getRemoveOldOutput()

If 'true', the [generateDirectory] dir will be deleted before the XJC binding compiler recompiles the source files.

Note that if set to 'false', the up-to-date check might not work, since XJC does not regenerate all files (i.e. files for "any" elements under 'xjc/org/w3/_2001/xmlschema' directory).


setRemoveOldOutput

public void setRemoveOldOutput(boolean removeOldOutput)

getOtherDepends

public java.lang.String[] getOtherDepends()
A list of of input files or URLs to consider during the up-to-date. By default it always considers: 1. schema files, 2. binding files, 3. catalog file, and 4. the pom.xml file of the project executing this plugin.


setOtherDepends

public void setOtherDepends(java.lang.String[] otherDepends)

getEpisodeFile

public java.io.File getEpisodeFile()

setEpisodeFile

public void setEpisodeFile(java.io.File episodeFile)

getEpisode

public boolean getEpisode()

setEpisode

public void setEpisode(boolean episode)

getClasspathElements

public java.util.List getClasspathElements()
Project classpath. Used internally when runing the XJC compiler.


setClasspathElements

public void setClasspathElements(java.util.List classpathElements)

getProject

public org.apache.maven.project.MavenProject getProject()

setProject

public void setProject(org.apache.maven.project.MavenProject project)

getPlugins

public Artifact[] getPlugins()
XJC plugins to be made available to XJC. They still need to be activated by using <args> and enable plugin activation option.


setPlugins

public void setPlugins(Artifact[] plugins)

getEpisodes

public Artifact[] getEpisodes()

setEpisodes

public void setEpisodes(Artifact[] episodes)

execute

public void execute()
             throws org.apache.maven.plugin.MojoExecutionException
Execute the maven2 mojo to invoke the xjc2 compiler based on any configuration settings.

Throws:
org.apache.maven.plugin.MojoExecutionException

setupOptions

protected com.sun.tools.xjc.Options setupOptions()
                                          throws org.apache.maven.plugin.MojoExecutionException
Ensure the any default settings are met and throws exceptions when settings are invalid and also stores the schemas and the bindings files into member vars for calculating timestamps, later. Exception will cause build to fail.

Throws:
org.apache.maven.plugin.MojoExecutionException

configureCatalogResolver

protected void configureCatalogResolver(com.sun.tools.xjc.Options options)
                                 throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

setupCmdLineArgs

protected void setupCmdLineArgs(com.sun.tools.xjc.Options xjcOpts)
                         throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

setupLogging

protected void setupLogging()
Sets up the verbose and debug mode depending on mvn logging level, and sets up hyperjaxb logging.


logSettings

protected void logSettings()
Log the configuration settings. Shown when exception thrown or when verbose is true.


logUserSettings

protected void logUserSettings(java.lang.StringBuffer sb)
Logs options defined directly as mojo parameters.


logCalcSettings

protected void logCalcSettings(java.lang.StringBuffer sb)
Logs options calculated by mojo parameters.


isUpdToDate

protected boolean isUpdToDate()
                       throws org.apache.maven.plugin.MojoExecutionException
Returns:
true to indicate results are up-to-date, that is, when the latest from input files is earlier than the younger from the output files (meaning no re-execution required).
Throws:
org.apache.maven.plugin.MojoExecutionException

gatherDependsFiles

protected void gatherDependsFiles(java.util.List inputFiles)

gatherProducesFiles

protected void gatherProducesFiles(java.util.List destFiles)
                            throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

runXJC

protected void runXJC(com.sun.tools.xjc.Options xjcOpts)
               throws org.apache.maven.plugin.MojoExecutionException
Parameters:
xjcOpts -
Throws:
org.apache.maven.plugin.MojoExecutionException

updateMavenPaths

protected void updateMavenPaths()
Updates compilePath ans resources.

Throws:
org.apache.maven.plugin.MojoExecutionException

findLastModified

protected long findLastModified(java.util.List files,
                                boolean oldest)
Parameters:
files - the fileNames or URLs to scan their lastModified timestamp.
oldest - if true, returns the latest modificationDate of all files, otherwise returns the earliest.
Returns:
the older or younger last modification timestamp of all files.

getInputSource

protected static org.xml.sax.InputSource getInputSource(java.io.File f)
Converts a File object to an InputSource.


gatherFiles

protected java.util.List gatherFiles(java.io.File baseDir,
                                     java.lang.String[] includesPattern,
                                     java.lang.String[] excludesPattern)
                              throws org.apache.maven.plugin.MojoExecutionException
Parameters:
baseDir -
includesPattern -
excludesPattern -
Returns:
all found absolute files (dirs and files).
Throws:
org.apache.maven.plugin.MojoExecutionException

getExcludes

protected java.lang.String[] getExcludes(java.lang.String[] origExcludes)

getExcludes

protected java.util.List getExcludes(java.util.List origExcludes)
Modifies input list by adding plexus tools default excludes.

Parameters:
origExcludes - a list that must support the 'add' operation.
Returns:
the augmented list or the input unchanged.

isDefined

protected static boolean isDefined(java.lang.Object setting,
                                   int minimumLength)
A generic setting validator. Check for null and zero length of strings, arrays and collections.

Parameters:
setting - the settings to validate
minimumLength - minimum length required.
Returns:
true if setting is not null and has length or more items.

recursiveToString

protected static java.lang.String recursiveToString(java.lang.Object setting)
A generic approach to turning the values inside arrays and collections into toString values.

Parameters:
setting -
Returns:
complete toString values for most contained objects.

getAllExMsgs

public static java.lang.String getAllExMsgs(java.lang.Throwable ex,
                                            boolean includeExName)

getAllExStackTraces

public static java.lang.String getAllExStackTraces(java.lang.Throwable ex)

getPluginURLs

public java.util.Collection<java.net.URL> getPluginURLs()
                                                 throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

getEpisodeFiles

public java.util.Collection<java.io.File> getEpisodeFiles()
                                                   throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

getArtifactFiles

protected java.util.Collection<java.io.File> getArtifactFiles(Artifact[] artifacts,
                                                              boolean resolveDependencies)
                                                       throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

resolveArtifactDependencies

protected java.util.Set<org.apache.maven.artifact.Artifact> resolveArtifactDependencies(org.apache.maven.artifact.Artifact artifact)
                                                                                 throws org.apache.maven.artifact.resolver.ArtifactResolutionException,
                                                                                        org.apache.maven.artifact.resolver.ArtifactNotFoundException,
                                                                                        org.apache.maven.project.ProjectBuildingException,
                                                                                        org.apache.maven.project.artifact.InvalidDependencyVersionException
This method resolves all transitive dependencies of an artifact.

Parameters:
artifact - the artifact used to retrieve dependencies
Returns:
resolved set of dependencies
Throws:
org.apache.maven.artifact.resolver.ArtifactResolutionException
org.apache.maven.artifact.resolver.ArtifactNotFoundException
org.apache.maven.project.ProjectBuildingException
org.apache.maven.project.artifact.InvalidDependencyVersionException

resolveDependencyArtifacts

protected java.util.Set<org.apache.maven.artifact.Artifact> resolveDependencyArtifacts(org.apache.maven.project.MavenProject theProject)
                                                                                throws org.apache.maven.artifact.resolver.ArtifactResolutionException,
                                                                                       org.apache.maven.artifact.resolver.ArtifactNotFoundException,
                                                                                       org.apache.maven.project.artifact.InvalidDependencyVersionException
This method resolves the dependency artifacts from the project.

Parameters:
theProject - The POM.
Returns:
resolved set of dependency artifacts.
Throws:
org.apache.maven.artifact.resolver.ArtifactResolutionException
org.apache.maven.artifact.resolver.ArtifactNotFoundException
org.apache.maven.project.artifact.InvalidDependencyVersionException


Copyright © 2006-2009. All Rights Reserved.