public abstract class AbstractJomcMojo extends AbstractMojo
JomcTool
s.Constructor and Description |
---|
AbstractJomcMojo()
Creates a new
AbstractJomcMojo instance. |
Modifier and Type | Method and Description |
---|---|
protected void |
assertValidParameters()
Validates the parameters of the goal.
|
protected void |
assertValidResources(Collection<? extends ResourceType> resources)
Validates a given resource collection.
|
protected void |
copyDirectory(File source,
File target)
Copies a directory recursively.
|
protected void |
copyFile(File source,
File target)
Deprecated.
This method will be removed in 2.0 due to availability of Java 7 file copying features.
|
protected ClassFileProcessor |
createClassFileProcessor(ModelContext context)
Creates a new tool instance for processing class files.
|
protected <T extends JomcTool> |
createJomcTool(ModelContext context,
String className,
Class<T> type)
Creates a new
JomcTool object for a given class name and type. |
protected ModelContext |
createModelContext(ClassLoader classLoader)
Creates a new model context instance for a given class loader.
|
protected <T> T |
createObject(ModelContext modelContext,
String className,
Class<T> type)
Creates a new object for a given class name and type.
|
protected <T> T |
createObject(String className,
Class<T> type)
Deprecated.
As of JOMC 1.8, replaced by method
createObject(org.jomc.modlet.ModelContext, java.lang.String, java.lang.Class) .
This method will be removed in JOMC 2.0. |
protected ResourceFileProcessor |
createResourceFileProcessor(ModelContext context)
Creates a new tool instance for processing resource files.
|
protected SourceFileProcessor |
createSourceFileProcessor(ModelContext context)
Creates a new tool instance for processing source files.
|
void |
execute() |
protected abstract void |
executeTool()
Executes this tool.
|
protected File |
getAbsoluteFile(String name)
Gets an absolute
File instance for a given name. |
protected URL |
getDirectory(String location)
Creates an
URL for a given directory location. |
protected abstract String |
getExecutionStrategy()
Gets the execution strategy of the instance.
|
protected ExecutorService |
getExecutorService()
Gets the
ExecutorService used to run tasks in parallel. |
protected abstract String |
getGoal()
Gets the goal of the instance.
|
protected ClassLoader |
getMainClassLoader()
Gets the project's runtime class loader of the instance.
|
protected Set<String> |
getMainClasspathElements()
Gets the project's runtime class path elements.
|
protected MavenProject |
getMavenProject()
Gets the Maven project of the instance.
|
protected MavenSession |
getMavenSession()
Gets the Maven session of the instance.
|
protected String |
getModel()
Gets the identifier of the model to process.
|
protected Model |
getModel(ModelContext context)
Gets the model to process.
|
protected String |
getModuleName()
Gets the name of the module to process.
|
protected File |
getOutputDirectory()
Gets the directory holding the compiled class files of the project.
|
protected Properties |
getProperties(ModelContext modelContext,
PropertiesResourceType propertiesResourceType)
Creates a new
Properties instance from a PropertiesResourceType . |
protected Properties |
getProperties(PropertiesResourceType propertiesResourceType)
Deprecated.
As of JOMC 1.8, replaced by method
getProperties(org.jomc.modlet.ModelContext, org.jomc.mojo.PropertiesResourceType) .
This method will be removed in JOMC 2.0. |
protected File |
getReportOutputDirectory()
Gets the directory holding the reports of the project.
|
protected URL |
getResource(ModelContext modelContext,
String location)
Creates an
URL for a given resource location. |
protected URL |
getResource(String location)
Deprecated.
As of JOMC 1.8, replaced by method
getResource(org.jomc.modlet.ModelContext, java.lang.String) .
This method will be removed in JOMC 2.0. |
protected File |
getSessionDirectory()
Gets the directory holding the session related files of the project.
|
protected File |
getSourceDirectory()
Gets the directory holding the source files of the project.
|
protected ClassLoader |
getTestClassLoader()
Gets the project's test class loader of the instance.
|
protected Set<String> |
getTestClasspathElements()
Gets the project's test class path elements.
|
protected String |
getTestModuleName()
Gets the name of the test module to process.
|
protected File |
getTestOutputDirectory()
Gets the directory holding the compiled test class files of the project.
|
protected File |
getTestSourceDirectory()
Gets the directory holding the test source files of the project.
|
protected Transformer |
getTransformer(ModelContext modelContext,
TransformerResourceType resource)
Creates a new
Transformer from a given TransformerResourceType . |
protected Transformer |
getTransformer(TransformerResourceType resource)
Deprecated.
As of JOMC 1.8, replaced by method
getTransformer(org.jomc.modlet.ModelContext, org.jomc.mojo.TransformerResourceType) .
This method will be removed in JOMC 2.0. |
protected boolean |
isClassProcessingEnabled()
Gets a flag indicating the processing of classes is enabled.
|
protected boolean |
isExecutionPermitted()
Gets a flag indicating the current execution is permitted.
|
protected boolean |
isLoggable(Level level)
Tests if messages at a given level are logged.
|
protected boolean |
isModelObjectClasspathResolutionEnabled()
Gets a flag indicating model object class path resolution is enabled.
|
protected boolean |
isModelProcessingEnabled()
Gets a flag indicating the processing of models is enabled.
|
protected boolean |
isResourceProcessingEnabled()
Gets a flag indicating the processing of resources is enabled.
|
protected boolean |
isSourceProcessingEnabled()
Gets a flag indicating the processing of sources is enabled.
|
protected boolean |
isVerbose()
Gets a flag indicating verbose output is enabled.
|
protected void |
log(Level level,
String message,
Throwable throwable)
Logs a message and throwable at a given level.
|
protected void |
log(ModelContext context,
Level level,
ModelValidationReport report)
Logs a
ModelValidationReport . |
protected void |
logMissingModule(String module)
Logs a message stating that a module has not been found.
|
protected void |
logProcessingModel(String toolName,
String model)
Logs a message stating a tool is starting to process a model.
|
protected void |
logProcessingModule(String toolName,
String module)
Logs a message stating a tool is starting to process a module.
|
protected void |
logSeparator()
Logs a separator.
|
protected void |
logSeparator(Level level)
Deprecated.
As of JOMC 1.1, please use method
logSeparator() . This method will be removed in version
2.0. |
protected void |
logToolSuccess(String toolName)
Logs a message stating that a tool successfully completed execution.
|
protected void |
setClassProcessingEnabled(boolean value)
Sets the flag indicating the processing of classes is enabled.
|
protected void |
setModelObjectClasspathResolutionEnabled(boolean value)
Sets the flag indicating model object class path resolution is enabled.
|
protected void |
setModelProcessingEnabled(boolean value)
Sets the flag indicating the processing of models is enabled.
|
protected void |
setResourceProcessingEnabled(boolean value)
Sets the flag indicating the processing of resources is enabled.
|
protected void |
setSourceProcessingEnabled(boolean value)
Sets the flag indicating the processing of sources is enabled.
|
protected void |
setupJomcTool(ModelContext context,
JomcTool tool)
Configures a
JomcTool instance. |
protected void |
setupModelContext(ModelContext context)
Configures a
ModelContext instance. |
protected void |
setVerbose(boolean value)
Sets the flag indicating verbose output is enabled.
|
getLog, getPluginContext, setLog, setPluginContext
public AbstractJomcMojo()
AbstractJomcMojo
instance.public void execute() throws MojoExecutionException, MojoFailureException
protected void assertValidParameters() throws MojoFailureException
MojoFailureException
- if illegal parameter values are detected.assertValidResources(java.util.Collection)
protected final void assertValidResources(Collection<? extends ResourceType> resources) throws MojoFailureException
resources
- The resource collection to validate or null
.MojoFailureException
- if a location property of a given resource holds a null
value or a given
PropertiesResourceType
holds an illegal format.assertValidParameters()
,
PropertiesResourceType.isFormatSupported(java.lang.String)
protected abstract void executeTool() throws Exception
Exception
- if execution of this tool fails.protected abstract String getGoal() throws MojoExecutionException
MojoExecutionException
- if getting the goal of the instance fails.protected abstract String getExecutionStrategy() throws MojoExecutionException
MojoExecutionException
- if getting the execution strategy of the instance fails.protected boolean isExecutionPermitted() throws MojoExecutionException
true
, if the current execution is permitted; false
, if the current execution is
suppressed.MojoExecutionException
- if getting the flag fails.getGoal()
,
getExecutionStrategy()
protected final ExecutorService getExecutorService()
ExecutorService
used to run tasks in parallel.ExecutorService
used to run tasks in parallel or null
.protected MavenProject getMavenProject() throws MojoExecutionException
MojoExecutionException
- if getting the Maven project of the instance fails.protected MavenSession getMavenSession() throws MojoExecutionException
MojoExecutionException
- if getting the Maven session of the instance fails.protected File getAbsoluteFile(String name) throws MojoExecutionException
File
instance for a given name.
This method constructs a new File
instance using the given name. If the resulting file is not
absolute, the value of the basedir
property of the current Maven project is prepended.
name
- The name to get an absolute File
instance for.File
instance constructed from name
.MojoExecutionException
- if getting an absolute File
instance for name
fails.NullPointerException
- if name
is null
.protected File getOutputDirectory() throws MojoExecutionException
MojoExecutionException
- if getting the directory fails.protected File getTestOutputDirectory() throws MojoExecutionException
MojoExecutionException
- if getting the directory fails.protected File getSourceDirectory() throws MojoExecutionException
MojoExecutionException
- if getting the directory fails.protected File getTestSourceDirectory() throws MojoExecutionException
MojoExecutionException
- if getting the directory fails.protected File getSessionDirectory() throws MojoExecutionException
MojoExecutionException
- if getting the directory fails.protected File getReportOutputDirectory() throws MojoExecutionException
MojoExecutionException
- if getting the directory fails.protected ClassLoader getMainClassLoader() throws MojoExecutionException
MojoExecutionException
- if getting the class loader fails.protected ClassLoader getTestClassLoader() throws MojoExecutionException
MojoExecutionException
- if getting the class loader fails.protected Set<String> getMainClasspathElements() throws MojoExecutionException
MojoExecutionException
- if getting the class path elements fails.protected Set<String> getTestClasspathElements() throws MojoExecutionException
MojoExecutionException
- if getting the class path elements fails.protected final boolean isVerbose() throws MojoExecutionException
true
, if verbose output is enabled; false
, if information messages are suppressed.MojoExecutionException
- if getting the flag fails.protected final void setVerbose(boolean value) throws MojoExecutionException
value
- true
, to enable verbose output; false
, to suppress information messages.MojoExecutionException
- if setting the flag fails.protected final boolean isSourceProcessingEnabled() throws MojoExecutionException
true
, if processing of sources is enabled; false
, else.MojoExecutionException
- if getting the flag fails.protected final void setSourceProcessingEnabled(boolean value) throws MojoExecutionException
value
- true
, to enable processing of sources; false
, to disable processing of sources.MojoExecutionException
- if setting the flag fails.protected final boolean isResourceProcessingEnabled() throws MojoExecutionException
true
, if processing of resources is enabled; false
, else.MojoExecutionException
- if getting the flag fails.protected final void setResourceProcessingEnabled(boolean value) throws MojoExecutionException
value
- true
, to enable processing of resources; false
, to disable processing of resources.MojoExecutionException
- if setting the flag fails.protected final boolean isClassProcessingEnabled() throws MojoExecutionException
true
, if processing of classes is enabled; false
, else.MojoExecutionException
- if getting the flag fails.protected final void setClassProcessingEnabled(boolean value) throws MojoExecutionException
value
- true
, to enable processing of classes; false
, to disable processing of classes.MojoExecutionException
- if setting the flag fails.protected final boolean isModelProcessingEnabled() throws MojoExecutionException
true
, if processing of models is enabled; false
, else.MojoExecutionException
- if getting the flag fails.protected final void setModelProcessingEnabled(boolean value) throws MojoExecutionException
value
- true
, to enable processing of models; false
, to disable processing of models.MojoExecutionException
- if setting the flag fails.protected final boolean isModelObjectClasspathResolutionEnabled() throws MojoExecutionException
true
, if model object class path resolution is enabled; false
, else.MojoExecutionException
- if getting the flag fails.protected final void setModelObjectClasspathResolutionEnabled(boolean value) throws MojoExecutionException
value
- true
, to enable model object class path resolution; false
, to disable model object
class path resolution.MojoExecutionException
- if setting the flag fails.protected String getModel() throws MojoExecutionException
MojoExecutionException
- if getting the identifier fails.protected String getModuleName() throws MojoExecutionException
MojoExecutionException
- if getting the name of the module fails.protected String getTestModuleName() throws MojoExecutionException
MojoExecutionException
- if getting the name of the test module fails.protected Model getModel(ModelContext context) throws MojoExecutionException
context
- The model context to get the model to process with.NullPointerException
- if context
is null
.MojoExecutionException
- if getting the model fails.protected ModelContext createModelContext(ClassLoader classLoader) throws MojoExecutionException
classLoader
- The class loader to use for creating the context.classLoader
.MojoExecutionException
- if creating the model context fails.setupModelContext(org.jomc.modlet.ModelContext)
protected SourceFileProcessor createSourceFileProcessor(ModelContext context) throws MojoExecutionException
context
- The context of the tool.NullPointerException
- if context
is null
.MojoExecutionException
- if creating a new tool instance fails.createJomcTool(org.jomc.modlet.ModelContext, java.lang.String, java.lang.Class)
protected ResourceFileProcessor createResourceFileProcessor(ModelContext context) throws MojoExecutionException
context
- The context of the tool.NullPointerException
- if context
is null
.MojoExecutionException
- if creating a new tool instance fails.createJomcTool(org.jomc.modlet.ModelContext, java.lang.String, java.lang.Class)
protected ClassFileProcessor createClassFileProcessor(ModelContext context) throws MojoExecutionException
context
- The context of the tool.NullPointerException
- if context
is null
.MojoExecutionException
- if creating a new tool instance fails.createJomcTool(org.jomc.modlet.ModelContext, java.lang.String, java.lang.Class)
protected <T extends JomcTool> T createJomcTool(ModelContext context, String className, Class<T> type) throws MojoExecutionException
JomcTool
object for a given class name and type.T
- The type of the object to create.context
- The context of the tool.className
- The name of the class to create an object of.type
- The class of the type of object to create.className
.NullPointerException
- if context
, className
or type
is null
.MojoExecutionException
- if creating a new JomcTool
object fails.createObject(org.jomc.modlet.ModelContext, java.lang.String, java.lang.Class)
,
setupJomcTool(org.jomc.modlet.ModelContext, org.jomc.tools.JomcTool)
@Deprecated protected <T> T createObject(String className, Class<T> type) throws MojoExecutionException
createObject(org.jomc.modlet.ModelContext, java.lang.String, java.lang.Class)
.
This method will be removed in JOMC 2.0.T
- The type of the object to create.className
- The name of the class to create an object of.type
- The class of the type of object to create.className
.NullPointerException
- if className
or type
is null
.MojoExecutionException
- if creating a new object fails.protected <T> T createObject(ModelContext modelContext, String className, Class<T> type) throws MojoExecutionException
T
- The type of the object to create.modelContext
- The model context to search.className
- The name of the class to create an object of.type
- The class of the type of object to create.className
.NullPointerException
- if modelContext
, className
or type
is null
.MojoExecutionException
- if creating a new object fails.@Deprecated protected URL getResource(String location) throws MojoExecutionException
getResource(org.jomc.modlet.ModelContext, java.lang.String)
.
This method will be removed in JOMC 2.0.URL
for a given resource location.
This method first searches the class path of the plugin for a single resource matching location
. If
such a resource is found, the URL of that resource is returned. If no such resource is found, an attempt is made
to parse the given location to an URL. On successful parsing, that URL is returned. Failing that, the given
location is interpreted as a file name relative to the project's base directory. If that file is found, the URL
of that file is returned. Otherwise null
is returned.
location
- The location to create an URL
from.URL
for location
or null
, if parsing location
to an URL fails and
location
points to a non-existent resource.NullPointerException
- if location
is null
.MojoExecutionException
- if creating an URL fails.protected URL getResource(ModelContext modelContext, String location) throws MojoExecutionException
URL
for a given resource location.
This method first searches the given model context for a single resource matching location
. If such a
resource is found, the URL of that resource is returned. If no such resource is found, an attempt is made to
parse the given location to an URL. On successful parsing, that URL is returned. Failing that, the given location
is interpreted as a file name relative to the project's base directory. If that file is found, the URL of that
file is returned. Otherwise null
is returned.
modelContext
- The model conext to search.location
- The location to create an URL
from.URL
for location
or null
, if parsing location
to an URL fails and
location
points to a non-existent resource.NullPointerException
- if modelContext
or location
is null
.MojoExecutionException
- if creating an URL fails.protected URL getDirectory(String location) throws MojoExecutionException
URL
for a given directory location.
This method first attempts to parse the given location to an URL. On successful parsing, that URL is returned.
Failing that, the given location is interpreted as a directory name relative to the project's base directory.
If that directory is found, the URL of that directory is returned. Otherwise null
is returned.
location
- The directory location to create an URL
from.URL
for location
or null
, if parsing location
to an URL fails and
location
points to a non-existent directory.NullPointerException
- if location
is null
.MojoExecutionException
- if creating an URL fails.@Deprecated protected Transformer getTransformer(TransformerResourceType resource) throws MojoExecutionException
getTransformer(org.jomc.modlet.ModelContext, org.jomc.mojo.TransformerResourceType)
.
This method will be removed in JOMC 2.0.Transformer
from a given TransformerResourceType
.resource
- The resource to initialize the transformer with.Transformer
for resource
or null
, if resource
is not found and flagged
optional.NullPointerException
- if resource
is null
.MojoExecutionException
- if creating a transformer fails.getResource(java.lang.String)
protected Transformer getTransformer(ModelContext modelContext, TransformerResourceType resource) throws MojoExecutionException
Transformer
from a given TransformerResourceType
.modelContext
- The model context to search.resource
- The resource to initialize the transformer with.Transformer
for resource
or null
, if resource
is not found and flagged
optional.NullPointerException
- if modelContext
or resource
is null
.MojoExecutionException
- if creating a transformer fails.getResource(org.jomc.modlet.ModelContext, java.lang.String)
@Deprecated protected Properties getProperties(PropertiesResourceType propertiesResourceType) throws MojoExecutionException
getProperties(org.jomc.modlet.ModelContext, org.jomc.mojo.PropertiesResourceType)
.
This method will be removed in JOMC 2.0.Properties
instance from a PropertiesResourceType
.propertiesResourceType
- The PropertiesResourceType
specifying the properties to create.propertiesResourceType
.NullPointerException
- if propertiesResourceType
is null
.MojoExecutionException
- if loading properties fails.getResource(java.lang.String)
protected Properties getProperties(ModelContext modelContext, PropertiesResourceType propertiesResourceType) throws MojoExecutionException
Properties
instance from a PropertiesResourceType
.modelContext
- The model context to search.propertiesResourceType
- The PropertiesResourceType
specifying the properties to create.propertiesResourceType
.NullPointerException
- if modelContext
or propertiesResourceType
is null
.MojoExecutionException
- if loading properties fails.getResource(org.jomc.modlet.ModelContext, java.lang.String)
protected boolean isLoggable(Level level) throws MojoExecutionException
level
- The level to test.true
, if messages at level
are logged; false
, if messages at level
are
suppressed.NullPointerException
- if level
is null
.MojoExecutionException
- if testing the level fails.isVerbose()
@Deprecated protected void logSeparator(Level level) throws MojoExecutionException
logSeparator()
. This method will be removed in version
2.0.level
- The level to log a separator at.MojoExecutionException
- if logging fails.protected void logSeparator() throws MojoExecutionException
MojoExecutionException
- if logging fails.protected void logProcessingModule(String toolName, String module) throws MojoExecutionException
toolName
- The tool starting execution.module
- The module getting processed.MojoExecutionException
- if logging fails.protected void logProcessingModel(String toolName, String model) throws MojoExecutionException
toolName
- The tool starting execution.model
- The model getting processed.MojoExecutionException
- if logging fails.protected void logMissingModule(String module) throws MojoExecutionException
module
- The module not having been found.MojoExecutionException
- if logging fails.protected void logToolSuccess(String toolName) throws MojoExecutionException
toolName
- The name of the tool.MojoExecutionException
- if logging fails.protected void log(ModelContext context, Level level, ModelValidationReport report) throws MojoExecutionException
ModelValidationReport
.context
- The context to use when marshalling detail elements of the report.level
- The level to log at.report
- The report to log.MojoExecutionException
- if logging report
fails.protected void log(Level level, String message, Throwable throwable) throws MojoExecutionException
level
- The level to log at.message
- The message to log or null
.throwable
- The throwable to log or null
.MojoExecutionException
- if logging fails.protected void setupModelContext(ModelContext context) throws MojoExecutionException
ModelContext
instance.context
- The model context to configure.NullPointerException
- if context
is null
.MojoExecutionException
- if configuring context
fails.protected void setupJomcTool(ModelContext context, JomcTool tool) throws MojoExecutionException
JomcTool
instance.context
- The model context to use for configuring tool
.tool
- The tool to configure.NullPointerException
- if context
of tool
is null
.MojoExecutionException
- if configuring tool
fails.@Deprecated protected final void copyFile(File source, File target) throws IOException
source
- The file to copy.target
- The file to copy the source file to.IOException
- if copying fails.protected final void copyDirectory(File source, File target) throws IOException
source
- The directory to copy.target
- The directory to copy to.IOException
- if copying fails.Copyright © 2005–2016 The JOMC Project. All rights reserved.