diff --git a/crates/socket-patch-cli/tests/vendor_jvm_cli.rs b/crates/socket-patch-cli/tests/vendor_jvm_cli.rs
index 1cd6b794eb..f09d34643d 100644
--- a/crates/socket-patch-cli/tests/vendor_jvm_cli.rs
+++ b/crates/socket-patch-cli/tests/vendor_jvm_cli.rs
@@ -1416,6 +1416,140 @@ fn maven_reactor_uncertain_property_version_withholds_vex() {
}
}
+/// #2378: Maven reads the version a module declares before any pin, so a
+/// module that requires the base version as the hard range `[1.0]`, or
+/// selects it from a range of its own, keeps the unpatched jar. `vex` does
+/// not attest it, `vendor --check` says so for the hard range (what an
+/// open range selects depends on the local repository, which the check
+/// does not read), and with nothing else to wire `vendor` refuses rather
+/// than counting the patch as applied over a pin that nothing reads.
+#[test]
+fn maven_reactor_declared_range_on_the_base_withholds_vex() {
+ // (what `a` declares, a sibling at the literal base, `b` added after
+ // vendoring and what it declares)
+ let cases: [(&str, bool, Option<&str>); 5] = [
+ ("[1.0]", false, None),
+ ("[1.0]", true, None),
+ ("1.0", false, Some("[1.0]")),
+ ("1.0", false, Some("[1.0,2.0)")),
+ ("1.0", false, Some("[2.0]")),
+ ];
+ for (declared, sibling, late) in cases {
+ let case = format!("a: {declared}, sibling: {sibling}, late: {late:?}");
+ let tmp = tempfile::tempdir().unwrap();
+ let root = tmp.path();
+ fixture(root, Shape::Reactor, &[("foo", FOO_UUID)]);
+ // What Maven lists when it resolves a range of `foo`.
+ write(
+ root,
+ "m2/org/example/foo/maven-metadata-local.xml",
+ b"org.examplefoo\
+ 1.0\n",
+ );
+ let pristine = std::fs::read_to_string(root.join("proj/a/pom.xml")).unwrap();
+ let declaring = |name: &str, version: &str| {
+ pristine
+ .replace(
+ "a",
+ &format!("{name}"),
+ )
+ .replace(
+ "1.0",
+ &format!("{version}"),
+ )
+ };
+ let add_b = |version: &str| {
+ let agg = std::fs::read_to_string(root.join("proj/pom.xml")).unwrap();
+ let agg = agg.replace(
+ "a",
+ "a\n b",
+ );
+ write(root, "proj/pom.xml", agg.as_bytes());
+ write(root, "proj/b/pom.xml", declaring("b", version).as_bytes());
+ };
+ let a = declaring("a", declared);
+ write(root, "proj/a/pom.xml", a.as_bytes());
+ if sibling {
+ add_b("1.0");
+ }
+ let vex = root.join("vex.json");
+ let vex_args = [
+ "vex",
+ "-O",
+ vex.to_str().unwrap(),
+ "--product",
+ "pkg:generic/x@1",
+ ];
+ if declared != "1.0" && !sibling {
+ assert_refused(root, "nothing_wired", "reason: range: a/pom.xml:6: ");
+ let (_, env) = socket(root, &vex_args);
+ assert!(!env.to_string().contains("not_affected"), "{case}: {env}");
+ assert!(!vex.exists(), "{case}: {env}");
+ continue;
+ }
+ let env = ok(root, &["vendor"]);
+ assert_eq!(
+ env.to_string().contains("reason: range: a/pom.xml:6: "),
+ declared != "1.0",
+ "{case}: {env}"
+ );
+ assert_eq!(
+ std::fs::read_to_string(root.join("proj/a/pom.xml")).unwrap() == a,
+ declared != "1.0",
+ "{case}"
+ );
+ assert!(wiring_text(root).contains("-socket."), "{case}: wired");
+ if let Some(version) = late {
+ add_b(version);
+ }
+
+ // The entry is intact and wired either way: the check passes, and
+ // names the declaration it can tell keeps the base version.
+ let env = ok(root, &["vendor", "--check"]);
+ let unattested: Vec<&str> = env["warnings"]
+ .as_array()
+ .into_iter()
+ .flatten()
+ .filter(|w| w["code"] == "vendor_jvm_unattested")
+ .filter_map(|w| w["detail"].as_str())
+ .collect();
+ let hard = match (declared, late) {
+ ("[1.0]", _) => Some("a/pom.xml:6"),
+ (_, Some("[1.0]")) => Some("b/pom.xml:6"),
+ _ => None,
+ };
+ match hard {
+ Some(at) => assert!(
+ unattested.len() == 1
+ && unattested[0].contains(&format!("{at} may still build org.example:foo:1.0")),
+ "{case}: {env}"
+ ),
+ None => assert!(unattested.is_empty(), "{case}: {env}"),
+ }
+
+ let (code, env) = socket(root, &vex_args);
+ if late == Some("[2.0]") {
+ // `b` requires another version: nothing of this patch.
+ assert_eq!(code, Some(0), "{case}: {env}");
+ let doc: serde_json::Value =
+ serde_json::from_slice(&std::fs::read(&vex).unwrap()).unwrap();
+ assert_eq!(doc["statements"][0]["status"], "not_affected", "{case}");
+ continue;
+ }
+ let withheld = match hard {
+ Some(_) => "vendor_unwired",
+ None => "vendor_jvm_shape_unsupported",
+ };
+ assert_eq!(
+ events(&env),
+ [(purl("foo"), "skipped".to_string(), withheld.to_string())],
+ "{case}: {env}"
+ );
+ assert!(!env.to_string().contains("not_affected"), "{case}: {env}");
+ assert!(!vex.exists(), "{case}: {env}");
+ }
+}
+
/// #584: a module added after vendoring that declares the base literally
/// builds the unpatched jar. `vendor --check` flags the drift and `vex`
/// withholds attestation until a re-vendor rewrites the module.
diff --git a/crates/socket-patch-core/src/vendor/jvm/maven_reactor.rs b/crates/socket-patch-core/src/vendor/jvm/maven_reactor.rs
index f1f23a8d40..fa0abb8c05 100644
--- a/crates/socket-patch-core/src/vendor/jvm/maven_reactor.rs
+++ b/crates/socket-patch-core/src/vendor/jvm/maven_reactor.rs
@@ -12,6 +12,7 @@ use std::ops::Range;
use serde_json::{json, Value};
use crate::crawlers::maven_selection::{MavenSelection, Verdict};
+use crate::formats::maven::version::VersionRange;
use crate::formats::maven::{
classpath_copy, declared_maven, interpolate_keeping, interpolate_strict,
is_executable_classifier, lookup_property, maven_config_properties as cli_properties,
@@ -919,12 +920,13 @@ pub fn pin_would_move(plan: &JvmPlan) -> Option<&str> {
/// [`wired_checked`], and no declaration of `c`'s g:a is left at a version
/// that may still read the base: the base itself, as a module or
-/// dependency added since vendoring declares it (#584), or a `${...}` the
-/// checkout does not define or that an inheriting pom or a profile moves
-/// (#513, #459), a version-less one whose local root is left unpinned, or
-/// an executable classifier or type copy of the GA (`tests`, `test-jar`, a
-/// native build) the pin does not retarget. Such a module builds the
-/// unpatched jar, so `vex` must not attest.
+/// dependency added since vendoring declares it (#584), a hard requirement
+/// on it (`[1.0]`, #2378), a `${...}` the checkout does not define or that
+/// an inheriting pom or a profile moves (#513, #459), a version-less one
+/// whose local root is left unpinned, or an executable classifier or type
+/// copy of the GA (`tests`, `test-jar`, a native build) the pin does not
+/// retarget. Such a module builds the unpatched jar, so `vex` must not
+/// attest.
pub fn attestable_checked(
read: ReadFn<'_>,
list: ListFn<'_>,
@@ -973,9 +975,10 @@ fn unattestable_in(reactor: &Reactor, c: &Coords<'_>) -> Option {
(!at.is_empty()).then(|| {
format!(
"{} may still build {ga}:{} rather than {sv}: a base version declared since \
- vendoring, a version a property, profile or unpinned root may move, or an \
- executable classifier or type copy the pin does not retarget",
+ vendoring or required as `[{}]`, a version a property, profile or unpinned root \
+ may move, or an executable classifier or type copy the pin does not retarget",
at.join(", "),
+ c.version,
c.version
)
})
@@ -1539,7 +1542,9 @@ impl Reactor {
/// What the modules at and below each pom select for `patch`: every
/// module is asked once, and its answer marked on each pom of its
/// chain. A module `skip` names has no say (hosted mode leaves out the
- /// modules a declaration already wires: a pin changes nothing there).
+ /// modules a declaration already wires: a pin changes nothing there),
+ /// and neither has one that requires the base version itself
+ /// ([`Self::requires_base`]): no pin reaches it.
fn under(
&self,
selection: &MavenSelection,
@@ -1549,6 +1554,9 @@ impl Reactor {
let (g, a, v) = (patch.group_id, patch.artifact_id, patch.version);
let mut out: BTreeMap = BTreeMap::new();
for module in self.reactor.iter().filter(|module| !skip(module)) {
+ if self.requires_base(module, g, a, v) {
+ continue;
+ }
let (own, version) = match selection.verdict(module, g, a, v) {
Verdict::Selected => (Own::Selected, None),
Verdict::Other(version) => (Own::Other, Some(version)),
@@ -1641,34 +1649,72 @@ impl Reactor {
/// Whether the patch `c` is wired for `module`: Maven reads its
/// suffixed version there from the nearest management on the module's
- /// chain (a pin, or the project's own entry), or from a declaration
- /// the module makes or inherits.
+ /// chain (a pin, or the project's own entry), unless the module
+ /// declares a version itself or inherits one
+ /// ([`Self::own_versions`]), which it reads first. A declared
+ /// suffixed version wires it; another plain version is the one it
+ /// builds, and leaves the management to wire what else it reaches; a
+ /// range, the base version or a version that cannot be read may be
+ /// the base, whatever the management says.
fn covers(&self, module: &str, c: &Coords<'_>) -> bool {
let sv = c.suffixed_version();
- if self
+ let managed = self
.managed_version(module, c.group_id, c.artifact_id)
.as_deref()
- == Some(sv.as_str())
- {
- return true;
- }
- self.chain(module).any(|p| {
- let doc = &self.poms[p].doc;
- self.keyed_declarations(p, c.group_id, c.artifact_id)
- .iter()
- .any(|(dep, _)| {
- let section = doc.section_of(*dep);
- !section.ends_with("dependencyManagement")
- && !section.starts_with("profile:")
- && doc.is_main_jar(*dep)
- && doc
- .child(*dep, "version")
- .and_then(|version| self.interpolate(module, &doc.text_of(version)))
- .as_deref()
- == Some(sv.as_str())
- })
+ == Some(sv.as_str());
+ let own = self.own_versions(module, c.group_id, c.artifact_id);
+ if own.is_empty() {
+ return managed;
+ }
+ own.iter().all(|own| match own.as_deref() {
+ Some(own) if own == sv || requires_exactly(own, &sv) => true,
+ Some(own) => managed && !is_range(own) && !is_base_like(own, c.version),
+ None => false,
})
}
+
+ /// The versions `module` declares for `g:a`'s main jar itself: the
+ /// `` of each `` entry in the nearest pom on
+ /// its chain that declares it (a module's entry replaces the one it
+ /// would inherit), as `module` interpolates it (`None`: it cannot).
+ /// Maven reads a declared version before any ``,
+ /// so no pin reaches such a module. Empty when those entries carry no
+ /// version, or no pom declares it: the management decides.
+ fn own_versions(&self, module: &str, g: &str, a: &str) -> Vec