Skip to content

Commit da619ae

Browse files
committed
build: fix windows path parsing
``` java.nio.file.InvalidPathException: Illegal char <:> at index 2 ``` ref #3428
1 parent 04760ce commit da619ae

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

modules/jooby-run/src/main/java/io/jooby/run/JoobyRun.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import java.io.File;
99
import java.io.IOException;
1010
import java.lang.reflect.InvocationTargetException;
11+
import java.net.URISyntaxException;
1112
import java.nio.file.ClosedWatchServiceException;
1213
import java.nio.file.Files;
1314
import java.nio.file.Path;
14-
import java.nio.file.Paths;
1515
import java.time.Clock;
1616
import java.util.ArrayList;
1717
import java.util.HashMap;
@@ -462,25 +462,28 @@ public void shutdown() {
462462
}
463463

464464
static Path baseDir(Path root, Class clazz) {
465-
var resource = clazz.getResource(".");
466-
if (resource != null) {
467-
if ("file".equals(resource.getProtocol())) {
468-
var buildFiles = new String[] {"pom.xml", "build.gradle", "build.gradle.kts"};
469-
var path = Paths.get(resource.getFile());
470-
while (path.startsWith(root)) {
471-
472-
var buildFile =
473-
Stream.of(buildFiles)
474-
.map(path::resolve)
475-
.filter(Files::exists)
476-
.findFirst()
477-
.orElse(null);
478-
if (buildFile != null) {
479-
return buildFile.getParent().toAbsolutePath();
465+
try {
466+
var resource = clazz.getResource(".");
467+
if (resource != null) {
468+
if ("file".equals(resource.getProtocol())) {
469+
var buildFiles = new String[] {"pom.xml", "build.gradle", "build.gradle.kts"};
470+
var path = new File(resource.toURI()).toPath();
471+
while (path.startsWith(root)) {
472+
473+
var buildFile =
474+
Stream.of(buildFiles)
475+
.map(path::resolve)
476+
.filter(Files::exists)
477+
.findFirst()
478+
.orElse(null);
479+
if (buildFile != null) {
480+
return buildFile.getParent().toAbsolutePath();
481+
}
482+
path = path.getParent();
480483
}
481-
path = path.getParent();
482484
}
483485
}
486+
} catch (URISyntaxException ignored) {
484487
}
485488
return null;
486489
}

0 commit comments

Comments
 (0)