Skip to content

Commit

Permalink
build: fix windows path parsing
Browse files Browse the repository at this point in the history
```
java.nio.file.InvalidPathException: Illegal char <:> at index 2
```

ref #3428
  • Loading branch information
jknack committed May 20, 2024
1 parent 04760ce commit da619ae
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions modules/jooby-run/src/main/java/io/jooby/run/JoobyRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
import java.nio.file.ClosedWatchServiceException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Clock;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -462,25 +462,28 @@ public void shutdown() {
}

static Path baseDir(Path root, Class clazz) {
var resource = clazz.getResource(".");
if (resource != null) {
if ("file".equals(resource.getProtocol())) {
var buildFiles = new String[] {"pom.xml", "build.gradle", "build.gradle.kts"};
var path = Paths.get(resource.getFile());
while (path.startsWith(root)) {

var buildFile =
Stream.of(buildFiles)
.map(path::resolve)
.filter(Files::exists)
.findFirst()
.orElse(null);
if (buildFile != null) {
return buildFile.getParent().toAbsolutePath();
try {
var resource = clazz.getResource(".");
if (resource != null) {
if ("file".equals(resource.getProtocol())) {
var buildFiles = new String[] {"pom.xml", "build.gradle", "build.gradle.kts"};
var path = new File(resource.toURI()).toPath();
while (path.startsWith(root)) {

var buildFile =
Stream.of(buildFiles)
.map(path::resolve)
.filter(Files::exists)
.findFirst()
.orElse(null);
if (buildFile != null) {
return buildFile.getParent().toAbsolutePath();
}
path = path.getParent();
}
path = path.getParent();
}
}
} catch (URISyntaxException ignored) {
}
return null;
}
Expand Down

0 comments on commit da619ae

Please sign in to comment.