You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2016/05/11 14:16:08 UTC
svn commit: r1743376 - in /sling/trunk: bundles/extensions/resourcebuilder/
testing/junit/teleporter/src/main/java/org/apache/sling/testing/teleporter/client/
testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/
Author: bdelacretaz
Date: Wed May 11 14:16:08 2016
New Revision: 1743376
URL: http://svn.apache.org/viewvc?rev=1743376&view=rev
Log:
SLING-5712 - avoid windows file separator issues in ClassResourceVisitor, based on a patch by Emanuele Lombardi, thanks!
Added:
sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/SanitizeResourceNameTest.java
Modified:
sling/trunk/bundles/extensions/resourcebuilder/pom.xml
sling/trunk/testing/junit/teleporter/src/main/java/org/apache/sling/testing/teleporter/client/ClassResourceVisitor.java
sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/ClassResourceVisitorTest.java
Modified: sling/trunk/bundles/extensions/resourcebuilder/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/resourcebuilder/pom.xml?rev=1743376&r1=1743375&r2=1743376&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/resourcebuilder/pom.xml (original)
+++ sling/trunk/bundles/extensions/resourcebuilder/pom.xml Wed May 11 14:16:08 2016
@@ -240,8 +240,8 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.junit.teleporter</artifactId>
- <!-- SNAPSHOT required due to SLING-5365 -->
- <version>1.0.5-SNAPSHOT</version>
+ <!-- SNAPSHOT required due to SLING-5712 -->
+ <version>1.0.7-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Modified: sling/trunk/testing/junit/teleporter/src/main/java/org/apache/sling/testing/teleporter/client/ClassResourceVisitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/teleporter/src/main/java/org/apache/sling/testing/teleporter/client/ClassResourceVisitor.java?rev=1743376&r1=1743375&r2=1743376&view=diff
==============================================================================
--- sling/trunk/testing/junit/teleporter/src/main/java/org/apache/sling/testing/teleporter/client/ClassResourceVisitor.java (original)
+++ sling/trunk/testing/junit/teleporter/src/main/java/org/apache/sling/testing/teleporter/client/ClassResourceVisitor.java Wed May 11 14:16:08 2016
@@ -61,8 +61,9 @@ public class ClassResourceVisitor {
if("file".equals(protocol)) {
// Get base path and remove ending slash
- String basePath = clazz.getResource("/").getPath();
- basePath = basePath.substring(0, basePath.length() - 1);
+ //String basePath = clazz.getResource("/").getPath();
+ //basePath = basePath.substring(0, basePath.length() - 1);
+ final String basePath = new File(clazz.getResource("/").getPath()).getAbsolutePath();
processFile(basePath, new File(resourceURL.getPath()), p);
} else if("jar".equals(protocol)) {
@@ -107,6 +108,13 @@ public class ClassResourceVisitor {
}
}
+ /* Backslashes are valid in Zip-files, BUT Java expects paths to be delimited by forward slashes.
+ * Windows provides file paths using backslashes, which need to be converted here.
+ */
+ static String sanitizeResourceName(String basePath, File resource) {
+ return resource.getAbsolutePath().substring(basePath.length()).replace("\\", "/");
+ }
+
private void processFile(String basePath, File f, Processor p) throws IOException {
if(f.isDirectory()) {
final String [] names = f.list();
@@ -118,7 +126,7 @@ public class ClassResourceVisitor {
} else {
final InputStream is = new BufferedInputStream(new FileInputStream(f));
try {
- p.process(f.getAbsolutePath().substring(basePath.length()), is);
+ p.process(sanitizeResourceName(basePath, f), is);
} finally {
is.close();
}
Modified: sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/ClassResourceVisitorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/ClassResourceVisitorTest.java?rev=1743376&r1=1743375&r2=1743376&view=diff
==============================================================================
--- sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/ClassResourceVisitorTest.java (original)
+++ sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/ClassResourceVisitorTest.java Wed May 11 14:16:08 2016
@@ -16,8 +16,8 @@
*/
package org.apache.sling.testing.teleporter.client;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
Added: sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/SanitizeResourceNameTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/SanitizeResourceNameTest.java?rev=1743376&view=auto
==============================================================================
--- sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/SanitizeResourceNameTest.java (added)
+++ sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/SanitizeResourceNameTest.java Wed May 11 14:16:08 2016
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+package org.apache.sling.testing.teleporter.client;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class SanitizeResourceNameTest {
+ @Parameterized.Parameters(name = "{0}/{1}")
+ public static Collection<String[]> data() {
+ return Arrays.asList(new String[][] {
+ { "some/base", "r/a/b", "/r/a/b" },
+ { "some\\base", "r\\c\\d", "/r/c/d" },
+ { "some/base", "r\\e\\f", "/r/e/f" },
+ { "some\\base", "r/g/h/i", "/r/g/h/i" },
+ });
+ }
+
+ private final String basePath;
+ private final String path;
+ private final String expected;
+
+ public SanitizeResourceNameTest(String basePath, String path, String expected) {
+ this.basePath = File.separator + basePath;
+ this.path = path;
+ this.expected = expected;
+ }
+
+ @Test
+ public void sanitize() {
+ final String actual = ClassResourceVisitor.sanitizeResourceName(basePath, new File(basePath, path));
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file