fix(StorageServiceImpl, StaticResourceServiceImpl): improve jar path handling for Windows and normalize path resolution
This commit is contained in:
@@ -28,14 +28,20 @@ public class StaticResourceServiceImpl implements StaticResourceService {
|
||||
if (location == null) {
|
||||
try {
|
||||
final URL url = StorageServiceImpl.class.getProtectionDomain().getCodeSource().getLocation();
|
||||
LOGGER.info("Code source location: {}", url);
|
||||
Path parent;
|
||||
if (url.toString().startsWith("jar:nested:")) {
|
||||
parent = Paths.get(url.toString().substring("jar:nested:".length(), url.toString().indexOf("/!"))).getParent();
|
||||
if (Objects.requireNonNullElse(System.getProperty("os.name"), "").toLowerCase().contains("windows")) {
|
||||
parent = Paths.get(url.toString().substring("jar:nested:/".length(), url.toString().indexOf("/!"))).getParent();
|
||||
}
|
||||
else {
|
||||
parent = url.toURI().toPath().getParent();
|
||||
parent = Paths.get(url.toString().substring("jar:nested:".length(), url.toString().indexOf("/!"))).getParent();
|
||||
}
|
||||
final Path jarPath = parent != null ? parent.toAbsolutePath().normalize() : url.toURI().toPath().toAbsolutePath().normalize();
|
||||
}
|
||||
else {
|
||||
parent = Paths.get(url.toURI()).getParent();
|
||||
}
|
||||
final Path jarPath = parent != null ? parent.toAbsolutePath().normalize() : Paths.get(url.toURI()).toAbsolutePath().normalize();
|
||||
|
||||
final String currentSubDir = jarPath.getFileName().toString();
|
||||
if ("bin".equals(currentSubDir) || "target".equals(currentSubDir)) {
|
||||
|
||||
@@ -40,12 +40,17 @@ public class StorageServiceImpl implements StorageService {
|
||||
final URL url = StorageServiceImpl.class.getProtectionDomain().getCodeSource().getLocation();
|
||||
Path parent;
|
||||
if (url.toString().startsWith("jar:nested:")) {
|
||||
parent = Paths.get(url.toString().substring("jar:nested:".length(), url.toString().indexOf("/!"))).getParent();
|
||||
if (Objects.requireNonNullElse(System.getProperty("os.name"), "").toLowerCase().contains("windows")) {
|
||||
parent = Paths.get(url.toString().substring("jar:nested:/".length(), url.toString().indexOf("/!"))).getParent();
|
||||
}
|
||||
else {
|
||||
parent = url.toURI().toPath().getParent();
|
||||
parent = Paths.get(url.toString().substring("jar:nested:".length(), url.toString().indexOf("/!"))).getParent();
|
||||
}
|
||||
final Path jarPath = parent != null ? parent.toAbsolutePath().normalize() : url.toURI().toPath().toAbsolutePath().normalize();
|
||||
}
|
||||
else {
|
||||
parent = Paths.get(url.toURI()).getParent();
|
||||
}
|
||||
final Path jarPath = parent != null ? parent.toAbsolutePath().normalize() : Paths.get(url.toURI()).toAbsolutePath().normalize();
|
||||
|
||||
final String currentSubDir = jarPath.getFileName().toString();
|
||||
if ("bin".equals(currentSubDir) || "target".equals(currentSubDir)) {
|
||||
|
||||
Reference in New Issue
Block a user