дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Plugin API 1.21 adds two read-only calls behind the build.read capability and the trusted-project gate: - build.sdks(project, kind?): the installed JDKs, interpreters and toolchains of a kind (or all), with the one the project uses marked active. - build.artifacts(project): the deployable WAR modules of the build model (origin build-model, with the ids the server run configurations use, e.g. maven:app/pom.xml) followed by the Project Structure > Artifacts entries (origin project-structure). The Rust SDK, its mock and the docs cover both, and the official plugins and test fixtures are rebuilt. Used by https://github.com/RuyimgByCN/openidea-smart-tomcat. Co-authored-by: RuyimgByCN <[email protected]>
124 рядки
4.8 KiB
Rust
124 рядки
4.8 KiB
Rust
use openidea_plugin::{
|
|
ArtifactInfo, ArtifactKind, ArtifactOrigin, DependencyNode, DependencyStatus, Error, SdkInfo, 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(_))));
|
|
}
|
|
|
|
#[test]
|
|
fn sdks_and_artifacts_respect_build_read_and_trust() {
|
|
let mock = MockHost::install().with_capabilities(&[]);
|
|
mock.set_sdks(vec![
|
|
SdkInfo {
|
|
kind: "jdk".into(),
|
|
name: "Temurin 21".into(),
|
|
path: "/Library/Java/21".into(),
|
|
version: Some("21.0.2".into()),
|
|
source: "system".into(),
|
|
home: Some("/Library/Java/21".into()),
|
|
active: true,
|
|
},
|
|
SdkInfo {
|
|
kind: "maven".into(),
|
|
name: "Maven 3.9.6".into(),
|
|
path: "/opt/maven/bin/mvn".into(),
|
|
version: Some("3.9.6".into()),
|
|
source: "homebrew".into(),
|
|
home: Some("/opt/maven".into()),
|
|
active: false,
|
|
},
|
|
]);
|
|
mock.set_artifacts(vec![
|
|
ArtifactInfo {
|
|
id: "maven:app/pom.xml".into(),
|
|
origin: ArtifactOrigin::BuildModel,
|
|
tool: "maven".into(),
|
|
name: "demo-app".into(),
|
|
kind: ArtifactKind::War,
|
|
module: "app".into(),
|
|
output_directory: String::new(),
|
|
main_class: String::new(),
|
|
include_libraries: Vec::new(),
|
|
},
|
|
ArtifactInfo {
|
|
id: "project:demo:war exploded".into(),
|
|
origin: ArtifactOrigin::ProjectStructure,
|
|
tool: "project".into(),
|
|
name: "demo:war exploded".into(),
|
|
kind: ArtifactKind::WarExploded,
|
|
module: ".".into(),
|
|
output_directory: "target/demo".into(),
|
|
main_class: String::new(),
|
|
include_libraries: vec!["lib".into()],
|
|
},
|
|
]);
|
|
let p = mock.invocation().project().unwrap();
|
|
assert!(matches!(p.sdks(None), Err(Error::Denied(c)) if c == "build.read"));
|
|
assert!(matches!(p.artifacts(), Err(Error::Denied(c)) if c == "build.read"));
|
|
|
|
let mock = mock.with_capabilities(&["build.read"]);
|
|
assert_eq!(p.sdks(None).unwrap().len(), 2);
|
|
let jdks = p.sdks(Some("jdk")).unwrap();
|
|
assert_eq!(jdks.len(), 1);
|
|
assert!(jdks[0].active);
|
|
assert!(matches!(p.sdks(Some("cobol")), Err(Error::Invalid(_))));
|
|
let artifacts = p.artifacts().unwrap();
|
|
assert_eq!(artifacts.len(), 2);
|
|
assert_eq!(artifacts[0].id, "maven:app/pom.xml");
|
|
assert_eq!(artifacts[0].origin, ArtifactOrigin::BuildModel);
|
|
assert_eq!(artifacts[0].tool, "maven");
|
|
assert_eq!(artifacts[1].origin, ArtifactOrigin::ProjectStructure);
|
|
assert_eq!(artifacts[1].kind, ArtifactKind::WarExploded);
|
|
|
|
mock.set_restricted(true);
|
|
assert!(matches!(p.sdks(None), Err(Error::Denied(_))));
|
|
assert!(matches!(p.artifacts(), Err(Error::Denied(_))));
|
|
}
|