java: automatically download and install jdt.ls if not given on command line

This commit is contained in:
Adrian Kuschelyagi Malacoda 2020-11-11 21:50:14 -06:00
parent f144963c32
commit 4639a79c00

View File

@ -1,11 +1,21 @@
import os
import sys
import tarfile
from urllib import request
from .lsp import LspServer, command, get_data_home
FILE_URI = "file://"
VERSION = "0.64.0"
DOWNLOADS_URI = "http://download.eclipse.org/jdtls/milestones/{version}/{file}"
LATEST = "latest.txt"
def locate_product_directory (jdt_ls_path):
if os.path.isdir(os.path.join(jdt_ls_path, "plugins")):
return jdt_ls_path
return os.path.join(jdt_ls_path, "org.eclipse.jdt.ls.product/target/repository")
def locate_launcher_jar (jdt_ls_path):
@ -15,8 +25,37 @@ def locate_launcher_jar (jdt_ls_path):
def locate_launcher_configuration (jdt_ls_path):
return os.path.join(jdt_ls_path, "config_linux")
def log (message, *args, **kwargs):
print(message.format(*args, **kwargs), file=sys.stderr)
def download_jdt_ls (destination):
raise Exception("download_jdt_ls not implemented")
if not os.path.isdir(destination):
os.makedirs(destination)
current_version = None
current_version_file = os.path.join(destination, LATEST)
if os.path.isfile(current_version_file):
with open(current_version_file) as f:
current_version = f.read().strip()
log("Currently downloaded version is {version}:", version=current_version)
latest_version = None
with request.urlopen(DOWNLOADS_URI.format(version=VERSION, file=LATEST)) as f:
latest_version = f.read().decode().strip()
log("Latest available version is {version}:", version=latest_version)
if not latest_version == current_version:
latest_uri = DOWNLOADS_URI.format(version=VERSION, file=latest_version)
log("Downloading latest version from: {uri}:", uri=latest_uri)
with request.urlopen(latest_uri) as f:
with tarfile.open(fileobj=f, mode="r|gz") as tar:
tar.extractall(destination)
print(tar)
with open(current_version_file, "w") as cvf:
cvf.write(latest_version)
return destination
# TODO
def locate_lombok ():