db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1503985 [1/2] - in /db/torque/torque4/trunk/torque-generator/src: main/java/org/apache/torque/generator/configuration/ main/java/org/apache/torque/generator/configuration/outlet/ test/java/org/apache/torque/generator/configuration/ test/re...
Date Wed, 17 Jul 2013 04:00:08 GMT
Author: tfischer
Date: Wed Jul 17 04:00:07 2013
New Revision: 1503985

URL: http://svn.apache.org/r1503985
Log:
TORQUE-296 Auto-define outlets by existence of templates

Added:
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/PackageResources.java
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/DirectoryConfigurationProviderTest.java
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/JarConfigurationProviderTest.java
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/PackageResourcesTest.java
    db/torque/torque4/trunk/torque-generator/src/test/resources/org/apache/torque/generator/test/readfromclasspath/outlets/javaOutlets.xml
    db/torque/torque4/trunk/torque-generator/src/test/resources/org/apache/torque/generator/test/readfromclasspath/outlets/velocityOutlets.xml
      - copied, changed from r1470232, db/torque/torque4/trunk/torque-generator/src/test/resources/org/apache/torque/generator/test/readfromclasspath/outlets/testGenerator.xml
Removed:
    db/torque/torque4/trunk/torque-generator/src/test/resources/org/apache/torque/generator/test/readfromclasspath/outlets/testGenerator.xml
Modified:
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ClasspathConfigurationProvider.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ConfigurationProvider.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/DirectoryConfigurationProvider.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/JarConfigurationProvider.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/CopyOutletSaxHandlerFactory.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/GroovyOutletSaxHandlerFactory.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/JavaOutletSaxHandlerFactory.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfiguration.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfigurationSaxHandler.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfigurationXmlParser.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/TypedOutletSaxHandlerFactory.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/VelocityOutletSaxHandlerFactory.java
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ClasspathConfigurationProviderTest.java

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ClasspathConfigurationProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ClasspathConfigurationProvider.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ClasspathConfigurationProvider.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ClasspathConfigurationProvider.java Wed Jul 17 04:00:07 2013
@@ -20,14 +20,9 @@ package org.apache.torque.generator.conf
  */
 
 import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
-import java.util.jar.JarFile;
 
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.logging.Log;
@@ -46,10 +41,7 @@ public class ClasspathConfigurationProvi
             = LogFactory.getLog(ClasspathConfigurationProvider.class);
 
     /** The description of the generation unit, not null. */
-    private UnitDescriptor unitDescriptor;
-
-    /** The prefix if an url points to a file. */
-    private static final String FILE_URL_PREFIX = "file:";
+    private final UnitDescriptor unitDescriptor;
 
     /**
      * Constructor.
@@ -57,12 +49,15 @@ public class ClasspathConfigurationProvi
      *
      * @throws NullPointerException if unitDescriptor is null.
      */
-    public ClasspathConfigurationProvider(UnitDescriptor unitDescriptor)
+    public ClasspathConfigurationProvider(final UnitDescriptor unitDescriptor)
     {
         super(unitDescriptor.getConfigurationPaths());
         this.unitDescriptor = unitDescriptor;
     }
 
+    /**
+     * @see ConfigurationProvider#getControlConfigurationLocation()
+     */
     public String getControlConfigurationLocation()
     {
         TorqueGeneratorPaths configurationPaths
@@ -73,8 +68,8 @@ public class ClasspathConfigurationProvi
     }
 
     protected String getFileName(
-            String name,
-            String directory)
+            final String name,
+            final String directory)
     {
         String fileName
                 = getConfigResourceBase()
@@ -88,10 +83,11 @@ public class ClasspathConfigurationProvi
         return fileName;
     }
 
+    @Override
     protected InputStream getInputStream(
-                String name,
-                String directory,
-                String fileDescription)
+                final String name,
+                final String directory,
+                final String fileDescription)
             throws ConfigurationException
     {
         String fileName = getFileName(name, directory);
@@ -121,7 +117,7 @@ public class ClasspathConfigurationProvi
     }
 
     public Collection<String> getOutletConfigurationNames()
-        throws ConfigurationException
+            throws ConfigurationException
     {
         String outletConfigurationSubdir = getConfigResourceBase()
                 + "/"
@@ -129,87 +125,28 @@ public class ClasspathConfigurationProvi
         outletConfigurationSubdir
                 = outletConfigurationSubdir.replace('\\', '/');
 
-        ClassLoader classLoader = unitDescriptor.getClassLoader();
-        if (classLoader == null)
-        {
-            classLoader = getClass().getClassLoader();
-        }
-
-        URL dirUrl = classLoader.getResource(outletConfigurationSubdir);
-        if (dirUrl == null)
-        {
-            log.error("Could not open Directory "
-                    + outletConfigurationSubdir
-                    + " in classpath");
-            throw new ConfigurationException(
-                    "outletConfigurationSubdir not found");
-        }
-        String dirUrlString = dirUrl.toExternalForm();
-        if (dirUrlString.startsWith("jar"))
-        {
-            String jarFilePath = dirUrl.getFile();
-            if (jarFilePath.startsWith(FILE_URL_PREFIX))
-            {
-                jarFilePath = jarFilePath.substring(FILE_URL_PREFIX.length());
-            }
-            jarFilePath = jarFilePath.substring(0, jarFilePath.indexOf("!"));
-            if (log.isDebugEnabled())
-            {
-                log.debug("outlet configuration located in jar file"
-                        + jarFilePath);
-            }
-            JarFile jarFile;
-            try
-            {
-                jarFile = new JarFile(jarFilePath);
-            }
-            catch (IOException e)
-            {
-                log.error("Could not open jar File "
-                        + jarFilePath);
-                throw new ConfigurationException(e);
-            }
-
-            String outletConfigurationDirectory
-                    = dirUrlString.substring(dirUrlString.lastIndexOf("!") + 1);
-            if (outletConfigurationDirectory.startsWith("/"))
-            {
-                outletConfigurationDirectory
-                        = outletConfigurationDirectory.substring(1);
-            }
-            return JarConfigurationProvider.getOutletConfigurationNames(
-                    jarFile,
-                    outletConfigurationDirectory);
-        }
-        File directory = new File(dirUrl.getFile());
-        if (!directory.exists())
-        {
-            throw new ConfigurationException(
-                    "Could not read outlet directory "
-                        + outletConfigurationSubdir
-                        + " in classpath; directory URL is "
-                        + dirUrl
-                        + " file is "
-                        + dirUrl.getFile());
-        }
-        String[] filenames = directory.list();
+        PackageResources packageResources = new PackageResources(
+                outletConfigurationSubdir,
+                getClass().getClassLoader());
+        return packageResources.getAllResourcesEndingWith(".xml", false);
+    }
 
-        List<String> result = new ArrayList<String>();
-        for (String filename : filenames)
-        {
-            File file = new File(filename);
-            if (file.isDirectory())
-            {
-                continue;
-            }
-            String rawName = file.getName();
-            if (!rawName.endsWith(".xml"))
-            {
-                continue;
-            }
-            result.add(filename);
-        }
-        return result;
+    /**
+     * @see ConfigurationProvider#getTemplateNames()
+     */
+    public List<String> getTemplateNames()
+            throws ConfigurationException
+    {
+        String templatesConfigurationSubdir = getConfigResourceBase()
+                + "/"
+                + unitDescriptor.getConfigurationPaths().getTemplateDirectory();
+        templatesConfigurationSubdir
+                = templatesConfigurationSubdir.replace('\\', '/');
+
+        PackageResources packageResources = new PackageResources(
+                templatesConfigurationSubdir,
+                getClass().getClassLoader());
+        return packageResources.getAllResourcesEndingWith(null, true);
     }
 
     /**

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ConfigurationProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ConfigurationProvider.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ConfigurationProvider.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ConfigurationProvider.java Wed Jul 17 04:00:07 2013
@@ -21,6 +21,7 @@ package org.apache.torque.generator.conf
 
 import java.io.InputStream;
 import java.util.Collection;
+import java.util.List;
 
 /**
  * Defines how the configuration for a generation unit can be accessed.
@@ -55,6 +56,17 @@ public interface ConfigurationProvider
     String getControlConfigurationLocation() throws ConfigurationException;
 
     /**
+     * Lists all available template names.
+     *
+     * @return a list of all available template names, not null.
+     *
+     * @throws ConfigurationException if the template names
+     *         cannot be determined.
+     */
+    List<String> getTemplateNames()
+                throws ConfigurationException;
+
+    /**
      * Creates a reader to access a template.
      * It is the callers responsibility to close the reader after use.
      *

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/DirectoryConfigurationProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/DirectoryConfigurationProvider.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/DirectoryConfigurationProvider.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/DirectoryConfigurationProvider.java Wed Jul 17 04:00:07 2013
@@ -47,13 +47,13 @@ public class DirectoryConfigurationProvi
     /**
      * The paths needed to interact with the enclosing project, not null.
      */
-    private ProjectPaths projectPaths;
+    private final ProjectPaths projectPaths;
 
     /**
      * The internal directory structure of the Torque generator configuration
      * files, not null.
      */
-    private TorqueGeneratorPaths configurationPaths;
+    private final TorqueGeneratorPaths configurationPaths;
 
     /**
      * Constructor.
@@ -67,8 +67,8 @@ public class DirectoryConfigurationProvi
      *         are null.
      */
     public DirectoryConfigurationProvider(
-            ProjectPaths projectPaths,
-            TorqueGeneratorPaths configurationPaths)
+            final ProjectPaths projectPaths,
+            final TorqueGeneratorPaths configurationPaths)
     {
         super(configurationPaths);
         if (projectPaths == null)
@@ -89,9 +89,9 @@ public class DirectoryConfigurationProvi
     }
 
     private File getFile(
-                String name,
-                String directory,
-                String description)
+                final String name,
+                final String directory,
+                final String description)
             throws ConfigurationException
     {
         File file = null;
@@ -115,10 +115,11 @@ public class DirectoryConfigurationProvi
         return file;
     }
 
+    @Override
     protected InputStream getInputStream(
-                String name,
-                String directory,
-                String description)
+                final String name,
+                final String directory,
+                final String description)
             throws ConfigurationException
     {
         File file = getFile(name, directory, description);
@@ -172,4 +173,20 @@ public class DirectoryConfigurationProvi
         }
         return result;
     }
+
+    /**
+     * @see ConfigurationProvider#getTemplateNames()
+     */
+    public List<String> getTemplateNames()
+            throws ConfigurationException
+    {
+        File templatesConfigurationSubdir = new File(
+                projectPaths.getConfigurationPath()
+                    + "/"
+                    + configurationPaths.getTemplateDirectory());
+
+        return PackageResources.getFilesInDirectoryWithSuffix(
+                templatesConfigurationSubdir, null, "", true);
+    }
+
 }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/JarConfigurationProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/JarConfigurationProvider.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/JarConfigurationProvider.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/JarConfigurationProvider.java Wed Jul 17 04:00:07 2013
@@ -22,9 +22,7 @@ package org.apache.torque.generator.conf
 import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Enumeration;
 import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
@@ -48,13 +46,13 @@ public class JarConfigurationProvider
     /**
      * The paths needed to interact with the enclosing project, not null.
      */
-    private ProjectPaths projectPaths;
+    private final ProjectPaths projectPaths;
 
     /**
      * The internal directory structure of the generator configuration files,
      * not null.
      */
-    private TorqueGeneratorPaths configurationPaths;
+    private final TorqueGeneratorPaths configurationPaths;
 
     /**
      * The jar file from which the configuration should be read, not null.
@@ -73,8 +71,8 @@ public class JarConfigurationProvider
      * @throws ConfigurationException if the jar file can not be accessed.
      */
     public JarConfigurationProvider(
-            ProjectPaths projectPaths,
-            TorqueGeneratorPaths configurationPaths)
+            final ProjectPaths projectPaths,
+            final TorqueGeneratorPaths configurationPaths)
         throws ConfigurationException
     {
         super(configurationPaths);
@@ -106,10 +104,11 @@ public class JarConfigurationProvider
             + configurationPaths.getControlConfigurationFile();
     }
 
+    @Override
     protected InputStream getInputStream(
-               String name,
-               String directory,
-               String description)
+               final String name,
+               final String directory,
+               final String description)
             throws ConfigurationException
     {
         String fileName = directory + "/" + name;
@@ -143,67 +142,34 @@ public class JarConfigurationProvider
     public Collection<String> getOutletConfigurationNames()
         throws ConfigurationException
     {
-        return getOutletConfigurationNames(
+        return PackageResources.getFilesInJarDirectoryWithSuffix(
+                configurationPaths.getOutletDirectory(),
                 jarFile,
-                configurationPaths.getOutletDirectory());
+                ".xml",
+                false);
     }
 
     /**
-     * Extracts the outlet configuration files from a jar file.
-     * @param jarFile the jar file to process, not null.
-     * @param outletConfigurationDirectory the name of the directory
-     *        which contains the outlet configuration files. Cannot be
-     *        a composite path like parent/child.
-     * @return a set with the names of all outlet configuration files
-     *         contained in the jar file.
-     * @throws NullPointerException if jarFile
-     *         or outletConfigurationDirectory is null
+     * @see ConfigurationProvider#getTemplateNames()
      */
-    static Collection<String> getOutletConfigurationNames(
-            JarFile jarFile,
-            String outletConfigurationDirectory)
+    public List<String> getTemplateNames()
+            throws ConfigurationException
     {
-        if (log.isDebugEnabled())
-        {
-            log.debug("Analyzing jar file " + jarFile.getName()
-                    +  " seeking Directory " + outletConfigurationDirectory);
-        }
-
-        List<String> result = new ArrayList<String>();
-
-        Enumeration<JarEntry> entries = jarFile.entries();
-        while (entries.hasMoreElements())
+        JarFile templatesConfigurationFile;
+        try
         {
-            JarEntry jarEntry = entries.nextElement();
-            if (jarEntry.isDirectory())
-            {
-                continue;
-            }
-            String rawName = jarEntry.getName();
-            if (!rawName.startsWith(outletConfigurationDirectory))
-            {
-                continue;
-            }
-            String name = rawName.substring(rawName.lastIndexOf('/') + 1);
-
-            int expectedRawNameLength
-                    = outletConfigurationDirectory.length()
-                        + name.length()
-                        + 1;
-            if (rawName.length() != expectedRawNameLength)
-            {
-                // file is in a subdirectory of outletConfigurationSubdir,
-                // we only consider files directly in
-                // outletConfigurationSubdir
-                continue;
-            }
-            result.add(name);
+            templatesConfigurationFile = new JarFile(
+                    projectPaths.getConfigurationPath());
         }
-        if (log.isDebugEnabled())
+        catch (IOException e)
         {
-            log.debug("Found the following outlet configuration files "
-                    + result);
+            throw new ConfigurationException(e);
         }
-        return result;
+
+        return PackageResources.getFilesInJarDirectoryWithSuffix(
+                projectPaths.getConfigurationPath().getPath(),
+                templatesConfigurationFile,
+                null,
+                true);
     }
 }

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/PackageResources.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/PackageResources.java?rev=1503985&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/PackageResources.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/PackageResources.java Wed Jul 17 04:00:07 2013
@@ -0,0 +1,333 @@
+package org.apache.torque.generator.configuration;
+
+/*
+ * 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.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A Container of resources which contain a specific package.
+ *
+ * @version $Id: $
+ */
+public class PackageResources
+{
+    /** The prefix if an url points to a file. */
+    private static final String FILE_URL_PREFIX = "file:";
+
+    /** The logger. */
+    private static Log log
+            = LogFactory.getLog(PackageResources.class);
+
+    /** The jar files containing the package. */
+    private final List<JarFile> jarFiles = new ArrayList<JarFile>();
+
+    /** The directories containing the package. */
+    private final List<File> directories = new ArrayList<File>();
+
+    /** The path to the package, not null. */
+    private final String packagePath;
+
+    /**
+     * Constructor, finds the resources for a certain package.
+     *
+     * @param packageToFind the path to the package, using / or \\ as path
+     *        separator.
+     * @param classLoader the class loader to use.
+     *
+     * @throws ConfigurationException when accessing the class path fails.
+     */
+    public PackageResources(
+                final String packageToFind,
+                final ClassLoader classLoader)
+            throws ConfigurationException
+    {
+        if (packageToFind == null)
+        {
+            throw new NullPointerException("packagePath must not be null");
+        }
+        if (packageToFind.startsWith("/"))
+        {
+            packagePath = packageToFind.substring(1);
+        }
+        else
+        {
+            packagePath = packageToFind;
+        }
+
+        final Enumeration<URL> dirUrls;
+        try
+        {
+            dirUrls = classLoader.getResources(packagePath);
+        }
+        catch (IOException e)
+        {
+            throw new ConfigurationException("Could not scan class path", e);
+        }
+
+        while (dirUrls.hasMoreElements())
+        {
+            URL dirUrl = dirUrls.nextElement();
+            String dirUrlString = dirUrl.toExternalForm();
+            if (dirUrlString.startsWith("jar"))
+            {
+                String jarFilePath = dirUrl.getFile();
+                if (jarFilePath.startsWith(FILE_URL_PREFIX))
+                {
+                    jarFilePath = jarFilePath.substring(
+                            FILE_URL_PREFIX.length());
+                }
+                jarFilePath = jarFilePath.substring(
+                        0,
+                        jarFilePath.indexOf("!"));
+                if (log.isTraceEnabled())
+                {
+                    log.trace("package " + packagePath + " found in jar file"
+                            + jarFilePath);
+                }
+                JarFile jarFile;
+                try
+                {
+                    jarFile = new JarFile(jarFilePath);
+                    jarFiles.add(jarFile);
+                }
+                catch (IOException e)
+                {
+                    log.error("Could not open jar File "
+                            + jarFilePath);
+                    throw new ConfigurationException(e);
+                }
+                continue;
+            }
+            File directory = new File(dirUrl.getFile());
+            if (!directory.exists())
+            {
+                throw new ConfigurationException(
+                        "Could not read directory "
+                            + packagePath
+                            + " in classpath; directory URL is "
+                            + dirUrl
+                            + " file is "
+                            + dirUrl.getFile());
+            }
+            directories.add(directory);
+        }
+    }
+
+    /**
+     * Returns all jar files containing the desired package.
+     *
+     * @return the jar files, not null.
+     */
+    public List<JarFile> getJarFiles()
+    {
+        return jarFiles;
+    }
+
+    /**
+     * Returns all directories containing the desired package.
+     *
+     * @return the directories, not null.
+     */
+    public List<File> getDirectories()
+    {
+        return directories;
+    }
+
+    /**
+     * Returns whether the queried package exists in the class path.
+     */
+    public boolean isEmpty()
+    {
+        return jarFiles.isEmpty() && directories.isEmpty();
+    }
+
+    /**
+     * Returns all resource names in the package ending with the defined suffix.
+     *
+     * @param suffix the suffix which the resource name must have.
+     * @param recurse true if subpackages should also be searched,
+     *        false if only the specified package should be searched.
+     *
+     * @return The list of resource names with the specified suffix,
+     *         not null. The contained file names are relative to
+     *         the scanned package.
+     */
+    public List<String> getAllResourcesEndingWith(
+            final String suffix,
+            final boolean recurse)
+    {
+        List<String> result = new ArrayList<String>();
+        for (JarFile jarFile : jarFiles)
+        {
+            String dirNameInJar = packagePath;
+            if (dirNameInJar.startsWith("/"))
+            {
+                dirNameInJar = dirNameInJar.substring(1);
+            }
+            result.addAll(getFilesInJarDirectoryWithSuffix(
+                    dirNameInJar,
+                    jarFile,
+                    suffix,
+                    recurse));
+        }
+        for (File directory : directories)
+        {
+            result.addAll(getFilesInDirectoryWithSuffix(
+                    directory,
+                    suffix,
+                    "",
+                    recurse));
+        }
+        return result;
+    }
+
+    /**
+     * Returns all files in a directory with end with a given suffix.
+     *
+     * @param directoryToScan the directory to check files in.
+     * @param suffix
+     * @param prefixToResult
+     * @param recurse
+     * @return
+     */
+    static List<String> getFilesInDirectoryWithSuffix(
+            final File directoryToScan,
+            final String suffix,
+            final String prefixToResult,
+            final boolean recurse)
+    {
+        final List<String> result = new ArrayList<String>();
+        if (suffix == null)
+        {
+            return result;
+        }
+
+        String[] filenames = directoryToScan.list();
+
+        for (String filename : filenames)
+        {
+            File file = new File(filename);
+            if (file.isDirectory())
+            {
+                if (recurse)
+                {
+                    result.addAll(getFilesInDirectoryWithSuffix(
+                            file,
+                            suffix,
+                            prefixToResult + "/" + filename,
+                            recurse));
+                }
+                continue;
+            }
+            String rawName = file.getName();
+            if (!rawName.endsWith(suffix))
+            {
+                continue;
+            }
+            result.add(prefixToResult + filename);
+        }
+        return result;
+    }
+
+    /**
+     * Extracts files in a directory from a jar file.
+     *
+     * @param directory the name of the directory
+     *        containing the files. Cannot be
+     *        a composite path like parent/child.
+     * @param jarFile the jar file to process, not null.
+     * @param suffix the suffix the files must have, or null in which case
+     *        no files are found.
+     * @param searchSubdirectories if files in subdirectories should
+     *        also be considered.
+     *
+     * @return a set with the names of all outlet configuration files
+     *         contained in the jar file.
+     * @throws NullPointerException if jarFile
+     *         or outletConfigurationDirectory is null
+     */
+    static List<String> getFilesInJarDirectoryWithSuffix(
+            final String directory,
+            final JarFile jarFile,
+            final String suffix,
+            final boolean searchSubdirectories)
+    {
+        if (log.isDebugEnabled())
+        {
+            log.debug("Analyzing jar file " + jarFile.getName()
+                    +  " seeking directory " + directory
+                    + " for files with suffix " + suffix);
+        }
+        List<String> result = new ArrayList<String>();
+        if (suffix == null)
+        {
+            log.debug("suffix is null, returning the empty list.");
+            return result;
+        }
+
+
+        Enumeration<JarEntry> entries = jarFile.entries();
+        while (entries.hasMoreElements())
+        {
+            JarEntry jarEntry = entries.nextElement();
+            if (jarEntry.isDirectory())
+            {
+                continue;
+            }
+            String rawName = jarEntry.getName();
+            if (!rawName.startsWith(directory))
+            {
+                continue;
+            }
+            if (!rawName.endsWith(suffix))
+            {
+                continue;
+            }
+            String name = rawName.substring(rawName.lastIndexOf('/') + 1);
+
+            int expectedRawNameLength
+                    = directory.length()
+                        + name.length()
+                        + 1;
+            if (rawName.length() != expectedRawNameLength
+                    && !searchSubdirectories)
+            {
+                continue;
+            }
+            result.add(name);
+        }
+        if (log.isDebugEnabled())
+        {
+            log.debug("Found the following files " + result);
+        }
+        return result;
+    }
+
+}

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/CopyOutletSaxHandlerFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/CopyOutletSaxHandlerFactory.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/CopyOutletSaxHandlerFactory.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/CopyOutletSaxHandlerFactory.java Wed Jul 17 04:00:07 2013
@@ -19,9 +19,13 @@ package org.apache.torque.generator.conf
  * under the License.
  */
 
+import java.util.Collection;
+import java.util.Collections;
+
 import org.apache.torque.generator.configuration.ConfigurationHandlers;
 import org.apache.torque.generator.configuration.ConfigurationProvider;
 import org.apache.torque.generator.configuration.UnitDescriptor;
+import org.apache.torque.generator.outlet.Outlet;
 import org.apache.torque.generator.qname.QualifiedName;
 import org.xml.sax.SAXException;
 
@@ -48,6 +52,38 @@ public class CopyOutletSaxHandlerFactory
     }
 
     /**
+     * Returns the filename extensions for templates which define outlets
+     * of this type. These extensions are used for scanning the templates tree.
+     *
+     * @return the empty list, as this outlet type is not described
+     *         by templates.
+     */
+    public Collection<String> getTemplatesFilenameExtensionsForScan()
+    {
+        return Collections.emptyList();
+    }
+
+    /**
+     * Creates an outlet for a template with the given file name.
+     * This implementaion throws a UnsupportedOperationException
+     * as java outlets are not template based.
+     *
+     * @param templateFileName the file name of the template.
+     * @param configurationProvider the configuration provider.
+     *
+     * @return always throws an Exception
+     *
+     * @throws UnsupportedOperationException always.
+     */
+    public Outlet createOutletForTemplate(
+            final String templateFileName,
+            final ConfigurationProvider configurationProvider)
+
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
      * Returns a JavaOutletSaxHandler for reading the configuration of
      * Java outlets. This implementation uses the provided name
      * as outlet name.
@@ -65,10 +101,10 @@ public class CopyOutletSaxHandlerFactory
      * @return a new JavaOutletSaxHandler.
      */
     public final OutletSaxHandler getOutletSaxHandler(
-            QualifiedName outletName,
-            ConfigurationProvider configurationProvider,
-            UnitDescriptor unitDescriptor,
-            ConfigurationHandlers configurationHandlers)
+            final QualifiedName outletName,
+            final ConfigurationProvider configurationProvider,
+            final UnitDescriptor unitDescriptor,
+            final ConfigurationHandlers configurationHandlers)
          throws SAXException
     {
         return new CopyOutletSaxHandler(

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/GroovyOutletSaxHandlerFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/GroovyOutletSaxHandlerFactory.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/GroovyOutletSaxHandlerFactory.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/GroovyOutletSaxHandlerFactory.java Wed Jul 17 04:00:07 2013
@@ -19,10 +19,18 @@ package org.apache.torque.generator.conf
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+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.UnitDescriptor;
+import org.apache.torque.generator.outlet.Outlet;
 import org.apache.torque.generator.qname.QualifiedName;
+import org.apache.torque.generator.template.groovy.GroovyScriptOutlet;
 import org.xml.sax.SAXException;
 
 /**
@@ -38,6 +46,20 @@ public class GroovyOutletSaxHandlerFacto
     private static final String OUTLET_TYPE = "groovyOutlet";
 
     /**
+     * The list of filename extensions which are automatically linked
+     * with this Factory.
+     */
+    private static final List<String> TEMPLATE_FILENAMES_EXTENSIONS;
+
+    static
+    {
+        List<String> templateFilenameExtensions = new ArrayList<String>();
+        templateFilenameExtensions.add(".groovy");
+        TEMPLATE_FILENAMES_EXTENSIONS = Collections.unmodifiableList(
+                templateFilenameExtensions);
+    }
+
+    /**
      * Returns the outlet type which can be handled by the
      * OutletSaxHandlers created by this factory.
      *
@@ -49,6 +71,39 @@ public class GroovyOutletSaxHandlerFacto
     }
 
     /**
+     * Returns the filename extensions for templates which define outlets
+     * of this type. These extensions are used for scanning the templates tree.
+     *
+     * @return A list with the entry ".groovy".
+     */
+    public Collection<String> getTemplatesFilenameExtensionsForScan()
+    {
+        return TEMPLATE_FILENAMES_EXTENSIONS;
+    }
+
+    /**
+     * Creates an outlet for a template with the given file name.
+     *
+     * @param templateFileName the file name of the template, not null.
+     * @param configurationProvider the configuration provider, not null.
+     *
+     * @return the outlet, not null.
+     */
+    public Outlet createOutletForTemplate(
+                final String templateFileName,
+                final ConfigurationProvider configurationProvider)
+            throws ConfigurationException
+    {
+        GroovyScriptOutlet result
+            = new GroovyScriptOutlet(
+                OutletConfigurationXmlParser.getTemplateNameForFilename(
+                        templateFileName),
+                configurationProvider,
+                templateFileName,
+                null);
+        return result;
+    }
+    /**
      * Returns a GroovyOutletSaxHandler for reading the configuration of
      * Groovy outlets. This implementation uses the provided name
      * as outlet name.
@@ -66,10 +121,10 @@ public class GroovyOutletSaxHandlerFacto
      * @return a new GroovyOutletSaxHandler.
      */
     public final OutletSaxHandler getOutletSaxHandler(
-            QualifiedName outletName,
-            ConfigurationProvider configurationProvider,
-            UnitDescriptor unitDescriptor,
-            ConfigurationHandlers configurationHandlers)
+            final QualifiedName outletName,
+            final ConfigurationProvider configurationProvider,
+            final UnitDescriptor unitDescriptor,
+            final ConfigurationHandlers configurationHandlers)
          throws SAXException
     {
         return new GroovyOutletSaxHandler(

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/JavaOutletSaxHandlerFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/JavaOutletSaxHandlerFactory.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/JavaOutletSaxHandlerFactory.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/JavaOutletSaxHandlerFactory.java Wed Jul 17 04:00:07 2013
@@ -19,9 +19,13 @@ package org.apache.torque.generator.conf
  * under the License.
  */
 
+import java.util.Collection;
+import java.util.Collections;
+
 import org.apache.torque.generator.configuration.ConfigurationHandlers;
 import org.apache.torque.generator.configuration.ConfigurationProvider;
 import org.apache.torque.generator.configuration.UnitDescriptor;
+import org.apache.torque.generator.outlet.Outlet;
 import org.apache.torque.generator.qname.QualifiedName;
 import org.xml.sax.SAXException;
 
@@ -48,6 +52,38 @@ public class JavaOutletSaxHandlerFactory
     }
 
     /**
+     * Returns the filename extensions for templates which define outlets
+     * of this type. These extensions are used for scanning the templates tree.
+     *
+     * @return the empty list, as this outlet type is not described
+     *         by templates.
+     */
+    public Collection<String> getTemplatesFilenameExtensionsForScan()
+    {
+        return Collections.emptyList();
+    }
+
+    /**
+     * Creates an outlet for a template with the given file name.
+     * This implementaion throws a UnsupportedOperationException
+     * as java outlets are not template based.
+     *
+     * @param templateFileName the file name of the template.
+     * @param configurationProvider the configuration provider.
+     *
+     * @return always throws an Exception
+     *
+     * @throws UnsupportedOperationException always.
+     */
+    public Outlet createOutletForTemplate(
+            final String templateFileName,
+            final ConfigurationProvider configurationProvider)
+
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
      * Returns a JavaOutletSaxHandler for reading the configuration of
      * Java outlets. This implementation uses the provided name
      * as outlet name.
@@ -65,10 +101,10 @@ public class JavaOutletSaxHandlerFactory
      * @return a new JavaOutletSaxHandler.
      */
     public final OutletSaxHandler getOutletSaxHandler(
-            QualifiedName outletName,
-            ConfigurationProvider configurationProvider,
-            UnitDescriptor unitDescriptor,
-            ConfigurationHandlers configurationHandlers)
+            final QualifiedName outletName,
+            final ConfigurationProvider configurationProvider,
+            final UnitDescriptor unitDescriptor,
+            final ConfigurationHandlers configurationHandlers)
          throws SAXException
     {
         return new JavaOutletSaxHandler(

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfiguration.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfiguration.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfiguration.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfiguration.java Wed Jul 17 04:00:07 2013
@@ -37,12 +37,12 @@ import org.apache.torque.generator.qname
 public class OutletConfiguration
 {
     /** A map containing all outlets, keyed by their name. */
-    private Map<QualifiedName, Outlet> outlets
+    private final Map<QualifiedName, Outlet> outlets
             = new HashMap<QualifiedName, Outlet>();
 
     /** A map containing all isolated mergepoint mappings,
      *  keyed by their name. */
-    private Map<String, MergepointMapping> mergepointMappings
+    private final Map<String, MergepointMapping> mergepointMappings
             = new HashMap<String, MergepointMapping>();
 
     /**
@@ -54,7 +54,7 @@ public class OutletConfiguration
     /**
      * Creates a OutletConfiguration containing a list of Outlets.
      *
-     * @param outlets the list of outlets, not null.
+     * @param outlets the map of outlets, keyed by their name, not null.
      * @param mergepointMappings all isolated mergepoint mappings, not null.
      * @param unitDescriptor the descriptor of the unit of generation,
      *        not null.
@@ -64,9 +64,9 @@ public class OutletConfiguration
      * @throws NullPointerException if a parameter is null.
      */
     public OutletConfiguration(
-                Collection<Outlet> outlets,
-                Collection<MergepointMapping> mergepointMappings,
-                UnitDescriptor unitDescriptor)
+                final Collection<Outlet> outlets,
+                final Collection<MergepointMapping> mergepointMappings,
+                final UnitDescriptor unitDescriptor)
             throws ConfigurationException
     {
         if (outlets == null)
@@ -170,7 +170,7 @@ public class OutletConfiguration
      * @throws IllegalStateException if the mergepoint mappings have not
      *         yet been resolved.
      */
-    public Outlet getOutlet(QualifiedName name)
+    public Outlet getOutlet(final QualifiedName name)
     {
         if (!mergepointMappingsResolved)
         {
@@ -191,7 +191,7 @@ public class OutletConfiguration
      *         already exists in the configuration.
      * @throws NullPointerException if outlet is null.
      */
-    public void addOutlet(Outlet outlet, UnitDescriptor unitDescriptor)
+    public void addOutlet(Outlet outlet, final UnitDescriptor unitDescriptor)
         throws ConfigurationException
     {
         if (outlet == null)
@@ -245,7 +245,7 @@ public class OutletConfiguration
      *
      * @return true if a outlet with the name exists, false otherwise.
      */
-    public boolean outletExists(QualifiedName qualifiedName)
+    public boolean outletExists(final QualifiedName qualifiedName)
     {
         return outlets.containsKey(qualifiedName);
     }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfigurationSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfigurationSaxHandler.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfigurationSaxHandler.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfigurationSaxHandler.java Wed Jul 17 04:00:07 2013
@@ -54,23 +54,23 @@ import org.xml.sax.helpers.DefaultHandle
 public class OutletConfigurationSaxHandler extends DefaultHandler
 {
     /** The access object for the configuration files, not null. */
-    private ConfigurationProvider configurationProvider;
+    private final ConfigurationProvider configurationProvider;
 
     /** The description of the generation unit, not null. */
-    private UnitDescriptor unitDescriptor;
+    private final UnitDescriptor unitDescriptor;
 
     /** The list of outlets which configuration was already parsed. */
-    private List<Outlet> outlets = new ArrayList<Outlet>();
+    private final List<Outlet> outlets = new ArrayList<Outlet>();
 
     /**
      * The list of separate mergepoint mappings (outside the outlets)
      * which configuration was already parsed.
      */
-    private List<MergepointMapping> mergepointMappings
+    private final List<MergepointMapping> mergepointMappings
             = new ArrayList<MergepointMapping>();
 
     /** The available configuration handlers. */
-    private ConfigurationHandlers configurationHandlers;
+    private final ConfigurationHandlers configurationHandlers;
 
     /**
      * The current delegate handler for parsing the current outlet's
@@ -99,9 +99,9 @@ public class OutletConfigurationSaxHandl
      * @throws NullPointerException if an argument is null.
      */
     public OutletConfigurationSaxHandler(
-            ConfigurationProvider configurationProvider,
-            UnitDescriptor unitDescriptor,
-            ConfigurationHandlers configurationHandlers)
+            final ConfigurationProvider configurationProvider,
+            final UnitDescriptor unitDescriptor,
+            final ConfigurationHandlers configurationHandlers)
     {
         if (configurationProvider == null)
         {
@@ -152,8 +152,8 @@ public class OutletConfigurationSaxHandl
      * {@inheritDoc}
      */
     @Override
-    public void startElement(String uri, String localName, String qName,
-                             Attributes attributes)
+    public void startElement(final String uri, final String localName, final String qName,
+                             final Attributes attributes)
             throws SAXException
     {
         String unqualifiedName = SaxHelper.getUnqualifiedName(localName, qName);
@@ -200,7 +200,7 @@ public class OutletConfigurationSaxHandl
      * {@inheritDoc}
      */
     @Override
-    public void endElement(String uri, String localName, String rawName)
+    public void endElement(final String uri, final String localName, final String rawName)
             throws SAXException
     {
         if (outletHandler != null)
@@ -240,7 +240,7 @@ public class OutletConfigurationSaxHandl
      * {@inheritDoc}
      */
     @Override
-    public void characters (char[] ch, int start, int length)
+    public void characters (final char[] ch, final int start, final int length)
             throws SAXException
     {
         if (outletHandler != null)
@@ -267,8 +267,8 @@ public class OutletConfigurationSaxHandl
      *         or if an error occurs while creating the handler.
      */
     public OutletSaxHandler getOutletHandler(
-            QualifiedName outletName,
-            String outletType)
+            final QualifiedName outletName,
+            final String outletType)
         throws SAXException
     {
         OutletTypes outletTypes = configurationHandlers.getOutletTypes();
@@ -319,7 +319,7 @@ public class OutletConfigurationSaxHandl
      *
      * @throws SAXException if the xsi:type attribute is not set.
      */
-    public static String getOutletType(Attributes attributes)
+    public static String getOutletType(final Attributes attributes)
             throws SAXException
     {
         String outletType
@@ -347,7 +347,8 @@ public class OutletConfigurationSaxHandl
      *
      * @see ConfigurationEntityResolver#resolveEntity(String, String)
      */
-    public InputSource resolveEntity(String publicId, String systemId)
+    @Override
+    public InputSource resolveEntity(final String publicId, final String systemId)
             throws SAXException, IOException
     {
         return new ConfigurationEntityResolver().resolveEntity(
@@ -355,20 +356,20 @@ public class OutletConfigurationSaxHandl
     }
 
     @Override
-    public void error(SAXParseException exception) throws SAXParseException
+    public void error(final SAXParseException exception) throws SAXParseException
     {
         throw exception;
     }
 
     @Override
-    public void fatalError(SAXParseException exception)
+    public void fatalError(final SAXParseException exception)
             throws SAXParseException
     {
         throw exception;
     }
 
     @Override
-    public void warning(SAXParseException exception) throws SAXParseException
+    public void warning(final SAXParseException exception) throws SAXParseException
     {
         throw exception;
     }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfigurationXmlParser.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfigurationXmlParser.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfigurationXmlParser.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/OutletConfigurationXmlParser.java Wed Jul 17 04:00:07 2013
@@ -23,7 +23,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
@@ -37,6 +39,7 @@ import org.apache.torque.generator.confi
 import org.apache.torque.generator.configuration.UnitDescriptor;
 import org.apache.torque.generator.configuration.mergepoint.MergepointMapping;
 import org.apache.torque.generator.outlet.Outlet;
+import org.apache.torque.generator.qname.QualifiedName;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXNotRecognizedException;
@@ -103,9 +106,9 @@ public class OutletConfigurationXmlParse
      *         or errors exists in the outlet configuration files.
      */
     public OutletConfiguration readOutletConfiguration(
-            ConfigurationProvider configurationProvider,
-            ConfigurationHandlers configurationHandlers,
-            UnitDescriptor unitDescriptor)
+            final ConfigurationProvider configurationProvider,
+            final ConfigurationHandlers configurationHandlers,
+            final UnitDescriptor unitDescriptor)
         throws ConfigurationException
     {
         if (configurationHandlers == null)
@@ -211,14 +214,16 @@ public class OutletConfigurationXmlParse
      *         file.
      * @throws IOException if the file cannot be read.
      * @throws ParserConfigurationException if a serious parser configuration
-     *         error occurs..
+     *         error occurs.
+     * @throws ConfigurationException if the templates names cannot be scanned.
      */
     private OutletConfigFileContent readOutletConfig(
-            InputStream outletConfigurationInputStream,
-            ConfigurationProvider configurationProvider,
-            UnitDescriptor unitDescriptor,
-            ConfigurationHandlers configurationHandlers)
-        throws SAXException, IOException, ParserConfigurationException
+            final InputStream outletConfigurationInputStream,
+            final ConfigurationProvider configurationProvider,
+            final UnitDescriptor unitDescriptor,
+            final ConfigurationHandlers configurationHandlers)
+        throws SAXException, IOException, ParserConfigurationException,
+                ConfigurationException
     {
         SAXParser parser = saxFactory.newSAXParser();
         OutletConfigurationSaxHandler saxHandler
@@ -229,11 +234,80 @@ public class OutletConfigurationXmlParse
         InputSource is = new InputSource(outletConfigurationInputStream);
         parser.parse(is, saxHandler);
 
+        List<Outlet> outlets = new ArrayList<Outlet>();
+        outlets.addAll(saxHandler.getOutlets());
+
+        // add outlets defined implicitly by templates
+        scanTemplatesForOutlets(
+                outlets,
+                configurationProvider,
+                configurationHandlers);
+
         return new OutletConfigFileContent(
-                saxHandler.getOutlets(),
+                outlets,
                 saxHandler.getMergepointMappings());
     }
 
+    private void scanTemplatesForOutlets(
+            final List<Outlet> outlets,
+            final ConfigurationProvider configurationProvider,
+            final ConfigurationHandlers configurationHandlers)
+            throws ConfigurationException
+    {
+        Set<QualifiedName> outletNames = new HashSet<QualifiedName>();
+        for (Outlet outlet : outlets)
+        {
+            outletNames.add(outlet.getName());
+        }
+        List<String> templateFileNames
+            = configurationProvider.getTemplateNames();
+        for (String templateFileName : templateFileNames)
+        {
+            Collection<TypedOutletSaxHandlerFactory> outletSaxHandlerFactories
+                    = configurationHandlers.getOutletTypes()
+                        .getTypedOutletHandlerFactories().values();
+            for (TypedOutletSaxHandlerFactory outletSaxHandlerFactory
+                        : outletSaxHandlerFactories)
+            {
+                if (outletSaxHandlerFactory
+                        .getTemplatesFilenameExtensionsForScan().contains(
+                                templateFileName))
+                {
+                    Outlet outlet
+                            = outletSaxHandlerFactory.createOutletForTemplate(
+                                    templateFileName,
+                                    configurationProvider);
+                    QualifiedName outletName = outlet.getName();
+                    if (!outletNames.contains(outletName))
+                    {
+                        outlets.add(outlet);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Creates a template name for a file name.
+     *
+     * @param filename the file name, not null.
+     *
+     * @return the template name, not null.
+     */
+    static QualifiedName getTemplateNameForFilename(final String filename)
+    {
+        String resultName = filename;
+        int dotIndex = resultName.lastIndexOf('.');
+        if (dotIndex != -1)
+        {
+            resultName = resultName.substring(0, dotIndex);
+        }
+        resultName = resultName.replace('/', '.');
+        resultName = resultName.replace('\\', '.');
+        QualifiedName result = new QualifiedName(resultName);
+        return result;
+    }
+
     /**
      * The parsed content of a outlet definition file.
      * Contains the parsed outlets and the isolated
@@ -254,8 +328,8 @@ public class OutletConfigurationXmlParse
          * @param mergepointMappings the isolated mergepoint mappings.
          */
         public OutletConfigFileContent(
-                List<Outlet> outlets,
-                List<MergepointMapping> mergepointMappings)
+                final List<Outlet> outlets,
+                final List<MergepointMapping> mergepointMappings)
         {
             this.outlets = outlets;
             this.mergepointMappings = mergepointMappings;

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/TypedOutletSaxHandlerFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/TypedOutletSaxHandlerFactory.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/TypedOutletSaxHandlerFactory.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/TypedOutletSaxHandlerFactory.java Wed Jul 17 04:00:07 2013
@@ -19,9 +19,13 @@ package org.apache.torque.generator.conf
  * under the License.
  */
 
+import java.util.Collection;
+
+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.UnitDescriptor;
+import org.apache.torque.generator.outlet.Outlet;
 import org.apache.torque.generator.qname.QualifiedName;
 import org.xml.sax.SAXException;
 
@@ -29,7 +33,7 @@ import org.xml.sax.SAXException;
  * Classes implementing this interface are responsible for creating
  * <code>OutletSaxHandler</code>s for a specific outlet type.
  */
-public abstract interface TypedOutletSaxHandlerFactory
+public interface TypedOutletSaxHandlerFactory
 {
     /**
      * Returns the outlet type handled by the OutletSaxHandlers which are
@@ -40,6 +44,33 @@ public abstract interface TypedOutletSax
     String getType();
 
     /**
+     * Returns the filename extensions for templates which define outlets
+     * of this type. These extensions are used for scanning the templates tree.
+     *
+     * @return the filename extension for scanning the templates,
+     *         or null if the templates should not be scanned.
+     */
+    Collection<String> getTemplatesFilenameExtensionsForScan();
+
+    /**
+     * Creates an outlet for a template with the given file name.
+     *
+     * @param templateFileName the file name of the template, not null.
+     * @param configurationProvider the configuration provider, not null.
+     *
+     * @return the outlet, not null.
+     *
+     * @throws ConfigurationException if the outlet cannot be created.
+     * @throws UnsupportedOperationException if the OutletSaxHandlerFactory
+     *         is not template based or cannot create outlets on file name
+     *         information alone.
+     */
+    Outlet createOutletForTemplate(
+            String templateFileName,
+            ConfigurationProvider configurationProvider)
+        throws ConfigurationException;
+
+    /**
      * Returns a OutletSaxHandler for reading in the configuration of
      * a outlet. The SAX Handler is used as a delegate handler
      * whenever a outlet element with the matching type

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/VelocityOutletSaxHandlerFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/VelocityOutletSaxHandlerFactory.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/VelocityOutletSaxHandlerFactory.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/VelocityOutletSaxHandlerFactory.java Wed Jul 17 04:00:07 2013
@@ -19,10 +19,18 @@ package org.apache.torque.generator.conf
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+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.UnitDescriptor;
+import org.apache.torque.generator.outlet.Outlet;
 import org.apache.torque.generator.qname.QualifiedName;
+import org.apache.torque.generator.template.velocity.VelocityOutlet;
 import org.xml.sax.SAXException;
 
 /**
@@ -38,6 +46,20 @@ public class VelocityOutletSaxHandlerFac
     private static final String OUTLET_TYPE = "velocityOutlet";
 
     /**
+     * The list of filename extensions which are automatically linked
+     * with this Factory.
+     */
+    private static final List<String> TEMPLATE_FILENAMES_EXTENSIONS;
+
+    static
+    {
+        List<String> templateFilenameExtensions = new ArrayList<String>();
+        templateFilenameExtensions.add(".vm");
+        TEMPLATE_FILENAMES_EXTENSIONS = Collections.unmodifiableList(
+                templateFilenameExtensions);
+    }
+
+    /**
      * Returns the outlet type which can be handled by the
      * OutletSaxHandlers created by this factory.
      *
@@ -49,6 +71,40 @@ public class VelocityOutletSaxHandlerFac
     }
 
     /**
+     * Returns the filename extensions for templates which define outlets
+     * of this type. These extensions are used for scanning the templates tree.
+     *
+     * @return A list with the entry ".vm".
+     */
+    public Collection<String> getTemplatesFilenameExtensionsForScan()
+    {
+        return TEMPLATE_FILENAMES_EXTENSIONS;
+    }
+
+    /**
+     * Creates an outlet for a template with the given file name.
+     *
+     * @param templateFileName the file name of the template, not null.
+     * @param configurationProvider the configuration provider, not null.
+     *
+     * @return the outlet, not null.
+     */
+    public Outlet createOutletForTemplate(
+                final String templateFileName,
+                final ConfigurationProvider configurationProvider)
+            throws ConfigurationException
+    {
+        VelocityOutlet result
+            = new VelocityOutlet(
+                OutletConfigurationXmlParser.getTemplateNameForFilename(
+                        templateFileName),
+                configurationProvider,
+                templateFileName,
+                null);
+        return result;
+    }
+
+    /**
      * Returns a VelocityOutletSaxHandler for reading the configuration of
      * Velocity outlets. This implementation uses the provided name
      * as outlet name.
@@ -66,10 +122,10 @@ public class VelocityOutletSaxHandlerFac
      * @return a new VelocityOutletSaxHandler.
      */
     public final OutletSaxHandler getOutletSaxHandler(
-            QualifiedName outletName,
-            ConfigurationProvider configurationProvider,
-            UnitDescriptor unitDescriptor,
-            ConfigurationHandlers configurationHandlers)
+            final QualifiedName outletName,
+            final ConfigurationProvider configurationProvider,
+            final UnitDescriptor unitDescriptor,
+            final ConfigurationHandlers configurationHandlers)
          throws SAXException
     {
         return new VelocityOutletSaxHandler(

Modified: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ClasspathConfigurationProviderTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ClasspathConfigurationProviderTest.java?rev=1503985&r1=1503984&r2=1503985&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ClasspathConfigurationProviderTest.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ClasspathConfigurationProviderTest.java Wed Jul 17 04:00:07 2013
@@ -20,9 +20,12 @@ package org.apache.torque.generator.conf
  */
 
 import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.io.FileUtils;
@@ -99,4 +102,16 @@ public class ClasspathConfigurationProvi
                         classpathConfigurationProvider.getResourceInputStream(
                             "../../../../../commons/io/CopyUtils.class")));
     }
+
+    @Test
+    public void testGetOutletConfigurationNames() throws Exception
+    {
+        List<String> expected = new ArrayList<String>();
+        expected.add("javaOutlets.xml");
+        expected.add("velocityOutlets.xml");
+        assertEquals(
+                expected,
+                classpathConfigurationProvider.getOutletConfigurationNames());
+    }
+
 }

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/DirectoryConfigurationProviderTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/DirectoryConfigurationProviderTest.java?rev=1503985&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/DirectoryConfigurationProviderTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/DirectoryConfigurationProviderTest.java Wed Jul 17 04:00:07 2013
@@ -0,0 +1,102 @@
+package org.apache.torque.generator.configuration;
+
+/*
+ * 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.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.torque.generator.configuration.paths.CustomProjectPaths;
+import org.apache.torque.generator.configuration.paths.DefaultTorqueGeneratorPaths;
+import org.apache.torque.generator.configuration.paths.ProjectPaths;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for the class DirectoryConfigurationProvider.
+ *
+ * @version $Id: ClasspathConfigurationProviderTest.java 1456694 2013-03-14 21:54:47Z tfischer $
+ */
+public class DirectoryConfigurationProviderTest
+{
+
+    private DirectoryConfigurationProvider directoryConfigurationProvider;
+
+    @Before
+    public void before()
+    {
+        Map<String, File> outputDirMap = new HashMap<String, File>();
+        outputDirMap.put(null, new File("generated-sources"));
+        ProjectPaths projectPaths = new CustomProjectPaths(
+                new File("src/test/resources/org/apache/torque/generator/test/readfromclasspath"),
+                null,
+                new File("src"),
+                outputDirMap,
+                new File("work"));
+
+        directoryConfigurationProvider = new DirectoryConfigurationProvider(
+                projectPaths,
+                new DefaultTorqueGeneratorPaths());
+    }
+
+    @Test
+    public void testGetTemplateInputStream() throws Exception
+    {
+        assertArrayEquals(
+                FileUtils.readFileToByteArray(new File(
+                        "src/test/resources/org/"
+                        + "apache/torque/generator/test/readfromclasspath/"
+                        + "templates/testTemplate.vm")),
+                IOUtils.toByteArray(
+                        directoryConfigurationProvider.getTemplateInputStream(
+                            "testTemplate.vm")));
+    }
+
+    @Test
+    public void testGetResourceWithDoubleDots() throws Exception
+    {
+        assertArrayEquals(
+                FileUtils.readFileToByteArray(new File(
+                        "src/test/resources/org/"
+                        + "apache/torque/generator/test/readfromclasspath/"
+                        + "templates/testTemplate.vm")),
+                IOUtils.toByteArray(
+                        directoryConfigurationProvider.getResourceInputStream(
+                            "../templates/testTemplate.vm")));
+    }
+
+    @Test
+    public void testGetOutletConfigurationNames() throws Exception
+    {
+        List<String> expected = new ArrayList<String>();
+        expected.add("javaOutlets.xml");
+        expected.add("velocityOutlets.xml");
+        assertEquals(
+                expected,
+                directoryConfigurationProvider.getOutletConfigurationNames());
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/JarConfigurationProviderTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/JarConfigurationProviderTest.java?rev=1503985&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/JarConfigurationProviderTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/JarConfigurationProviderTest.java Wed Jul 17 04:00:07 2013
@@ -0,0 +1,94 @@
+package org.apache.torque.generator.configuration;
+
+/*
+ * 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.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.torque.generator.configuration.paths.CustomProjectPaths;
+import org.apache.torque.generator.configuration.paths.DefaultTorqueGeneratorPaths;
+import org.apache.torque.generator.configuration.paths.ProjectPaths;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for the class JarConfigurationProvider.
+ *
+ * @version $Id: ClasspathConfigurationProviderTest.java 1456694 2013-03-14 21:54:47Z tfischer $
+ */
+public class JarConfigurationProviderTest
+{
+
+    private JarConfigurationProvider jarConfigurationProvider;
+
+    @Before
+    public void before() throws ConfigurationException
+    {
+        Map<String, File> outputDirMap = new HashMap<String, File>();
+        outputDirMap.put(null, new File("generated-sources"));
+        ProjectPaths projectPaths = new CustomProjectPaths(
+                new File("target/test/propertyToJavaJar/src/main/torque-gen/propertyToJava.jar"),
+                null,
+                new File("src"),
+                outputDirMap,
+                new File("work"));
+
+        jarConfigurationProvider = new JarConfigurationProvider(
+                projectPaths,
+                new DefaultTorqueGeneratorPaths());
+    }
+
+    @Test
+    public void testGetTemplateInputStream() throws Exception
+    {
+        assertArrayEquals(
+                FileUtils.readFileToByteArray(new File(
+                        "src/test/propertyToJava/src/main/torque-gen/templates/"
+                            + "propertiesToJava.vm")),
+                IOUtils.toByteArray(
+                        jarConfigurationProvider.getTemplateInputStream(
+                            "propertiesToJava.vm")));
+    }
+
+    @Test
+    public void testGetOutletConfigurationNames() throws Exception
+    {
+        Set<String> expected = new HashSet<String>();
+        expected.add("javaTestOutlet.xml");
+        expected.add("logoCopyOutlet.xml");
+        expected.add("velocityExtendedPropertiesOutlet.xml");
+        expected.add("velocityPropertiesCopy.xml");
+        expected.add("velocityPropertiesOutlet.xml");
+        expected.add("velocityVariableAssignment.xml");
+        expected.add("velocityVariableDefinition.xml");
+        assertEquals(
+                expected,
+                new HashSet(
+                    jarConfigurationProvider.getOutletConfigurationNames()));
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/PackageResourcesTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/PackageResourcesTest.java?rev=1503985&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/PackageResourcesTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/PackageResourcesTest.java Wed Jul 17 04:00:07 2013
@@ -0,0 +1,229 @@
+package org.apache.torque.generator.configuration;
+
+/*
+ * 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.util.HashSet;
+import java.util.List;
+import java.util.jar.JarFile;
+
+import org.junit.Test;
+
+/**
+ * Tests for the class PackageResources.
+ *
+ * @version $Id: ClasspathConfigurationProviderTest.java 1456694 2013-03-14 21:54:47Z tfischer $
+ */
+public class PackageResourcesTest
+{
+
+    /**
+     * Testet, dass ein Paket in mehreren Jar files und directories
+     * gefunden wird, wenn der Pfad nicht mit einem Slash anfängt und endet.
+     *
+     * @throws Exception wenn der Test Fehlschlägt.
+     */
+    @Test
+    public void testGetJarFilesAndDirectories() throws Exception
+    {
+        // Package kommt mindestens in commons-beanutils
+        // und in commons-collections vor
+        PackageResources packageResources = new PackageResources(
+                "org/apache",
+                this.getClass().getClassLoader());
+        List<JarFile> jarFiles = packageResources.getJarFiles();
+        boolean foundCommonsBeanutils = false;
+        boolean foundCommonsCollections = false;
+        for (JarFile jarFile : jarFiles)
+        {
+            String name = jarFile.getName();
+            if (name.contains("commons-collections"))
+            {
+                foundCommonsCollections = true;
+            }
+            if (name.contains("commons-beanutils-core"))
+            {
+                foundCommonsBeanutils = true;
+            }
+        }
+        assertTrue(foundCommonsCollections);
+        assertTrue(foundCommonsBeanutils);
+
+        List<File> directories = packageResources.getDirectories();
+        assertEquals(2, directories.size());
+        boolean foundTargetClasses = false;
+        boolean foundTargetTestClasses = false;
+        for (File directory : directories)
+        {
+            String name = directory.getAbsolutePath().replace('\\', '/');
+            if (name.endsWith("target/classes/org/apache"))
+            {
+                foundTargetClasses = true;
+            }
+            if (name.endsWith("target/test-classes/org/apache"))
+            {
+                foundTargetTestClasses = true;
+            }
+        }
+        assertTrue(foundTargetClasses);
+        assertTrue(foundTargetTestClasses);
+    }
+
+    /**
+     * Testet, dass ein Paket in mehreren Jar files und directories
+     * gefunden wird, wenn der Pfad mit einem Slash anfängt und endet.
+     *
+     * @throws Exception wenn der Test Fehlschlägt.
+     */
+    @Test
+    public void testGetJarFilesAndDirectoriesSlashes() throws Exception
+    {
+        // Package kommt mindestens in commons-beanutils
+        // und in commons-collections vor
+        PackageResources packageResources = new PackageResources(
+                "/org/apache/",
+                this.getClass().getClassLoader());
+        List<JarFile> jarFiles = packageResources.getJarFiles();
+        boolean foundCommonsBeanutils = false;
+        boolean foundCommonsCollections = false;
+        for (JarFile jarFile : jarFiles)
+        {
+            String name = jarFile.getName();
+            if (name.contains("commons-collections"))
+            {
+                foundCommonsCollections = true;
+            }
+            if (name.contains("commons-beanutils-core"))
+            {
+                foundCommonsBeanutils = true;
+            }
+        }
+        assertTrue(foundCommonsCollections);
+        assertTrue(foundCommonsBeanutils);
+
+        List<File> directories = packageResources.getDirectories();
+        assertEquals(2, directories.size());
+        boolean foundTargetClasses = false;
+        boolean foundTargetTestClasses = false;
+        for (File directory : directories)
+        {
+            String name = directory.getAbsolutePath().replace('\\', '/');
+            if (name.endsWith("target/classes/org/apache"))
+            {
+                foundTargetClasses = true;
+            }
+            if (name.endsWith("target/test-classes/org/apache"))
+            {
+                foundTargetTestClasses = true;
+            }
+        }
+        assertTrue(foundTargetClasses);
+        assertTrue(foundTargetTestClasses);
+    }
+
+    public void testFileNamesInDirectory()
+    {
+        HashSet<String> actual = new HashSet<String>();
+        actual.addAll(PackageResources.getFilesInDirectoryWithSuffix(
+                new File("src/test/file"),
+                ".properties",
+                "",
+                false));
+        HashSet<String> expected = new HashSet<String>();
+        expected.add("1.properties");
+        expected.add("11.properties");
+        assertEquals(expected, actual);
+    }
+
+    public void testFileNamesInDirectorySearchSubdirectories()
+    {
+        HashSet<String> actual = new HashSet<String>();
+        actual.addAll(PackageResources.getFilesInDirectoryWithSuffix(
+                new File("src/test/file"),
+                ".properties",
+                "",
+                true));
+        HashSet<String> expected = new HashSet<String>();
+        expected.add("1.properties");
+        expected.add("11.properties");
+        expected.add("subfolder/2.properties");
+        expected.add("subfolder/subsubfolder/3.properties");
+        assertEquals(expected, actual);
+    }
+
+    public void testFileNamesInDirectorySuffixNull()
+    {
+        HashSet<String> actual = new HashSet<String>();
+        actual.addAll(PackageResources.getFilesInDirectoryWithSuffix(
+                new File("src/test/file"),
+                null,
+                "",
+                true));
+        HashSet<String> expected = new HashSet<String>();
+        assertEquals(expected, actual);
+    }
+
+    public void testFileNamesInJarDirectory() throws Exception
+    {
+        HashSet<String> actual = new HashSet<String>();
+        actual.addAll(PackageResources.getFilesInJarDirectoryWithSuffix(
+                "templates",
+                new JarFile("target/test/propertyToJavaJar/src/main/torque-gen/propertyToJava.jar"),
+                ".vm",
+                false));
+        HashSet<String> expected = new HashSet<String>();
+        expected.add("propertiesCopy.vm");
+        expected.add("propertiesExtendedToJava.vm");
+        expected.add("propertiesToJava.vm");
+        expected.add("propertyCopy.vm");
+        expected.add("variableAssignment.vm");
+        expected.add("variableDefinition.vm");
+        assertEquals(expected, actual);
+    }
+
+    public void testFileNamesInJarDirectorySearchSubdirectories()
+            throws Exception
+    {
+        HashSet<String> actual = new HashSet<String>();
+        actual.addAll(PackageResources.getFilesInJarDirectoryWithSuffix(
+                "templates",
+                new JarFile("target/test/propertyToJavaJar/src/main/torque-gen/propertyToJava.jar"),
+                ".xml",
+                true));
+        assertEquals(8, actual.size());
+        assertTrue(actual.contains("conf/control.xml"));
+        assertTrue(actual.contains("src/propertiesData.xml"));
+    }
+
+    public void testFileNamesInJarDirectorySuffixNull() throws Exception
+    {
+        HashSet<String> actual = new HashSet<String>();
+        actual.addAll(PackageResources.getFilesInJarDirectoryWithSuffix(
+                "templates",
+                new JarFile("target/test/propertyToJavaJar/src/main/torque-gen/propertyToJava.jar"),
+                null,
+                true));
+        HashSet<String> expected = new HashSet<String>();
+        assertEquals(expected, actual);
+    }
+}



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