Skip to content

Commit 20b1e61

Browse files
committed
Add single installation script and language server entry script
1 parent 4911c80 commit 20b1e61

File tree

6 files changed

+122
-22
lines changed

6 files changed

+122
-22
lines changed

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,26 @@ A Java [language server](https://github.com/Microsoft/vscode-languageserver-prot
88

99
## Installation (other editors)
1010

11-
### Vim (with vim-lsc)
11+
### Base Install Steps
1212

1313
- Checkout this repository
14-
- Run `./scripts/link_{linux|mac|windows}.sh`
15-
- Run `mvn package -DskipTests`
14+
- Run ./scripts/install.sh
15+
16+
### Vim (with vim-lsc)
17+
18+
- [Follow Base Install Steps](#base-install-steps)
1619
- Add the vim plugin [natebosch/vim-lsc](https://github.com/natebosch/vim-lsc) to your vimrc
1720
- Add vim-lsc configuration:
1821
```vimrc
19-
let g:lsc_server_commands = {'java': '<path-to-java-language-server>/java-language-server/dist/lang_server_{linux|mac|windows}.sh'}
22+
let g:lsc_server_commands = {'java': '/usr/local/bin/java-language-server'}
2023
```
2124
- See the [vim-lsc README](https://github.com/natebosch/vim-lsc/blob/master/README.md) for other configuration options.
2225

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

2528
### KDE Kate
2629

27-
- Checkout this repository
28-
- Run `./scripts/link_{linux|mac|windows}.sh`
29-
- Run `mvn package -DskipTests`
30+
- [Follow Base Install Steps](#base-install-steps)
3031
- Open your Kate editor
3132
- Go to Settings > Configure Kate... > LSP Client > User Server Settings
3233
- 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
3637
{
3738
"java":
3839
{
39-
"command": ["bash","<path-to-java-language-server>/java-language-server/dist/lang_server_{linux|mac|windows}.sh"],
40+
"command": ["bash", "/usr/local/bin/java-language-server"],
4041
"url": "https://github.com/georgewfraser/java-language-server",
4142
"highlightingModeRegex": "^Java$"
4243
}
@@ -47,9 +48,7 @@ Note: This tool is not compatible with [vim-lsp](https://github.com/prabirshrest
4748

4849
### Sublime 3 (with LSP)
4950

50-
- Checkout this repository
51-
- Run `./scripts/link_{linux|mac|windows}.sh`
52-
- Run `mvn package -DskipTests`
51+
- [Follow Base Install Steps](#base-install-steps)
5352
- Open your Sublime 3
5453
- Install Package Control (if missing)
5554
- 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
6261
"jls":
6362
{
6463
"enabled": true,
65-
"command": ["bash", "<path-to-java-language-server>/java-language-server/dist/lang_server_{linux|mac|windows}.sh"],
64+
"command": ["bash", "/usr/local/bin/java-language-server"],
6665
"scopes": ["source.java"],
6766
"syntaxes": ["Packages/Java/Java.sublime-syntax"],
6867
"languageId": "java"

dist/java-language-server

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
OS="unknown"
4+
if which -s uname;then
5+
OS=$(uname |tr '[:upper:]' '[:lower:]')
6+
fi
7+
SCRIPTS_DIR=$(dirname $(readlink -f "${BASH_SOURCE[0]}"))
8+
if [[ "${OS}" == 'darwin' ]]; then
9+
${SCRIPTS_DIR}/lang_server_mac.sh
10+
elif [[ "${OS}" == 'linux' ]]; then
11+
${SCRIPTS_DIR}/lang_server_linux.sh
12+
else
13+
${SCRIPTS_DIR}/lang_server_windows.sh
14+
fi

scripts/download_mac_jdk.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33

44
set -e
55

6-
# Download mac jdk
6+
# Download mac jdk if it doesn't exist
7+
if [[ -x jdks/mac/jdk-18/Contents/Home/bin/java ]];then
8+
exit 0
9+
fi
10+
711
mkdir -p jdks/mac
812
cd jdks/mac
913
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
1014
gunzip -c mac.tar.gz | tar xopf -
1115
rm mac.tar.gz
12-
mv jdk-18.0.1.1.jdk jdk-18
13-
cd ../..
16+
ln -s jdk-18.0.1.1.jdk jdk-18
17+
cd ../..

scripts/install.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
INSTALL_DIR=${INSTALL_DIR:="/usr/local/java-language-server"}
3+
INSTALL_BIN=${INSTALL_BIN:="/usr/local/bin"}
4+
OS="unknown"
5+
if which -s uname;then
6+
OS=$(uname |tr '[:upper:]' '[:lower:]')
7+
fi
8+
9+
uninstall() {
10+
if echo ${INSTALL_DIR}|grep -q "/usr/local" || echo ${INSTALL_BIN}|grep -q "/usr/local";then
11+
local sudoprompt="SUDO password required to remove language server from INSTALL_DIR=${INSTALL_DIR} and INSTALL_BIN=${INSTALL_BIN}: "
12+
sudo -p "${sudoprompt}" rm -rf ${INSTALL_DIR} ${INSTALL_BIN}/java-language-server
13+
else
14+
rm -rf ${INSTALL_DIR} ${INSTALL_BIN}/java-language-server
15+
fi
16+
}
17+
18+
install() {
19+
if ! echo "${OS}" |grep -Eq '(darwin|linux)';then
20+
echo "Windows/Uknown OS easy install not implemented yet please manually install"
21+
exit 1
22+
fi
23+
24+
if echo ${INSTALL_DIR}|grep -q "/usr/local" || echo ${INSTALL_BIN}|grep -q "/usr/local";then
25+
local sudoprompt="SUDO password required to install language server to INSTALL_DIR=${INSTALL_DIR} and INSTALL_BIN=${INSTALL_BIN}: "
26+
27+
sudo -p "${sudoprompt}" -v
28+
uninstall
29+
sudo -p "${sudoprompt}" cp -r dist ${INSTALL_DIR}
30+
sudo -p "${sudoprompt}" ln -s "${INSTALL_DIR}/java-language-server" "${INSTALL_BIN}/java-language-server"
31+
32+
else
33+
uninstall
34+
cp -r dist ${INSTALL_DIR}
35+
ln -s "${INSTALL_DIR}/java-language-server" "${INSTALL_BIN}/java-language-server"
36+
fi
37+
}
38+
39+
build() {
40+
if [[ "${OS}" == 'darwin' ]]; then
41+
./scripts/download_mac_jdk.sh
42+
./scripts/link_mac.sh
43+
elif [[ "${OS}" == 'linux' ]]; then
44+
./scripts/download_linux_jdk.sh
45+
./scripts/link_linux.sh
46+
else # hopefully windows
47+
./scripts/download_windows_jdk.sh
48+
./scripts/link_windows.sh
49+
fi
50+
}
51+
52+
case "$1" in
53+
build)
54+
build
55+
;;
56+
uninstall)
57+
uninstall
58+
;;
59+
install)
60+
build
61+
install
62+
;;
63+
help)
64+
echo "Usage: $0 { install(default) | build | uninstall }"
65+
echo "defaults to install"
66+
exit 1
67+
;;
68+
*)
69+
echo -n "Do you want to install? Y/N: " && read -r
70+
r=$(echo "${REPLY}" |tr '[:upper:]' '[:lower:]')
71+
if [[ "${r}" == "y" ]];then
72+
build
73+
install
74+
else
75+
echo "Install cancelled..."
76+
exit 1
77+
fi
78+
;;
79+
esac

scripts/link_linux.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ JAVA_HOME="./jdks/linux/jdk-18"
88

99
# Build in dist/linux
1010
rm -rf dist/linux
11-
jlink \
12-
--module-path $JAVA_HOME/jmods \
11+
${JAVA_HOME}/jlink \
12+
--module-path ${JAVA_HOME}/jmods \
1313
--add-modules java.base,java.compiler,java.logging,java.sql,java.xml,jdk.compiler,jdk.jdi,jdk.unsupported,jdk.zipfs \
1414
--output dist/linux \
1515
--no-header-files \
1616
--no-man-pages \
17-
--compress 2
17+
--compress 2
18+
19+
mvn package -DskipTests

scripts/link_mac.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
set -e
55

66
# Set env variables to build with mac toolchain but linux target
7-
JAVA_HOME="./jdks/mac/jdk-18"
7+
JAVA_HOME="./jdks/mac/jdk-18/Contents/Home"
88

99
# Build using jlink
1010
rm -rf dist/mac
11-
jlink \
12-
--module-path $JAVA_HOME/Contents/Home/jmods \
11+
${JAVA_HOME}/bin/jlink \
12+
--module-path ${JAVA_HOME}/jmods \
1313
--add-modules java.base,java.compiler,java.logging,java.sql,java.xml,jdk.compiler,jdk.jdi,jdk.unsupported,jdk.zipfs \
1414
--output dist/mac \
1515
--no-header-files \
1616
--no-man-pages \
17-
--compress 2
17+
--compress 2
18+
19+
mvn package -DskipTests

0 commit comments

Comments
 (0)