sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1405270 - in /sis/branches/JDK7/sis-build-helper/src: main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java main/java/org/apache/sis/util/resources/ResourceCompilerMojo.java site/apt/index.apt
Date Sat, 03 Nov 2012 02:55:39 GMT
Author: desruisseaux
Date: Sat Nov  3 02:55:39 2012
New Revision: 1405270

URL: http://svn.apache.org/viewvc?rev=1405270&view=rev
Log:
Resources location: replaced the hard-coded "org.apache.sis.util.resources"
location by a search of any package name ending with "resources".
We will need that for resources in other modules.

Modified:
    sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java
    sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/ResourceCompilerMojo.java
    sis/branches/JDK7/sis-build-helper/src/site/apt/index.apt

Modified: sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java?rev=1405270&r1=1405269&r2=1405270&view=diff
==============================================================================
--- sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java
(original)
+++ sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java
Sat Nov  3 02:55:39 2012
@@ -26,10 +26,10 @@ import java.util.regex.Pattern;
  * Reads a given list of {@code .properties} files and copies their content to {@code .utf}
files
  * using UTF-8 encoding. It also checks for key validity and checks values for {@link MessageFormat}
  * compatibility. Finally, it writes the key values in the Java source files.
- * <p>
- * This class is independent of any Mojo and could be executed from the command-line.
+ *
+ * <p>This class is independent of any Mojo and could be executed from the command-line.
  * For now we keep it package-private, but we could consider to enable execution from
- * the command-line in a future version if this happen to be useful.
+ * the command-line in a future version if this happen to be useful.</p>
  *
  * @author Martin Desruisseaux (IRD, Geomatys)
  * @since   0.3 (derived from geotk-1.2)
@@ -283,8 +283,8 @@ class IndexedResourceCompiler implements
      * conventions (i.e. resources expecting some arguments must have a key name ending with
      * {@code "_$n"} where {@code "n"} is the number of arguments). This method transforms
resource
      * values into legal {@link MessageFormat} patterns when necessary.
-     * <p>
-     * The following methods must be invoked before this one:
+     *
+     * <p>The following methods must be invoked before this one:</p>
      *
      * <ul>
      *   <li>{@link #initialize}</li>

Modified: sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/ResourceCompilerMojo.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/ResourceCompilerMojo.java?rev=1405270&r1=1405269&r2=1405270&view=diff
==============================================================================
--- sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/ResourceCompilerMojo.java
(original)
+++ sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/ResourceCompilerMojo.java
Sat Nov  3 02:55:39 2012
@@ -55,6 +55,16 @@ public class ResourceCompilerMojo extend
     private String outputDirectory;
 
     /**
+     * The <code>compileSourceRoots</code> named "java" as a <code>File</code>.
+     */
+    private File javaDirectoryFile;
+
+    /**
+     * The <code>outputDirectory</code> as a <code>File</code>.
+     */
+    private File outputDirectoryFile;
+
+    /**
      * Executes the mojo.
      *
      * @throws MojoExecutionException if the plugin execution failed.
@@ -63,14 +73,12 @@ public class ResourceCompilerMojo extend
     @SuppressWarnings({"unchecked","rawtypes"}) // Generic array creation.
     public void execute() throws MojoExecutionException {
         int errors = 0;
-        final File target = new File(outputDirectory);
+        outputDirectoryFile = new File(outputDirectory);
         for (final String sourceDirectory : compileSourceRoots) {
-            File directory = new File(sourceDirectory);
+            final File directory = new File(sourceDirectory);
             if (directory.getName().equals("java")) {
-                final File[] resourcesToProcess = new File(sourceDirectory, "org/apache/sis/util/resources").listFiles(this);
-                if (resourcesToProcess != null && resourcesToProcess.length != 0)
{
-                    errors += new Compiler(directory, target, resourcesToProcess).run();
-                }
+                javaDirectoryFile = directory;
+                errors += processAllResourceDirectories(directory);
             }
         }
         if (errors != 0) {
@@ -79,6 +87,27 @@ public class ResourceCompilerMojo extend
     }
 
     /**
+     * Recursively scans the directories for a sub-package named "resources",
+     * then invokes the resource compiler for that directory.
+     */
+    private int processAllResourceDirectories(final File directory) throws ResourceCompilerException
{
+        int errors = 0;
+        for (final File subdir : directory.listFiles()) {
+            if (subdir.isDirectory()) {
+                if (subdir.getName().equals("resources")) {
+                    final File[] resourcesToProcess = subdir.listFiles(this);
+                    if (resourcesToProcess != null && resourcesToProcess.length !=
0) {
+                        errors += new Compiler(resourcesToProcess).run();
+                    }
+                } else {
+                    errors += processAllResourceDirectories(subdir);
+                }
+            }
+        }
+        return errors;
+    }
+
+    /**
      * Returns {@code true} if the given file is the source code for a resources bundle.
      * This method returns {@code true} if the given file is a Java source file and if a
      * properties file of the same name exists.
@@ -101,8 +130,8 @@ public class ResourceCompilerMojo extend
      * A resource compiler that delegates the messages to the Mojo logger.
      */
     private final class Compiler extends IndexedResourceCompiler {
-        public Compiler(File sourceDirectory, File buildDirectory, File[] resourcesToProcess)
{
-            super(sourceDirectory, buildDirectory, resourcesToProcess);
+        public Compiler(File[] resourcesToProcess) {
+            super(javaDirectoryFile, outputDirectoryFile, resourcesToProcess);
         }
 
         /**

Modified: sis/branches/JDK7/sis-build-helper/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-build-helper/src/site/apt/index.apt?rev=1405270&r1=1405269&r2=1405270&view=diff
==============================================================================
--- sis/branches/JDK7/sis-build-helper/src/site/apt/index.apt (original)
+++ sis/branches/JDK7/sis-build-helper/src/site/apt/index.apt Sat Nov  3 02:55:39 2012
@@ -50,7 +50,7 @@ Building Apache SIS
 
   The resource compiler is executed at Maven build time if the <<<pom.xml>>>
file
   contains the following declaration. Note that current implementation looks only for resources
-  in the <<<org.apache.sis.util.resources>>> package; all other packages
are ignored.
+  in any package ending with the <<<resources>>> name; all other packages
are ignored.
 
 +-----------------------------------------------------
 <build>



Mime
View raw message