From 4a850518b55629cb87f9f6b32d7ea6023ed03424 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch Date: Tue, 19 Feb 2019 05:08:35 +0000 Subject: Remove src.zip and get it from JAVA_HOME What === Remove src.zip and get it from the path pointed to by the JAVA_HOME environment variable. Why === When using this tool standalone the lib/src.zip file doesn't seem to be packaged inside what is jlinked which causes exceptions on startup. It also seems odd to package src.zip inside the tool when Java JDK installations come with src, and in the event they don't (e.g. OpenJDK on Debian) they can be easily installed using the distros built in package manager. As a side note the src.zip licensing is ambiguous to me and it's not clear from any other documentation in this repository how it is being licensed. I assume it is properly licensed to have been included, but regardless removing any licensing ambiguity from the tool seems ideal for those using it. --- javaLsFlag.txt | 1 - lib/src.zip | Bin 61243737 -> 0 bytes src/main/java/org/javacs/Docs.java | 14 ++++++++++---- src/main/java/org/javacs/Lib.java | 21 ++++++++++++++------- 4 files changed, 24 insertions(+), 12 deletions(-) delete mode 100644 javaLsFlag.txt delete mode 100644 lib/src.zip 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 Binary files a/lib/src.zip and /dev/null 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 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 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 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 SRC_ZIP = srcZipPath(); } -- cgit v1.2.3