You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2011/07/20 21:31:47 UTC

svn commit: r1148912 - /db/torque/torque4/trunk/maven-torque-generator-plugin/src/main/java/org/apache/torque/generator/maven/TorqueGeneratorMojo.java

Author: tfischer
Date: Wed Jul 20 19:31:47 2011
New Revision: 1148912

URL: http://svn.apache.org/viewvc?rev=1148912&view=rev
Log:
allow overriding of generator options via a properties file.

Modified:
    db/torque/torque4/trunk/maven-torque-generator-plugin/src/main/java/org/apache/torque/generator/maven/TorqueGeneratorMojo.java

Modified: db/torque/torque4/trunk/maven-torque-generator-plugin/src/main/java/org/apache/torque/generator/maven/TorqueGeneratorMojo.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/maven-torque-generator-plugin/src/main/java/org/apache/torque/generator/maven/TorqueGeneratorMojo.java?rev=1148912&r1=1148911&r2=1148912&view=diff
==============================================================================
--- db/torque/torque4/trunk/maven-torque-generator-plugin/src/main/java/org/apache/torque/generator/maven/TorqueGeneratorMojo.java (original)
+++ db/torque/torque4/trunk/maven-torque-generator-plugin/src/main/java/org/apache/torque/generator/maven/TorqueGeneratorMojo.java Wed Jul 20 19:31:47 2011
@@ -20,9 +20,14 @@ package org.apache.torque.generator.mave
  */
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 import org.apache.maven.model.Resource;
@@ -301,11 +306,22 @@ public class TorqueGeneratorMojo extends
 
     /**
      * Additional options which can be added to the generation process.
-     * This overrides existing options.
+     * This overrides both the options set in the templates
+     * and the options in optionsFile.
      *
      * @parameter
      */
     private Map<String, String> options;
+    
+    /**
+     * Properties file which contains the options which can be added
+     * to the generation process.
+     * This overrides the options set in the templates, but not the
+     * options set by the parameter <code>options</code>.
+     *
+     * @parameter
+     */
+    private File optionsFile;
 
     /**
      * The Maven project this plugin runs in.
@@ -436,8 +452,44 @@ public class TorqueGeneratorMojo extends
         getLog().debug("ProjectPaths = " + projectPaths);
 
         OptionsConfiguration optionConfiguration = null;
-        if (options != null)
+        if (options != null || optionsFile != null)
         {
+            if (options == null)
+            {
+                options = new HashMap<String, String>();
+            }
+            if (optionsFile != null)
+            {
+                Properties optionProperties = new Properties();
+                try
+                {
+                    optionProperties.load(new FileInputStream(optionsFile));
+                }
+                catch (FileNotFoundException e)
+                {
+                    getLog().error(e);
+                    throw new MojoExecutionException(e.getMessage());
+                }
+                catch (IOException e)
+                {
+                    getLog().error(e);
+                    throw new MojoExecutionException(e.getMessage());
+                }
+                getLog().debug("loaded options file from " 
+                        + optionsFile.getAbsolutePath() + ", contents: "
+                        + optionProperties);
+                for (Map.Entry<Object, Object> propertiesEntry 
+                        : optionProperties.entrySet())
+                {
+                    if (!options.containsKey(propertiesEntry.getKey()))
+                    {
+                        options.put(
+                                (String) propertiesEntry.getKey(),
+                                (String) propertiesEntry.getValue());
+                    }
+                }
+            }
+            getLog().debug("options = " + options);
             optionConfiguration = new MapOptionsConfiguration(options);
         }
         Loglevel convertedLoglevel = null;



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org