This repository has been archived on 2026-10-10. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
opencode-sandbox/scripts/jdtls
2026-09-28 09:59:14 +02:00

39 lines
1.7 KiB
Bash
Executable file

#!/bin/sh
# jdtls launcher: the eclipse.jdt.ls project ships no bin/jdtls of its own --
# every consumer (nvim-jdtls, mason.nvim, coc-java, etc.) hand-writes one, so
# this mirrors that same well-established convention. Installed at
# /usr/local/bin/jdtls by the Containerfile so OpenCode's Java LSP
# integration (which has no auto-download fallback for jdtls, unlike gopls)
# can find a bare `jdtls` command on PATH.
set -eu
JDTLS_HOME=/opt/jdtls
# jdtls requires a persistent, project-specific workspace dir (`-data`): the
# same one must be reused across restarts for a given project, and different
# projects must NOT share one (jdtls indexes it as if it were a single
# workspace). Derived from a hash of the real project path and stored under
# OpenCode's own host-persisted data dir (see the Makefile's DATA_DIR bind
# mount) so it survives container restarts instead of vanishing with `--rm`.
workspace_hash=$(printf '%s' "$(pwd -P)" | cksum | cut -d' ' -f1)
data_dir="$HOME/.local/share/opencode/jdtls-workspaces/$workspace_hash"
mkdir -p "$data_dir"
launcher=$(ls "$JDTLS_HOME"/plugins/org.eclipse.equinox.launcher_*.jar 2>/dev/null | head -n1)
if [ -z "$launcher" ]; then
echo "jdtls: equinox launcher jar not found under $JDTLS_HOME/plugins" >&2
exit 1
fi
exec java \
--add-modules=ALL-SYSTEM \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens java.base/java.lang=ALL-UNNAMED \
-Declipse.application=org.eclipse.jdt.ls.core.id1 \
-Dosgi.bundles.defaultStartLevel=4 \
-Declipse.product=org.eclipse.jdt.ls.core.product \
-Dlog.protocol=true -Dlog.level=ALL -Xmx1G \
-jar "$launcher" \
-configuration "$JDTLS_HOME/config_linux" \
-data "$data_dir" \
"$@"