db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1036838 - in /db/torque/torque4/trunk/torque-generator/src: main/java/org/apache/torque/generator/configuration/ main/java/org/apache/torque/generator/configuration/source/ main/java/org/apache/torque/generator/file/ main/java/org/apache/t...
Date Fri, 19 Nov 2010 13:47:51 GMT
Author: tfischer
Date: Fri Nov 19 13:47:50 2010
New Revision: 1036838

URL: http://svn.apache.org/viewvc?rev=1036838&view=rev
Log:
Add a transformer which can add additional files into an existing source tree.

Added:
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformer.java
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformerTest.java
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/package.html
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/conf/
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/conf/control.xml
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/outlets/
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/outlets/outlets.xml
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/additional1.xml
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/additional2.xml
    db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/source.xml
Modified:
    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/source/SourceTransformerSaxHandler.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/file/Fileset.java

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=1036838&r1=1036837&r2=1036838&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
Fri Nov 19 13:47:50 2010
@@ -56,6 +56,9 @@ public class UnitConfiguration
     /** The entity references for resolving schema files for XML sources. */
     private EntityReferences entityReferences;
 
+    /** The configuration handlers which are used to read this configuration. */
+    private ConfigurationHandlers configurationHandlers;
+
     /**
      * The root directory where the generated file which are generated
      * each time anew are put into.
@@ -74,7 +77,7 @@ public class UnitConfiguration
     /**
      * Returns the configuration of the outlets in this generation unit.
      *
-     * @return the outlet configuration, or null if not set.
+     * @return the outlet configuration, not null.
      *
      * @throws IllegalStateException if outletConfiguration was not set.
      */
@@ -283,6 +286,43 @@ public class UnitConfiguration
     }
 
     /**
+     * Returns the configuration handlers used to parse the configuration
+     * of this generation unit.
+     *
+     * @return the configuration handlers, not null.
+     *
+     * @throws IllegalStateException if configurationHandlers was not set.
+     */
+    public ConfigurationHandlers getConfigurationHandlers()
+    {
+        if (configurationHandlers == null)
+        {
+            throw new IllegalStateException(
+                    "configurationHandlers is not initialized");
+        }
+        return configurationHandlers;
+    }
+
+    /**
+     * Sets the configuration handlers used to parse the configuration
+     * of this generation unit.
+     *
+     * @param configurationHandlers the configuration handlers, not null.
+     *
+     * @throws NullPointerException if configurationHandlers is null.
+     */
+    public void setConfigurationHandlers(
+            ConfigurationHandlers configurationHandlers)
+    {
+        if (configurationHandlers == null)
+        {
+            throw new NullPointerException(
+                    "configurationHandlers cannot be null");
+        }
+        this.configurationHandlers = configurationHandlers;
+    }
+
+    /**
      * Returns the source provider which overrides the source provider defined
      * in the control file.
      *
@@ -363,6 +403,7 @@ public class UnitConfiguration
             || newFileTargetDirectory == null
             || modifiedFileTargetDirectory == null
             || loglevel == null
+            || configurationHandlers == null
             || entityReferences == null
             || !overrideSourceProviderInitialized)
         {

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=1036838&r1=1036837&r2=1036838&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
Fri Nov 19 13:47:50 2010
@@ -87,6 +87,8 @@ class UnitConfigurationReader
         }
 
         UnitConfiguration unitConfiguration = new UnitConfiguration();
+        unitConfiguration.setConfigurationHandlers(
+                configurationHandlers);
         unitConfiguration.setNewFileTargetDirectory(
                 unitDescriptor.getProjectPaths().getNewFileTargetPath());
         unitConfiguration.setModifiedFileTargetDirectory(

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceTransformerSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceTransformerSaxHandler.java?rev=1036838&r1=1036837&r2=1036838&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceTransformerSaxHandler.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/SourceTransformerSaxHandler.java
Fri Nov 19 13:47:50 2010
@@ -25,9 +25,11 @@ import static org.apache.torque.generato
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
 
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.torque.generator.configuration.ConfigurationProvider;
@@ -62,9 +64,25 @@ public class SourceTransformerSaxHandler
 
     /**
      * The value of the currently read bean property of the transformer,
-     * or null if no property is currently read.
+     * or null if no property is currently read or the property is a
+     * list property.
+     */
+    private StringBuilder simplePropertyValue;
+
+    /**
+     * The value of the currently read bean property of the transformer,
+     * or null if no property is currently read or the property is a
+     * simple property.
+     */
+    private ArrayList<String> listPropertyValue;
+
+    /**
+     * The value of the currently read list entry of the currently read
+     * property of the transformer,
+     * or null if no list entry is currently read or the property is a
+     * simple property.
      */
-    private StringBuilder propertyValue;
+    private StringBuilder listPropertyEntry;
 
     /**
      * Constructor.
@@ -123,7 +141,24 @@ public class SourceTransformerSaxHandler
         {
             level++;
             propertyName = rawName;
-            propertyValue = new StringBuilder();
+            simplePropertyValue = new StringBuilder();
+        }
+        else if (level == 2)
+        {
+            level++;
+            if (simplePropertyValue.length() > 0 
+                    && !StringUtils.isWhitespace(simplePropertyValue.toString()))
+            {
+                throw new SAXException(
+                        "Cannot parse both text content and child elements "
+                        + " in element " + propertyName);
+            }
+            simplePropertyValue = null;
+            if (listPropertyValue == null)
+            {
+                listPropertyValue = new ArrayList<String>();
+            }
+            listPropertyEntry = new StringBuilder();
         }
         else
         {
@@ -139,7 +174,12 @@ public class SourceTransformerSaxHandler
         throws SAXException
     {
         level--;
-        if (level == 1)
+        if (level == 2)
+        {
+            listPropertyValue.add(listPropertyEntry.toString());
+            listPropertyEntry = null;
+        }
+        else if (level == 1)
         {
             if (!PropertyUtils.isWriteable(sourceTransformer, propertyName))
             {
@@ -148,12 +188,21 @@ public class SourceTransformerSaxHandler
                         + " in class "
                         + sourceTransformer.getClass().getName());
             }
+            Object propertyValue;
+            if (simplePropertyValue != null)
+            {
+                propertyValue = simplePropertyValue.toString();
+            }
+            else
+            {
+                propertyValue = listPropertyValue;
+            }
             try
             {
                 BeanUtils.copyProperty(
                         sourceTransformer,
                         propertyName,
-                        propertyValue.toString());
+                        propertyValue);
             }
             catch (InvocationTargetException e)
             {
@@ -180,7 +229,7 @@ public class SourceTransformerSaxHandler
         }
         else if (level != 0)
         {
-            throw new SAXException("endElemend reached Level" + level);
+            throw new SAXException("endElemend reached Level " + level);
         }
     }
 
@@ -191,13 +240,21 @@ public class SourceTransformerSaxHandler
     public void characters(char[] ch, int start, int length)
             throws SAXException
     {
-        if (propertyName == null)
+        if (simplePropertyValue != null)
         {
+            for (int i = start; i < start + length; ++i)
+            {
+                simplePropertyValue.append(ch[i]);
+            }
             return;
         }
-        for (int i = start; i < start + length; ++i)
+        if (listPropertyEntry != null)
         {
-            propertyValue.append(ch[i]);
+            for (int i = start; i < start + length; ++i)
+            {
+                listPropertyEntry.append(ch[i]);
+            }
+            return;
         }
     }
 

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/file/Fileset.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/file/Fileset.java?rev=1036838&r1=1036837&r2=1036838&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/file/Fileset.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/file/Fileset.java
Fri Nov 19 13:47:50 2010
@@ -23,9 +23,9 @@ import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.io.IOCase;
@@ -52,13 +52,13 @@ public class Fileset
      * The patterns for the files to include.
      * If null or empty, all Files are included.
      */
-    private Set<String> includes;
+    private Collection<String> includes;
 
     /**
      * The patterns for the files to exclude.
      * If null or empty, no Files are excluded.
      */
-    private Set<String> excludes;
+    private Collection<String> excludes;
 
     /**
      * Default constructor.
@@ -76,7 +76,9 @@ public class Fileset
      * @param excludes The patterns for the files to exclude.
      *        If null or empty, no Files are excluded.
      */
-    public Fileset(File basedir, Set<String> includes, Set<String> excludes)
+    public Fileset(File basedir,
+            Collection<String> includes,
+            Collection<String> excludes)
     {
         this.basedir = basedir;
         this.includes = includes;
@@ -108,7 +110,7 @@ public class Fileset
      *
      * @return the include patterns, or null if all files should be included.
      */
-    public Set<String> getIncludes()
+    public Collection<String> getIncludes()
     {
         return includes;
     }
@@ -118,7 +120,7 @@ public class Fileset
      *
      * @return the include patterns, or null if all files should be included.
      */
-    public void setIncludes(Set<String> includes)
+    public void setIncludes(Collection<String> includes)
     {
         this.includes = includes;
     }
@@ -128,7 +130,7 @@ public class Fileset
      *
      * @return the exclude patterns, or null if all files should be excluded.
      */
-    public Set<String> getExcludes()
+    public Collection<String> getExcludes()
     {
         return excludes;
     }
@@ -138,7 +140,7 @@ public class Fileset
      *
      * @return the exclude patterns, or null if all files should be excluded.
      */
-    public void setExcludes(Set<String> excludes)
+    public void setExcludes(Collection<String> excludes)
     {
         this.excludes = excludes;
     }

Added: 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=1036838&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformer.java
(added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformer.java
Fri Nov 19 13:47:50 2010
@@ -0,0 +1,237 @@
+package org.apache.torque.generator.source.transform;
+
+/*
+ * 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.util.List;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.generator.configuration.ConfigurationException;
+import org.apache.torque.generator.configuration.ConfigurationHandlers;
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.file.Fileset;
+import org.apache.torque.generator.source.Source;
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.SourceException;
+import org.apache.torque.generator.source.SourcePath;
+import org.apache.torque.generator.source.stream.FileSourceProvider;
+import org.apache.torque.generator.source.stream.StreamSourceFormat;
+
+/**
+ * A SourceTransformer which loads other sources into the current source graph.
+ *
+ * @version $Id: $
+ */
+public class LoadAdditionalSourceTransformer implements SourceTransformer
+{
+    /** The class log. */
+    private static Log log
+            = LogFactory.getLog(LoadAdditionalSourceTransformer.class);
+
+    /**
+     * The element where the newly loaded source should be added.
+     */
+    private String element;
+
+    /**
+     * The include path for the files to load,
+     * relative to the current source file.
+     */
+    private List<String> fileIncludes;
+
+    /**
+     * The exclude path for the files to load,
+     * relative to the current source file.
+     */
+    private List<String> fileExcludes;
+
+    /**
+     * The format of the source.
+     */
+    private String sourceFormat;
+
+    /**
+     * Loads the additional source into the current source graph.
+     *
+     * @param root the root of the source graph, not null.
+     * @param controllerState the controller state, not null.
+     *
+     * @throws SourceTransformerException if the additional source
+     *         cannot be loaded or the element to add to does not exist.
+     */
+    public SourceElement transform(
+            SourceElement root,
+            ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        // the element where the additional source should be anchored.
+        SourceElement sourceElement;
+        List<SourceElement> sourceElementList 
+                = SourcePath.getElementsFromRoot(root, element);
+        if (sourceElementList.isEmpty())
+        {
+            throw new SourceTransformerException(
+                    "Source element " + element + " does not exist");
+        }
+        sourceElement = sourceElementList.get(0);
+
+        ConfigurationHandlers configurationHandlers
+                = controllerState.getUnitConfiguration()
+                        .getConfigurationHandlers();
+        Set<StreamSourceFormat> streamSourceFormats
+            = configurationHandlers.getStreamSourceFormats();
+        StreamSourceFormat streamSourceFormat = null;
+        for (StreamSourceFormat candidate : streamSourceFormats)
+        {
+            if (sourceFormat.equals(candidate.getKey()))
+            {
+                streamSourceFormat = candidate;
+                break;
+            }
+        }
+        if (streamSourceFormat == null)
+        {
+            throw new SourceTransformerException(
+                    "Unknown source format" + sourceFormat);
+        }
+        
+        FileSourceProvider fileSourceProvider;
+        try
+        {
+            fileSourceProvider = new FileSourceProvider(
+                    streamSourceFormat,
+                    new Fileset(
+                            controllerState.getSourceFile().getParentFile(),
+                            fileIncludes, 
+                            fileExcludes));
+            fileSourceProvider.init(configurationHandlers, controllerState);
+        }
+        catch (ConfigurationException e)
+        {
+            throw new SourceTransformerException(
+                    "Could initialize file source provider", e);
+        }
+        while (fileSourceProvider.hasNext())
+        {
+            Source additionalSource = fileSourceProvider.next();
+            SourceElement additionalSourceRoot;
+            try
+            {
+                additionalSourceRoot = additionalSource.getRootElement();
+            }
+            catch (SourceException e)
+            {
+                log.error("Could not construct source from schema file "
+                        + additionalSource.getDescription(),
+                    e);
+                throw new SourceTransformerException(
+                        "Could not construct source from schema file "
+                            + additionalSource.getDescription(),
+                        e);
+            }
+            sourceElement.getChildren().add(additionalSourceRoot);
+        }
+
+        return root;
+    }
+
+    /**
+     * Returns the path to the source element to which the additional sources
+     * should be added.
+     * 
+     * @return the path to the anchor element.
+     */
+    public String getElement()
+    {
+        return element;
+    }
+
+    /**
+     * Sets the path to the source element to which the additional sources
+     * should be added.
+     *
+     * @param element the path to the anchor element.
+     */
+    public void setElement(String element)
+    {
+        this.element = element;
+    }
+
+    /**
+     * Returns the file patterns to include to the sources to read.
+     *
+     * @return the file patterns to include.
+     */
+    public List<String> getFileIncludes()
+    {
+        return fileIncludes;
+    }
+
+    /**
+     * Sets the file patterns to include to the sources to read.
+     *
+     * @param fileIncludes the file patterns to include.
+     */
+    public void setFileIncludes(List<String> fileIncludes)
+    {
+        this.fileIncludes = fileIncludes;
+    }
+
+    /**
+     * Returns the file patterns to exclude from the sources to read.
+     *
+     * @return the file patterns to exclude.
+     */
+    public List<String> getFileExcludes()
+    {
+        return fileExcludes;
+    }
+
+    /**
+     * Sets the file patterns to exclude from the sources to read.
+     *
+     * @param fileExcludes the file patterns to exclude.
+     */
+    public void setFileExcludes(List<String> fileExcludes)
+    {
+        this.fileExcludes = fileExcludes;
+    }
+
+    /**
+     * Returns the key of the format of the source file(s).
+     *
+     * @return the key for the source format.
+     */
+    public String getSourceFormat()
+    {
+        return sourceFormat;
+    }
+
+    /**
+     * Sets the key of the source format of the source file(s).
+     *
+     * @param sourceFormat the key for the source format.
+     */
+    public void setSourceFormat(String sourceFormat)
+    {
+        this.sourceFormat = sourceFormat;
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformerTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformerTest.java?rev=1036838&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformerTest.java
(added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/transform/LoadAdditionalSourceTransformerTest.java
Fri Nov 19 13:47:50 2010
@@ -0,0 +1,93 @@
+package org.apache.torque.generator.source.transform;
+
+/*
+ * 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.FileReader;
+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.apache.torque.generator.control.Controller;
+import org.junit.Test;
+
+/**
+ * Tests whether the loadAdditionalSourceTransformer works correctly.
+ */
+public class LoadAdditionalSourceTransformerTest extends BaseTest
+{
+    private static final String EXPECTED = "<root>\n"
+        + "  <element>\n"
+        + "    <child/>\n"
+        + "    <additional>\n"
+        + "      <element/>\n"
+        + "    </additional>\n"
+        + "    <additional>\n"
+        + "      <element/>\n"
+        + "    </additional>\n"
+        + "  </element>\n"
+        + "  <element/>\n"
+        + "</root>\n";
+    
+    @Test
+    public void testLoadAdditionalSourceTransformerGeneration() throws Exception
+    {
+        File targetDir = new File("target/test/loadAdditionalSourceTransformer");
+        FileUtils.deleteDirectory(targetDir);
+        Controller controller = new Controller();
+        List<UnitDescriptor> unitDescriptors = new ArrayList<UnitDescriptor>();
+        CustomProjectPaths projectPaths = new CustomProjectPaths(
+                new Maven2DirectoryProjectPaths(
+                        new File("src/test/loadAdditionalSourceTransformer")));
+        projectPaths.setNewFileTargetDir(targetDir);
+        unitDescriptors.add(new UnitDescriptor(
+                UnitDescriptor.Packaging.DIRECTORY,
+                projectPaths,
+                new DefaultTorqueGeneratorPaths()));
+        controller.run(unitDescriptors);
+
+        assertTrue(targetDir.exists());
+        File targetFile = new File(targetDir, "output.txt");
+        assertTrue(targetFile.exists());
+
+        FileReader fileReader = new FileReader(targetFile);
+        StringBuilder content = new StringBuilder();
+        int readChars;
+        char[] buffer = new char[50];
+        do
+        {
+            readChars = fileReader.read(buffer);
+            if (readChars != -1)
+            {
+                content.append(buffer, 0, readChars);
+            }
+        }
+        while (readChars != -1);
+        assertEquals(EXPECTED, content.toString());
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/package.html?rev=1036838&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/package.html
(added)
+++ db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/package.html
Fri Nov 19 13:47:50 2010
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2001-2010 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 LoadAdditionalSourceTransformer</h2>
+
+<p>
+  This directory and its subdirectories contain a test configuration
+  which is used by the LoadAdditionalSourceTransformerTest to check whether
+  the LoadAdditionalSourceTransformer works correctly.
+</p>
+ 
\ No newline at end of file

Added: db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/conf/control.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/conf/control.xml?rev=1036838&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/conf/control.xml
(added)
+++ db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/conf/control.xml
Fri Nov 19 13:47:50 2010
@@ -0,0 +1,39 @@
+<?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 loglevel="debug"
+    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="output" file="output.txt">
+    <source xsi:type="fileSource" elements="root" format="xml">
+      <transformer class="org.apache.torque.generator.source.transform.LoadAdditionalSourceTransformer">
+        <element>/root/element</element>
+        <fileIncludes>
+          <fileInclude>additional*.xml</fileInclude>
+        </fileIncludes>
+        <sourceFormat>xml</sourceFormat>
+      </transformer>
+      <include>source.xml</include>
+    </source>
+    <outlet name="debugSourceOutlet"/>
+  </output>
+</control>
+  
\ No newline at end of file

Added: db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/outlets/outlets.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/outlets/outlets.xml?rev=1036838&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/outlets/outlets.xml
(added)
+++ db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/outlets/outlets.xml
Fri Nov 19 13:47:50 2010
@@ -0,0 +1,29 @@
+<?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.
+-->
+
+<outlets xmlns="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="debugSourceOutlet"
+      xsi:type="javaOutlet" 
+      class="org.apache.torque.generator.outlet.java.XmlOutlet">
+  </outlet>
+</outlets>
\ No newline at end of file

Added: db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/additional1.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/additional1.xml?rev=1036838&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/additional1.xml
(added)
+++ db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/additional1.xml
Fri Nov 19 13:47:50 2010
@@ -0,0 +1,23 @@
+<?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.
+-->
+
+<additional>
+  <element/>
+</additional>
\ No newline at end of file

Added: db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/additional2.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/additional2.xml?rev=1036838&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/additional2.xml
(added)
+++ db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/additional2.xml
Fri Nov 19 13:47:50 2010
@@ -0,0 +1,23 @@
+<?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.
+-->
+
+<additional>
+  <element/>
+</additional>
\ No newline at end of file

Added: db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/source.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/source.xml?rev=1036838&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/source.xml
(added)
+++ db/torque/torque4/trunk/torque-generator/src/test/loadAdditionalSourceTransformer/src/main/torque-gen/src/source.xml
Fri Nov 19 13:47:50 2010
@@ -0,0 +1,26 @@
+<?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.
+-->
+
+<root>
+  <element>
+    <child/>
+  </element>
+  <element/>
+</root>
\ No newline at end of file



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