|
8 | 8 | import java.io.File; |
9 | 9 | import java.io.IOException; |
10 | 10 | import java.lang.reflect.InvocationTargetException; |
| 11 | +import java.net.URISyntaxException; |
11 | 12 | import java.nio.file.ClosedWatchServiceException; |
12 | 13 | import java.nio.file.Files; |
13 | 14 | import java.nio.file.Path; |
14 | | -import java.nio.file.Paths; |
15 | 15 | import java.time.Clock; |
16 | 16 | import java.util.ArrayList; |
17 | 17 | import java.util.HashMap; |
@@ -462,25 +462,28 @@ public void shutdown() { |
462 | 462 | } |
463 | 463 |
|
464 | 464 | 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(); |
480 | 483 | } |
481 | | - path = path.getParent(); |
482 | 484 | } |
483 | 485 | } |
| 486 | + } catch (URISyntaxException ignored) { |
484 | 487 | } |
485 | 488 | return null; |
486 | 489 | } |
|
0 commit comments