Skip to content

Commit

Permalink
Merge pull request #38 from kazuki43zoo/gh-22
Browse files Browse the repository at this point in the history
Replace to getURL instead of getURI when resolve resource path
  • Loading branch information
kazuki43zoo committed Jun 5, 2022
2 parents 2cf68ef + 17b4358 commit 685b10f
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ private Set<Class<?>> scanClasses(String[] packagePatterns, Class<?> assignableT

private Set<String> scanResources(String[] mapperLocationPatterns) {
try {
String baseUri = new ClassPathResource("/").getURI().toString();
String baseUrl = new ClassPathResource("/").getURL().toString();
return Stream.of(mapperLocationPatterns).flatMap(location -> Stream.of(getResources(location)))
.map(x -> toPath(x, baseUri)).collect(Collectors.toSet());
.map(x -> toPath(x, baseUrl)).collect(Collectors.toSet());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand All @@ -273,14 +273,14 @@ private Resource[] getResources(String locationPattern) {
}
}

private String toPath(Resource resource, String baseUri) {
private String toPath(Resource resource, String baseUrl) {
try {
String uri = resource.getURI().toString();
String path = uri;
if (uri.startsWith(baseUri)) {
path = uri.replace(baseUri, "");
} else if (uri.contains(".jar!")) {
path = JAR_RESOURCE_PREFIX_PATTERN.matcher(uri).replaceFirst("");
String url = resource.getURL().toString();
String path = url;
if (url.startsWith(baseUrl)) {
path = url.replace(baseUrl, "");
} else if (url.contains(".jar!")) {
path = JAR_RESOURCE_PREFIX_PATTERN.matcher(url).replaceFirst("");
}
return path;
} catch (IOException e) {
Expand Down

0 comments on commit 685b10f

Please sign in to comment.