|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.maven.plugin.AbstractMojo
com.edugility.jpa.maven.plugin.AbstractJPAMojo
com.edugility.jpa.maven.plugin.ListEntityClassnamesMojo
public class ListEntityClassnamesMojo
Generates a .properties
file, suitable for use as a Maven
filter,
whose contents are the set of names of classes that have been
annotated with the Entity
, MappedSuperclass
, Embeddable
and IdClass
annotations.
AbstractJPAMojo
,
Entity
,
MappedSuperclass
,
Embeddable
,
IdClass
Field Summary | |
---|---|
private static String |
DEFAULT_DEFAULT_PROPERTY_NAME
The property name to use for classnames that belong to the default package when another default property name cannot be found. |
private static String |
DEFAULT_OUTPUT_FILENAME
The default name used in constructing the outputFile when no output file has been specified
and the return value of the getUseOutputFile() method is
true . |
(package private) static String |
DEFAULT_SUBDIR_PREFIX
The default subdirectory prefix that is added to the value of the current Maven project's build directory when constructing a prefix for non-absolute output file specifications. |
private String |
defaultPropertyName
The property key under which the entity classname listing will be stored. |
private String |
encoding
The character encoding to use when writing the outputFile . |
private String |
firstItemPrefix
The textual prefix to prepend to the list of classnames. |
private static List<String> |
JPA_ANNOTATIONS
The List of JPA
annotations that this ListEntityClassnamesMojo scans for. |
private String |
lastItemSuffix
The suffix to append to the list of classnames. |
private File |
outputFile
The File to which entity- and mapped superclass-annotated
classnames will be written. |
private String |
prefix
The textual prefix to prepend to every element of the list of classnames, excluding the first element. |
private Map<String,String> |
propertyNames
A Map of property names indexed by package prefix
segments. |
private static Pattern |
quotePattern
A workaround for MODELLO-256; a Pattern used to strip initial leading and (matching)
trailing quotes from a String . |
private boolean |
stripQuotes
A workaround for MODELLO-256; if true then values for the prefix ,
suffix , firstItemPrefix and lastItemSuffix
will have any leading and trailing quotes (if they are a matched
pair) removed. |
private String |
suffix
The suffix to append to every element of the list of classnames, excluding the last element. |
private Set<URL> |
urls
The Set of URL s to scan. |
(package private) boolean |
useOutputFile
Whether or not to write properties to an external file. |
Fields inherited from interface org.apache.maven.plugin.Mojo |
---|
ROLE |
Constructor Summary | |
---|---|
ListEntityClassnamesMojo()
Creates a new ListEntityClassnamesMojo . |
Method Summary | |
---|---|
protected AnnotationDB |
createAnnotationDB()
Creates a new AnnotationDB in the (common) case where a
user has not supplied this AbstractJPAMojo with a
pre-configured AnnotationDB . |
protected String |
decorate(String classname,
String prefix,
String suffix)
Decorates the supplied class name with
the supplied prefix and suffix parameters and
returns the result. |
String |
determinePropertyName(String className)
Returns the appropriate property name given a class name. |
void |
execute()
Executes this mojo. |
String |
getDefaultPropertyName()
Returns the property name to use for the names of Class es
that belong to the default package. |
String |
getEncoding()
Returns the encoding used to write the Properties file
that this mojo generates. |
String |
getFirstItemPrefix()
Returns the prefix prepended to the list of classnames. |
String |
getLastItemSuffix()
Returns the suffix appended to the list of classnames. |
File |
getOutputFile()
Returns the output File . |
String |
getPrefix()
Returns the prefix prepended to every element of the list of classnames, excluding the first element. |
String |
getProjectBuildDirectoryName()
Returns this ListEntityClassnamesMojo 's best guess as to
its related Maven project's
build directory. |
Map<String,String> |
getPropertyNames()
Returns a Map of property names indexed by package
fragments. |
String |
getSuffix()
Returns the suffix appended to every element of the list of classnames, excluding the last element. |
private Set<URL> |
getTestClasspathURLs()
Returns a Set of URL s that represents the test
classpath. |
Set<URL> |
getURLs()
Returns the Set of URL s to scan for annotations. |
boolean |
getUseOutputFile()
Returns whether or not this ListEntityClassnamesMojo
should write its properties out to the associated output file . |
private void |
initialize()
Called by the execute() method; initializes all fields
to their defaults if for some reason they were not already set
appropriately. |
private File |
initializeOutputFile()
Initializes the outputFile property and
returns its value. |
(package private) File |
initializeOutputFile(File outputFile)
Validates and "absolutizes" the supplied File and returns
the corrected version. |
private void |
initializePropertyNames()
Called by the initialize() method; sets up the propertyNames field appropriately. |
private Set<URL> |
initializeURLs()
Initializes the Set of URL s to scan and returns it. |
private AnnotationDB |
scan()
Scans the Set of URLs this ListEntityClassnamesMojo has been configured with
and returns the AnnotationDB that performed the scanning. |
void |
setDefaultPropertyName(String defaultPropertyName)
Sets the property name to use for the names of Class es
that belong to the default package. |
void |
setEncoding(String encoding)
Sets the encoding used to write the Properties file that
this mojo generates. |
void |
setFirstItemPrefix(String firstItemPrefix)
Sets the prefix prepended to the list of classnames. |
void |
setLastItemSuffix(String lastItemSuffix)
Sets the suffix appended to the list of classnames. |
void |
setOutputFile(File file)
Sets the File to use as the output file parameter. |
void |
setPrefix(String prefix)
Sets the prefix prepended to every element of the list of classnames, excluding the first element. |
void |
setPropertyNames(Map<String,String> propertyNames)
Sets the Map of property names indexed by package
fragments that will be used to determine under which property
name a given class name should be listed. |
void |
setSuffix(String suffix)
Sets the suffix appended to every element of the list of classnames, excluding the last element. |
void |
setURLs(Set<URL> urls)
Sets the Set of URL s to scan for annotations. |
void |
setUseOutputFile(boolean useOutputFile)
Sets whether or not this ListEntityClassnamesMojo should
write its properties out to the associated output file. |
(package private) String |
stripQuotes(String text)
A workaround for MODELLO-256; strips leading and trailing quotes from the supplied text
parameter value and returns the result. |
private boolean |
validateOutputDirectory(File outputDirectory)
Ensures that the supplied File , after this method is
invoked, will designate a directory that exists and is
writable. |
Methods inherited from class com.edugility.jpa.maven.plugin.AbstractJPAMojo |
---|
cloneAnnotationDB, getProject, getURLFilter, scan, setAnnotationDB, setProject, setURLFilter |
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 |
---|
private static final Pattern quotePattern
Pattern
used to strip initial leading and (matching)
trailing quotes from a String
. Used indirectly by the
setPrefix(String)
, setSuffix(String)
, setFirstItemPrefix(String)
and setLastItemSuffix(String)
methods.
stripQuotes(String)
private static final String DEFAULT_DEFAULT_PROPERTY_NAME
private static final String DEFAULT_OUTPUT_FILENAME
outputFile
when no output file has been specified
and the return value of the getUseOutputFile()
method is
true
.
static final String DEFAULT_SUBDIR_PREFIX
This field is package-private for unit testing purposes only.
private static final List<String> JPA_ANNOTATIONS
List
of JPA
annotations that this ListEntityClassnamesMojo
scans for.
A class that has been annotated with one of these annotations
must be made known to the JPA persistence unit in some fashion,
which is the task with which this mojo provides assistance.
Embeddable
,
Entity
,
IdClass
,
MappedSuperclass
,
Java
Persistence 2.0 Specificationprivate boolean stripQuotes
true
then values for the prefix
,
suffix
, firstItemPrefix
and lastItemSuffix
will have any leading and trailing quotes (if they are a matched
pair) removed. This should protect these values from undesired
trimming by Maven.
private String encoding
outputFile
. The default value as configured by Maven will be
${project.build.sourceEncoding}
. This field may be
null
at any point.
private File outputFile
File
to which entity- and mapped superclass-annotated
classnames will be written. This field may be null
at
any point. If this File
is found to be relative, it will
be relative to
${project.build.directory}${file.separator}generated-test-sources${file.separator}jpa-maven-plugin${file.separator}.
boolean useOutputFile
private String defaultPropertyName
entityClassnames
. This field may be null
at any point.
private Map<String,String> propertyNames
Map
of property names indexed by package prefix
segments. Class names found belonging to packages that start
with the given package prefix segment will be stored in the
outputFile
indexed by the corresponding property name.
Segments in package names are delimited with a period (.
). The following are examples of package prefix segments:
com.foobar.biz
com.foobar
com
private String firstItemPrefix
private String prefix
private String suffix
null
at any point.
private String lastItemSuffix
private Set<URL> urls
Set
of URL
s to scan. If not explicitly
specified, this mojo will scan the test classpath.
Constructor Detail |
---|
public ListEntityClassnamesMojo()
ListEntityClassnamesMojo
.
Method Detail |
---|
public Map<String,String> getPropertyNames()
Map
of property names indexed by package
fragments.
This method may return null
.
Map
of property names indexed by package
fragments, or null
public void setPropertyNames(Map<String,String> propertyNames)
Map
of property names indexed by package
fragments that will be used to determine under which property
name a given class name should be listed.
Note: it is technically permissible for the
determinePropertyName(String)
method to be overridden
such that this Map
is ignored.
propertyNames
- the Map
of property names indexed by
package fragments; may be null
in which case the
default property name will
be used for all classesfinal String stripQuotes(String text)
text
parameter value and returns the result.
This method may return null
.
This method only does something if the stripQuotes
field is set to true
.
This method is package-private for testing only.
text
- the text to strip; may be null
in which case
no substitution will occur
text
with leading and trailing
quotes stripped, or null
if the supplied text
was
null
public String getPrefix()
This method may return null
.
null
setPrefix(String)
public void setPrefix(String prefix)
prefix
- the prefix in question; may be null
getPrefix()
,
setFirstItemPrefix(String)
public String getFirstItemPrefix()
This method may return null
.
null
getPrefix()
,
setFirstItemPrefix(String)
public void setFirstItemPrefix(String firstItemPrefix)
firstItemPrefix
- the prefix to be prepended to the list of
classnames; may be null
getFirstItemPrefix()
,
setPrefix(String)
public String getSuffix()
This method may return null
.
null
setSuffix(String)
public void setSuffix(String suffix)
suffix
- the suffix in question; may be null
getSuffix()
,
setLastItemSuffix(String)
public String getLastItemSuffix()
This method may return null
.
null
getSuffix()
,
setLastItemSuffix(String)
public void setLastItemSuffix(String lastItemSuffix)
lastItemSuffix
- the suffix to be appended to the list of
classnames; may be null
getLastItemSuffix()
,
setSuffix(String)
private final Set<URL> initializeURLs() throws org.apache.maven.artifact.DependencyResolutionRequiredException
Set
of URL
s to scan and returns it.
This method calls setURLs(Set)
as part of its
implementation.
This method never returns null
.
Set
of URL
s that will be returned by
future calls to getURLs()
; never null
org.apache.maven.artifact.DependencyResolutionRequiredException
private final Set<URL> getTestClasspathURLs() throws org.apache.maven.artifact.DependencyResolutionRequiredException
Set
of URL
s that represents the test
classpath.
This uses the associated
MavenProject to supply the information.
If that MavenProject
is null
, then an empty unmodifiable Set is
returned.
String
-to-URL
conversion is accomplished like
this:
MavenProject.getTestClasspathElements()
method
returns an untyped List
. There is no contractual
guarantee about the type of its contents. Each element is
therefore treated as an Object
.null
, then its Object.toString()
method is invoked. The resulting String
is used to construct a
File.File
's File.toURI()
method is
invoked and the result's URI.toURL()
method is invoked. The return value is added to the Set
that will be returned.This method never returns null
.
Set
of URL
s representing the test
classpath, never null
. The Set
's iteration order
is guaranteed to be equal to that of the iteration order of the
return value of the MavenProject.getTestClasspathElements()
method.
org.apache.maven.artifact.DependencyResolutionRequiredException
- if the MavenProject.getTestClasspathElements()
method throws a DependencyResolutionRequiredException
public final String getProjectBuildDirectoryName()
ListEntityClassnamesMojo
's best guess as to
its related Maven project's
build directory. If this
ListEntityClassnamesMojo
actually has a MavenProject
installed, it will use the return value of that MavenProject
's Build
's
getDirectory()
method. Otherwise, it will
return the following:
System.getProperty("maven.project.build.directory", System.getProperty("project.build.directory", String.format("%1$s%2$starget", System.getProperty("basedir", System.getProperty("user.dir", ".")), File.separator)));
This method never returns null
.
null
private final File initializeOutputFile() throws FileException
outputFile
property and
returns its value.
This method never returns null
.
outputFile
property; never null
FileException
- if the outputFile
property could not be initializedfinal File initializeOutputFile(File outputFile) throws FileException
File
and returns
the corrected version.
The return value of this method is guaranteed to be a File
that is:
null
If the supplied File
is a relative File
, then
it will be made absolute by prepending it with the following
platform-neutral path: ${project.build.directory
}/generated-test-sources/jpa-maven-plugin/
outputFile
- the File
to validate
outputFile
parameter; never null
FileException
- if the supplied outputFile
did
not pass validationprivate boolean validateOutputDirectory(File outputDirectory) throws FileException
File
, after this method is
invoked, will designate a directory that exists and is
writable.
outputDirectory
- the File
to validate; must not be
null
true
if File.mkdirs()
was invoked on
outputDirectory
; false
otherwise
IllegalArgumentException
- if outputDirectory
is
null
FileException
- if the supplied outputDirectory
failed validationprivate final void initialize() throws org.apache.maven.artifact.DependencyResolutionRequiredException, FileException
execute()
method; initializes all fields
to their defaults if for some reason they were not already set
appropriately.
This method calls the following methods in order:
org.apache.maven.artifact.DependencyResolutionRequiredException
FileException
private final void initializePropertyNames()
initialize()
method; sets up the propertyNames
field appropriately.
public String getEncoding()
Properties
file
that this mojo generates.
This method may return null
.
Properties
file
that this mojo generates, or null
public void setEncoding(String encoding)
Properties
file that
this mojo generates.
If null
is supplied to this method, then "UTF8
" will be used instead.
encoding
- the encoding to use; may be null
in which
case "UTF8
" will be used instead; otherwise the value is
trimmed and used as-ispublic File getOutputFile()
File
. This method does not perform
any validation or initialization.
This method may return null
.
File
, or null
initializeOutputFile()
public void setOutputFile(File file)
File
to use as the output file parameter. This
method does not perform any validation or initialization.
file
- the File
to use; may be null
initializeOutputFile()
public boolean getUseOutputFile()
ListEntityClassnamesMojo
should write its properties out to the associated output file
. By default this method returns
true
for backwards compatibility.
ListEntityClassnamesMojo
should write its properties out to the associated output file
public void setUseOutputFile(boolean useOutputFile)
ListEntityClassnamesMojo
should
write its properties out to the associated output file.
useOutputFile
- whether or not to use the associated
output filepublic Set<URL> getURLs()
Set
of URL
s to scan for annotations.
This method does not perform any validation or initialization.
Set
of URL
s to scan, or null
initializeURLs()
public void setURLs(Set<URL> urls)
Set
of URL
s to scan for annotations.
This method does not perform any validation or initialization.
urls
- the Set
of URL
s to scan; may be
null
initializeURLs()
private final AnnotationDB scan() throws IOException, MojoExecutionException, MojoFailureException
ListEntityClassnamesMojo
has been configured with
and returns the AnnotationDB
that performed the scanning.
This method may return null
in exceptional
circumstances.
AnnotationDB
containing the scan results, or
null
if an AnnotationDB could not be found
MojoExecutionException
- if this mojo could not execute
MojoFailureExcetpion
- if the build should fail
IOException
MojoFailureException
public void execute() throws MojoExecutionException, MojoFailureException
MojoExecutionException
- if this mojo could not be executed
MojoFailureException
- if the build should failpublic String getDefaultPropertyName()
Class
es
that belong to the default package.
This method may return null
. However, other portions
of this mojo's code may substitute a default value in such
cases.
Class
es
that belong to the default package, or null
public void setDefaultPropertyName(String defaultPropertyName)
Class
es
that belong to the default package.
defaultPropertyName
- the property name; may be null
, but this mojo may use a default value insteadpublic String determinePropertyName(String className)
If the supplied className
is null
or consists
solely of whitespace,
then the default property
name is returned.
Otherwise, a property name is
protected String decorate(String classname, String prefix, String suffix)
class name
with
the supplied prefix
and suffix
parameters and
returns the result.
This method may return null
.
classname
- the class name to decorate; if null
then
null
will be returnedprefix
- the prefix to decorate with; may be null
suffix
- the suffix to decorate with; may be null
null
protected AnnotationDB createAnnotationDB()
AnnotationDB
in the (common) case where a
user has not supplied this AbstractJPAMojo
with a
pre-configured AnnotationDB
.
This method never returns null
. Subclasses overriding
this method must ensure that their overridden implementation
never returns null
.
This implementation overrides that of AbstractJPAMojo
to ensure that the created AnnotationDB
only scans
Class-level annotations.
createAnnotationDB
in class AbstractJPAMojo
AnnotationDB
; never null
AnnotationDB
,
AnnotationDB
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |