Return-Path: Delivered-To: apmail-db-torque-dev-archive@www.apache.org Received: (qmail 62375 invoked from network); 7 Sep 2010 18:07:47 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 7 Sep 2010 18:07:47 -0000 Received: (qmail 84848 invoked by uid 500); 7 Sep 2010 18:07:47 -0000 Delivered-To: apmail-db-torque-dev-archive@db.apache.org Received: (qmail 84759 invoked by uid 500); 7 Sep 2010 18:07:46 -0000 Mailing-List: contact torque-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Apache Torque Developers List" Reply-To: "Apache Torque Developers List" Delivered-To: mailing list torque-dev@db.apache.org Received: (qmail 84751 invoked by uid 500); 7 Sep 2010 18:07:46 -0000 Received: (qmail 84748 invoked by uid 99); 7 Sep 2010 18:07:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Sep 2010 18:07:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Sep 2010 18:07:45 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3EED623889B2; Tue, 7 Sep 2010 18:07:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Tue, 07 Sep 2010 18:07:25 -0000 To: torque-commits@db.apache.org From: tfischer@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100907180725.3EED623889B2@eris.apache.org> 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