Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

Commit

Permalink
Install specific JDTLS version (#21)
Browse files Browse the repository at this point in the history
Closes #6
  • Loading branch information
tobii-dev authored Sep 21, 2022
1 parent 10eb177 commit 561f3db
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions jdtls-launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ function print_version {
function print_help {
echo 'jdtls-launcher: install and launch jdtls with a single command'
echo 'available options:'
echo ' -v | --version prints version of all components'
echo ' -h | --help prints this menu'
echo ' -i | --install install jdtls if not installed'
echo ' --uninstall uninstall jdtls if installed'
echo ' --update uninstall and install jdtls creating a backup and restoring in case of failure'
echo ' --backup creates a backup of the current jdtls installation'
echo ' --restore restores the jdtls backup'
echo ' -v | --version prints version of all components'
echo ' -h | --help prints this menu'
echo ' -i | --install [version] install jdtls if not installed. optionally specify a version like 1.15.0'
echo ' --uninstall uninstall jdtls if installed'
echo ' --update uninstall and install jdtls creating a backup and restoring in case of failure'
echo ' --backup creates a backup of the current jdtls installation'
echo ' --restore restores the jdtls backup'
}

function install_lombok {
Expand Down Expand Up @@ -99,6 +99,48 @@ function jdtls_install {
return 0
}

# Takes a VERSION as argument. EXAMPLE: jdtls_install_version "1.15.0"
function jdtls_install_version {
VERSION="$1"
echo "Finding jdtls:${VERSION}"
if [ ! -w "$SCRIPT_ROOT" ]; then
echo "Permission denied, don't you need sudo?" >> /dev/stderr
return 1
fi
if [ -d "$JDTLS_ROOT" ]; then
echo "Jdtls installation found at $JDTLS_ROOT, aborting installation" >> /dev/stderr
return 1
fi

# EXAMPLE LINK: https://download.eclipse.org/jdtls/milestones/1.15.0/latest.txt
LATEST=$(curl -fLs "http://download.eclipse.org/jdtls/milestones/${VERSION}/latest.txt")
if [ -z "$LATEST" ]; then
echo "ERROR: curl http://download.eclipse.org/jdtls/milestones/${VERSION}/latest.txt failed. Are you sure that version exists?" >> /dev/stderr
exit 1
fi
echo "${LATEST%.tar.gz} is going to be installed"

mkdir -p "$JDTLS_ROOT"
cd "$JDTLS_ROOT"
curl -L "http://download.eclipse.org/jdtls/milestones/$VERSION/$LATEST" --output "$LATEST" --progress-bar
tar -xf "$LATEST"
rm "$LATEST"
chmod -R 755 "$JDTLS_ROOT"
chmod -R 777 "$JDTLS_ROOT"/config_*

EQUINOX_LAUNCHER=`find "$JDTLS_ROOT/plugins" -type f -name 'org.eclipse.equinox.launcher_*' 2> /dev/null`
if ! [[ -f "$EQUINOX_LAUNCHER" ]]; then
echo 'JDTLS installation failure' >> /dev/stderr
return 1
fi

install_lombok

echo "JDTLS:$VERSION installation succesfull"
return 0
}


function jdtls_uninstall {
echo 'Uninstalling jdtls...'
if [ ! -w "$SCRIPT_ROOT" ]; then
Expand Down Expand Up @@ -204,7 +246,11 @@ case "$1" in
exit
;;
-i|--install)
jdtls_install
if [ -z "$2" ]; then
jdtls_install
else
jdtls_install_version $2
fi
exit
;;
--uninstall)
Expand Down

0 comments on commit 561f3db

Please sign in to comment.