дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
fix(maven): pick the IDE's plugin goals by the Maven version that runs them (#8126)
Sync, help:evaluate, dependency:build-classpath and source downloads used the newest cached maven-help-plugin / maven-dependency-plugin, or a pinned 3.5.1 / 3.8.1, whatever Maven ran them; those need Maven 3.6.3 (help 3.6.0 needs 3.9.0), so with Maven 3.3.9 every reload failed. The Maven version now comes from the wrapper's distributionUrl or the installation's maven-core jar; cached plugins whose descriptor requires a newer Maven are skipped, and the pinned fallback is the newest release that Maven can load. An unknown Maven version keeps the previous choice. Fixes #8114
Цей коміт міститься в:
1 джерело
979d19d066
коміт
86a39c6573
6 files changed
+238
-46
No files matched your search
@@ -29,7 +29,7 @@ pub fn plan(root: &Path, model: &BuildModel, module: &Path, cache: &Path) -> Ide
|
||||
let repo = crate::maven::local_repository_for(&p.options);
|
||||
args.extend([
|
||||
"process-resources".into(),
|
||||
crate::maven::plugin_goal("help:evaluate", repo.as_deref()),
|
||||
crate::maven::plugin_goal("help:evaluate", repo.as_deref(), crate::maven::maven_version(&p.command)),
|
||||
"-Dexpression=project.build.outputDirectory".into(),
|
||||
format!("-Doutput={}", manifest.display()),
|
||||
]);
|
||||
|
||||
@@ -405,8 +405,11 @@ fn classpaths(
|
||||
if compile_first {
|
||||
args.push("compile");
|
||||
}
|
||||
let build_classpath =
|
||||
maven::plugin_goal("dependency:build-classpath", maven::local_repository_for(&top.options).as_deref());
|
||||
let build_classpath = maven::plugin_goal(
|
||||
"dependency:build-classpath",
|
||||
maven::local_repository_for(&top.options).as_deref(),
|
||||
maven::maven_version(&top.command),
|
||||
);
|
||||
args.extend([build_classpath.as_str(), output_arg.as_str(), scope_arg.as_str(), "-q"]);
|
||||
let top_dir = subdir(root, &top.dir);
|
||||
let owned_args: Vec<String> = args.into_iter().map(str::to_owned).collect();
|
||||
|
||||
@@ -657,25 +657,88 @@ pub fn local_repository_for(options: &[String]) -> Option<PathBuf> {
|
||||
/// A goal of the IDE's own (`help:evaluate`, `dependency:build-classpath`, …) by its plugin's
|
||||
/// coordinates rather than its prefix: offline, Maven resolves a prefix only from group metadata
|
||||
/// in the local repository, which a repository filled from a private mirror often lacks even when
|
||||
/// the plugin itself is there. Uses the newest 3.x version already in `repo`, so nothing is
|
||||
/// downloaded, else a pinned one.
|
||||
pub fn plugin_goal(goal: &str, repo: Option<&Path>) -> String {
|
||||
/// the plugin itself is there. Uses the newest 3.x version already in `repo` that `maven` (the
|
||||
/// version of the Maven that runs it, when known) can load, so nothing is downloaded, else a
|
||||
/// pinned one for that Maven.
|
||||
pub fn plugin_goal(goal: &str, repo: Option<&Path>, maven: Option<MavenVersion>) -> String {
|
||||
let (prefix, goal) = goal.split_once(':').expect("prefix:goal");
|
||||
let (artifact, pinned) = match prefix {
|
||||
"help" => ("maven-help-plugin", "3.5.1"),
|
||||
"dependency" => ("maven-dependency-plugin", "3.8.1"),
|
||||
let artifact = match prefix {
|
||||
"help" => "maven-help-plugin",
|
||||
"dependency" => "maven-dependency-plugin",
|
||||
_ => unreachable!("not a goal of the IDE's own: {prefix}"),
|
||||
};
|
||||
let version = repo.and_then(|repo| newest_local_plugin(repo, artifact, 3)).unwrap_or_else(|| pinned.to_owned());
|
||||
let version = repo
|
||||
.and_then(|repo| newest_local_plugin(repo, artifact, 3, maven))
|
||||
.unwrap_or_else(|| pinned_plugin(artifact, maven).to_owned());
|
||||
format!("org.apache.maven.plugins:{artifact}:{version}:{goal}")
|
||||
}
|
||||
|
||||
/// The version of the IDE's own plugin `artifact` to download for `maven`: the current one,
|
||||
/// or the newest that still loads in an older Maven (their `requiredMavenVersion`).
|
||||
pub(crate) fn pinned_plugin(artifact: &str, maven: Option<MavenVersion>) -> &'static str {
|
||||
let at_least = |v: MavenVersion| maven.is_none_or(|m| m >= v);
|
||||
match artifact {
|
||||
"maven-help-plugin" if at_least((3, 6, 3)) => "3.5.1",
|
||||
"maven-help-plugin" if at_least((3, 2, 5)) => "3.3.0",
|
||||
"maven-help-plugin" => "3.2.0",
|
||||
"maven-dependency-plugin" if at_least((3, 6, 3)) => "3.8.1",
|
||||
"maven-dependency-plugin" if at_least((3, 2, 5)) => "3.6.1",
|
||||
"maven-dependency-plugin" => "3.1.2",
|
||||
_ => unreachable!("not a plugin of the IDE's own: {artifact}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// A Maven version as `(major, minor, patch)`.
|
||||
pub type MavenVersion = (u64, u64, u64);
|
||||
|
||||
fn parse_maven_version(v: &str) -> Option<MavenVersion> {
|
||||
let mut parts = v.trim().split(['.', '-']).map(str::parse::<u64>);
|
||||
let major = parts.next()?.ok()?;
|
||||
let minor = parts.next().and_then(Result::ok).unwrap_or(0);
|
||||
let patch = parts.next().and_then(Result::ok).unwrap_or(0);
|
||||
Some((major, minor, patch))
|
||||
}
|
||||
|
||||
/// The version of the Maven that `command` starts: a wrapper's `distributionUrl`, else the
|
||||
/// `maven-core` jar of the installation the launcher belongs to (`<home>/lib`, or
|
||||
/// `<home>/libexec/lib` for Homebrew's layout). `None` when it can't be told (mvnd, another
|
||||
/// layout); callers then keep their defaults.
|
||||
pub fn maven_version(command: &str) -> Option<MavenVersion> {
|
||||
let path = Path::new(command);
|
||||
let name = path.file_name()?.to_str()?;
|
||||
if name.eq_ignore_ascii_case("mvnw") || name.eq_ignore_ascii_case("mvnw.cmd") {
|
||||
let props = path.parent()?.join(".mvn").join("wrapper").join("maven-wrapper.properties");
|
||||
let text = std::fs::read_to_string(props).ok()?;
|
||||
let url = text.lines().find_map(|l| l.trim().strip_prefix("distributionUrl"))?;
|
||||
let version = url.split("apache-maven-").nth(1)?.split("-bin").next()?;
|
||||
return parse_maven_version(version);
|
||||
}
|
||||
let launcher = if path.components().count() > 1 {
|
||||
path.to_path_buf()
|
||||
} else {
|
||||
ide_core::process::find_executable(command, &ide_core::tool_path::search_path())?
|
||||
};
|
||||
let launcher = dunce::canonicalize(launcher).ok()?;
|
||||
let home = launcher.parent()?.parent()?;
|
||||
[home.join("lib"), home.join("libexec").join("lib")].iter().find_map(|lib| {
|
||||
std::fs::read_dir(lib).ok()?.flatten().find_map(|e| {
|
||||
let name = e.file_name().into_string().ok()?;
|
||||
parse_maven_version(name.strip_prefix("maven-core-")?.strip_suffix(".jar")?)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// The newest release of `org.apache.maven.plugins:<artifact>` whose jar is in `repo`,
|
||||
/// from major version `min_major` up.
|
||||
pub(crate) fn newest_local_plugin(repo: &Path, artifact: &str, min_major: u64) -> Option<String> {
|
||||
/// from major version `min_major` up, that `maven` can load (when it is known).
|
||||
pub(crate) fn newest_local_plugin(
|
||||
repo: &Path,
|
||||
artifact: &str,
|
||||
min_major: u64,
|
||||
maven: Option<MavenVersion>,
|
||||
) -> Option<String> {
|
||||
let dir = repo.join("org/apache/maven/plugins").join(artifact);
|
||||
let parse = |v: &str| v.split('.').map(|n| n.parse::<u64>().ok()).collect::<Option<Vec<u64>>>();
|
||||
std::fs::read_dir(&dir)
|
||||
let mut versions: Vec<(Vec<u64>, String)> = std::fs::read_dir(&dir)
|
||||
.ok()?
|
||||
.flatten()
|
||||
.filter_map(|e| e.file_name().into_string().ok())
|
||||
@@ -684,8 +747,24 @@ pub(crate) fn newest_local_plugin(repo: &Path, artifact: &str, min_major: u64) -
|
||||
n.first().is_some_and(|&major| major >= min_major)
|
||||
&& dir.join(v).join(format!("{artifact}-{v}.jar")).is_file()
|
||||
})
|
||||
.max()
|
||||
.map(|(_, v)| v)
|
||||
.collect();
|
||||
versions.sort();
|
||||
versions.into_iter().rev().map(|(_, v)| v).find(|v| {
|
||||
maven.is_none_or(|maven| {
|
||||
required_maven_version(&dir.join(v).join(format!("{artifact}-{v}.jar"))).is_none_or(|need| maven >= need)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// The `requiredMavenVersion` a plugin jar's descriptor declares (plugins built since
|
||||
/// maven-plugin-plugin 3.x do; older ones run on any Maven 3).
|
||||
fn required_maven_version(jar: &Path) -> Option<MavenVersion> {
|
||||
let file = std::fs::File::open(jar).ok()?;
|
||||
let mut archive = zip::ZipArchive::new(file).ok()?;
|
||||
let mut entry = archive.by_name("META-INF/maven/plugin.xml").ok()?;
|
||||
let mut text = String::new();
|
||||
entry.read_to_string(&mut text).ok()?;
|
||||
parse_maven_version(&xml::parse(&text)?.text_of("requiredMavenVersion")?)
|
||||
}
|
||||
|
||||
impl Resolver {
|
||||
@@ -2720,6 +2799,84 @@ mod tests {
|
||||
zip.finish().unwrap();
|
||||
}
|
||||
|
||||
/// A plugin jar whose descriptor declares `requiredMavenVersion` (none when `None`).
|
||||
fn write_plugin_requiring(repo: &Path, artifact: &str, version: &str, maven: Option<&str>) {
|
||||
let dir = repo.join("org/apache/maven/plugins").join(artifact).join(version);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let required = maven.map(|m| format!("<requiredMavenVersion>{m}</requiredMavenVersion>")).unwrap_or_default();
|
||||
let file = std::fs::File::create(dir.join(format!("{artifact}-{version}.jar"))).unwrap();
|
||||
let mut zip = zip::ZipWriter::new(file);
|
||||
zip.start_file("META-INF/maven/plugin.xml", zip::write::SimpleFileOptions::default()).unwrap();
|
||||
std::io::Write::write_all(&mut zip, format!("<plugin>{required}<mojos/></plugin>").as_bytes()).unwrap();
|
||||
zip.finish().unwrap();
|
||||
}
|
||||
|
||||
/// #8114: with Maven 3.3.9, a cached maven-help-plugin 3.6.0 (needs Maven 3.9.0) made every
|
||||
/// sync fail; the newest cached version that Maven can load is used, else an older pinned one.
|
||||
#[test]
|
||||
fn plugin_goals_skip_plugins_the_maven_cannot_load() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let repo = tmp.path();
|
||||
let old = Some((3, 3, 9));
|
||||
assert_eq!(
|
||||
plugin_goal("help:effective-pom", Some(repo), old),
|
||||
"org.apache.maven.plugins:maven-help-plugin:3.3.0:effective-pom"
|
||||
);
|
||||
assert_eq!(
|
||||
plugin_goal("dependency:build-classpath", None, old),
|
||||
"org.apache.maven.plugins:maven-dependency-plugin:3.6.1:build-classpath"
|
||||
);
|
||||
assert_eq!(pinned_plugin("maven-help-plugin", Some((3, 0, 5))), "3.2.0");
|
||||
assert_eq!(pinned_plugin("maven-dependency-plugin", Some((3, 9, 6))), "3.8.1");
|
||||
write_plugin_requiring(repo, "maven-help-plugin", "3.6.0", Some("3.9.0"));
|
||||
write_plugin_requiring(repo, "maven-help-plugin", "3.4.1", Some("3.6.3"));
|
||||
write_plugin_requiring(repo, "maven-help-plugin", "3.3.0", None);
|
||||
assert_eq!(
|
||||
plugin_goal("help:effective-pom", Some(repo), old),
|
||||
"org.apache.maven.plugins:maven-help-plugin:3.3.0:effective-pom"
|
||||
);
|
||||
assert_eq!(
|
||||
plugin_goal("help:effective-pom", Some(repo), Some((3, 9, 6))),
|
||||
"org.apache.maven.plugins:maven-help-plugin:3.6.0:effective-pom"
|
||||
);
|
||||
// An unknown Maven keeps the newest, as before.
|
||||
assert_eq!(
|
||||
plugin_goal("help:effective-pom", Some(repo), None),
|
||||
"org.apache.maven.plugins:maven-help-plugin:3.6.0:effective-pom"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn maven_version_comes_from_the_wrapper_or_the_installation() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let project = tmp.path().join("project");
|
||||
std::fs::create_dir_all(project.join(".mvn/wrapper")).unwrap();
|
||||
std::fs::write(
|
||||
project.join(".mvn/wrapper/maven-wrapper.properties"),
|
||||
"distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip\n",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(maven_version(&project.join("mvnw").to_string_lossy()), Some((3, 3, 9)));
|
||||
assert_eq!(maven_version(&project.join("mvnw.cmd").to_string_lossy()), Some((3, 3, 9)));
|
||||
|
||||
let home = tmp.path().join("apache-maven-3.9.6");
|
||||
std::fs::create_dir_all(home.join("bin")).unwrap();
|
||||
std::fs::create_dir_all(home.join("lib")).unwrap();
|
||||
std::fs::write(home.join("bin/mvn"), "").unwrap();
|
||||
std::fs::write(home.join("lib/maven-core-3.9.6.jar"), "").unwrap();
|
||||
assert_eq!(maven_version(&home.join("bin/mvn").to_string_lossy()), Some((3, 9, 6)));
|
||||
|
||||
// Homebrew: `<prefix>/bin/mvn` starts `libexec/bin/mvn`; the jars are in `libexec/lib`.
|
||||
let brew = tmp.path().join("Cellar/maven/4.0.0");
|
||||
std::fs::create_dir_all(brew.join("bin")).unwrap();
|
||||
std::fs::create_dir_all(brew.join("libexec/lib")).unwrap();
|
||||
std::fs::write(brew.join("bin/mvn"), "").unwrap();
|
||||
std::fs::write(brew.join("libexec/lib/maven-core-4.0.0-rc-5.jar"), "").unwrap();
|
||||
assert_eq!(maven_version(&brew.join("bin/mvn").to_string_lossy()), Some((4, 0, 0)));
|
||||
|
||||
assert_eq!(maven_version(&tmp.path().join("nowhere/bin/mvn").to_string_lossy()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_plugin_lists_the_goals_its_jar_declares() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
@@ -2805,7 +2962,7 @@ mod tests {
|
||||
assert_eq!(local_repository_for(&explicit), Some(PathBuf::from("/tmp/r")));
|
||||
// No repository known: a pinned version, still by coordinates.
|
||||
assert_eq!(
|
||||
plugin_goal("dependency:build-classpath", None),
|
||||
plugin_goal("dependency:build-classpath", None, None),
|
||||
"org.apache.maven.plugins:maven-dependency-plugin:3.8.1:build-classpath"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ use std::fs::{self, File};
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use std::time::SystemTime;
|
||||
|
||||
const DEPENDENCY_PLUGIN: &str = "org.apache.maven.plugins:maven-dependency-plugin:3.8.1";
|
||||
const SOURCE_REFRESH_WORKERS: usize = 4;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
@@ -99,6 +98,11 @@ fn resolve(
|
||||
args.extend(profile_args.iter().cloned());
|
||||
args.push(format!("-Dmaven.repo.local={}", repository.display()));
|
||||
let coordinate = format!("-Dartifact={}:{}:{}:jar:sources", artifact.group, artifact.name, artifact.version);
|
||||
// The newest `maven-dependency-plugin` the project's Maven can load (#8114).
|
||||
let plugin = format!(
|
||||
"org.apache.maven.plugins:maven-dependency-plugin:{}",
|
||||
super::pinned_plugin("maven-dependency-plugin", super::maven_version(&project.command))
|
||||
);
|
||||
let stage = if let Some(binary) = stale {
|
||||
// Keep the existing attachment readable while Maven resolves the timestamped snapshot.
|
||||
// Disable Resolver's in-place copy to the base -SNAPSHOT filename.
|
||||
@@ -107,14 +111,14 @@ fn resolve(
|
||||
args.extend([
|
||||
"-U".into(),
|
||||
"-Daether.artifactResolver.snapshotNormalization=false".into(),
|
||||
format!("{DEPENDENCY_PLUGIN}:copy"),
|
||||
format!("{plugin}:copy"),
|
||||
coordinate,
|
||||
"-Dmdep.useBaseVersion=true".into(),
|
||||
format!("-DoutputDirectory={}", stage.path().display()),
|
||||
]);
|
||||
Some((stage, binary))
|
||||
} else {
|
||||
args.extend([format!("{DEPENDENCY_PLUGIN}:get"), coordinate, "-Dtransitive=false".into()]);
|
||||
args.extend([format!("{plugin}:get"), coordinate, "-Dtransitive=false".into()]);
|
||||
None
|
||||
};
|
||||
let output = process::run(&project.command, &args, &root.join(&project.dir), &project.env, cancel, |_, _| {})?;
|
||||
|
||||
@@ -89,34 +89,39 @@ const MODEL_INIT_SCRIPT: &str = include_str!("gradle-model.gradle");
|
||||
const MAVEN_CACHE: &str = "maven.json";
|
||||
const MAVEN_CACHE_VERSION: u32 = 1;
|
||||
|
||||
/// `dependency:tree` of a plugin version whose `-Dverbose` lists the occurrences Maven
|
||||
/// omitted (conflicts, duplicates): verbose output was dropped in 3.0 and is back since 3.2.
|
||||
/// Offline, it is used only when an earlier sync downloaded it; otherwise the newest version
|
||||
/// in the local repository is.
|
||||
const DEPENDENCY_TREE: &str = "org.apache.maven.plugins:maven-dependency-plugin:3.8.1:tree";
|
||||
const DEPENDENCY_TREE_JAR: &str =
|
||||
"org/apache/maven/plugins/maven-dependency-plugin/3.8.1/maven-dependency-plugin-3.8.1.jar";
|
||||
|
||||
/// The goals that read the effective POM into `effective` and the verbose dependency trees;
|
||||
/// `repo` is the local repository the build resolves from. Both goals name their plugin by
|
||||
/// coordinates: offline, a prefix resolves only from group metadata the repository may lack.
|
||||
/// Offline without a cached 3.x `maven-help-plugin`, `effective-pom` is skipped so `mvn -o`
|
||||
/// still resolves the dependency tree instead of failing to download the help plugin.
|
||||
fn maven_sync_goals(effective: &Path, offline: bool, repo: Option<&Path>) -> Vec<String> {
|
||||
let pinned = !offline || repo.is_some_and(|repo| repo.join(DEPENDENCY_TREE_JAR).is_file());
|
||||
/// `repo` is the local repository the build resolves from and `maven` the version of the Maven
|
||||
/// that runs them, when known. Both goals name their plugin by coordinates: offline, a prefix
|
||||
/// resolves only from group metadata the repository may lack. The tree uses a pinned
|
||||
/// `maven-dependency-plugin` whose `-Dverbose` lists the occurrences Maven omitted (conflicts,
|
||||
/// duplicates; dropped in 3.0, back since 3.2), the newest that `maven` can load; offline it is
|
||||
/// used only when an earlier sync downloaded it, otherwise the newest compatible version in the
|
||||
/// local repository is. Offline without a cached compatible 3.x `maven-help-plugin`,
|
||||
/// `effective-pom` is skipped so `mvn -o` still resolves the dependency tree instead of failing
|
||||
/// to download the help plugin.
|
||||
fn maven_sync_goals(
|
||||
effective: &Path,
|
||||
offline: bool,
|
||||
repo: Option<&Path>,
|
||||
maven: Option<maven::MavenVersion>,
|
||||
) -> Vec<String> {
|
||||
let version = maven::pinned_plugin("maven-dependency-plugin", maven);
|
||||
let jar =
|
||||
format!("org/apache/maven/plugins/maven-dependency-plugin/{version}/maven-dependency-plugin-{version}.jar");
|
||||
let pinned = !offline || repo.is_some_and(|repo| repo.join(jar).is_file());
|
||||
let tree = if pinned {
|
||||
DEPENDENCY_TREE.to_owned()
|
||||
format!("org.apache.maven.plugins:maven-dependency-plugin:{version}:tree")
|
||||
} else {
|
||||
repo.and_then(|repo| maven::newest_local_plugin(repo, "maven-dependency-plugin", 2)).map_or_else(
|
||||
repo.and_then(|repo| maven::newest_local_plugin(repo, "maven-dependency-plugin", 2, maven)).map_or_else(
|
||||
|| "dependency:tree".to_owned(),
|
||||
|v| format!("org.apache.maven.plugins:maven-dependency-plugin:{v}:tree"),
|
||||
)
|
||||
};
|
||||
let has_help =
|
||||
!offline || repo.is_some_and(|repo| maven::newest_local_plugin(repo, "maven-help-plugin", 3).is_some());
|
||||
!offline || repo.is_some_and(|repo| maven::newest_local_plugin(repo, "maven-help-plugin", 3, maven).is_some());
|
||||
let mut goals = Vec::with_capacity(4);
|
||||
if has_help {
|
||||
goals.push(maven::plugin_goal("help:effective-pom", repo));
|
||||
goals.push(maven::plugin_goal("help:effective-pom", repo, maven));
|
||||
goals.push(format!("-Doutput={}", effective.to_string_lossy()));
|
||||
}
|
||||
goals.push(tree);
|
||||
@@ -414,9 +419,9 @@ pub fn sync_maven(
|
||||
if !options.profiles.is_empty() {
|
||||
args.push(format!("-P{}", options.profiles.join(",")));
|
||||
}
|
||||
args.extend(maven_sync_goals(&effective, options.offline, repo.as_deref()));
|
||||
progress(SyncProgress { message: format!("Reading {}", top.display_name), fraction: None });
|
||||
let command = options.maven_command.as_deref().unwrap_or(&top.command);
|
||||
args.extend(maven_sync_goals(&effective, options.offline, repo.as_deref(), maven::maven_version(command)));
|
||||
progress(SyncProgress { message: format!("Reading {}", top.display_name), fraction: None });
|
||||
let out = run(command, &args, &root.join(&top.dir), &options.env, cancel, |line| {
|
||||
if let Some((name, i, total)) = maven_building(line) {
|
||||
let fraction = (i.saturating_sub(1) as f32 / total.max(1) as f32).min(1.0);
|
||||
@@ -959,15 +964,19 @@ mod tests {
|
||||
assert!(!save_maven_offline(&tmp.path().join("other"), false).unwrap(), "online is the default");
|
||||
}
|
||||
|
||||
const DEPENDENCY_TREE: &str = "org.apache.maven.plugins:maven-dependency-plugin:3.8.1:tree";
|
||||
const DEPENDENCY_TREE_JAR: &str =
|
||||
"org/apache/maven/plugins/maven-dependency-plugin/3.8.1/maven-dependency-plugin-3.8.1.jar";
|
||||
|
||||
#[test]
|
||||
fn sync_reads_verbose_trees_with_a_pinned_plugin_unless_offline_without_it() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let help = "org.apache.maven.plugins:maven-help-plugin:3.5.1:effective-pom";
|
||||
let online = maven_sync_goals(Path::new("e.xml"), false, Some(tmp.path()));
|
||||
let online = maven_sync_goals(Path::new("e.xml"), false, Some(tmp.path()), None);
|
||||
assert_eq!(online, [help, "-Doutput=e.xml", DEPENDENCY_TREE, "-Dverbose"]);
|
||||
// Offline with neither plugin cached: `effective-pom` is skipped so `mvn -o` does not fail
|
||||
// on an uncached `maven-help-plugin`, and the tree falls back to the project's own version.
|
||||
let offline = maven_sync_goals(Path::new("e.xml"), true, Some(tmp.path()));
|
||||
let offline = maven_sync_goals(Path::new("e.xml"), true, Some(tmp.path()), None);
|
||||
assert_eq!(offline, ["dependency:tree", "-Dverbose"]);
|
||||
// #5757 / #5844: offline, plugins in the local repository are named by their coordinates,
|
||||
// since the prefix needs group metadata a repository filled from a private mirror may lack;
|
||||
@@ -978,21 +987,37 @@ mod tests {
|
||||
std::fs::create_dir_all(jar.parent().unwrap()).unwrap();
|
||||
std::fs::write(&jar, "").unwrap();
|
||||
}
|
||||
let offline = maven_sync_goals(Path::new("e.xml"), true, Some(tmp.path()));
|
||||
let offline = maven_sync_goals(Path::new("e.xml"), true, Some(tmp.path()), None);
|
||||
assert_eq!(offline, ["org.apache.maven.plugins:maven-dependency-plugin:3.6.1:tree", "-Dverbose"]);
|
||||
let help_jar = tmp.path().join("org/apache/maven/plugins/maven-help-plugin/3.4.0/maven-help-plugin-3.4.0.jar");
|
||||
std::fs::create_dir_all(help_jar.parent().unwrap()).unwrap();
|
||||
std::fs::write(&help_jar, "").unwrap();
|
||||
// A version folder without its jar (only the POM was fetched) doesn't count.
|
||||
std::fs::create_dir_all(tmp.path().join("org/apache/maven/plugins/maven-help-plugin/3.10.0")).unwrap();
|
||||
let offline = maven_sync_goals(Path::new("e.xml"), true, Some(tmp.path()));
|
||||
let offline = maven_sync_goals(Path::new("e.xml"), true, Some(tmp.path()), None);
|
||||
assert_eq!(offline[0], "org.apache.maven.plugins:maven-help-plugin:3.4.0:effective-pom");
|
||||
assert_eq!(offline[2], "org.apache.maven.plugins:maven-dependency-plugin:3.6.1:tree");
|
||||
// Downloaded by an online sync: offline keeps using it, the project's version may be missing.
|
||||
let jar = tmp.path().join(DEPENDENCY_TREE_JAR);
|
||||
std::fs::create_dir_all(jar.parent().unwrap()).unwrap();
|
||||
std::fs::write(&jar, "").unwrap();
|
||||
assert_eq!(maven_sync_goals(Path::new("e.xml"), true, Some(tmp.path()))[2], DEPENDENCY_TREE);
|
||||
assert_eq!(maven_sync_goals(Path::new("e.xml"), true, Some(tmp.path()), None)[2], DEPENDENCY_TREE);
|
||||
}
|
||||
|
||||
/// #8114: an old Maven gets plugin versions it can load, also for the verbose tree.
|
||||
#[test]
|
||||
fn sync_goals_follow_the_maven_version() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let goals = maven_sync_goals(Path::new("e.xml"), false, Some(tmp.path()), Some((3, 3, 9)));
|
||||
assert_eq!(
|
||||
goals,
|
||||
[
|
||||
"org.apache.maven.plugins:maven-help-plugin:3.3.0:effective-pom",
|
||||
"-Doutput=e.xml",
|
||||
"org.apache.maven.plugins:maven-dependency-plugin:3.6.1:tree",
|
||||
"-Dverbose",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -125,8 +125,11 @@ pub fn build(root: &Path, model: &BuildModel, id: &str, cache: &Path) -> IdeResu
|
||||
// POM's effective identity first; profiles and -D options can change its GAV.
|
||||
let output = cache.join("artifact-project.txt");
|
||||
let mut probe = top.options.clone();
|
||||
let evaluate =
|
||||
crate::maven::plugin_goal("help:evaluate", crate::maven::local_repository_for(&top.options).as_deref());
|
||||
let evaluate = crate::maven::plugin_goal(
|
||||
"help:evaluate",
|
||||
crate::maven::local_repository_for(&top.options).as_deref(),
|
||||
crate::maven::maven_version(&top.command),
|
||||
);
|
||||
probe.extend([
|
||||
"-f".into(),
|
||||
root.join(&p.pom).to_string_lossy().into_owned(),
|
||||
|
||||
Reference in new issue
Заблокувати користувача