summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--javaLsFlag.txt1
-rw-r--r--lib/src.zipbin61243737 -> 0 bytes
-rw-r--r--src/main/java/org/javacs/Docs.java14
-rw-r--r--src/main/java/org/javacs/Lib.java21
4 files changed, 24 insertions, 12 deletions
diff --git a/javaLsFlag.txt b/javaLsFlag.txt
deleted file mode 100644
index 4babb58..0000000
--- a/javaLsFlag.txt
+++ /dev/null
@@ -1 +0,0 @@
-This file is a flag to help Lib#installRoot find the root directory of the extension. \ No newline at end of file
diff --git a/lib/src.zip b/lib/src.zip
deleted file mode 100644
index d08e5b4..0000000
--- a/lib/src.zip
+++ /dev/null
Binary files differ
diff --git a/src/main/java/org/javacs/Docs.java b/src/main/java/org/javacs/Docs.java
index 586d3f9..1920fb7 100644
--- a/src/main/java/org/javacs/Docs.java
+++ b/src/main/java/org/javacs/Docs.java
@@ -15,10 +15,13 @@ public class Docs {
/** File manager with source-path + platform sources, which we will use to look up individual source files */
private final SourceFileManager fileManager = new SourceFileManager();
- private static Path srcZip() {
+ private static Optional<Path> srcZip() {
+ if (!Lib.SRC_ZIP.isPresent()) {
+ return Optional.empty();
+ }
try {
- var fs = FileSystems.newFileSystem(Lib.SRC_ZIP, Docs.class.getClassLoader());
- return fs.getPath("/");
+ var fs = FileSystems.newFileSystem(Lib.SRC_ZIP.get(), Docs.class.getClassLoader());
+ return Optional.of(fs.getPath("/"));
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -30,7 +33,10 @@ public class Docs {
try {
fileManager.setLocation(StandardLocation.SOURCE_PATH, sourcePathFiles);
- fileManager.setLocationFromPaths(StandardLocation.MODULE_SOURCE_PATH, Set.of(srcZip()));
+ Optional<Path> srcZipPath = srcZip();
+ if (srcZipPath.isPresent()) {
+ fileManager.setLocationFromPaths(StandardLocation.MODULE_SOURCE_PATH, Set.of(srcZipPath.get()));
+ }
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/src/main/java/org/javacs/Lib.java b/src/main/java/org/javacs/Lib.java
index 924f98c..61c5bc4 100644
--- a/src/main/java/org/javacs/Lib.java
+++ b/src/main/java/org/javacs/Lib.java
@@ -1,15 +1,22 @@
package org.javacs;
+import java.io.File;
+import java.lang.System;
+import java.util.Optional;
import java.nio.file.*;
class Lib {
- static Path installRoot() {
- var root = Paths.get(".").toAbsolutePath();
- var p = root;
- while (p != null && !Files.exists(p.resolve("javaLsFlag.txt"))) p = p.getParent();
- if (p == null) throw new RuntimeException("Couldn't find javaLsFlag.txt in any parent of " + root);
- return p;
+ static Optional<Path> srcZipPath() {
+ return Optional.ofNullable(System.getenv("JAVA_HOME"))
+ .flatMap(home -> Optional.of(Paths.get(home).resolve("lib/src.zip")))
+ .flatMap(path -> {
+ if (path.toFile().exists()) {
+ return Optional.of(path);
+ } else {
+ return Optional.empty();
+ }
+ });
}
- static final Path SRC_ZIP = installRoot().resolve("lib/src.zip");
+ static final Optional<Path> SRC_ZIP = srcZipPath();
}