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

feature: allow downgrade / install specific version #21

Merged
merged 3 commits into from
Sep 21, 2022
Merged
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
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