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

Commit

Permalink
1.1.0 main features (#4)
Browse files Browse the repository at this point in the history
Yes! 1.1.0
  • Loading branch information
eruizc-dev authored Jun 3, 2021
2 parents ede4982 + 056a15c commit db99796
Show file tree
Hide file tree
Showing 2 changed files with 241 additions and 122 deletions.
127 changes: 40 additions & 87 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,97 +1,50 @@
#!/bin/bash

INSTALL_LOCATION='/usr/local/lib/jdtls-launcher'
LINK_LOCATION='/usr/local/bin/jdtls'
JDTLS_ROOT="$INSTALL_LOCATION/jdtls"
LOMBOK="$JDTLS_ROOT/plugins/lombok.jar"

function install_launcher {
if [[ -d "$INSTALL_LOCATION" ]]; then
echo "ERROR: Installation found at $INSTALL_LOCATION" >> /dev/stderr
fi

mkdir -p "$INSTALL_LOCATION"
chmod 755 "$INSTALL_LOCATION"
cp jdtls-launcher.sh "$INSTALL_LOCATION"
chmod +x "$INSTALL_LOCATION/jdtls-launcher.sh"
ln -s "$INSTALL_LOCATION/jdtls-launcher.sh" "$LINK_LOCATION"
}

function install_jdtls {
EQUINOX_LAUNCHER=`find "$JDTLS_ROOT/plugins" -type f -name 'org.eclipse.equinox.launcher_*' 2> /dev/null`
if [[ -f "EQUINOX_LAUNCHER" ]]; then
echo "ERROR: JDTLS installation found at $JDTLS_ROOT" >> /dev/stderr
exit 1
fi

LATEST=`curl -s http://download.eclipse.org/jdtls/snapshots/latest.txt`
echo "INFO: About to install $LATEST to $JDTLS_ROOT"

rm -rf "$JDTLS_ROOT"
mkdir -p "$JDTLS_ROOT" || exit 1
cd "$JDTLS_ROOT"

curl "http://download.eclipse.org/jdtls/snapshots/$LATEST" > "$LATEST"
tar -xf "$LATEST"
rm "$LATEST"
chmod -R 777 "$JDTLS_ROOT"

# Installation check
EQUINOX_LAUNCHER=`find "$JDTLS_ROOT/plugins" -type f -name 'org.eclipse.equinox.launcher_*' 2> /dev/null`
if ! [[ -f "$EQUINOX_LAUNCHER" ]]; then
echo 'ERROR: JDTLS installation failure' > /dev/stderr
exit 1
else
echo 'INFO: JDTLS installation succesfull'
fi
}
### GATHER INSTALL INFORMATION ###
if [ "$EUID" -ne 0 ]; then
echo 'INFO: Performing user level installation'
INSTALL_LOCATION=${1:-"$HOME/.local/lib/jdtls-launcher"}
LINK_LOCATION="$HOME/.local/bin/jdtls"
else
echo 'INFO: Performing system level installation'
INSTALL_LOCATION=${1:-'/usr/local/lib/jdtls-launcher'}
LINK_LOCATION='/usr/local/bin/jdtls'
fi
INSTALL_ROOT=${INSTALL_LOCATION%/*}
TARBALL_LOCATION='/tmp/jdtls-launcher.tar.gz'
DOWNLOAD_URL=`curl -s https://api.github.com/repos/eruizc-dev/jdtls-launcher/releases/latest | grep 'tarball_url' | egrep -o 'https://[^"]+'`

function install_lombok {
if [[ -f "$LOMBOK" ]]; then
echo "ERROR: Lombok installation found at $LOMBOK"> /dev/stderr
exit 1
fi
### CHECK PERMISSIONS ###
if [ ! -d "$INSTALL_ROOT" ]; then
echo "ERROR: $INSTALL_ROOT not a directory" >> /dev/stderr
exit 1
fi

echo "INFO: Installing Lombok to $LOMBOK"
curl "https://projectlombok.org/downloads/lombok.jar" > "$LOMBOK"
if [ ! -w "$INSTALL_ROOT" ]; then
echo "ERROR: not enough permissions to install to $INSTALL_ROOT" >> /dev/stderr
exit 1
fi

if ! [[ -f "$LOMBOK" ]]; then
echo 'ERROR: Lombok installation failure' > /dev/stderr
exit 1
else
echo 'INFO: Lombok installation succesfull'
fi
}
### CHECK EXISTING INSTALLATION ###
if [ -d "$INSTALL_LOCATION" ]; then
echo "ERROR: $INSTALL_LOCATION already exists, delete it manually and try again " >> /dev/stderr
exit 1
fi

function install {
install_launcher
install_jdtls
install_lombok
}
### DOWNLOAD JDTLS-LAUNCHER ###
echo 'INFO: Downloading JDTLS-LAUNCHER'
curl -fLo "$TARBALL_LOCATION" "$DOWNLOAD_URL"

function uninstall {
rm -rf "$INSTALL_LOCATION"
rm -f '/usr/local/bin/jdtls'
}
echo 'INFO: Extracting JDTLS-LAUNCHER'
tar -xf "$TARBALL_LOCATION" --directory "$INSTALL_ROOT"
mv "$INSTALL_ROOT"/eruizc-dev-jdtls-launcher* "$INSTALL_LOCATION"
chmod -R 755 "$INSTALL_LOCATION"

if [ "$EUID" -ne 0 ]; then
echo 'ERROR: Command must be run as root to complete installation' >> /dev/stderr
exit 1
fi
### CREATE LINK ###
echo "INFO: Creating symlink ${LINK_LOCATION}"
rm "$LINK_LOCATION" 2> /dev/null
ln -s "$INSTALL_LOCATION/jdtls-launcher.sh" "$LINK_LOCATION"

if [[ -d "$INSTALL_LOCATION" ]]; then
read -p 'WARNING: Installation found, reinstall? y/[N]: ' CHOICE
case "$CHOICE" in
y|Y )
uninstall
install
;;
* )
echo 'INFO: Installation aborted by user'
exit 0
esac
else
install
fi
### INSTALL JDTLS ###
jdtls --install

echo 'INFO: Process finished'
236 changes: 201 additions & 35 deletions jdtls-launcher.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,59 +1,225 @@
#!/bin/bash

SCRIPT_VERSION='v1.0.2'
SYSTEM=`uname -s`

SCRIPT_VERSION='v1.1.0-pre-release'
SCRIPT_ROOT=`dirname $(realpath "$0")`

JDTLS_ROOT="$SCRIPT_ROOT/jdtls"
JDTLS_WORKSPACE="$HOME/.cache/jdtls-workspace"
JDTLS_CORE=`find "$JDTLS_ROOT/plugins" -type f -name 'org.eclipse.jdt.ls.core_*' 2> /dev/null`
JDTLS_EQUINOX_LAUNCHER=`find "$JDTLS_ROOT/plugins" -type f -name 'org.eclipse.equinox.launcher_*' 2> /dev/null`
JDTLS_BACKUP_ROOT="$SCRIPT_ROOT/jdtls-old"

JDTLS_ROOT="/usr/local/lib/jdtls-launcher/jdtls"
EQUINOX_LAUNCHER=`find "$JDTLS_ROOT/plugins" -type f -name 'org.eclipse.equinox.launcher_*'`
JDTLS_CORE=`find "$JDTLS_ROOT/plugins" -type f -name 'org.eclipse.jdt.ls.core_*'`
LOMBOK="$JDTLS_ROOT/plugins/lombok.jar"
WORKSPACE="$HOME/workspace"

function get_version {
### UTILS ###
function get_jar_version {
echo $(basename "$1" | awk '{ gsub(/^[^-_]*[-_]?|\.jar$/, ""); print }' | awk '{ gsub(/^$/, "custom"); print }')
}

### ACTIONS ###
function print_version {
echo "jdtls-launcher $SCRIPT_VERSION"
echo "equinox-launcher $(get_version "$EQUINOX_LAUNCHER")"
echo "jdtls-core $(get_version "$JDTLS_CORE")"
echo "lombok $(get_version "$LOMBOK")"
echo "equinox-launcher $(get_jar_version "$JDTLS_EQUINOX_LAUNCHER")"
echo "jdtls-core $(get_jar_version "$JDTLS_CORE")"
echo "lombok $(get_jar_version "$LOMBOK")"
java --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 ' --install install jdtls if not installed'
echo ' --uninstall uninstall jdtls if installed'
echo ' --reinstall 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 {
echo 'Installing lombok...'
if [ ! -w "$SCRIPT_ROOT" ]; then
echo "Permission denied, don't you need sudo?" >> /dev/stderr
return 1
fi
if [ -f "$LOMBOK" ]; then
echo "Lombok installation found at $LOMBOK, aborting installation" >> /dev/stderr
return 0
fi

curl "https://projectlombok.org/downloads/lombok.jar" > "$LOMBOK"

if [ ! -f "$LOMBOK" ]; then
echo ' Lombok installation failure' > /dev/stderr
return 1
fi
echo 'Lombok installation succesfull'
return 0
}

function jdtls_install {
echo 'Installing jdtls...'
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

LATEST=`curl -s 'http://download.eclipse.org/jdtls/snapshots/latest.txt'`
echo "${LATEST%.tar.gz} is going to be installed"

mkdir -p "$JDTLS_ROOT"
cd "$JDTLS_ROOT"

curl "http://download.eclipse.org/jdtls/snapshots/$LATEST" > "$LATEST"
tar -xf "$LATEST"
rm "$LATEST"
chmod -R 755 "$JDTLS_ROOT"
chmod -R 775 "$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 installation succesfull'
return 0
}

function jdtls_uninstall {
echo 'Uninstalling jdtls...'
if [ ! -w "$SCRIPT_ROOT" ]; then
echo "Permission denied, don't you need sudo?" >> /dev/stderr
return 1
fi
rm -rf "$JDTLS_ROOT"
echo 'JDTLS uninstalled'
return 0
}

function jdtls_reinstall {
if [ ! -w "$SCRIPT_ROOT" ]; then
echo "Permission denied, don't you need sudo?" >> /dev/stderr
return 1
fi
jdtls_create_backup && (jdtls_uninstall && jdtls_install || jdtls_restore_backup)
}

function jdtls_create_backup {
echo 'Creating jdtls backup...'
if [ ! -w "$SCRIPT_ROOT" ]; then
echo "Permission denied, don't you need sudo?" >> /dev/stderr
return 1
fi
if [ ! -d "$JDTLS_ROOT" ]; then
echo 'Cannot create backup, jdtls installation does not exist' >> /dev/stderr
return 1
fi
rm -rf "$JDTLS_BACKUP_ROOT"
cp -r "$JDTLS_ROOT" "$JDTLS_BACKUP_ROOT"
echo 'Backup created'
return 0
}

function jdtls_restore_backup {
echo 'Restoring jdtls backup...'
if [ ! -w "$SCRIPT_ROOT" ]; then
echo "Permission denied, don't you need sudo?" >> /dev/stderr
return 1
fi
if [ ! -d "$JDTLS_BACKUP_ROOT" ]; then
echo 'Cannot restore backup, backup does not exist' >> /dev/stderr
return 1
fi
rm -rf "$JDTLS_ROOT"
mv "$JDTLS_BACKUP_ROOT" "$JDTLS_ROOT"
echo 'Backup restored'
return 0
}

function run {
if [ ! -d "$JDTLS_ROOT" ]; then
echo 'Jdtls installation not found' >> /dev/stderr
return 1
fi

case "$SYSTEM" in
[Ll]inux) # Linux and WSL
CONFIG="$JDTLS_ROOT/config_linux"
;;
[Dd]arwin) # MacOS
CONFIG="$JDTLS_ROOT/config_mac"
;;
*)
echo "ERROR: Unknown or unsupported system $SYSTEM" >> /dev/stderr
echo "Consider opening a new issue: https://github.com/eruizc-dev/jdtls-launcher/issues/new?title=Unsupported%20system%20$SYSTEM" >> /dev/stderr
return 1
;;
esac

java \
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 \
-Declipse.application=org.eclipse.jdt.ls.core.id1 \
-Dosgi.bundles.defaultStartLevel=4 \
-Declipse.product=org.eclipse.jdt.ls.core.product \
-Dlog.level=ALL \
-noverify \
-Xmx1G \
-javaagent:"$LOMBOK" \
-jar "$JDTLS_EQUINOX_LAUNCHER" \
-configuration "$CONFIG" \
-data "$JDTLS_WORKSPACE" \
--add-modules=ALL-SYSTEM \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens java.base/java.lang=ALL-UNNAMED
}

### PARAM PARSING ###
case "$1" in
-v|--version)
print_version
exit 0
;;
esac

SYSTEM=`uname -s`
case "$SYSTEM" in
[Ll]inux) # Linux and WSL
CONFIG="$JDTLS_ROOT/config_linux"
-h|--help)
print_help
exit 0
;;
--backup)
jdtls_create_backup
exit
;;
--restore)
jdtls_restore_backup
exit
;;
[Dd]arwin) # MacOS
CONFIG="$JDTLS_ROOT/config_mac"
--install)
jdtls_install
exit
;;
--uninstall)
jdtls_uninstall
exit
;;
--reinstall)
jdtls_reinstall
exit
;;
"")
run
exit
;;
*)
echo "ERROR: Unknown or unsupported system $SYSTEM" >> /dev/stderr
echo "Consider opening a new issue: https://github.com/eruizc-dev/jdtls-launcher/issues/new?title=Unsupported%20system%20$SYSTEM" >> /dev/stderr
echo "unknown option $1"
print_help
exit 1
;;
esac

java \
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 \
-Declipse.application=org.eclipse.jdt.ls.core.id1 \
-Dosgi.bundles.defaultStartLevel=4 \
-Declipse.product=org.eclipse.jdt.ls.core.product \
-Dlog.level=ALL \
-noverify \
-Xmx1G \
-javaagent:"$LOMBOK" \
-jar "$EQUINOX_LAUNCHER" \
-configuration "$CONFIG" \
-data "$WORKSPACE" \
--add-modules=ALL-SYSTEM \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens java.base/java.lang=ALL-UNNAMED

0 comments on commit db99796

Please sign in to comment.