This method detects if the virtual machine has a flaw where it cannot find the javac resource because of odd handling of JARs dynamically loaded at run-time. If the flaw needs to have a work-around then a JAR will be printed to standard output. @sine 2018/01/13
()
| 463 | * @sine 2018/01/13 |
| 464 | */ |
| 465 | private static final void __detectToolsFlaw() |
| 466 | { |
| 467 | String vmname = System.getProperty("java.vm.name", ""); |
| 468 | |
| 469 | // JamVM has an issue where when tools.jar is dynamically loaded it |
| 470 | // will fail to find the named resource. This will cause all |
| 471 | // compilation with the system Java compiler to fail. |
| 472 | if (vmname.equalsIgnoreCase("jamvm")) |
| 473 | { |
| 474 | // The JAR to locate will be in the specified location, likely |
| 475 | // /usr/lib/jvm/java-7-openjdk-powerpc/lib/tools.jar |
| 476 | Path jhome = Paths.get(System.getProperty("java.home", "")); |
| 477 | |
| 478 | // Maybe it is here? |
| 479 | Path mightbe = jhome.resolve("tools.jar"); |
| 480 | if (Files.exists(mightbe)) |
| 481 | { |
| 482 | System.out.println(mightbe); |
| 483 | return; |
| 484 | } |
| 485 | |
| 486 | // Try to see if we can get in the library directory |
| 487 | jhome = jhome.getParent(); |
| 488 | if (jhome != null) |
| 489 | jhome = jhome.resolve("lib"); |
| 490 | |
| 491 | // It could be here |
| 492 | mightbe = jhome.resolve("tools.jar"); |
| 493 | if (Files.exists(mightbe)) |
| 494 | { |
| 495 | System.out.println(mightbe); |
| 496 | return; |
| 497 | } |
| 498 | |
| 499 | // These paths will need to be searched for the tools.jar |
| 500 | // It will be in a path like: |
| 501 | String[] bootpaths = System.getProperty("sun.boot.class.path", ""). |
| 502 | split(Pattern.quote( |
| 503 | System.getProperty("path.separator", ":"))); |
| 504 | |
| 505 | // Go through each path and try to find tools.jar |
| 506 | for (String rbp : bootpaths) |
| 507 | { |
| 508 | Path p = Paths.get(rbp); |
| 509 | |
| 510 | // If this refers to a file then try to its directory |
| 511 | if (!Files.isDirectory(p)) |
| 512 | p = p.getParent(); |
| 513 | |
| 514 | // Ignore it because it could not be found |
| 515 | if (p == null || !Files.isDirectory(p)) |
| 516 | continue; |
| 517 | |
| 518 | // If there is a tools.jar here, indicate that |
| 519 | p = p.resolve("tools.jar"); |
| 520 | if (Files.exists(p)) |
| 521 | { |
| 522 | System.out.println(p); |
no test coverage detected