db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1353994 - in /db/torque/torque4/trunk: torque-ant-tasks/src/main/java/org/apache/torque/ant/task/ torque-generator/src/main/java/org/apache/torque/generator/configuration/ torque-generator/src/main/java/org/apache/torque/generator/configur...
Date Tue, 26 Jun 2012 12:33:28 GMT
Author: tfischer
Date: Tue Jun 26 12:33:26 2012
New Revision: 1353994

URL: http://svn.apache.org/viewvc?rev=1353994&view=rev
Log:
Allow setting a defaultOutputEncoding from the maven and ant plugins

Added:
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/control/OutputEncodingTest.java
    db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/
    db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/package.html
    db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/
    db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/
    db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/
    db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/conf/
    db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/conf/control.xml
    db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/outlets/
    db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/outlets/outputEncoding.xml
    db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/src/
    db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/src/source.xml
Modified:
    db/torque/torque4/trunk/torque-ant-tasks/src/main/java/org/apache/torque/ant/task/TorqueGeneratorTask.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfigurationReader.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitDescriptor.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/controller/Output.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ReadConfigurationTest.java
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/java/JavaOutlet.java
    db/torque/torque4/trunk/torque-maven-plugin/src/main/java/org/apache/torque/generator/maven/TorqueGeneratorMojo.java

Modified: db/torque/torque4/trunk/torque-ant-tasks/src/main/java/org/apache/torque/ant/task/TorqueGeneratorTask.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-ant-tasks/src/main/java/org/apache/torque/ant/task/TorqueGeneratorTask.java?rev=1353994&r1=1353993&r2=1353994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-ant-tasks/src/main/java/org/apache/torque/ant/task/TorqueGeneratorTask.java
(original)
+++ db/torque/torque4/trunk/torque-ant-tasks/src/main/java/org/apache/torque/ant/task/TorqueGeneratorTask.java
Tue Jun 26 12:33:26 2012
@@ -134,6 +134,12 @@ public class TorqueGeneratorTask extends
     private String loglevel;
 
     /**
+     * The encoding which should be used for the files which do not have an
+     * output encoding set in the templates.
+     */
+    private String defaultOutputEncoding;
+
+    /**
      * Whether all source files should be combined into one source tree.
      * If false, each source file will be read in its own source tree
      * and start a new generation run.
@@ -318,11 +324,11 @@ public class TorqueGeneratorTask extends
         UnitDescriptor unitDescriptor = new UnitDescriptor(
                 packaging,
                 projectPaths,
-                new DefaultTorqueGeneratorPaths(),
-                null,
-                fileSourceProvider,
-                optionConfiguration,
-                convertedLoglevel);
+                new DefaultTorqueGeneratorPaths());
+        unitDescriptor.setOverrideSourceProvider(fileSourceProvider);
+        unitDescriptor.setOverrideOptions(optionConfiguration);
+        unitDescriptor.setLoglevel(convertedLoglevel);
+        unitDescriptor.setDefaultOutputEncoding(defaultOutputEncoding);
         log("unit descriptor created", Project.MSG_DEBUG);
         if (overrideConfigDir != null)
         {
@@ -330,15 +336,18 @@ public class TorqueGeneratorTask extends
                 = new CustomProjectPaths(projectPaths);
             childProjectPaths.setConfigurationDir(overrideConfigDir);
 
-            unitDescriptor = new UnitDescriptor(
+            UnitDescriptor parentUnitDescriptor = new UnitDescriptor(
                     Packaging.DIRECTORY,
                     childProjectPaths,
-                    new DefaultTorqueGeneratorPaths(),
-                    unitDescriptor,
-                    fileSourceProvider,
-                    optionConfiguration,
-                    convertedLoglevel);
+                    new DefaultTorqueGeneratorPaths());
+            parentUnitDescriptor.setInheritsFrom(unitDescriptor);
+            parentUnitDescriptor.setOverrideSourceProvider(fileSourceProvider);
+            parentUnitDescriptor.setOverrideOptions(optionConfiguration);
+            parentUnitDescriptor.setLoglevel(convertedLoglevel);
+            parentUnitDescriptor.setDefaultOutputEncoding(
+                    defaultOutputEncoding);
             log("child unit descriptor created",Project.MSG_DEBUG);
+            unitDescriptor = parentUnitDescriptor;
         }
         unitDescriptors.add(unitDescriptor);
         try
@@ -474,6 +483,19 @@ public class TorqueGeneratorTask extends
     }
 
     /**
+     * Sets the encoding which should be used for the files which do not have
+     * an output encoding set in the templates.
+     *
+     * @param defaultOutputEncoding the default output encoding,
+     *        or null to use the generator default
+     *        (the platform default encoding).
+     */
+    public void setDefaultOutputEncoding(String defaultOutputEncoding)
+    {
+        this.defaultOutputEncoding = defaultOutputEncoding;
+    }
+
+    /**
      * Sets whether all source files should be combined into one source tree.
      * If false, each source file will be read in its own source tree
      * and start a new generation run.

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java?rev=1353994&r1=1353993&r2=1353994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java
Tue Jun 26 12:33:26 2012
@@ -76,6 +76,12 @@ public class UnitConfiguration
     private Loglevel loglevel = Loglevel.INFO;
 
     /**
+     * The output encoding if no specific encoding has been set in the output;
+     * null for the default platform encoding.
+     */
+    private String defaultOutputEncoding = null;
+
+    /**
      * Returns the configuration of the outlets in this generation unit.
      *
      * @return the outlet configuration, not null.
@@ -422,6 +428,30 @@ public class UnitConfiguration
     }
 
     /**
+     * Returns the output encoding if no specific encoding has been set
+     * in the output.
+     *
+     * @return the default output encoding, null for the default
+     *         platform encoding.
+     */
+    public String getDefaultOutputEncoding()
+    {
+        return defaultOutputEncoding;
+    }
+
+    /**
+     * Sets the output encoding if no specific encoding has been set
+     * in the output.
+     *
+     * @param defaultOutputEncoding the default output encoding,
+     *        null for the default platform encoding.
+     */
+    public void setDefaultOutputEncoding(String defaultOutputEncoding)
+    {
+        this.defaultOutputEncoding = defaultOutputEncoding;
+    }
+
+    /**
      * Checks whether the unit configuration is fully initialized.
      *
      * @return true if the unit configuration is fully initialized,

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfigurationReader.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfigurationReader.java?rev=1353994&r1=1353993&r2=1353994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfigurationReader.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfigurationReader.java
Tue Jun 26 12:33:26 2012
@@ -353,9 +353,14 @@ class UnitConfigurationReader
                                 configurationProvider));
             }
             unitConfiguration.setOptions(options);
-            unitConfiguration.setEntityReferences(
-                    controlConfiguration.getEntityReferences());
+            {
+                log.debug("End reading options");
+            }
         }
+        unitConfiguration.setEntityReferences(
+                controlConfiguration.getEntityReferences());
+        unitConfiguration.setDefaultOutputEncoding(
+                unitDescriptor.getDefaultOutputEncoding());
         if (log.isDebugEnabled())
         {
             log.debug("Control configuration successfully read.");

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitDescriptor.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitDescriptor.java?rev=1353994&r1=1353993&r2=1353994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitDescriptor.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitDescriptor.java
Tue Jun 26 12:33:26 2012
@@ -76,54 +76,25 @@ public class UnitDescriptor
     private Loglevel loglevel;
 
     /**
-     * Constructor without inheritance, override options, overrideSourceFileset
-     * and loglevel.
-     *
-     * @param packaging The packaging of the generation unit, not null.
-     * @param projectPaths The paths the Torque generator must know about
-     *        the surrounding project, not null.
-     * @param configurationPaths The paths within the configuration
-     *        of the configuration unit, not null.
+     * The output encoding if no specific encoding has been set in the output;
+     * null for the default platform encoding.
      */
-    public UnitDescriptor(
-            Packaging packaging,
-            ProjectPaths projectPaths,
-            TorqueGeneratorPaths configurationPaths)
-    {
-        this(packaging,
-                projectPaths,
-                configurationPaths,
-                null,
-                null,
-                null,
-                null);
-    }
+    private String defaultOutputEncoding = null;
 
     /**
-     * Constructor.
+     * Constructor without inheritance, override options, overrideSourceFileset
+     * and loglevel.
      *
      * @param packaging The packaging of the generation unit, not null.
      * @param projectPaths The paths the Torque generator must know about
      *        the surrounding project, not null.
      * @param configurationPaths The paths within the configuration
      *        of the configuration unit, not null.
-     * @param inheritsFrom the parent of this generation unit,
-     *        or null if it does not inherit from a generation unit.
-     * @param overrideSourceProvider overrides the source defined in the
-     *        control file.
-     * @param overrideOptions Options to override the settings in the project
-     *        Directory, or null if no options are overridden.
-     * @param loglevel The loglevel to override the log level, or null to use
-     *        the log level defined in the configuration.
      */
     public UnitDescriptor(
             Packaging packaging,
             ProjectPaths projectPaths,
-            TorqueGeneratorPaths configurationPaths,
-            UnitDescriptor inheritsFrom,
-            SourceProvider overrideSourceProvider,
-            OptionsConfiguration overrideOptions,
-            Loglevel loglevel)
+            TorqueGeneratorPaths configurationPaths)
     {
         if (packaging == null)
         {
@@ -143,10 +114,6 @@ public class UnitDescriptor
         this.packaging = packaging;
         this.projectPaths = projectPaths;
         this.configurationPaths = configurationPaths;
-        this.inheritsFrom = inheritsFrom;
-        this.overrideSourceProvider = overrideSourceProvider;
-        this.overrideOptions = overrideOptions;
-        this.loglevel = loglevel;
     }
 
     /**
@@ -193,6 +160,18 @@ public class UnitDescriptor
     }
 
     /**
+     * Sets the descriptor of the generation unit from which this generation
+     * unit inherits.
+     *
+     * @param inheritsFrom the parents unit descriptor,
+     *        or null if no parent exists.
+     */
+    public void setInheritsFrom(UnitDescriptor inheritsFrom)
+    {
+        this.inheritsFrom = inheritsFrom;
+    }
+
+    /**
      * Returns the source provider overriding the source defined in the
      * control file, or null if the control file definition
      * is not overridden.
@@ -205,6 +184,18 @@ public class UnitDescriptor
     }
 
     /**
+     * Sets the source provider overriding the source defined in the
+     * control file.
+     *
+     * @param overrideSourceProvider the overriding source provider,
+     *        or null if the control file definition is not overridden.
+     */
+    public void setOverrideSourceProvider(SourceProvider overrideSourceProvider)
+    {
+        this.overrideSourceProvider = overrideSourceProvider;
+    }
+
+    /**
      * Returns the configuration of the overriding options, if any.
      *
      * @return the configuration of the overriding options, or null.
@@ -215,6 +206,17 @@ public class UnitDescriptor
     }
 
     /**
+     * Sets the configuration of the overriding options, if any.
+     *
+     * @param overrideOptions the configuration of the overriding options,
+     *        or null.
+     */
+    public void setOverrideOptions(OptionsConfiguration overrideOptions)
+    {
+        this.overrideOptions = overrideOptions;
+    }
+
+    /**
      * Returns the log level overriding the loglevel defined in the
      * configuration unit.
      *
@@ -224,4 +226,39 @@ public class UnitDescriptor
     {
         return loglevel;
     }
+
+    /**
+     * Sets the log level overriding the loglevel defined in the
+     * configuration unit.
+     *
+     * @param loglevel the log level, or null.
+     */
+    public void setLoglevel(Loglevel loglevel)
+    {
+        this.loglevel = loglevel;
+    }
+
+    /**
+     * Returns the output encoding if no specific encoding has been set
+     * in the output.
+     *
+     * @return the default output encoding, null for the default
+     *         platform encoding.
+     */
+    public String getDefaultOutputEncoding()
+    {
+        return defaultOutputEncoding;
+    }
+
+    /**
+     * Sets the output encoding which is used if no specific encoding
+     * has been set in the output.
+     *
+     * @param defaultOutputEncoding the default output encoding,
+     *        null for the default platform encoding.
+     */
+    public void setDefaultOutputEncoding(String defaultOutputEncoding)
+    {
+        this.defaultOutputEncoding = defaultOutputEncoding;
+    }
 }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/controller/Output.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/controller/Output.java?rev=1353994&r1=1353993&r2=1353994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/controller/Output.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/controller/Output.java
Tue Jun 26 12:33:26 2012
@@ -80,7 +80,7 @@ public class Output
      * The character encoding of the generated file, or null for the platform
      * default encoding.
      */
-    private String encoding = "ISO-8859-1";
+    private String encoding;
 
     /**
      * Constructor.

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java?rev=1353994&r1=1353993&r2=1353994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java
Tue Jun 26 12:33:26 2012
@@ -22,6 +22,7 @@ package org.apache.torque.generator.cont
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -400,7 +401,7 @@ public class Controller
         if (!existingTargetStrategy.beforeGeneration(
                 output.getOutputDirKey(),
                 output.getFilename(),
-                output.getEncoding(),
+                getOutputEncoding(output, unitConfiguration),
                 unitConfiguration))
         {
             log.info("Skipping generation of File "
@@ -478,7 +479,7 @@ public class Controller
         existingTargetStrategy.afterGeneration(
                 output.getOutputDirKey(),
                 output.getFilename(),
-                output.getEncoding(),
+                getOutputEncoding(output, unitConfiguration),
                 result,
                 unitConfiguration);
 
@@ -555,4 +556,29 @@ public class Controller
         }
         return result;
     }
+
+    /**
+     * Calculates the output encoding for an output.
+     *
+     * @param output The output, not null.
+     * @param unitConfiguration the configuration of the unit of generation
+     *        to which the output belongs.
+     *
+     * @return the encoding, not null.
+     */
+    private String getOutputEncoding(
+            Output output,
+            UnitConfiguration unitConfiguration)
+    {
+        if (output.getEncoding() != null)
+        {
+            return output.getEncoding();
+        }
+        if (unitConfiguration.getDefaultOutputEncoding() != null)
+        {
+            return unitConfiguration.getDefaultOutputEncoding();
+        }
+        return Charset.defaultCharset().displayName();
+    }
+
 }

Modified: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ReadConfigurationTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ReadConfigurationTest.java?rev=1353994&r1=1353993&r2=1353994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ReadConfigurationTest.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ReadConfigurationTest.java
Tue Jun 26 12:33:26 2012
@@ -509,11 +509,8 @@ public class ReadConfigurationTest exten
         UnitDescriptor unitDescriptor = new UnitDescriptor(
                 UnitDescriptor.Packaging.DIRECTORY,
                 projectPaths,
-                new DefaultTorqueGeneratorPaths(),
-                null,
-                null,
-                optionConfiguration,
-                null);
+                new DefaultTorqueGeneratorPaths());
+        unitDescriptor.setOverrideOptions(optionConfiguration);
         ConfigurationHandlers configurationHandlers
                 = new ConfigurationHandlers();
         UnitConfigurationReader configurationReader
@@ -559,11 +556,7 @@ public class ReadConfigurationTest exten
             UnitDescriptor parentUnitDescriptor = new UnitDescriptor(
                     UnitDescriptor.Packaging.DIRECTORY,
                     parentProjectPaths,
-                    new DefaultTorqueGeneratorPaths(),
-                    null,
-                    null,
-                    null,
-                    null);
+                    new DefaultTorqueGeneratorPaths());
 
             projectPaths = new CustomProjectPaths(
                     new Maven2DirectoryProjectPaths(
@@ -577,11 +570,8 @@ public class ReadConfigurationTest exten
             UnitDescriptor unitDescriptor = new UnitDescriptor(
                     UnitDescriptor.Packaging.DIRECTORY,
                     projectPaths,
-                    new DefaultTorqueGeneratorPaths(),
-                    parentUnitDescriptor,
-                    null,
-                    null,
-                    null);
+                    new DefaultTorqueGeneratorPaths());
+            unitDescriptor.setInheritsFrom(parentUnitDescriptor);
             UnitConfigurationReader configurationReader
                     = new UnitConfigurationReader();
             unitConfiguration

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/control/OutputEncodingTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/control/OutputEncodingTest.java?rev=1353994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/control/OutputEncodingTest.java
(added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/control/OutputEncodingTest.java
Tue Jun 26 12:33:26 2012
@@ -0,0 +1,80 @@
+package org.apache.torque.generator.control;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.torque.generator.BaseTest;
+import org.apache.torque.generator.configuration.UnitDescriptor;
+import org.apache.torque.generator.configuration.paths.CustomProjectPaths;
+import org.apache.torque.generator.configuration.paths.DefaultTorqueGeneratorPaths;
+import org.apache.torque.generator.configuration.paths.Maven2DirectoryProjectPaths;
+import org.junit.Test;
+
+/**
+ * Tests whether the output encoding handling is correct.
+ */
+public class OutputEncodingTest extends BaseTest
+{
+    @Test
+    public void testOutputEncoding() throws Exception
+    {
+        File targetDir = new File("target/test/outputEncoding");
+        FileUtils.deleteDirectory(targetDir);
+        Controller controller = new Controller();
+        List<UnitDescriptor> unitDescriptors = new ArrayList<UnitDescriptor>();
+        CustomProjectPaths projectPaths = new CustomProjectPaths(
+                new Maven2DirectoryProjectPaths(
+                        new File("src/test/outputEncoding")));
+        projectPaths.setOutputDirectory(null, targetDir);
+        unitDescriptors.add(new UnitDescriptor(
+                UnitDescriptor.Packaging.DIRECTORY,
+                projectPaths,
+                new DefaultTorqueGeneratorPaths()));
+        controller.run(unitDescriptors);
+
+        assertTrue(targetDir.exists());
+        checkFile(
+                new File(targetDir, "defaultEncoding.txt"),
+                Charset.defaultCharset().displayName());
+        checkFile(
+                new File(targetDir, "iso-8859-1.txt"),
+                "iso-8859-1");
+        checkFile(
+                new File(targetDir, "utf8.txt"),
+                "utf-8");
+    }
+
+    private void checkFile(File file, String encoding)
+            throws IOException
+    {
+        assertTrue(file.exists());
+        String content = FileUtils.readFileToString(file, encoding);
+        assertEquals("Test Outlet output; foo=öäü; bar=ÖÄÜ", content);
+    }
+}

Modified: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/java/JavaOutlet.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/java/JavaOutlet.java?rev=1353994&r1=1353993&r2=1353994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/java/JavaOutlet.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/java/JavaOutlet.java
Tue Jun 26 12:33:26 2012
@@ -113,7 +113,7 @@ public class JavaOutlet extends OutletIm
     public String execute(ControllerState controllerState)
             throws GeneratorException
     {
-        return "Test Outlet output";
+        return "Test Outlet output; foo=" + foo + "; bar=" + bar;
     }
 
     public void setFoo(String foo)

Added: db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/package.html?rev=1353994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/package.html (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/package.html Tue Jun
26 12:33:26 2012
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2001-2006 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License")
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<h2>Test configuration for the OutputEncodingTest</h2>
+
+<p>
+  This directory and its subdirectories contain a test configuration
+  which is used by the OutputEncodingTest to check whether
+  output encoding settings work correctly.
+</p>
+ 
\ No newline at end of file

Added: db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/conf/control.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/conf/control.xml?rev=1353994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/conf/control.xml
(added)
+++ db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/conf/control.xml
Tue Jun 26 12:33:26 2012
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<control
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://db.apache.org/torque/4.0/generator/configuration http://db.apache.org/torque/4.0/generator/configuration.xsd"
+    xmlns="http://db.apache.org/torque/4.0/generator/configuration">
+
+  <output name="defaultEncodingOutput" file="defaultEncoding.txt">
+    <source xsi:type="fileSource">
+      <include>source.xml</include>
+    </source>
+    <outlet name="org.apache.torque.generator.test.outputencoding.javaOutlet"/>
+  </output>
+  <output name="UTF8-Output" file="utf8.txt" encoding="UTF-8">
+    <source xsi:type="fileSource">
+      <include>source.xml</include>
+    </source>
+    <outlet name="org.apache.torque.generator.test.outputencoding.javaOutlet"/>
+  </output>
+  <output name="ISO8859-1-Output" file="iso-8859-1.txt" encoding="ISO-8859-1">
+    <source xsi:type="fileSource">
+      <include>source.xml</include>
+    </source>
+    <outlet name="org.apache.torque.generator.test.outputencoding.javaOutlet"/>
+  </output>
+</control>
+  
\ No newline at end of file

Added: db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/outlets/outputEncoding.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/outlets/outputEncoding.xml?rev=1353994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/outlets/outputEncoding.xml
(added)
+++ db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/outlets/outputEncoding.xml
Tue Jun 26 12:33:26 2012
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<torqueGenConf:outlets xmlns="http://db.apache.org/torque/4.0/generator/configuration"
+    xmlns:torqueGenConf="http://db.apache.org/torque/4.0/generator/configuration"
+    xsi:schemaLocation="http://db.apache.org/torque/4.0/generator/configuration http://db.apache.org/torque/4.0/generator/configuration.xsd"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <outlet name="org.apache.torque.generator.test.outputencoding.javaOutlet"
+      xsi:type="javaOutlet" 
+      class="org.apache.torque.generator.java.JavaOutlet">
+    <input elementName="source"/>
+    <foo>öäü</foo>
+    <bar>ÖÄÜ</bar>
+  </outlet>
+</torqueGenConf:outlets>
\ No newline at end of file

Added: db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/src/source.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/src/source.xml?rev=1353994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/src/source.xml
(added)
+++ db/torque/torque4/trunk/torque-generator/src/test/outputEncoding/src/main/torque-gen/src/source.xml
Tue Jun 26 12:33:26 2012
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<source>
+</source>

Modified: db/torque/torque4/trunk/torque-maven-plugin/src/main/java/org/apache/torque/generator/maven/TorqueGeneratorMojo.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-maven-plugin/src/main/java/org/apache/torque/generator/maven/TorqueGeneratorMojo.java?rev=1353994&r1=1353993&r2=1353994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-maven-plugin/src/main/java/org/apache/torque/generator/maven/TorqueGeneratorMojo.java
(original)
+++ db/torque/torque4/trunk/torque-maven-plugin/src/main/java/org/apache/torque/generator/maven/TorqueGeneratorMojo.java
Tue Jun 26 12:33:26 2012
@@ -370,6 +370,18 @@ public class TorqueGeneratorMojo extends
     private File optionsFile;
 
     /**
+     * The encoding which should be used for the files which do not have an
+     * output encoding set in the templates.
+     * If not set, the property project.build.sourceEncoding from the
+     * maven pom is used.
+     * If that is also not set, the generator default is used
+     * (which is the platform default encoding).
+     *
+     * @parameter
+     */
+    private String defaultOutputEncoding;
+
+    /**
      * The Maven project this plugin runs in.
      *
      * @parameter expression="${project}"
@@ -575,14 +587,20 @@ public class TorqueGeneratorMojo extends
         {
             convertedLoglevel = Loglevel.getByKey(loglevel);
         }
+        String encoding = defaultOutputEncoding;
+        if (encoding == null)
+        {
+            encoding = project.getProperties().getProperty(
+                    "project.build.sourceEncoding");
+        }
         UnitDescriptor unitDescriptor = new UnitDescriptor(
                 packaging,
                 projectPaths,
-                new DefaultTorqueGeneratorPaths(),
-                null,
-                fileSourceProvider,
-                optionConfiguration,
-                convertedLoglevel);
+                new DefaultTorqueGeneratorPaths());
+        unitDescriptor.setOverrideSourceProvider(fileSourceProvider);
+        unitDescriptor.setOverrideOptions(optionConfiguration);
+        unitDescriptor.setLoglevel(convertedLoglevel);
+        unitDescriptor.setDefaultOutputEncoding(encoding);
         getLog().debug("unit descriptor created");
         if (overrideConfigDir != null)
         {
@@ -590,15 +608,17 @@ public class TorqueGeneratorMojo extends
                 = new CustomProjectPaths(projectPaths);
             childProjectPaths.setConfigurationDir(overrideConfigDir);
 
-            unitDescriptor = new UnitDescriptor(
+            UnitDescriptor parentUnitDescriptor = new UnitDescriptor(
                     Packaging.DIRECTORY,
                     childProjectPaths,
-                    new DefaultTorqueGeneratorPaths(),
-                    unitDescriptor,
-                    fileSourceProvider,
-                    optionConfiguration,
-                    convertedLoglevel);
+                    new DefaultTorqueGeneratorPaths());
+            parentUnitDescriptor.setInheritsFrom(unitDescriptor);
+            parentUnitDescriptor.setOverrideSourceProvider(fileSourceProvider);
+            parentUnitDescriptor.setOverrideOptions(optionConfiguration);
+            parentUnitDescriptor.setLoglevel(convertedLoglevel);
+            parentUnitDescriptor.setDefaultOutputEncoding(encoding);
             getLog().debug("child unit descriptor created");
+            unitDescriptor = parentUnitDescriptor;
         }
         unitDescriptors.add(unitDescriptor);
         try
@@ -907,6 +927,19 @@ public class TorqueGeneratorMojo extends
     }
 
     /**
+     * Sets the encoding which should be used for the files which do not have
+     * an output encoding set in the templates.
+     *
+     * @param defaultOutputEncoding the default output encoding,
+     *        or null to use the generator default
+     *        (the platform default encoding).
+     */
+    public void setDefaultOutputEncoding(String defaultOutputEncoding)
+    {
+        this.defaultOutputEncoding = defaultOutputEncoding;
+    }
+
+    /**
      * Sets additional options which can be added to the generation process.
      * These options overrides existing options in the templates.
      *



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


Mime
View raw message