db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1504272 - 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/property...
Date Wed, 17 Jul 2013 20:47:12 GMT
Author: tfischer
Date: Wed Jul 17 20:47:12 2013
New Revision: 1504272

URL: http://svn.apache.org/r1504272
Log:
TORQUE-296 finish auto-defining outlets by existence of templates

Modified:
    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/PackageResources.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/test/java/org/apache/torque/generator/configuration/ReadConfigurationTest.java
    db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/expectedPropertiesDebugOutput.properties
    db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/src/main/torque-gen/outlets/velocityPropertiesCopy.xml

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=1504272&r1=1504271&r2=1504272&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 20:47:12 2013
@@ -167,7 +167,7 @@ public class JarConfigurationProvider
         }
 
         return PackageResources.getFilesInJarDirectoryWithSuffix(
-                projectPaths.getConfigurationPath().getPath(),
+                configurationPaths.getTemplateDirectory(),
                 templatesConfigurationFile,
                 null,
                 true);

Modified: 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=1504272&r1=1504271&r2=1504272&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/PackageResources.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/PackageResources.java
Wed Jul 17 20:47:12 2013
@@ -171,7 +171,8 @@ public class PackageResources
     /**
      * Returns all resource names in the package ending with the defined suffix.
      *
-     * @param suffix the suffix which the resource name must have.
+     * @param suffix the suffix which the resource name must have,
+     *        or null to match every file name.
      * @param recurse true if subpackages should also be searched,
      *        false if only the specified package should be searched.
      *
@@ -212,10 +213,13 @@ public class PackageResources
      * 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
+     * @param suffix the suffix the files must have,
+     *        or null to match every file name.
+     * @param prefixToResult a prefix to the path,
+     *        to be able to recurse in subdirectories
+     * @param recurse whether to scan subdirectories.
+     *
+     * @return the list of matching files, not null.
      */
     static List<String> getFilesInDirectoryWithSuffix(
             final File directoryToScan,
@@ -223,14 +227,23 @@ public class PackageResources
             final String prefixToResult,
             final boolean recurse)
     {
+        if (log.isDebugEnabled())
+        {
+            log.debug("Analyzing directory " + directoryToScan
+                    +  " with subdirectory " + prefixToResult
+                    + " for files with suffix " + suffix);
+        }
         final List<String> result = new ArrayList<String>();
-        if (suffix == null)
+        String[] filenames = directoryToScan.list();
+        if (filenames == null)
         {
+            if (log.isDebugEnabled())
+            {
+                log.debug(directoryToScan
+                        + " does not exist, returning the empty list");
+            }
             return result;
         }
-
-        String[] filenames = directoryToScan.list();
-
         for (String filename : filenames)
         {
             File file = new File(filename);
@@ -247,12 +260,16 @@ public class PackageResources
                 continue;
             }
             String rawName = file.getName();
-            if (!rawName.endsWith(suffix))
+            if (suffix != null && !rawName.endsWith(suffix))
             {
                 continue;
             }
             result.add(prefixToResult + filename);
         }
+        if (log.isDebugEnabled())
+        {
+            log.debug("Found the following files " + result);
+        }
         return result;
     }
 
@@ -263,8 +280,8 @@ public class PackageResources
      *        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 suffix the suffix the files must have,
+     *        or null to match every file name.
      * @param searchSubdirectories if files in subdirectories should
      *        also be considered.
      *
@@ -286,12 +303,6 @@ public class PackageResources
                     + " 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())
@@ -306,7 +317,7 @@ public class PackageResources
             {
                 continue;
             }
-            if (!rawName.endsWith(suffix))
+            if (suffix != null && !rawName.endsWith(suffix))
             {
                 continue;
             }

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=1504272&r1=1504271&r2=1504272&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 20:47:12 2013
@@ -189,6 +189,12 @@ public class OutletConfigurationXmlParse
                 }
             }
         }
+        // add outlets defined implicitly by templates
+        scanTemplatesForOutlets(
+                allOutlets,
+                configurationProvider,
+                configurationHandlers);
+
         return new OutletConfiguration(
                 allOutlets,
                 allMergepointMappings,
@@ -237,12 +243,6 @@ public class OutletConfigurationXmlParse
         List<Outlet> outlets = new ArrayList<Outlet>();
         outlets.addAll(saxHandler.getOutlets());
 
-        // add outlets defined implicitly by templates
-        scanTemplatesForOutlets(
-                outlets,
-                configurationProvider,
-                configurationHandlers);
-
         return new OutletConfigFileContent(
                 outlets,
                 saxHandler.getMergepointMappings());
@@ -269,18 +269,21 @@ public class OutletConfigurationXmlParse
             for (TypedOutletSaxHandlerFactory outletSaxHandlerFactory
                         : outletSaxHandlerFactories)
             {
-                if (outletSaxHandlerFactory
-                        .getTemplatesFilenameExtensionsForScan().contains(
-                                templateFileName))
+                for (String suffix : outletSaxHandlerFactory
+                        .getTemplatesFilenameExtensionsForScan())
                 {
-                    Outlet outlet
-                            = outletSaxHandlerFactory.createOutletForTemplate(
-                                    templateFileName,
-                                    configurationProvider);
-                    QualifiedName outletName = outlet.getName();
-                    if (!outletNames.contains(outletName))
+                    if (templateFileName.endsWith(suffix))
                     {
-                        outlets.add(outlet);
+                        Outlet outlet
+                                = outletSaxHandlerFactory.createOutletForTemplate(
+                                        templateFileName,
+                                        configurationProvider);
+                        QualifiedName outletName = outlet.getName();
+                        if (!outletNames.contains(outletName))
+                        {
+                            outlets.add(outlet);
+                            continue;
+                        }
                     }
                 }
             }

Modified: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ReadConfigurationTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ReadConfigurationTest.java?rev=1504272&r1=1504271&r2=1504272&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ReadConfigurationTest.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ReadConfigurationTest.java
Wed Jul 17 20:47:12 2013
@@ -373,7 +373,7 @@ public class ReadConfigurationTest exten
                     = unitConfiguration.getOutletConfiguration();
             Map<QualifiedName, Outlet> outletMap
                     = outletConfiguration.getOutlets();
-            assertEquals(2, outletMap.size());
+            assertEquals(3, outletMap.size());
             {
                 JavaOutlet outlet
                         = (JavaOutlet) outletMap.get(new QualifiedName(
@@ -444,6 +444,25 @@ public class ReadConfigurationTest exten
                 assertFalse(outlet.isSourceAttributesInContext());
                 assertFalse(outlet.isVariablesInContext());
             }
+
+            {
+                VelocityOutlet outlet
+                        = (VelocityOutlet) outletMap.get(new QualifiedName(
+                                "testTemplate"));
+                String templateContent
+                        = outlet.getContent(controllerState);
+                // remove License from template by comparing only
+                // the last line
+                String templateContentLicenseRemoved
+                        = StringUtils.substringAfterLast(templateContent, "\r\n");
+                assertEquals(
+                        "test template output",
+                        templateContentLicenseRemoved);
+                assertEquals(0, outlet.getMergepointMappings().size());
+                assertTrue(outlet.isOptionsInContext());
+                assertTrue(outlet.isSourceAttributesInContext());
+                assertTrue(outlet.isVariablesInContext());
+            }
         }
     }
 
@@ -481,12 +500,13 @@ public class ReadConfigurationTest exten
         }
 
         // check that the outlets are read
+        // two from explicit configuration and one from the templates
         {
             OutletConfiguration outletConfiguration
                     = unitConfiguration.getOutletConfiguration();
             Map<QualifiedName, Outlet> outletMap
                     = outletConfiguration.getOutlets();
-            assertEquals(2, outletMap.size());
+            assertEquals(3, outletMap.size());
         }
     }
 
@@ -905,7 +925,7 @@ public class ReadConfigurationTest exten
                     = unitConfiguration.getOutletConfiguration();
             Map<QualifiedName, Outlet> outletMap
                     = outletConfiguration.getOutlets();
-            assertEquals(3, outletMap.size());
+            assertEquals(4, outletMap.size());
             {
                 JavaOutlet outlet
                         = (JavaOutlet) outletMap.get(new QualifiedName(
@@ -988,12 +1008,27 @@ public class ReadConfigurationTest exten
                         templateContentLicenseRemoved);
                 assertEquals(0, outlet.getMergepointMappings().size());
             }
+            {
+                VelocityOutlet outlet
+                        = (VelocityOutlet) outletMap.get(new QualifiedName(
+                                "testTemplate"));
+                String templateContent
+                        = outlet.getContent(controllerState);
+                // remove License from template by comparing only
+                // the last line
+                String templateContentLicenseRemoved
+                        = StringUtils.substringAfterLast(templateContent, "\r\n");
+                assertEquals(
+                        "test template output",
+                        templateContentLicenseRemoved);
+                assertEquals(0, outlet.getMergepointMappings().size());
+            }
         }
     }
 
     private static void assertFileSourceProviderEquals(
-            FileSourceProvider expected,
-            FileSourceProvider actual)
+            final FileSourceProvider expected,
+            final FileSourceProvider actual)
     {
         assertEquals(
                 expected.getSourceFormat(),
@@ -1016,8 +1051,8 @@ public class ReadConfigurationTest exten
     }
 
     private static void assertJdbcMetadataSourceProviderEquals(
-            JdbcMetadataSourceProvider expected,
-            JdbcMetadataSourceProvider actual)
+            final JdbcMetadataSourceProvider expected,
+            final JdbcMetadataSourceProvider actual)
     {
         assertEquals(
                 expected.getDriverOption(),
@@ -1051,7 +1086,7 @@ public class ReadConfigurationTest exten
                 actual.getUsername());
     }
 
-    private static void assertOptionsEquals(Options expected, Options actual)
+    private static void assertOptionsEquals(final Options expected, final Options actual)
     {
         Map<QualifiedName, Option> expectedMap
                 = expected.getGlobalScope();
@@ -1069,8 +1104,8 @@ public class ReadConfigurationTest exten
     }
 
     private void assertSourceProcessConfigurationEquals(
-            SourceProcessConfiguration expected,
-            SourceProcessConfiguration actual)
+            final SourceProcessConfiguration expected,
+            final SourceProcessConfiguration actual)
     {
         if (expected.getSkipDecider() != null)
         {
@@ -1097,7 +1132,7 @@ public class ReadConfigurationTest exten
      *
      * @return the Set containing all the strings.
      */
-    private static Set<String> createSetFrom(String... content)
+    private static Set<String> createSetFrom(final String... content)
     {
         Set<String> result = new HashSet<String>();
         for (String part : content)

Modified: db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/expectedPropertiesDebugOutput.properties
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/expectedPropertiesDebugOutput.properties?rev=1504272&r1=1504271&r2=1504272&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/expectedPropertiesDebugOutput.properties
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/expectedPropertiesDebugOutput.properties
Wed Jul 17 20:47:12 2013
@@ -16,10 +16,10 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-# start output of outlet org.apache.torque.generator.velocity.propertyCopy, current model
element is (name=entry,attributes=(key=propertyName1,null=propertyValue1),children=())
+# start output of outlet propertyCopy, current model element is (name=entry,attributes=(key=propertyName1,null=propertyValue1),children=())
 propertyName1 = propertyValue1
-# end output of outlet org.apache.torque.generator.velocity.propertyCopy, current model is
(name=entry,attributes=(key=propertyName1,null=propertyValue1),children=())
-# start output of outlet org.apache.torque.generator.velocity.propertyCopy, current model
element is (name=entry,attributes=(key=propertyName2,null=propertyValue2),children=())
+# end output of outlet propertyCopy, current model is (name=entry,attributes=(key=propertyName1,null=propertyValue1),children=())
+# start output of outlet propertyCopy, current model element is (name=entry,attributes=(key=propertyName2,null=propertyValue2),children=())
 propertyName2 = propertyValue2
-# end output of outlet org.apache.torque.generator.velocity.propertyCopy, current model is
(name=entry,attributes=(key=propertyName2,null=propertyValue2),children=())
+# end output of outlet propertyCopy, current model is (name=entry,attributes=(key=propertyName2,null=propertyValue2),children=())
 # end output of outlet org.apache.torque.generator.velocity.propertiesCopy, current model
is (name=properties,attributes=(),children=((name=entry,attributes=(key=propertyName1,null=propertyValue1),children=()),(name=entry,attributes=(key=propertyName2,null=propertyValue2),children=())))

Modified: db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/src/main/torque-gen/outlets/velocityPropertiesCopy.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/src/main/torque-gen/outlets/velocityPropertiesCopy.xml?rev=1504272&r1=1504271&r2=1504272&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/src/main/torque-gen/outlets/velocityPropertiesCopy.xml
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/src/main/torque-gen/outlets/velocityPropertiesCopy.xml
Wed Jul 17 20:47:12 2013
@@ -26,10 +26,8 @@
       path="propertiesCopy.vm">
     <mergepoint name="properties">
       <action xsi:type="traverseAllAction" element="entry" 
-          outlet="org.apache.torque.generator.velocity.propertyCopy"/>
+          outlet="propertyCopy"/>
     </mergepoint>
   </outlet>
-  <outlet name="org.apache.torque.generator.velocity.propertyCopy"
-      xsi:type="velocityOutlet" 
-      path="propertyCopy.vm"/>
+  <!-- outlet propertyCopy auto-defined by template scan -->
 </outlets>
\ 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