You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2010/09/07 20:07:25 UTC

svn commit: r993449 - in /db/torque/torque4/trunk/torque-generator/src: main/java/org/apache/torque/generator/configuration/ClasspathConfigurationProvider.java test/java/org/apache/torque/generator/configuration/ClasspathConfigurationProviderTest.java

Author: tfischer
Date: Tue Sep  7 18:07:24 2010
New Revision: 993449

URL: http://svn.apache.org/viewvc?rev=993449&view=rev
Log:
allow double dots in class path resources 

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

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=993449&r1=993448&r2=993449&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 Tue Sep  7 18:07:24 2010
@@ -29,6 +29,7 @@ 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;
 import org.apache.commons.logging.LogFactory;
 import org.apache.torque.generator.configuration.paths.ProjectPaths;
@@ -141,6 +142,10 @@ public class ClasspathConfigurationProvi
                     + directory
                     + "/"
                     + name;
+        
+        // make double dots work for resources in jar files
+        fileName = FilenameUtils.normalizeNoEndSeparator(fileName);
+        fileName = FilenameUtils.separatorsToUnix(fileName);
     
         InputStream inputStream
                 = getClass().getClassLoader().getResourceAsStream(

Added: 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=993449&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ClasspathConfigurationProviderTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ClasspathConfigurationProviderTest.java Tue Sep  7 18:07:24 2010
@@ -0,0 +1,95 @@
+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 java.io.File;
+
+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 ClasspathConfigurationProvider.
+ *
+ * @version $Id:$
+ */
+public class ClasspathConfigurationProviderTest
+{
+
+    private ClasspathConfigurationProvider classpathConfigurationProvider;
+
+    @Before
+    public void before()
+    {
+        ProjectPaths projectPaths = new CustomProjectPaths(
+                null, 
+                "org.apache.torque.generator.test.readfromclasspath",
+                new File("src"),
+                new File("target"),
+                new File("generated-sources"));
+                
+        classpathConfigurationProvider = new ClasspathConfigurationProvider(
+                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(
+                        classpathConfigurationProvider.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(
+                        classpathConfigurationProvider.getResourceInputStream(
+                            "../templates/testTemplate.vm")));
+    }
+
+    @Test
+    public void testGetResourceFromJarWithDoubleDots() throws Exception
+    {
+        assertArrayEquals(
+                IOUtils.toByteArray(getClass().getResourceAsStream(
+                        "/org/apache/commons/io/CopyUtils.class")),
+                IOUtils.toByteArray(
+                        classpathConfigurationProvider.getResourceInputStream(
+                            "../../../../../commons/io/CopyUtils.class")));
+    }
+}



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