Prevent duplicate files from getting onto sources
This commit is contained in:
parent
7a33afa722
commit
12ede8689a
|
@ -115,7 +115,7 @@ public abstract class ResourceUtils {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.add(resource.getURL().toExternalForm());
|
result.add(absolutePath(resource));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -127,12 +127,19 @@ public abstract class ResourceUtils {
|
||||||
List<String> childFiles = new ArrayList<String>();
|
List<String> childFiles = new ArrayList<String>();
|
||||||
for (Resource child : children) {
|
for (Resource child : children) {
|
||||||
if (!child.getFile().isDirectory()) {
|
if (!child.getFile().isDirectory()) {
|
||||||
childFiles.add(child.getURL().toExternalForm());
|
childFiles.add(absolutePath(child));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return childFiles;
|
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) {
|
private static String stripLeadingSlashes(String path) {
|
||||||
while (path.startsWith("/")) {
|
while (path.startsWith("/")) {
|
||||||
path = path.substring(1);
|
path = path.substring(1);
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.boot.cli.util;
|
package org.springframework.boot.cli.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -39,6 +42,16 @@ public class ResourceUtilsTests {
|
||||||
assertTrue(urls.get(0).startsWith("file:"));
|
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
|
@Test
|
||||||
public void explicitClasspathResourceWithSlash() {
|
public void explicitClasspathResourceWithSlash() {
|
||||||
List<String> urls = ResourceUtils.getUrls("classpath:/init.groovy",
|
List<String> urls = ResourceUtils.getUrls("classpath:/init.groovy",
|
||||||
|
|
Loading…
Reference in New Issue