summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2018-12-28 19:31:38 -0800
committerGeorge Fraser <george@fivetran.com>2018-12-28 19:31:38 -0800
commit9a02922e98d84bb1ea0b19ff8d2259b5cb7b0e9c (patch)
treea8621acc6a35e55d33627bb2f77cd85aef358e73 /scripts
parent3bdefe1c30f531c7a646df9b9b14eec232f1fe1b (diff)
downloadjava-language-server-9a02922e98d84bb1ea0b19ff8d2259b5cb7b0e9c.zip
Use jlink to build self-contained distribution
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build.sh2
-rwxr-xr-xscripts/link.sh42
-rwxr-xr-xscripts/patch_gson.sh29
3 files changed, 48 insertions, 25 deletions
diff --git a/scripts/build.sh b/scripts/build.sh
index 457de4d..c93246d 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -9,7 +9,7 @@ JAVA_HOME=$(/usr/libexec/java_home -v 11)
npm install
# Build fat jar
-mvn package -DskipTests
+./scripts/link.sh
# Build vsix
vsce package -o build.vsix
diff --git a/scripts/link.sh b/scripts/link.sh
index 972da7d..07ae214 100755
--- a/scripts/link.sh
+++ b/scripts/link.sh
@@ -1,33 +1,27 @@
#!/bin/bash
-# Work-in-progress!
-# This script tries to link everything into a self-contained executable using jlink.
-# It doesn't yet work because our dependencies aren't modularized
+# Links everything into a self-contained executable using jlink.
set -e
-# Needed once
-npm install
+# Needed if you have a java version other than 11 as default
+JAVA_HOME=$(/usr/libexec/java_home -v 11)
+
+# Compile sources
+mvn compile
+
+# Patch gson
+if [ ! -e modules/gson.jar ]; then
+ ./scripts/patch_gson.sh
+fi
-# Build jar
-mvn package -DskipTests
-# Copy dependencies
-rm -rf target/deps
-mvn dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=target/deps
-# Copy class files
-mkdir -p target/mods
-mv target/classes target/mods/javacs
# Build using jlink
-jlink \
- --module-path target/mods:target/deps \
- --add-modules javacs \
+rm -rf dist
+$JAVA_HOME/bin/jlink \
+ --module-path modules/gson.jar:target/classes \
+ --add-modules gson,javacs \
--launcher javacs=javacs/org.javacs.Main \
--output dist \
- --strip-debug \
- --compress 2 \
- --no-header-files \
- --no-man-pages
-
-# Build vsix
-vsce package -o build.vsix
+ --compress 2
-echo 'Install build.vsix using the extensions menu'
+# TODO: need to run this again with windows jdk!
+# https://stackoverflow.com/questions/47593409/create-java-runtime-image-on-one-platform-for-another-using-jlink \ No newline at end of file
diff --git a/scripts/patch_gson.sh b/scripts/patch_gson.sh
new file mode 100755
index 0000000..d2981ea
--- /dev/null
+++ b/scripts/patch_gson.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# Patch Gson with module-info.java
+# When Gson releases a new version, we will no longer need to do this
+# https://github.com/google/gson/issues/1315
+
+set -e
+
+# Needed if you have a java version other than 11 as default
+JAVA_HOME=$(/usr/libexec/java_home -v 11)
+
+# Download Gson jar
+cd modules
+curl https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.5/gson-2.8.5.jar > gson.jar
+
+# Unpack jar into modules/classes
+mkdir classes
+cd classes
+jar xf ../gson.jar
+cd ..
+
+# Compile module-info.java to module-info.class
+javac -p com.google.gson -d classes module-info.java
+
+# Update gson.jar with module-info.class
+jar uf gson.jar -C classes module-info.class
+
+# Clean up
+rm -rf classes
+cd .. \ No newline at end of file