Файли
openidea/sdk/rust/openidea-plugin/tests/build_dependencies.rs
T
Bert Verhelstтаbertyhell e6daffae76 feat(plugins): read the Maven / Gradle dependency graph (API 1.10) (#3829)
Plugins had to run mvn dependency:tree / gradlew dependencies themselves or parse build files. A new build interface in wit/workspace.wit, build.dependencies(project, module), returns the graph the Dependency Analyzer has as a flat list of dependency-node records (group, artifact, version, scope, status, requested version, parent), each module a root, behind the low-risk build.read capability in trusted projects. Nothing is resolved by the call: Maven returns the trees cached by the last Reload (declared dependencies before one); Gradle dependency reports, which only lived in the frontend, are now saved per project and configuration in the build cache and dropped on a build-file change. Capped at 100,000 nodes per call. SDK: Project::build_dependencies with a mock; checked-in components rebuilt.

Closes #3715

Co-authored-by: bertyhell <[email protected]>
2026-11-17 03:29:39 +08:00

52 рядки
2.1 KiB
Rust

use openidea_plugin::{DependencyNode, DependencyStatus, Error, mock::MockHost};
fn node(group: &str, artifact: &str, version: &str, scope: &str, parent: Option<u32>) -> DependencyNode {
DependencyNode {
group: group.into(),
artifact: artifact.into(),
version: version.into(),
scope: scope.into(),
status: DependencyStatus::Resolved,
requested_version: None,
parent,
}
}
#[test]
fn the_graph_of_one_module_or_all_behind_the_grant() {
let mock = MockHost::install().with_capabilities(&[]);
let lost = DependencyNode {
status: DependencyStatus::OmittedForConflict,
requested_version: Some("3.12.0".into()),
..node("org.apache.commons", "commons-lang3", "3.14.0", "compile", Some(1))
};
mock.set_build_dependencies(vec![
node("com.example", "app", "1.0", "", None),
node("org.apache.commons", "commons-text", "1.11.0", "compile", Some(0)),
lost.clone(),
node("", ":web", "", "", None),
node("org.yaml", "snakeyaml", "2.2", "runtimeClasspath", Some(3)),
]);
let p = mock.invocation().project().unwrap();
assert!(matches!(p.build_dependencies(None), Err(Error::Denied(c)) if c == "build.read"));
let mock = mock.with_capabilities(&["build.read"]);
assert_eq!(p.build_dependencies(None).unwrap().len(), 5);
let app = p.build_dependencies(Some("com.example:app")).unwrap();
assert_eq!(app.len(), 3);
assert_eq!(app[2], lost);
// Why is commons-lang3 here: up through commons-text to the module.
let why: Vec<_> =
std::iter::successors(Some(2), |&i| app[i].parent.map(|p| p as usize)).map(|i| &app[i].artifact).collect();
assert_eq!(why, ["commons-lang3", "commons-text", "app"]);
let web = p.build_dependencies(Some(":web")).unwrap();
assert_eq!(
web,
[node("", ":web", "", "", None), node("org.yaml", "snakeyaml", "2.2", "runtimeClasspath", Some(0))]
);
assert!(matches!(p.build_dependencies(Some("app")), Err(Error::NotFound(_))));
mock.set_restricted(true);
assert!(matches!(p.build_dependencies(None), Err(Error::Denied(_))));
}