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 Classes
    Modifier and Type
    Class
    Description
    private final class 
    A resource compiler that delegates the messages to the Mojo logger.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private org.sonatype.plexus.build.incremental.BuildContext
    A handler for the Eclipse workspace, used for declaring new resources.
    private List<String>
    The source directories containing the sources to be compiled.
    private File
    The compileSourceRoots named "java" as a File.
    private File
    Directory containing the generated class files.
    private org.apache.maven.project.MavenProject
    Project 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
    Constructor
    Description
    Constructs a new resource compiler MOJO.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    accept(File directory, String name)
    Accepts all "*.properties" files.
    private void
    Declares outputDirectory as resource, for inclusion by Maven in the JAR file.
    void
    Executes the mojo.
    (package private) static int
    filterLanguages(File[] resourcesToProcess)
    Retains only the properties files which seems to be about internationalized resources.
    private int
    Recursively scans the directories and find all Java classes having a property files of the same name.
    private static int
    toJavaSourceFiles(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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PROPERTIES_PATTERN

      private static final String[] PROPERTIES_PATTERN
      Pattern to filter properties files that were modified.
    • project

      @Parameter(property="project", required=true, readonly=true) private org.apache.maven.project.MavenProject project
      Project information (name, version, URL).
    • buildContext

      @Component private org.sonatype.plexus.build.incremental.BuildContext buildContext
      A 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> compileSourceRoots
      The source directories containing the sources to be compiled.
    • outputDirectory

      @Parameter(defaultValue="${project.build.directory}/generated-resources", required=true) private File outputDirectory
      Directory 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 the generated-resources directory would not prevent clash in the JAR file anyway.

    • javaDirectoryFile

      private File javaDirectoryFile
      The compileSourceRoots named "java" as a File.
  • Constructor Details

    • ResourceCompilerMojo

      public ResourceCompilerMojo()
      Constructs a new resource compiler MOJO.
  • Method Details

    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException
      Executes the mojo.
      Specified by:
      execute in interface org.apache.maven.plugin.Mojo
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if the plugin execution failed.
    • declareOutputDirectory

      private void declareOutputDirectory()
      Declares outputDirectory as resource, for inclusion by Maven in the JAR file.
    • processAllResourceDirectories

      private int processAllResourceDirectories(File directory) throws ResourceCompilerException
      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

      public final boolean accept(File directory, String name)
      Accepts all "*.properties" files.
      Specified by:
      accept in interface FilenameFilter
      Parameters:
      directory - the directory.
      name - the file name.
      Returns:
      true if the given file is a property file.
    • filterLanguages

      static int filterLanguages(File[] resourcesToProcess)
      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"
      Then this method will retain the following files:
      • "Errors.properties"
      • "Messages.properties"
      Parameters:
      resourcesToProcess - the files to filter. This array will be overwritten in-place.
      Returns:
      number of valid elements in the resourcesToProcess after this method completion.
    • toJavaSourceFiles

      private static int toJavaSourceFiles(File[] resourcesToProcess, int count)
      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 by filterLanguages(File[]).
      count - number of valid elements in resourcesToProcess.
      Returns:
      number of valid elements after this method completion.