Prevent duplicate files from getting onto sources

pull/755/head
Dave Syer 11 years ago
parent 7a33afa722
commit 12ede8689a

@ -115,7 +115,7 @@ public abstract class ResourceUtils {
continue;
}
}
result.add(resource.getURL().toExternalForm());
result.add(absolutePath(resource));
}
}
return result;
@ -127,12 +127,19 @@ public abstract class ResourceUtils {
List<String> childFiles = new ArrayList<String>();
for (Resource child : children) {
if (!child.getFile().isDirectory()) {
childFiles.add(child.getURL().toExternalForm());
childFiles.add(absolutePath(child));
}
}
return childFiles;
}
private static String absolutePath(Resource resource) throws IOException {
if (!resource.getURI().getScheme().equals("file")) {
return resource.getURL().toExternalForm();
}
return resource.getFile().getAbsoluteFile().toURI().toString();
}
private static String stripLeadingSlashes(String path) {
while (path.startsWith("/")) {
path = path.substring(1);

@ -16,6 +16,9 @@
package org.springframework.boot.cli.util;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;
import org.junit.Test;
@ -39,6 +42,16 @@ public class ResourceUtilsTests {
assertTrue(urls.get(0).startsWith("file:"));
}
@Test
public void duplicateResource() throws Exception {
URLClassLoader loader = new URLClassLoader(new URL[] {
new URL("file:./src/test/resources/"),
new File("src/test/resources/").getAbsoluteFile().toURI().toURL() });
List<String> urls = ResourceUtils.getUrls("classpath:init.groovy", loader);
assertEquals(1, urls.size());
assertTrue(urls.get(0).startsWith("file:"));
}
@Test
public void explicitClasspathResourceWithSlash() {
List<String> urls = ResourceUtils.getUrls("classpath:/init.groovy",

Loading…
Cancel
Save