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) {
|
if (location == null) {
|
||||||
try {
|
try {
|
||||||
final URL url = StorageServiceImpl.class.getProtectionDomain().getCodeSource().getLocation();
|
final URL url = StorageServiceImpl.class.getProtectionDomain().getCodeSource().getLocation();
|
||||||
|
LOGGER.info("Code source location: {}", url);
|
||||||
Path parent;
|
Path parent;
|
||||||
if (url.toString().startsWith("jar:nested:")) {
|
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 {
|
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();
|
final String currentSubDir = jarPath.getFileName().toString();
|
||||||
if ("bin".equals(currentSubDir) || "target".equals(currentSubDir)) {
|
if ("bin".equals(currentSubDir) || "target".equals(currentSubDir)) {
|
||||||
|
|||||||
@@ -40,12 +40,17 @@ public class StorageServiceImpl implements StorageService {
|
|||||||
final URL url = StorageServiceImpl.class.getProtectionDomain().getCodeSource().getLocation();
|
final URL url = StorageServiceImpl.class.getProtectionDomain().getCodeSource().getLocation();
|
||||||
Path parent;
|
Path parent;
|
||||||
if (url.toString().startsWith("jar:nested:")) {
|
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 {
|
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();
|
final String currentSubDir = jarPath.getFileName().toString();
|
||||||
if ("bin".equals(currentSubDir) || "target".equals(currentSubDir)) {
|
if ("bin".equals(currentSubDir) || "target".equals(currentSubDir)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user