Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 14 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,26 @@ jobs:
with:
path: .artifacts/jdtls-downloads
key: third-party-${{ hashFiles('third_party/*/manifest.json') }}
# The package ships no JDK. This one compiles the plugin's own JDT LS
# extension bundle while packaging, and the integration tests run the
# tested JDT LS release on it, as a user's JDK 21+ would.
- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: "21"
- name: Build, verify and archive both architectures
run: |
set -euo pipefail
for arch in arm64 x86_64; do
package=$(scripts/build-package.sh --arch "$arch")
scripts/archive-package.sh --package "$package" --arch "$arch"
done
# The package ships no JDK; the integration tests run the tested JDT LS
# release on this one, as a user's JDK 21+ would.
- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: "21"
- name: Verify native compiler settings and JARs with the user's JDT LS
run: |
package=".artifacts/package/$(uname -m)/io.github.lithe-idea.java-support"
node scripts/compiler/test-live.mjs "$package"
LITHE_JAVA_PROJECT_KIND=eclipse node scripts/compiler/test-live.mjs "$package"
node scripts/compiler/test-project-models.mjs "$package"
- name: Upload native compiler projections
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -139,6 +141,12 @@ jobs:
run: node scripts/package/build-linux.mjs "${{ matrix.arch }}"
- name: Start the packaged backend and the user's language server
run: node scripts/package/smoke-linux.mjs dist/*-linux-${{ matrix.arch }}.zip
- name: Compile legacy and cross-IDE project models with the user's language server
run: |
package=$(mktemp -d)
unzip -q dist/*-linux-${{ matrix.arch }}.zip -d "$package"
node scripts/compiler/test-project-models.mjs "$package/io.github.lithe-idea.java-support"
rm -rf "$package"
- uses: actions/upload-artifact@v4
with:
name: java-linux-${{ matrix.arch }}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ jobs:
echo "::error::Tag $GITHUB_REF_NAME does not match plugin.json version $version"
exit 1
fi
# Packaging compiles the plugin's own JDT LS extension bundle, which
# needs javac 21 or later (scripts/package/project-model-bundle.mjs).
- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: "21"
- name: Build and verify both architectures
run: |
set -euo pipefail
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Java Support for Lithe

> **3.0.1 识别旧式与跨 IDE 工程**:没有 Maven/Gradle 的项目,插件只读识别 Eclipse WTP/MyEclipse 容器
> (Web App Libraries、EAR Libraries、Server Runtime)、IntelliJ IDEA 的模块与库,以及传统 Web 的 `WEB-INF/lib`,
> 在内存中补全类路径并自动找到 Tomcat 等 Servlet 容器,不修改项目文件,详见 [docs/project-models.md](docs/project-models.md)。
>
> **3.0.0 起使用你自己的 JDT LS**:插件包不再附带 Eclipse JDT Language Server 和运行它的 JDK(包从约 250 MB 降到约 11 MB),
> 做法和 Go 插件使用你自己的 `gopls` 一样。需要先安装 JDT LS(例如 `brew install jdtls`)和 JDK 21 或更新版本,
> 详见下文[语言服务器与 JDK](#语言服务器与-jdk)。
Expand Down
48 changes: 44 additions & 4 deletions backend/src/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use crate::jdtls::{
self, SearchEnvironment, ServerInstallation, LAUNCH_SERVER_INVALID, LAUNCH_SERVER_MISSING,
SERVER_HOME_SETTING,
};
use crate::project_model::{ModelOptions, ProjectModel};
use crate::run::file_uri;
use crate::settings_session::{java_configuration, jdt_settings, SettingsSession, SERVER_ID};
use lithe_java_domain::jdt_integration::launch_resources::{bundles_in, missing_resource_message};
Expand Down Expand Up @@ -121,10 +122,22 @@ pub const LAUNCH_CONFIGURATION_CLEANUP_FAILED: &str = "launch.configuration_clea
/// launch names no `triggerFiles` and JDT LS falls back to the first opened
/// file to lay out a workspace without a build file.
pub const LAUNCH_WORKSPACE_FOLDERS_UNAVAILABLE: &str = "launch.workspace_folders_unavailable";
/// The project needs servlet container libraries (a web module, a Server
/// Runtime container) and none was found, so `javax.servlet` stays
/// unresolved until the user configures one.
pub const LAUNCH_SERVLET_CONTAINER_MISSING: &str = "launch.servlet_container_missing";
/// Libraries the project model declares could not be added; the count is
/// how many. The Java libraries settings page lists them.
pub const LAUNCH_PROJECT_MODEL_UNRESOLVED: &str = "launch.project_model_unresolved";
/// The project model scan stopped at its budget; deeper layouts were not read.
pub const LAUNCH_PROJECT_MODEL_TRUNCATED: &str = "launch.project_model_truncated";
/// Every degraded-diagnostic category `java.resolveLaunch` reports.
pub const LAUNCH_CATEGORIES: &[&str] = &[
LAUNCH_CONFIGURATION_CLEANUP_FAILED,
LAUNCH_WORKSPACE_FOLDERS_UNAVAILABLE,
LAUNCH_SERVLET_CONTAINER_MISSING,
LAUNCH_PROJECT_MODEL_UNRESOLVED,
LAUNCH_PROJECT_MODEL_TRUNCATED,
];

/// Most `.java` files named as `triggerFiles`. JDT LS uses the first one
Expand Down Expand Up @@ -180,11 +193,13 @@ pub const EXTENSIONS_DIRECTORY: &str = "jdtls-extensions";
/// Package path of the Lombok agent JDT LS runs with.
pub const LOMBOK_AGENT: &str = "jdtls-extensions/lombok/lombok.jar";
/// Package directories whose JAR files JDT LS loads as extension bundles, in
/// this order and then by file name: the Java Debug Server, then the Java
/// Test extensions.
/// this order and then by file name: the Java Debug Server, the Java Test
/// extensions, then the plugin's own project model bundle, built from
/// `jdtls-extension/project-model` by `scripts/package/project-model-bundle.mjs`.
pub const EXTENSION_BUNDLE_DIRECTORIES: &[&str] = &[
"jdtls-extensions/java-debug",
"jdtls-extensions/java-test/extensions",
"jdtls-extensions/project-model",
];
/// Package path of the Java Test runner JAR the test flow adds to the class
/// path of TestNG launches; JDT LS itself does not load it.
Expand All @@ -196,6 +211,7 @@ pub const PACKAGE_LAYOUT: &[&str] = &[
LOMBOK_AGENT,
EXTENSION_BUNDLE_DIRECTORIES[0],
EXTENSION_BUNDLE_DIRECTORIES[1],
EXTENSION_BUNDLE_DIRECTORIES[2],
TEST_RUNNER,
];
/// Directory under `workspaceStateDirectory` passed to JDT LS as `-data`.
Expand Down Expand Up @@ -238,6 +254,8 @@ pub struct LaunchRequest {
/// with that JDK, so the server must compile for it. Empty when the host
/// found none, which leaves the server on the runtimes it already knows.
pub java_runtimes: Vec<JdtJavaRuntime>,
/// `settings.projectModelDetection` and `settings.servletContainerHome`.
pub model_options: ModelOptions,
}

/// The files of a JDT LS launch, absolute.
Expand Down Expand Up @@ -301,6 +319,7 @@ pub fn parse_launch_params(params: &Value) -> Result<LaunchRequest, PluginError>
}
},
};
let model_options = crate::project_model::parse_options(&settings).map_err(invalid_params)?;
Ok(LaunchRequest {
os: os.to_string(),
architecture: architecture.to_string(),
Expand All @@ -313,6 +332,7 @@ pub fn parse_launch_params(params: &Value) -> Result<LaunchRequest, PluginError>
server_home,
server_runtime_version: host_tool_version(params, SERVER_RUNTIME_TOOL),
java_runtimes: jdt_java_runtimes(&host_java_tool(params)),
model_options,
})
}

Expand Down Expand Up @@ -651,6 +671,22 @@ fn now_unix_seconds() -> u64 {
.map_or(0, |elapsed| elapsed.as_secs())
}

/// Reports what detection could not do for the project; the launch stands.
pub fn report_model(model: &ProjectModel, report: &dyn Fn(&str, u64)) {
if model.needs_servlet && model.servlet.runtime.is_none() {
report(LAUNCH_SERVLET_CONTAINER_MISSING, 1);
}
if !model.unresolved.is_empty() {
report(
LAUNCH_PROJECT_MODEL_UNRESOLVED,
model.unresolved.len() as u64,
);
}
if model.truncated {
report(LAUNCH_PROJECT_MODEL_TRUNCATED, 1);
}
}

/// Runs a call of `java.resolveLaunch`.
///
/// The workspace comes from the call's `context`. The settings are the ones
Expand Down Expand Up @@ -681,8 +717,10 @@ pub fn resolve_launch_function(
};
let (fragments, folders) = match context.workspace_context() {
Some(workspace) => {
// The pushes after this start repeat the runtimes it configures.
// The pushes after this start repeat the runtimes and the
// project model settings it configures.
session.set_java_runtimes(workspace, request.java_runtimes.clone());
session.set_model_options(workspace, request.model_options.clone());
let folders = match workspace_folders(context.host(), workspace) {
Ok(folders) => folders,
Err(_) => {
Expand All @@ -708,10 +746,12 @@ pub fn resolve_launch_function(
&report,
)?;
if let Some(folder) = folders.first() {
let configuration = crate::settings_session::with_native_settings(
let (configuration, model) = crate::settings_session::with_native_model(
answer["workspaceConfiguration"].clone(),
folder,
&request.model_options,
)?;
report_model(&model, &report);
answer["workspaceConfiguration"] = configuration.clone();
answer["initializationOptions"]["settings"] = configuration;
}
Expand Down
4 changes: 3 additions & 1 deletion backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
pub mod class_content;
pub mod jdtls;
pub mod launch;
pub mod library_settings;
pub mod plugin_functions;
pub mod project_model;
pub mod project_settings;
pub mod run;
pub mod settings_session;
Expand Down Expand Up @@ -253,7 +255,7 @@ pub fn backend() -> Result<Backend, SdkError> {
backend.suppress_success_diagnostics(function)?;
}
backend.function("compiler.prepareSettings", move |params, context| {
projects.edit(params, context)
projects.edit(params, context, &session)
})?;
Ok(backend)
}
Expand Down
Loading
Loading