Package org.apache.sis.util.resources
Class ResourceCompilerMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.sis.util.resources.ResourceCompilerMojo
- All Implemented Interfaces:
FilenameFilter,org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
@Mojo(name="compile-resources",
defaultPhase=GENERATE_RESOURCES)
public class ResourceCompilerMojo
extends org.apache.maven.plugin.AbstractMojo
implements FilenameFilter
Compiles the international resources that are found in the module from which this mojo is invoked.
See the
sis-build-helper module for more information.- Since:
- 0.3
- Version:
- 0.7
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classA resource compiler that delegates the messages to the Mojo logger. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.sonatype.plexus.build.incremental.BuildContextA handler for the Eclipse workspace, used for declaring new resources.The source directories containing the sources to be compiled.private FileThecompileSourceRootsnamed "java" as aFile.private FileDirectory containing the generated class files.private org.apache.maven.project.MavenProjectProject information (name, version, URL).private static final String[]Pattern to filter properties files that were modified.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanAccepts all"*.properties"files.private voidDeclaresoutputDirectoryas resource, for inclusion by Maven in the JAR file.voidexecute()Executes the mojo.(package private) static intfilterLanguages(File[] resourcesToProcess) Retains only the properties files which seems to be about internationalized resources.private intprocessAllResourceDirectories(File directory) Recursively scans the directories and find all Java classes having a property files of the same name.private static inttoJavaSourceFiles(File[] resourcesToProcess, int count) Converts the given property files into Java source file, provided that the latter exists.Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
PROPERTIES_PATTERN
Pattern to filter properties files that were modified. -
project
@Parameter(property="project", required=true, readonly=true) private org.apache.maven.project.MavenProject projectProject information (name, version, URL). -
buildContext
@Component private org.sonatype.plexus.build.incremental.BuildContext buildContextA handler for the Eclipse workspace, used for declaring new resources. When Maven is run from the command line, this object does nothing.- See Also:
-
compileSourceRoots
@Parameter(property="project.compileSourceRoots", required=true, readonly=true) private List<String> compileSourceRootsThe source directories containing the sources to be compiled. -
outputDirectory
@Parameter(defaultValue="${project.build.directory}/generated-resources", required=true) private File outputDirectoryDirectory containing the generated class files.Note: at the time of writing, we found no well-established convention for generated resources. The conventions that we found were rather for generated sources. In the latter case, the conventions use a different directory for each Maven plugin, e.g.
"generated-sources/xxx". But in our case (for resources), such separation seems of limited use since the resources are copied verbatim in the JAR file, so preventing clash in thegenerated-resourcesdirectory would not prevent clash in the JAR file anyway. -
javaDirectoryFile
ThecompileSourceRootsnamed "java" as aFile.
-
-
Constructor Details
-
ResourceCompilerMojo
public ResourceCompilerMojo()Constructs a new resource compiler MOJO.
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionExceptionExecutes the mojo.- Specified by:
executein interfaceorg.apache.maven.plugin.Mojo- Throws:
org.apache.maven.plugin.MojoExecutionException- if the plugin execution failed.
-
declareOutputDirectory
private void declareOutputDirectory()DeclaresoutputDirectoryas resource, for inclusion by Maven in the JAR file. -
processAllResourceDirectories
Recursively scans the directories and find all Java classes having a property files of the same name. Then invokes the resource compiler for those files.- Throws:
ResourceCompilerException
-
accept
Accepts all"*.properties"files.- Specified by:
acceptin interfaceFilenameFilter- Parameters:
directory- the directory.name- the file name.- Returns:
trueif the given file is a property file.
-
filterLanguages
Retains only the properties files which seems to be about internationalized resources. For example if the given array contains the following files:"Errors.properties""Errors_en.properties""Errors_fr.properties""Messages.properties""Messages_en.properties""Messages_fr.properties""NotAnInternationalResource.properties"
"Errors.properties""Messages.properties"
- Parameters:
resourcesToProcess- the files to filter. This array will be overwritten in-place.- Returns:
- number of valid elements in the
resourcesToProcessafter this method completion.
-
toJavaSourceFiles
Converts the given property files into Java source file, provided that the latter exists. The given array is overwritten in place.- Parameters:
resourcesToProcess- the filtered resource files, as returned byfilterLanguages(File[]).count- number of valid elements inresourcesToProcess.- Returns:
- number of valid elements after this method completion.
-