diff --git a/README.md b/README.md index c2aff2d6b..80158fe1e 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,18 @@ A Java [language server](https://github.com/Microsoft/vscode-languageserver-prot ## Installation (other editors) -### Vim (with vim-lsc) +### Base Install Steps - Checkout this repository -- Run `./scripts/link_{linux|mac|windows}.sh` -- Run `mvn package -DskipTests` +- Run ./scripts/install.sh + +### Vim (with vim-lsc) + +- [Follow Base Install Steps](#base-install-steps) - Add the vim plugin [natebosch/vim-lsc](https://github.com/natebosch/vim-lsc) to your vimrc - Add vim-lsc configuration: ```vimrc - let g:lsc_server_commands = {'java': '/java-language-server/dist/lang_server_{linux|mac|windows}.sh'} + let g:lsc_server_commands = {'java': '/usr/local/bin/java-language-server'} ``` - See the [vim-lsc README](https://github.com/natebosch/vim-lsc/blob/master/README.md) for other configuration options. @@ -24,9 +27,7 @@ Note: This tool is not compatible with [vim-lsp](https://github.com/prabirshrest ### KDE Kate -- Checkout this repository -- Run `./scripts/link_{linux|mac|windows}.sh` -- Run `mvn package -DskipTests` +- [Follow Base Install Steps](#base-install-steps) - Open your Kate editor - Go to Settings > Configure Kate... > LSP Client > User Server Settings - Add this lines to your User Server Settings: @@ -36,7 +37,7 @@ Note: This tool is not compatible with [vim-lsp](https://github.com/prabirshrest { "java": { - "command": ["bash","/java-language-server/dist/lang_server_{linux|mac|windows}.sh"], + "command": ["bash", "/usr/local/bin/java-language-server"], "url": "https://github.com/georgewfraser/java-language-server", "highlightingModeRegex": "^Java$" } @@ -47,9 +48,7 @@ Note: This tool is not compatible with [vim-lsp](https://github.com/prabirshrest ### Sublime 3 (with LSP) -- Checkout this repository -- Run `./scripts/link_{linux|mac|windows}.sh` -- Run `mvn package -DskipTests` +- [Follow Base Install Steps](#base-install-steps) - Open your Sublime 3 - Install Package Control (if missing) - Install the [LSP Package](https://packagecontrol.io/packages/LSP) (if missing) @@ -62,7 +61,7 @@ Note: This tool is not compatible with [vim-lsp](https://github.com/prabirshrest "jls": { "enabled": true, - "command": ["bash", "/java-language-server/dist/lang_server_{linux|mac|windows}.sh"], + "command": ["bash", "/usr/local/bin/java-language-server"], "scopes": ["source.java"], "syntaxes": ["Packages/Java/Java.sublime-syntax"], "languageId": "java" diff --git a/dist/debug_adapter_linux.sh b/dist/debug_adapter_linux.sh index b415c7345..22e168bc7 100755 --- a/dist/debug_adapter_linux.sh +++ b/dist/debug_adapter_linux.sh @@ -1,3 +1,3 @@ #!/bin/sh -DIR=`dirname $0` -$DIR/launch_linux.sh org.javacs.debug.JavaDebugServer $@ +DIST_DIR=$(dirname $(readlink -f "$0")) +${DIST_DIR}/launch_linux.sh org.javacs.debug.JavaDebugServer $@ diff --git a/dist/debug_adapter_mac.sh b/dist/debug_adapter_mac.sh index 73f9fc1d3..6a5904418 100755 --- a/dist/debug_adapter_mac.sh +++ b/dist/debug_adapter_mac.sh @@ -1,3 +1,3 @@ #!/bin/sh -DIR=`dirname $0` -$DIR/launch_mac.sh org.javacs.debug.JavaDebugServer $@ +DIST_DIR=$(dirname $(readlink -f "$0")) +${DIST_DIR}/launch_mac.sh org.javacs.debug.JavaDebugServer $@ diff --git a/dist/debug_adapter_windows.sh b/dist/debug_adapter_windows.sh index f62a1c1df..27d505908 100644 --- a/dist/debug_adapter_windows.sh +++ b/dist/debug_adapter_windows.sh @@ -1,3 +1,3 @@ #!/bin/sh -DIR=`dirname $0` -$DIR/launch_windows.sh org.javacs.debug.JavaDebugServer $@ +DIST_DIR=$(dirname $(readlink -f "$0")) +${DIST_DIR}/launch_windows.sh org.javacs.debug.JavaDebugServer $@ diff --git a/dist/java-debug-server b/dist/java-debug-server new file mode 100755 index 000000000..83a58bac2 --- /dev/null +++ b/dist/java-debug-server @@ -0,0 +1,14 @@ +#!/bin/sh + +OS="unknown" +if which -s uname;then + OS=$(uname |tr '[:upper:]' '[:lower:]') +fi +DIST_DIR=$(dirname $(readlink -f "$0")) +if [ "${OS}" = 'darwin' ]; then + ${DIST_DIR}/debug_adapter_mac.sh $@ +elif [ "${OS}" = 'linux' ]; then + ${DIST_DIR}/debug_adapter_linux.sh $@ +else + ${DIST_DIR}/debug_adapter_windows.sh $@ +fi diff --git a/dist/java-language-server b/dist/java-language-server new file mode 100755 index 000000000..968e81f34 --- /dev/null +++ b/dist/java-language-server @@ -0,0 +1,14 @@ +#!/bin/sh + +OS="unknown" +if which -s uname;then + OS=$(uname |tr '[:upper:]' '[:lower:]') +fi +DIST_DIR=$(dirname $(readlink -f "$0")) +if [ "${OS}" = 'darwin' ]; then + ${DIST_DIR}/lang_server_mac.sh $@ +elif [ "${OS}" = 'linux' ]; then + ${DIST_DIR}/lang_server_linux.sh $@ +else + ${DIST_DIR}/lang_server_windows.sh $@ +fi diff --git a/dist/lang_server_linux.sh b/dist/lang_server_linux.sh index af65ba67a..04828cd56 100755 --- a/dist/lang_server_linux.sh +++ b/dist/lang_server_linux.sh @@ -1,3 +1,3 @@ #!/bin/sh -DIR=`dirname $0` -$DIR/launch_linux.sh org.javacs.Main $@ +DIST_DIR=$(dirname $(readlink -f "$0")) +${DIST_DIR}/launch_linux.sh org.javacs.Main $@ diff --git a/dist/lang_server_mac.sh b/dist/lang_server_mac.sh index c1ae29bc8..2c1123b6a 100755 --- a/dist/lang_server_mac.sh +++ b/dist/lang_server_mac.sh @@ -1,3 +1,3 @@ #!/bin/sh -DIR=`dirname $0` -$DIR/launch_mac.sh org.javacs.Main $@ +DIST_DIR=$(dirname $(readlink -f "$0")) +${DIST_DIR}/launch_mac.sh org.javacs.Main $@ diff --git a/dist/lang_server_windows.sh b/dist/lang_server_windows.sh index b2d659213..2b2aafe1f 100644 --- a/dist/lang_server_windows.sh +++ b/dist/lang_server_windows.sh @@ -1,3 +1,3 @@ #!/bin/sh -DIR=`dirname $0` -$DIR/launch_windows.sh org.javacs.Main $@ +DIST_DIR=$(dirname $(readlink -f "$0")) +${DIST_DIR}/launch_windows.sh org.javacs.Main $@ diff --git a/dist/launch_linux.sh b/dist/launch_linux.sh index 905620eb0..301b9549c 100755 --- a/dist/launch_linux.sh +++ b/dist/launch_linux.sh @@ -8,6 +8,7 @@ JLINK_VM_OPTIONS="\ --add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" -DIR=`dirname $0` -CLASSPATH_OPTIONS="-classpath $DIR/classpath/gson-2.8.9.jar:$DIR/classpath/protobuf-java-3.19.3.jar:$DIR/classpath/java-language-server.jar" -$DIR/linux/bin/java $JLINK_VM_OPTIONS $CLASSPATH_OPTIONS $@ +DIST_DIR=$(dirname $(readlink -f "$0")) +CLASSPATH_JARS="$(find ${DIST_DIR}/classpath -type f -iname '*.jar'|xargs |sed 's/ /:/g')" +CLASSPATH_OPTIONS="-classpath ${CLASSPATH_JARS}" +${DIST_DIR}/linux/bin/java $JLINK_VM_OPTIONS $CLASSPATH_OPTIONS $@ diff --git a/dist/launch_mac.sh b/dist/launch_mac.sh index 82d8276c0..126a9a639 100755 --- a/dist/launch_mac.sh +++ b/dist/launch_mac.sh @@ -8,6 +8,7 @@ JLINK_VM_OPTIONS="\ --add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" -DIR=`dirname $0` -CLASSPATH_OPTIONS="-classpath $DIR/classpath/gson-2.8.9.jar:$DIR/classpath/protobuf-java-3.19.3.jar:$DIR/classpath/java-language-server.jar" -$DIR/mac/bin/java $JLINK_VM_OPTIONS $CLASSPATH_OPTIONS $@ +DIST_DIR=$(dirname $(readlink -f "$0")) +CLASSPATH_JARS="$(find ${DIST_DIR}/classpath -type f -iname '*.jar'|xargs |sed 's/ /:/g')" +CLASSPATH_OPTIONS="-classpath ${CLASSPATH_JARS}" +${DIST_DIR}/mac/bin/java $JLINK_VM_OPTIONS $CLASSPATH_OPTIONS $@ diff --git a/dist/launch_windows.sh b/dist/launch_windows.sh index 2dc0a411e..262da42ba 100644 --- a/dist/launch_windows.sh +++ b/dist/launch_windows.sh @@ -8,6 +8,7 @@ JLINK_VM_OPTIONS="\ --add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" -DIR=`dirname $0` -CLASSPATH_OPTIONS="-classpath $DIR/classpath/gson-2.8.9.jar;$DIR/classpath/protobuf-java-3.19.3.jar;$DIR/classpath/java-language-server.jar" -$DIR/windows/bin/java $JLINK_VM_OPTIONS $CLASSPATH_OPTIONS $@ +DIST_DIR=$(dirname $(readlink -f "$0")) +CLASSPATH_JARS="$(find ${DIST_DIR}/classpath -type f -iname '*.jar'|xargs |sed 's/ /:/g')" +CLASSPATH_OPTIONS="-classpath ${CLASSPATH_JARS}" +${DIST_DIR}/windows/bin/java $JLINK_VM_OPTIONS $CLASSPATH_OPTIONS $@ diff --git a/scripts/download_mac_jdk.sh b/scripts/download_mac_jdk.sh index d2eca3f7d..798ec7ded 100755 --- a/scripts/download_mac_jdk.sh +++ b/scripts/download_mac_jdk.sh @@ -3,11 +3,15 @@ set -e -# Download mac jdk +# Download mac jdk if it doesn't exist +if [[ -x jdks/mac/jdk-18/Contents/Home/bin/java ]];then + exit 0 +fi + mkdir -p jdks/mac cd jdks/mac curl https://download.java.net/java/GA/jdk18.0.1.1/65ae32619e2f40f3a9af3af1851d6e19/2/GPL/openjdk-18.0.1.1_macos-x64_bin.tar.gz > mac.tar.gz gunzip -c mac.tar.gz | tar xopf - rm mac.tar.gz -mv jdk-18.0.1.1.jdk jdk-18 -cd ../.. \ No newline at end of file +ln -s jdk-18.0.1.1.jdk jdk-18 +cd ../.. diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 000000000..f736f624b --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,81 @@ +#!/bin/bash +INSTALL_DIR=${INSTALL_DIR:="/usr/local/java-language-server"} +INSTALL_BIN=${INSTALL_BIN:="/usr/local/bin"} +OS="unknown" +if which -s uname;then + OS=$(uname |tr '[:upper:]' '[:lower:]') +fi + +uninstall() { + if echo ${INSTALL_DIR}|grep -q "/usr/local" || echo ${INSTALL_BIN}|grep -q "/usr/local";then + local sudoprompt="SUDO password required to remove language server from INSTALL_DIR=${INSTALL_DIR} and INSTALL_BIN=${INSTALL_BIN}: " + sudo -p "${sudoprompt}" rm -rf ${INSTALL_DIR} ${INSTALL_BIN}/{java-debug-server,java-language-server} + else + rm -rf ${INSTALL_DIR} ${INSTALL_BIN}/{java-debug-server,java-language-server} + fi +} + +install() { + if ! echo "${OS}" |grep -Eq '(darwin|linux)';then + echo "Windows/Uknown OS easy install not implemented yet please manually install" + exit 1 + fi + + if echo ${INSTALL_DIR}|grep -q "/usr/local" || echo ${INSTALL_BIN}|grep -q "/usr/local";then + local sudoprompt="SUDO password required to install language server to INSTALL_DIR=${INSTALL_DIR} and INSTALL_BIN=${INSTALL_BIN}: " + + sudo -p "${sudoprompt}" -v + uninstall + sudo -p "${sudoprompt}" cp -r dist ${INSTALL_DIR} + sudo -p "${sudoprompt}" ln -s "${INSTALL_DIR}/java-language-server" "${INSTALL_BIN}/java-language-server" + sudo -p "${sudoprompt}" ln -s "${INSTALL_DIR}/java-debug-server" "${INSTALL_BIN}/java-debug-server" + + else + uninstall + cp -r dist ${INSTALL_DIR} + ln -s "${INSTALL_DIR}/java-language-server" "${INSTALL_BIN}/java-language-server" + ln -s "${INSTALL_DIR}/java-debug-server" "${INSTALL_BIN}/java-debug-server" + fi +} + +build() { + if [[ "${OS}" == 'darwin' ]]; then + ./scripts/download_mac_jdk.sh + ./scripts/link_mac.sh + elif [[ "${OS}" == 'linux' ]]; then + ./scripts/download_linux_jdk.sh + ./scripts/link_linux.sh + else # hopefully windows + ./scripts/download_windows_jdk.sh + ./scripts/link_windows.sh + fi +} + +case "$1" in + build) + build + ;; + uninstall) + uninstall + ;; + install) + build + install + ;; + help) + echo "Usage: $0 { install(default) | build | uninstall }" + echo "defaults to install" + exit 1 + ;; + *) + echo -n "Do you want to install? Y/N: " && read -r + r=$(echo "${REPLY}" |tr '[:upper:]' '[:lower:]') + if [[ "${r}" == "y" ]];then + build + install + else + echo "Install cancelled..." + exit 1 + fi + ;; +esac diff --git a/scripts/link_linux.sh b/scripts/link_linux.sh index a6a0e0b09..7d9b0e922 100755 --- a/scripts/link_linux.sh +++ b/scripts/link_linux.sh @@ -8,10 +8,12 @@ JAVA_HOME="./jdks/linux/jdk-18" # Build in dist/linux rm -rf dist/linux -jlink \ - --module-path $JAVA_HOME/jmods \ +${JAVA_HOME}/jlink \ + --module-path ${JAVA_HOME}/jmods \ --add-modules java.base,java.compiler,java.logging,java.sql,java.xml,jdk.compiler,jdk.jdi,jdk.unsupported,jdk.zipfs \ --output dist/linux \ --no-header-files \ --no-man-pages \ - --compress 2 \ No newline at end of file + --compress 2 + +mvn package -DskipTests diff --git a/scripts/link_mac.sh b/scripts/link_mac.sh index 5adae0bce..8ed8fd73d 100755 --- a/scripts/link_mac.sh +++ b/scripts/link_mac.sh @@ -4,14 +4,16 @@ set -e # Set env variables to build with mac toolchain but linux target -JAVA_HOME="./jdks/mac/jdk-18" +JAVA_HOME="./jdks/mac/jdk-18/Contents/Home" # Build using jlink rm -rf dist/mac -jlink \ - --module-path $JAVA_HOME/Contents/Home/jmods \ +${JAVA_HOME}/bin/jlink \ + --module-path ${JAVA_HOME}/jmods \ --add-modules java.base,java.compiler,java.logging,java.sql,java.xml,jdk.compiler,jdk.jdi,jdk.unsupported,jdk.zipfs \ --output dist/mac \ --no-header-files \ --no-man-pages \ - --compress 2 \ No newline at end of file + --compress 2 + +mvn package -DskipTests