Skip to content

Commit eda7b20

Browse files
mikolalysenkoclaude
andcommitted
Address /code-review on the simplify commit
- Hosted build_versions are computed for every declaration again, so an empty list only ever means "no <version>"; the index reads a new PomScope::build_versions (the build half of resolve_version) instead of resolving the pom-spelled version it discarded. - assert_withheld takes the case it checks, so a table-driven failure names the failing case again. - The discovery module doc lists the bypasses it withholds for (classifier copies, profile declarations and management, profile properties moving a version or coordinates, -D overrides) and the interpolation bounds. - The reactor's classifier comment says where its type rule is narrower. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 157b6d4 commit eda7b20

4 files changed

Lines changed: 67 additions & 43 deletions

File tree

‎crates/socket-patch-core/src/formats/maven/mod.rs‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,24 +317,26 @@ impl PomScope {
317317
/// The `<version>` text of the declaration at `pos`, resolved as
318318
/// [`PomDep::version`], [`PomDep::build_version`] and
319319
/// [`PomDep::version_alternatives`] describe.
320-
pub(crate) fn resolve_version(
321-
&self,
322-
text: &str,
323-
pos: usize,
324-
) -> (String, String, Vec<Alternative>) {
320+
fn resolve_version(&self, text: &str, pos: usize) -> (String, String, Vec<Alternative>) {
325321
if !text.contains("${") {
326322
return (text.to_string(), text.to_string(), Vec::new());
327323
}
328324
let own = self.own_profile(pos);
329325
let spelled = interpolate_strict(text, &|name| self.lookup(name, &own, false))
330326
.unwrap_or_else(|| text.to_string());
327+
let (build, alternatives) = self.build_versions(text, pos);
328+
(spelled, build, alternatives)
329+
}
330+
331+
/// [`PomDep::build_version`] and [`PomDep::version_alternatives`] of
332+
/// the `<version>` text of the declaration at `pos`.
333+
pub(crate) fn build_versions(&self, text: &str, pos: usize) -> (String, Vec<Alternative>) {
331334
match self.resolve_in_build(text, pos) {
332-
(Some(build), alternatives) => (spelled, build, alternatives),
335+
(Some(build), alternatives) => (build, alternatives),
333336
// Unresolved here (a parent pom this reader never sees may
334337
// define it): the build version stays as written, but a value
335338
// some profiles give it is still one the build may resolve.
336339
(None, alternatives) => (
337-
spelled,
338340
text.to_string(),
339341
alternatives
340342
.into_iter()

‎crates/socket-patch-core/src/patch/redirect/maven_index.rs‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ pub(super) struct IndexedDep {
3333
/// Inside a `<dependencyManagement>`.
3434
pub(super) managed: bool,
3535
/// Every version the build may resolve for it, as VEX discovery reads
36-
/// one ([`PomScope::resolve_version`]): with no profile active but the
36+
/// one ([`PomScope::build_versions`]): with no profile active but the
3737
/// one holding it, then each combination of profiles whose
3838
/// `<properties>` move it (as written where one leaves it unresolved).
39-
/// Empty when it has no `<version>`, and for a live declaration that is
40-
/// no classifier copy, whose versions no check reads.
39+
/// Empty when it has no `<version>`.
4140
pub(super) build_versions: Vec<String>,
4241
}
4342

@@ -159,18 +158,12 @@ impl PomIndex {
159158
managed: managed
160159
.iter()
161160
.any(|m| d.element.start >= m.start && d.element.start < m.end),
162-
build_versions: d
163-
.version_text
164-
.as_deref()
165-
.filter(|_| {
166-
d.in_profile || is_variant(d.type_text.as_deref(), d.classifier.as_deref())
167-
})
168-
.map_or_else(Vec::new, |text| {
169-
let (_, build, alternatives) = scope.resolve_version(text, d.element.start);
170-
std::iter::once(build)
171-
.chain(alternatives.into_iter().map(|a| a.value))
172-
.collect()
173-
}),
161+
build_versions: d.version_text.as_deref().map_or_else(Vec::new, |text| {
162+
let (build, alternatives) = scope.build_versions(text, d.element.start);
163+
std::iter::once(build)
164+
.chain(alternatives.into_iter().map(|a| a.value))
165+
.collect()
166+
}),
174167
group: d.group,
175168
artifact: d.artifact,
176169
version_inner: d.version_inner,

‎crates/socket-patch-core/src/vendor/jvm/maven_reactor.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,8 +2292,9 @@ impl Reactor {
22922292
};
22932293
let type_text = doc.child_text(dep, "type").filter(|t| !t.is_empty());
22942294
let classifier_text = doc.child_text(dep, "classifier").filter(|c| !c.is_empty());
2295-
// Mapped as discovery and the hosted rewriter map it (the type
2296-
// check below drops any other literal type).
2295+
// `test-jar` is the `tests` copy ([`classpath_copy`]); the type
2296+
// check below drops any other literal type but `jar`, even with
2297+
// an explicit classifier.
22972298
let classifier = classpath_copy(type_text.as_deref(), classifier_text.as_deref())
22982299
.flatten()
22992300
.map(str::to_string);

‎crates/socket-patch-core/src/vex/discover/maven.rs‎

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,28 @@
4545
//! a ref (rollback / remove find it) but marked unattested: a module's
4646
//! own literal `<version>` overrides it, and only the root pom is read here
4747
//! (the rewriter refuses such roots, #261). A `${property}` version is
48-
//! read twice: as the pom spells it (the root `<properties>`, what the
49-
//! rewriter writes and rolls back) and as the build resolves it
50-
//! (`.mvn/maven.config`'s `-D` user properties first, Maven's order). A
51-
//! Socket version only the build config supplies is diagnosed, never a
52-
//! ref (hosted mode never writes one; rollback / remove never edit
53-
//! `.mvn/maven.config`). Every pin is then weighed by [`bypasses`]: an
54-
//! executable classifier copy, a `<profiles>` declaration, profile
55-
//! `<properties>` that move its version or its `${property}` coordinates,
56-
//! or a `-D` override that makes the build resolve anything else keeps
57-
//! the ref but marks it unattested.
48+
//! interpolated through every property it names (at most 16 deep; a cycle
49+
//! or an undefined name never resolves to a pin) twice: as the pom spells
50+
//! it (the root `<properties>`, what the rewriter writes and rolls back)
51+
//! and as the build resolves it (`.mvn/maven.config`'s `-D` user
52+
//! properties first, Maven's order). A Socket version only the build
53+
//! config supplies is diagnosed, never a ref (hosted mode never writes
54+
//! one; rollback / remove never edit `.mvn/maven.config`).
55+
//!
56+
//! Every pin is then weighed by [`bypasses`], and each way the build may
57+
//! resolve something else keeps the ref but marks it unattested:
58+
//! - an executable classifier copy (anything but `sources` / `javadoc`),
59+
//! live or in a profile, at another version or none in this pom;
60+
//! - a `<profiles>` declaration of the main jar at another version (a
61+
//! profile's `<dependencyManagement>` only where management governs the
62+
//! pin); every profile counts, as vendored mode treats every profile
63+
//! as live;
64+
//! - profile `<properties>` (any combination of profiles) that move the
65+
//! pin's `${property}` version, or a `${property}` groupId / artifactId
66+
//! so the pin names another package or another declaration names this
67+
//! one (a coordinate property this pom cannot resolve may name
68+
//! anything);
69+
//! - a `-D` user property that moves the pin's `${property}` version.
5870
//!
5971
//! Integrity: when the pom sha256 was known the rewriter also writes Maven
6072
//! Trusted Checksums — `.mvn/checksums/checksums.sha256` lines
@@ -1554,6 +1566,7 @@ mod tests {
15541566
&out,
15551567
UnattestedKind::MavenClassifierUnpatched,
15561568
&["org.slf4j:slf4j-api:"],
1569+
&format!("{deps} {managed}"),
15571570
);
15581571
}
15591572

@@ -2044,6 +2057,7 @@ mod tests {
20442057
&out,
20452058
UnattestedKind::MavenConfigOverride,
20462059
&[".mvn/maven.config"],
2060+
&what,
20472061
);
20482062
}
20492063
assert!(
@@ -2158,7 +2172,12 @@ mod tests {
21582172
];
21592173
for (live, profile, kind) in &unattested {
21602174
let out = run(&project(live, profile)).await;
2161-
assert_withheld(&out, *kind, &["org.slf4j:slf4j-api", "<profiles>"]);
2175+
assert_withheld(
2176+
&out,
2177+
*kind,
2178+
&["org.slf4j:slf4j-api", "<profiles>"],
2179+
&format!("{live} {profile}"),
2180+
);
21622181
}
21632182

21642183
let attested = [
@@ -2209,16 +2228,24 @@ mod tests {
22092228

22102229
/// `out` finds the hosted slf4j-api pin for `UUID_A` but withholds it:
22112230
/// exactly one unattested entry, of `kind`, for that pin, whose detail
2212-
/// names every one of `needles`.
2231+
/// names every one of `needles` (`case` names the case in a failure).
22132232
#[track_caller]
2214-
fn assert_withheld(out: &Discovery, kind: UnattestedKind, needles: &[&str]) {
2233+
fn assert_withheld(out: &Discovery, kind: UnattestedKind, needles: &[&str], case: &str) {
22152234
assert_refs(out, &[(FX_PURL, UUID_A, WiringMode::Hosted)]);
2216-
assert_eq!(out.unattested.len(), 1, "{:?}", out.unattested);
2235+
assert_eq!(out.unattested.len(), 1, "{case}: {:?}", out.unattested);
22172236
let u = &out.unattested[0];
2218-
assert_eq!(u.kind, kind, "{}", u.detail);
2219-
assert_eq!((u.purl.as_str(), u.uuid.as_str()), (FX_PURL, UUID_A));
2237+
assert_eq!(u.kind, kind, "{case}: {}", u.detail);
2238+
assert_eq!(
2239+
(u.purl.as_str(), u.uuid.as_str()),
2240+
(FX_PURL, UUID_A),
2241+
"{case}"
2242+
);
22202243
for needle in needles {
2221-
assert!(u.detail.contains(needle), "{needle:?}: {}", u.detail);
2244+
assert!(
2245+
u.detail.contains(needle),
2246+
"{case}: {needle:?}: {}",
2247+
u.detail
2248+
);
22222249
}
22232250
}
22242251

@@ -2298,6 +2325,7 @@ mod tests {
22982325
&out,
22992326
UnattestedKind::MavenProfileUnpatched,
23002327
&["org.slf4j:slf4j-api", "<properties>"],
2328+
&format!("{root} {decl} {profiles:?}"),
23012329
);
23022330
}
23032331

@@ -3166,7 +3194,7 @@ mod tests {
31663194
"<properties><revision>1.7.36</revision></properties>",
31673195
))
31683196
.await;
3169-
assert_withheld(&out, UnattestedKind::MavenProfileUnpatched, &[]);
3197+
assert_withheld(&out, UnattestedKind::MavenProfileUnpatched, &[], "");
31703198
// One that keeps it does not.
31713199
let out = run(&project(
31723200
&pin,
@@ -3289,7 +3317,7 @@ mod tests {
32893317
&[broken],
32903318
);
32913319
let out = run(&p).await;
3292-
assert_withheld(&out, UnattestedKind::MavenProfileUnpatched, &[]);
3320+
assert_withheld(&out, UnattestedKind::MavenProfileUnpatched, &[], "");
32933321
let p = property_project("", &direct_decl(&pin), &[broken]);
32943322
let out = run(&p).await;
32953323
assert!(

0 commit comments

Comments
 (0)