db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1204787 - in /db/torque/torque4/trunk: maven-torque-generator-plugin/src/main/java/org/apache/torque/generator/maven/ torque-ant-tasks/src/main/java/org/apache/torque/ant/task/ torque-generator/src/main/java/org/apache/torque/generator/con...
Date Tue, 22 Nov 2011 02:31:29 GMT
Author: tfischer
Date: Tue Nov 22 02:31:26 2011
New Revision: 1204787

URL: http://svn.apache.org/viewvc?rev=1204787&view=rev
Log:
- TORQUE-173: Add possibility to combine all read files into one source tree
- Fix basis output directory for modifiable sources in maven generator plugin

Added:
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/CombinedFileSource.java
Modified:
    db/torque/torque4/trunk/maven-torque-generator-plugin/src/main/java/org/apache/torque/generator/maven/TorqueGeneratorMojo.java
    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/source/FileSourceSaxHandler.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceConfigurationTags.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSourceProvider.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSourceProvider.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformer.java
    db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd
    db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen-parent/conf/control.xml
    db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/control.xml
    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/source/stream/FileSourceProviderTest.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=1204787&r1=1204786&r2=1204787&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
Tue Nov 22 02:31:26 2011
@@ -201,6 +201,31 @@ public class TorqueGeneratorMojo extends
     private Set<String> sourceExcludes;
 
     /**
+     * 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.
+     * If true, a single source tree with the following structure will be
+     * built from all source files:
+     * &lt;source&gt;
+     *   &lt;file path="path/to/file1"&gt;
+     *      &lt;rootOfFile1&gt;
+     *        ...
+     *      &lt;/rootOfFile1&gt;
+     *   &lt;/file&gt;
+     *   &lt;file path="path/to/file2"&gt;
+     *      &lt;rootOfFile2&gt;
+     *        ...
+     *      &lt;/rootOfFile2&gt;
+     *   &lt;/file&gt;
+     *   ...
+     * &lt;/source&gt;
+     * If not set, the settings from the templates will be used.
+     *
+     * @parameter
+     */
+    private Boolean combineFiles;
+
+    /**
      * The default base output directory for the generated files.
      * Whether the configured templates use this directory or not,
      * is up to the templates; check the template documentation.
@@ -458,8 +483,10 @@ public class TorqueGeneratorMojo extends
                     + sourceExcludes);
             try
             {
-                fileSourceProvider
-                        = new FileSourceProvider(null, sourceFileset);
+                fileSourceProvider = new FileSourceProvider(
+                        null,
+                        sourceFileset,
+                        combineFiles);
             }
             catch (ConfigurationException e)
             {
@@ -478,7 +505,7 @@ public class TorqueGeneratorMojo extends
             {
                 outputDirMap.put(
                         Maven2ProjectPaths.MODIFIABLE_OUTPUT_DIR_KEY,
-                        new File(project.getBuild().getDirectory()
+                        new File(project.getBasedir()
                                 + "/"
                                 + Maven2ProjectPaths.MODIFIABLE_OUTPUT_DIR));
             }

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=1204787&r1=1204786&r2=1204787&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 Nov 22 02:31:26 2011
@@ -133,6 +133,29 @@ public class TorqueGeneratorTask extends
      */
     private String loglevel;
 
+    /**
+     * 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.
+     * If true, a single source tree with the following structure will be
+     * built from all source files:
+     * &lt;source&gt;
+     *   &lt;file path="path/to/file1"&gt;
+     *      &lt;rootOfFile1&gt;
+     *        ...
+     *      &lt;/rootOfFile1&gt;
+     *   &lt;/file&gt;
+     *   &lt;file path="path/to/file2"&gt;
+     *      &lt;rootOfFile2&gt;
+     *        ...
+     *      &lt;/rootOfFile2&gt;
+     *   &lt;/file&gt;
+     *   ...
+     * &lt;/source&gt;
+     * If not set, the settings from the templates will be used.
+     */
+    private Boolean combineFiles;
+
     /** The list of options for the generation task. */
     private List<Option> options = new ArrayList<Option>();
 
@@ -242,8 +265,10 @@ public class TorqueGeneratorTask extends
                     Project.MSG_DEBUG);
             try
             {
-                fileSourceProvider
-                        = new FileSourceProvider(null, sourceFileset);
+                fileSourceProvider = new FileSourceProvider(
+                        null,
+                        sourceFileset,
+                        combineFiles);
             }
             catch (ConfigurationException e)
             {
@@ -446,4 +471,32 @@ public class TorqueGeneratorTask extends
     {
         this.loglevel = loglevel;
     }
+
+    /**
+     * 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.
+     * If true, a single source tree with the following structure will be
+     * built from all source files:
+     * &lt;source&gt;
+     *   &lt;file path="path/to/file1"&gt;
+     *      &lt;rootOfFile1&gt;
+     *        ...
+     *      &lt;/rootOfFile1&gt;
+     *   &lt;/file&gt;
+     *   &lt;file path="path/to/file2"&gt;
+     *      &lt;rootOfFile2&gt;
+     *        ...
+     *      &lt;/rootOfFile2&gt;
+     *   &lt;/file&gt;
+     *   ...
+     * &lt;/source&gt;
+     * If not set, the settings from the templates will be used.
+     *
+     * @param combineFiles whether all sources should be combined.
+     */
+    public void setCombineFiles(Boolean combineFiles)
+    {
+        this.combineFiles = combineFiles;
+    }
 }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/FileSourceSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/FileSourceSaxHandler.java?rev=1204787&r1=1204786&r2=1204787&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/FileSourceSaxHandler.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/FileSourceSaxHandler.java
Tue Nov 22 02:31:26 2011
@@ -19,6 +19,7 @@ package org.apache.torque.generator.conf
  * under the License.
  */
 
+import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.COMBINE_FILES_ATTRIBUTE;
 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.EXCLUDE_TAG;
 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.FORMAT_ATTRIBUTE;
 import static org.apache.torque.generator.configuration.source.SourceConfigurationTags.INCLUDE_TAG;
@@ -30,6 +31,7 @@ import java.util.Set;
 import org.apache.torque.generator.configuration.ConfigurationException;
 import org.apache.torque.generator.configuration.ConfigurationHandlers;
 import org.apache.torque.generator.configuration.ConfigurationProvider;
+import org.apache.torque.generator.configuration.SaxHelper;
 import org.apache.torque.generator.configuration.paths.ProjectPaths;
 import org.apache.torque.generator.file.Fileset;
 import org.apache.torque.generator.source.SourceProvider;
@@ -52,6 +54,9 @@ public class FileSourceSaxHandler extend
     /** The source file names which should be excluded from generation. */
     private Set<String> excludes = new HashSet<String>();
 
+    /** Whether to combine all source files. */
+    private Boolean combineFiles;
+
     /**
      * The string builder for an include definition.
      * Not null if an include tag is currently parsed.
@@ -107,6 +112,13 @@ public class FileSourceSaxHandler extend
         {
             super.startElement(uri, localName, rawName, attributes);
             format = attributes.getValue(FORMAT_ATTRIBUTE);
+            if (attributes.getValue(COMBINE_FILES_ATTRIBUTE) != null)
+            {
+                combineFiles = SaxHelper.getBooleanAttribute(
+                        COMBINE_FILES_ATTRIBUTE,
+                        attributes,
+                        "the element " + SOURCE_TAG);
+            }
         }
         else
         {
@@ -162,7 +174,8 @@ public class FileSourceSaxHandler extend
 
                 sourceProvider = new FileSourceProvider(
                         sourceFormat,
-                        sourceFileset);
+                        sourceFileset,
+                        combineFiles);
             }
             catch (ConfigurationException e)
             {

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceConfigurationTags.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceConfigurationTags.java?rev=1204787&r1=1204786&r2=1204787&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceConfigurationTags.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceConfigurationTags.java
Tue Nov 22 02:31:26 2011
@@ -43,6 +43,9 @@ public final class SourceConfigurationTa
     /** Attribute name for the "format" attribute. */
     public static final String FORMAT_ATTRIBUTE = "format";
 
+    /** Attribute name for the "combineFiles" attribute. */
+    public static final String COMBINE_FILES_ATTRIBUTE = "combineFiles";
+
     /** Tag name for the "transformer" tag. */
     public static final String TRANSFORMER_TAG = "transformer";
 

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=1204787&r1=1204786&r2=1204787&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 Nov 22 02:31:26 2011
@@ -194,7 +194,7 @@ public class Controller
                 UnitConfiguration unitConfiguration)
             throws GeneratorException
     {
-        log.debug("Processing output " + output.getFilename());
+        log.info("Processing output " + output.getName());
         controllerState.setOutput(output);
 
         SourceProvider sourceProvider = output.getSourceProvider();
@@ -202,12 +202,8 @@ public class Controller
                 = unitConfiguration.getOverrideSourceProvider();
         if (overrideSourceProvider != null)
         {
-            if (overrideSourceProvider.isInit())
-            {
-                overrideSourceProvider.reset(
-                        unitConfiguration.getConfigurationHandlers(),
-                        controllerState);
-            }
+            overrideSourceProvider = overrideSourceProvider.copy();
+            overrideSourceProvider.copyNotSetSettingsFrom(sourceProvider);
             sourceProvider = overrideSourceProvider;
         }
         controllerState.setSourceProvider(sourceProvider);

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java?rev=1204787&r1=1204786&r2=1204787&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java
Tue Nov 22 02:31:26 2011
@@ -135,4 +135,15 @@ public abstract class SourceProvider imp
      *         be initialized.
      */
     public abstract SourceProvider copy() throws ConfigurationException;
+
+    /**
+     * Copies settings which are not set in this source provider from another
+     * source provider. This only works if the type of the other source
+     * provider is known to this source provider.
+     * Only a subset of all properties are typically used for overwriting.
+     * No Properties which are already set are overwritten.
+     *
+     * @param sourceProvider the source provoder to copy the settings from.
+     */
+    public abstract void copyNotSetSettingsFrom(SourceProvider sourceProvider);
 }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSourceProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSourceProvider.java?rev=1204787&r1=1204786&r2=1204787&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSourceProvider.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSourceProvider.java
Tue Nov 22 02:31:26 2011
@@ -216,4 +216,13 @@ public class JdbcMetadataSourceProvider 
                 schemaOption);
         return result;
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void copyNotSetSettingsFrom(SourceProvider sourceProvider)
+    {
+        // do nothing.
+    }
+
 }

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/CombinedFileSource.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/CombinedFileSource.java?rev=1204787&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/CombinedFileSource.java
(added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/CombinedFileSource.java
Tue Nov 22 02:31:26 2011
@@ -0,0 +1,159 @@
+package org.apache.torque.generator.source.stream;
+
+/*
+ * 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 java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.SourceException;
+import org.apache.torque.generator.source.SourceImpl;
+
+/**
+ * A source which uses several files as input and combines them into one file.
+ * The source tree will look as follows:
+ * &lt;source&gt;
+ *   &lt;file path="path/to/file1"&gt;
+ *      &lt;rootOfFile1&gt;
+ *        ...
+ *      &lt;/rootOfFile1&gt;
+ *   &lt;/file&gt;
+ *   &lt;file path="path/to/file2"&gt;
+ *      &lt;rootOfFile2&gt;
+ *        ...
+ *      &lt;/rootOfFile2&gt;
+ *   &lt;/file&gt;
+ *   ...
+ * &lt;/source&gt;
+ */
+public class CombinedFileSource extends SourceImpl
+{
+    /** The name of the root element of the produced source tree. */
+    public static final String ROOT_ELEMENT_NAME = "source";
+
+    /** The name of the root element's children of the produced source tree. */
+    public static final String FILE_ELEMENT_NAME = "file";
+
+    /** The name of the path attribute of the file elements. */
+    public static final String PATH_ATTRIBUTE_NAME = "path";
+
+    /**
+     * The log of the class.
+     */
+    private static Log log = LogFactory.getLog(CombinedFileSource.class);
+
+    /**
+     * The list of contained file sources, not null..
+     */
+    private List<FileSource> fileSources;
+
+    /**
+     * Constructor.
+     *
+     * @param fileSources the file sources, not null.
+     *
+     * @throws NullPointerException if path or format is null.
+     */
+    public CombinedFileSource(
+            Collection<FileSource> fileSources)
+    {
+        if (fileSources == null)
+        {
+            throw new NullPointerException("path must not be null");
+        }
+        this.fileSources = new ArrayList<FileSource>(fileSources);
+    }
+
+    /**
+     * Reads and parses the input file and creates the element tree from it.
+     *
+     * @throws SourceException if the input file cannot be read or parsed.
+     *
+     * @return the root element of the element tree.
+     */
+    @Override
+    public SourceElement createRootElement() throws SourceException
+    {
+        if (log.isDebugEnabled())
+        {
+            log.debug("start creating root Element");
+        }
+
+        SourceElement result = new SourceElement(ROOT_ELEMENT_NAME);
+        for (FileSource fileSource : fileSources)
+        {
+            SourceElement fileElement = new SourceElement(FILE_ELEMENT_NAME);
+            fileElement.setAttribute(
+                    PATH_ATTRIBUTE_NAME,
+                    fileSource.getPath().getPath());
+            fileElement.getChildren().add(fileSource.getRootElement());
+            result.getChildren().add(fileElement);
+        }
+
+        if (log.isDebugEnabled())
+        {
+            log.debug("finished creating root Element, source is\n"
+                    + new SourceToXml().toXml(result, true));
+        }
+        return result;
+    }
+
+    /**
+     * Returns the path of the files as a description.
+     *
+     * @return path of the files,separated by a semicolon, not null.
+     *
+     * @see org.apache.torque.generator.source.Source#getDescription()
+     */
+    public String getDescription()
+    {
+        StringBuilder result = new StringBuilder();
+        for (FileSource fileSource : fileSources)
+        {
+            if (result.length() > 0)
+            {
+                result.append(';');
+            }
+            result.append(fileSource.getPath());
+        }
+        return result.toString();
+    }
+
+    /**
+     * Returns the source file, if applicable. As no single source file
+     * exists, the method returns always null.
+     *
+     * @return null.
+     */
+    public File getSourceFile()
+    {
+        return null;
+    }
+
+    @Override
+    public String toString()
+    {
+        return getDescription();
+    }
+}

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSourceProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSourceProvider.java?rev=1204787&r1=1204786&r2=1204787&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSourceProvider.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSourceProvider.java
Tue Nov 22 02:31:26 2011
@@ -21,6 +21,7 @@ package org.apache.torque.generator.sour
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -54,6 +55,13 @@ public class FileSourceProvider extends 
     /** The fileset defining the source files, not null. */
     private Fileset sourceFileset;
 
+    /**
+     * Whether all files should be combined into one source tree.
+     * Null to allow overriding this property (but will count as false
+     * if not overridden).
+     */
+    private Boolean combineFiles;
+
     /** The paths of all contained Files. */
     private List<File> paths;
 
@@ -73,11 +81,8 @@ public class FileSourceProvider extends 
      * @param sourceFormat the source format, or null if the source format
      *        should be determined from the file extension.
      * @param sourceFileset the fileset defining the source files, not null.
-     * @param elements the path to the source elements to read, or null
-     *        if the root element should be used.
-     * @param sourceFilter the fully qualified class name of the source filter,
-     *        or null. The referenced class must have a standard constructor.
-     * @param configurationHandlers All known configuration handlers, not null.
+     * @param combineFiles whether all files should be combined into
+     *        one source tree.
      *
      * @throws IllegalArgumentException if the source type is unknown.
      * @throws NullPointerException if path is null.
@@ -86,7 +91,8 @@ public class FileSourceProvider extends 
      */
     public FileSourceProvider(
                     StreamSourceFormat sourceFormat,
-                    Fileset sourceFileset)
+                    Fileset sourceFileset,
+                    Boolean combineFiles)
             throws ConfigurationException
     {
         if (sourceFileset == null)
@@ -95,6 +101,7 @@ public class FileSourceProvider extends 
         }
         this.sourceFormat = sourceFormat;
         this.sourceFileset = sourceFileset;
+        this.combineFiles = combineFiles;
     }
 
     /**
@@ -164,6 +171,23 @@ public class FileSourceProvider extends 
                     "init() must be called on this SourceProvider "
                     + "before hasNext can be called");
         }
+        if (combineFiles == null || !combineFiles)
+        {
+            return getNextFileSource();
+        }
+        else
+        {
+            List<FileSource> fileSources = new ArrayList<FileSource>();
+            while (pathIt.hasNext())
+            {
+                fileSources.add(getNextFileSource());
+            }
+            return new CombinedFileSource(fileSources);
+        }
+    }
+
+    private FileSource getNextFileSource()
+    {
         File currentPath = pathIt.next();
         StreamSourceFormat currentSourceFormat = sourceFormat;
         if (currentSourceFormat == null)
@@ -270,13 +294,56 @@ public class FileSourceProvider extends 
     }
 
     /**
+     * Returns whether source files are combined into one source tree.
+     *
+     * @return true if the source files are combined into one source tree,
+     *         false otherwise, null to allow overriding this property
+     *         (but will count as false if not overridden).
+     */
+    public Boolean getCombineFiles()
+    {
+        return combineFiles;
+    }
+
+    /**
      * {@inheritDoc}
      */
     public SourceProvider copy() throws ConfigurationException
     {
         FileSourceProvider result = new FileSourceProvider(
                 sourceFormat,
-                sourceFileset);
+                sourceFileset,
+                combineFiles);
         return result;
     }
+
+    /**
+     * Copies settings which are not set in this source provider from another
+     * source provider. This only works if the type of the other source
+     * provider is known to this source provider.
+     * Only a subset of all properties are typically used for overwriting.
+     * No Properties which are already set are overwritten.
+     *
+     * @param sourceProvider the source provoder to copy the settings from.
+     */
+    public void copyNotSetSettingsFrom(SourceProvider sourceProvider)
+    {
+        if (sourceProvider == null)
+        {
+            return;
+        }
+        if (!(sourceProvider instanceof FileSourceProvider))
+        {
+            return;
+        }
+        FileSourceProvider fileSourceProvider
+                = (FileSourceProvider) sourceProvider;
+        if (combineFiles == null)
+        {
+            log.debug("copying combineFiles property"
+                    + " from other source provider");
+            combineFiles = fileSourceProvider.getCombineFiles();
+        }
+    }
+
 }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformer.java?rev=1204787&r1=1204786&r2=1204787&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformer.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformer.java
Tue Nov 22 02:31:26 2011
@@ -121,7 +121,8 @@ public class LoadAdditionalSourceTransfo
                     new Fileset(
                             controllerState.getSourceFile().getParentFile(),
                             fileIncludes,
-                            fileExcludes));
+                            fileExcludes),
+                    false);
             fileSourceProvider.init(configurationHandlers, controllerState);
         }
         catch (ConfigurationException e)

Modified: db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd?rev=1204787&r1=1204786&r2=1204787&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd
Tue Nov 22 02:31:26 2011
@@ -206,6 +206,19 @@
           <element name="exclude" type="string" minOccurs="0" maxOccurs="unbounded"/>
         </sequence>
         <attribute name="format" type="string" use="optional"/>
+        <attribute name="combineFiles" type="boolean" use="optional">
+          <annotation>
+            <documentation>
+              Whether to combine all source files in a single source tree.
+              Default is false. If true, the name of the source tree's root
+              element will be source. Each loaded source file will be put
+              into a child element with element name file. The root element
+              of the single file will be the only child element of the file
+              element. The name of the file will be put into the attribute 
+              path of the file element.
+            </documentation>
+          </annotation>
+        </attribute>
       </extension>
     </complexContent>
   </complexType>

Modified: db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen-parent/conf/control.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen-parent/conf/control.xml?rev=1204787&r1=1204786&r2=1204787&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen-parent/conf/control.xml
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen-parent/conf/control.xml
Tue Nov 22 02:31:26 2011
@@ -41,6 +41,7 @@
     <source xsi:type="fileSource"
         elements="parentSourceElement"
         format="xml"
+        combineFiles="false"
         skipDecider="org.apache.torque.generator.configuration.OtherConfigurationTestSkipDecider">
       <transformer elements="parent/database" 
           class="org.apache.torque.generator.configuration.OtherConfigurationTestTransformer"
/>

Modified: db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/control.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/control.xml?rev=1204787&r1=1204786&r2=1204787&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/control.xml
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/control.xml
Tue Nov 22 02:31:26 2011
@@ -47,6 +47,7 @@
     <source xsi:type="fileSource" 
         elements="properties/entry"
         format="properties"
+        combineFiles="true"
         skipDecider="org.apache.torque.generator.configuration.ConfigurationTestSkipDecider">
       <transformer class="org.apache.torque.generator.configuration.ConfigurationTestTransformer"
/>
       <transformer elements="database" 

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=1204787&r1=1204786&r2=1204787&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 Nov 22 02:31:26 2011
@@ -218,7 +218,8 @@ public class ReadConfigurationTest exten
                             new HashSet<String>());
                     FileSourceProvider sourceProvider = new FileSourceProvider(
                             new XmlSourceFormat(),
-                            sourceFileset);
+                            sourceFileset,
+                            null);
                     sourceProvider.init(
                             configurationHandlers,
                             controllerState);
@@ -284,7 +285,8 @@ public class ReadConfigurationTest exten
                             createSetFrom("second.excluded.properties"));
                     FileSourceProvider sourceProvider = new FileSourceProvider(
                             new PropertiesSourceFormat(),
-                            sourceFileset);
+                            sourceFileset,
+                            true);
                     sourceProvider.init(
                             configurationHandlers,
                             controllerState);
@@ -697,7 +699,8 @@ public class ReadConfigurationTest exten
                             new HashSet<String>());
                     FileSourceProvider sourceProvider = new FileSourceProvider(
                             new XmlSourceFormat(),
-                            sourceFileset);
+                            sourceFileset,
+                            false);
                     output.getSourceProvider().init(
                             configurationHandlers,
                             controllerState);
@@ -767,7 +770,8 @@ public class ReadConfigurationTest exten
                             new HashSet<String>());
                     FileSourceProvider sourceProvider = new FileSourceProvider(
                             new XmlSourceFormat(),
-                            sourceFileset);
+                            sourceFileset,
+                            null);
                     sourceProvider.init(
                             configurationHandlers,
                             controllerState);
@@ -829,7 +833,8 @@ public class ReadConfigurationTest exten
                             createSetFrom("second.excluded.properties"));
                     FileSourceProvider sourceProvider = new FileSourceProvider(
                             new PropertiesSourceFormat(),
-                            sourceFileset);
+                            sourceFileset,
+                            true);
                     sourceProvider.init(
                             configurationHandlers,
                             controllerState);
@@ -1023,6 +1028,9 @@ public class ReadConfigurationTest exten
         assertEquals(
                 expected.getPaths(),
                 actual.getPaths());
+        assertEquals(
+                expected.getCombineFiles(),
+                actual.getCombineFiles());
     }
 
     private static void assertJdbcMetadataSourceProviderEquals(

Modified: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/stream/FileSourceProviderTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/stream/FileSourceProviderTest.java?rev=1204787&r1=1204786&r2=1204787&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/stream/FileSourceProviderTest.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/stream/FileSourceProviderTest.java
Tue Nov 22 02:31:26 2011
@@ -21,8 +21,8 @@ package org.apache.torque.generator.sour
 
 import static org.apache.torque.generator.file.FileTestUtils.createSetFrom;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.util.HashSet;
@@ -49,7 +49,7 @@ public class FileSourceProviderTest
                 createSetFrom("*.properties"),
                 null);
         FileSourceProvider fileSourceProvider
-                = new FileSourceProvider(null, fileset);
+                = new FileSourceProvider(null, fileset, false);
         fileSourceProvider.init(
                 new ConfigurationHandlers(),
                 new ControllerState());
@@ -79,6 +79,62 @@ public class FileSourceProviderTest
         assertEquals(expectedKeys, resultKeys);
     }
 
+    @Test
+    public void testReadFilesCombineFiles()
+            throws ConfigurationException, SourceException
+    {
+        Fileset fileset = new Fileset(
+                TEST_BASE_DIR,
+                createSetFrom("*.properties"),
+                null);
+        FileSourceProvider fileSourceProvider
+                = new FileSourceProvider(null, fileset, true);
+        fileSourceProvider.init(
+                new ConfigurationHandlers(),
+                new ControllerState());
+
+        // We read all sources and add the first property key to a hash set.
+        // As all the source files only have one key equal to the base filename
+        // we can make sure we have read the expected files correctly.
+        Set<String> resultKeys = new HashSet<String>();
+        assertTrue(fileSourceProvider.hasNext());
+        Source source = fileSourceProvider.next();
+
+        assertEquals(2, source.getRootElement().getChildren("file").size());
+        Object key = source.getRootElement()
+                .getChildren("file").get(0)
+                .getChild("properties")
+                .getChild("entry")
+                .getAttribute("key");
+        resultKeys.add((String) key);
+        key = source.getRootElement()
+                .getChildren("file").get(1)
+                .getChild("properties")
+                .getChild("entry")
+                .getAttribute("key");
+        resultKeys.add((String) key);
+        Set<String> expectedKeys = new HashSet<String>();
+        expectedKeys.add("1");
+        expectedKeys.add("11");
+        assertEquals(expectedKeys, resultKeys);
+
+        Set<String> resultPaths = new HashSet<String>();
+        String expectedPath = (String) source.getRootElement()
+                .getChildren("file").get(0).getAttribute("path");
+        expectedPath = expectedPath.replace('\\', '/');
+        resultPaths.add(expectedPath);
+        expectedPath = (String) source.getRootElement()
+                .getChildren("file").get(1).getAttribute("path");
+        expectedPath = expectedPath.replace('\\', '/');
+        resultPaths.add(expectedPath);
+        Set<String> expectedPaths = new HashSet<String>();
+        expectedPaths.add("src/test/file/./1.properties");
+        expectedPaths.add("src/test/file/./11.properties");
+        assertEquals(expectedPaths, resultPaths);
+
+        assertFalse(fileSourceProvider.hasNext());
+    }
+
     @Test(expected = ConfigurationException.class)
     public void testReadFilesBasedirNull()
             throws ConfigurationException, SourceException
@@ -88,7 +144,7 @@ public class FileSourceProviderTest
                 createSetFrom("*.properties"),
                 null);
         FileSourceProvider fileSourceProvider
-                = new FileSourceProvider(null, fileset);
+                = new FileSourceProvider(null, fileset, false);
         fileSourceProvider.init(
                 new ConfigurationHandlers(),
                 new ControllerState());



---------------------------------------------------------------------
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