Skip to content

Install & Usage Improvements: Add single installation script and java-language-server entrypoint script #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@ 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': '<path-to-java-language-server>/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.

Note: This tool is not compatible with [vim-lsp](https://github.com/prabirshrestha/vim-lsp) as it only supports LSPv2.0.

### 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:
Expand All @@ -36,7 +37,7 @@ Note: This tool is not compatible with [vim-lsp](https://github.com/prabirshrest
{
"java":
{
"command": ["bash","<path-to-java-language-server>/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$"
}
Expand All @@ -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)
Expand All @@ -62,7 +61,7 @@ Note: This tool is not compatible with [vim-lsp](https://github.com/prabirshrest
"jls":
{
"enabled": true,
"command": ["bash", "<path-to-java-language-server>/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"
Expand Down
4 changes: 2 additions & 2 deletions dist/debug_adapter_linux.sh
Original file line number Diff line number Diff line change
@@ -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 $@
4 changes: 2 additions & 2 deletions dist/debug_adapter_mac.sh
Original file line number Diff line number Diff line change
@@ -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 $@
4 changes: 2 additions & 2 deletions dist/debug_adapter_windows.sh
Original file line number Diff line number Diff line change
@@ -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 $@
14 changes: 14 additions & 0 deletions dist/java-debug-server
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions dist/java-language-server
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions dist/lang_server_linux.sh
Original file line number Diff line number Diff line change
@@ -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 $@
4 changes: 2 additions & 2 deletions dist/lang_server_mac.sh
Original file line number Diff line number Diff line change
@@ -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 $@
4 changes: 2 additions & 2 deletions dist/lang_server_windows.sh
Original file line number Diff line number Diff line change
@@ -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 $@
7 changes: 4 additions & 3 deletions dist/launch_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@
7 changes: 4 additions & 3 deletions dist/launch_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@
7 changes: 4 additions & 3 deletions dist/launch_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@
10 changes: 7 additions & 3 deletions scripts/download_mac_jdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ../..
ln -s jdk-18.0.1.1.jdk jdk-18
cd ../..
81 changes: 81 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 5 additions & 3 deletions scripts/link_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
--compress 2

mvn package -DskipTests
10 changes: 6 additions & 4 deletions scripts/link_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
--compress 2

mvn package -DskipTests