Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fd06421
Pin a Maven patch only where Maven selects its base version
mikolalysenko Nov 16, 2026
abfabe0
Restore the line breaks of two vendored Maven warnings
mikolalysenko Nov 16, 2026
6c1467a
Read a dependency a pom declares twice as Maven does
mikolalysenko Nov 16, 2026
d5eb740
Pin a vendored Maven patch in the modules that select its version
mikolalysenko Nov 16, 2026
82d9239
Keep vendored Maven pins where they were committed, on every machine
mikolalysenko Nov 16, 2026
fbe0982
Merge the review fixes of the Maven selection work
mikolalysenko Nov 16, 2026
104f968
Never hold a pin that moves a module, and attest only wired modules
mikolalysenko Nov 16, 2026
cf3353c
Keep a Maven selection only while every read it was made from still h…
mikolalysenko Nov 16, 2026
a8d8045
Merge branch 'fix/maven-pin-follows-mediation' into fix/maven-pin-per…
mikolalysenko Nov 16, 2026
7795510
Let a deeper range the model cannot resolve hold the selection back
claude Nov 17, 2026
905c05b
Plan hosted Maven pins over a reactor, and wire ${property} versions
mikolalysenko Nov 17, 2026
9b79a5d
Find and restore hosted Maven pins in every pom of a reactor
mikolalysenko Nov 17, 2026
6ee38a8
Test hosted Maven reactors and property versions against real Maven
mikolalysenko Nov 17, 2026
8d4fbb8
Let a later hosted scan pin the Maven modules an earlier one could no…
mikolalysenko Nov 17, 2026
c377458
Never fail a hosted run on a Maven module pom that cannot be read
mikolalysenko Nov 17, 2026
d879384
Read an earlier release's Maven pin by its shape only in a single pom
mikolalysenko Nov 17, 2026
36c418f
Write a hosted Maven plan whole or not at all, over a reactor read once
mikolalysenko Nov 17, 2026
56ae4ee
Test the hosted Maven invariant against real Maven, and document it
mikolalysenko Nov 17, 2026
7e1f39c
test(maven): pin the hosted property and reactor rewrites in the gold…
mikolalysenko Nov 17, 2026
14ffdc7
Ask a hosted Maven repository only for the version it serves
mikolalysenko Nov 18, 2026
c2fd330
Test against real Maven what a hosted Socket repository is asked for
mikolalysenko Nov 18, 2026
2ce982c
Merge origin/main into fix/maven-hosted-reactors-and-properties
mikolalysenko Nov 18, 2026
56377bf
Merge fix/maven-hosted-reactors-and-properties (with main) into fix/m…
mikolalysenko Nov 18, 2026
dc3ccc2
Never take a reactor pom that is not UTF-8 text for a missing one
mikolalysenko Nov 18, 2026
89bbf72
Merge fix/maven-hosted-reactors-and-properties into fix/maven-hosted-…
mikolalysenko Nov 18, 2026
3b8dd67
Merge origin/main into fix/maven-hosted-reactors-and-properties
mikolalysenko Nov 18, 2026
39eb8e2
Merge fix/maven-hosted-reactors-and-properties into fix/maven-hosted-…
mikolalysenko Nov 19, 2026
2f75e07
Fix the review findings on the Maven repository filter
mikolalysenko Nov 19, 2026
7bdc058
Merge origin/main into fix/maven-hosted-reactors-and-properties
mikolalysenko Nov 19, 2026
234f1f7
Merge the base branch's last head into fix/maven-hosted-repo-scoping
mikolalysenko Nov 19, 2026
81000f2
Merge origin/main into fix/maven-hosted-repo-scoping
mikolalysenko Nov 19, 2026
c14138f
Name the Maven filter directory as the checksums directory is named
mikolalysenko Nov 19, 2026
17393a7
Never let the Maven repository filter refuse a run or fail a build
mikolalysenko Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 159 additions & 2 deletions crates/socket-patch-cli/CLI_CONTRACT.md

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions crates/socket-patch-cli/src/commands/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,17 @@ impl EjectSnapshot {
.iter()
.map(|s| s.to_string()),
);
// A hosted Maven pin's restore also removes the repository filter
// files hosted mode keeps for it, one per patch: its own regular
// files only. Anything else in that directory (a subdirectory, a
// link, a file of the user's) is not the restore's to touch, and
// must not be read as a file here.
let disk = socket_patch_core::vendor::lock_inventory::ProjectView::Disk(root);
planned.extend(
socket_patch_core::patch::redirect::hosted_maven_filter_dir(&disk)
.await
.owned,
);
let mut files = std::collections::BTreeMap::new();
for rel in root_files.iter().chain(planned.iter()) {
if files.contains_key(rel) {
Expand Down Expand Up @@ -8298,6 +8309,39 @@ mod eject_snapshot_tests {
let err = taken.err().expect("a FIFO must fail the snapshot");
assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);
}

/// The snapshot takes hosted Maven's own filter files, which the
/// restore of a hosted pin removes, and nothing else of that
/// directory: a subdirectory or a FIFO there (not hosted mode's, and
/// not a file) must not fail the eject of every ecosystem.
#[cfg(unix)]
#[tokio::test]
async fn snapshot_takes_only_hosted_maven_filter_files_of_their_directory() {
let tmp = tempfile::tempdir().unwrap();
let dir = tmp.path().join(".mvn/socket-patch");
std::fs::create_dir_all(dir.join("notes")).unwrap();
let ours = "prefixes-socket-patch-77777777-7777-4777-8777-777777777777.txt";
std::fs::write(dir.join(ours), "## repository-prefixes/2.0\n").unwrap();
std::fs::write(dir.join("prefixes-central.txt"), "/org\n").unwrap();
let fifo = dir.join("prefixes-socket-patch-88888888-8888-4888-8888-888888888888.txt");
let c = std::ffi::CString::new(fifo.to_str().unwrap()).unwrap();
assert_eq!(unsafe { libc::mkfifo(c.as_ptr(), 0o644) }, 0);
let snapshot = tokio::time::timeout(
std::time::Duration::from_secs(10),
EjectSnapshot::take(tmp.path(), &[]),
)
.await
.expect("nothing in the filter directory wedges the snapshot")
.expect("nor fails it");
let taken: Vec<&str> = snapshot
.planned
.iter()
.map(String::as_str)
.filter(|rel| rel.starts_with(".mvn/socket-patch/"))
.collect();
assert_eq!(taken, [format!(".mvn/socket-patch/{ours}").as_str()]);
assert!(snapshot.files[&format!(".mvn/socket-patch/{ours}")].is_some());
}
}

#[cfg(test)]
Expand Down
377 changes: 374 additions & 3 deletions crates/socket-patch-cli/tests/e2e_redirect_maven_build.rs

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions crates/socket-patch-cli/tests/in_process_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,62 @@ async fn scan_hosted_with_nothing_to_redirect_heals_the_maven_config() {
);
}

/// The same for the repository filter's directory line, here with no
/// Trusted Checksums block beside it: the scan that redirects nothing
/// reads the config for that line alone and respells it, so it does not go
/// on stopping Maven 3.9.2 to 3.9.8 from starting with `-f` from outside
/// the project.
#[tokio::test]
#[serial]
async fn scan_hosted_with_nothing_to_redirect_heals_the_maven_filter_line() {
use socket_patch_cli::commands::scan::ScanMode;
let _no_jvm_caches = NoJvmCaches::new();
let m2 = tempfile::tempdir().unwrap();
std::env::set_var("MAVEN_REPO_LOCAL", m2.path());
let server = MockServer::start().await;
mock_batch_empty(&server).await;
let lines = |property: &str| {
format!(
"-B\n-Daether.remoteRepositoryFilter.prefixes=true\n\
-Daether.remoteRepositoryFilter.prefixes.basedir={property}/.mvn/socket-patch\n"
)
};
let earlier = lines("${session.rootDirectory}");
let healed = lines("${maven.multiModuleProjectDirectory}");
let args_for = |root: &Path, dry_run: bool| {
let mut args = default_args(root);
args.common.api_url = Some(server.uri());
args.common.dry_run = dry_run;
args.mode = Some(ScanMode::Hosted);
args
};
let config = |root: &Path| std::fs::read_to_string(root.join(".mvn/maven.config")).unwrap();

let tmp = tempfile::tempdir().unwrap();
project_with_a_stale_maven_config(tmp.path());
std::fs::write(tmp.path().join(".mvn/maven.config"), &earlier).unwrap();
// Dry: nothing written, no lock taken.
assert_eq!(run_scrubbed(args_for(tmp.path(), true)).await, 0);
assert_eq!(config(tmp.path()), earlier);
assert!(!tmp.path().join(".socket").exists());
// Wet: the one line is respelled, and a second run has nothing to do.
assert_eq!(run_scrubbed(args_for(tmp.path(), false)).await, 0);
assert_eq!(config(tmp.path()), healed);
assert_eq!(run_scrubbed(args_for(tmp.path(), false)).await, 0);
assert_eq!(config(tmp.path()), healed);

// This project's own spelling: the run reads it and touches nothing.
let settled = tempfile::tempdir().unwrap();
project_with_a_stale_maven_config(settled.path());
std::fs::write(settled.path().join(".mvn/maven.config"), &healed).unwrap();
assert_eq!(run_scrubbed(args_for(settled.path(), false)).await, 0);
assert_eq!(config(settled.path()), healed);
assert!(
!settled.path().join(".socket").exists(),
"a run with nothing to write takes no lock"
);
}

/// The heal is never a reason to fail a run that has nothing else to do:
/// while another run holds the write lock the line is left for the next
/// scan, and the scan still exits 0.
Expand Down
15 changes: 15 additions & 0 deletions crates/socket-patch-cli/tests/maven_build_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ impl Mvn {
self.numeric() >= vec![3, 9, 4]
}

/// Maven ≥ 3.9.2 reads the repository prefix file the hosted rewriter
/// commits under `.mvn/socket-patch/`, and asks a Socket repository for
/// nothing but the version it lists. 3.9.0 / 3.9.1 interpolate neither
/// root-directory property in `maven.config`, so the file is never
/// found; older lines have no such filter. Below 3.9.2 the Socket
/// repository is asked for every artifact the local repository lacks,
/// like any repository a pom declares.
///
/// Maven 4 finds the directory only when it is named through
/// `${session.rootDirectory}`, which the rewriter writes for a project
/// that declares Maven 4; under the default spelling it runs unfiltered.
pub fn filters_repositories(&self) -> bool {
self.numeric() >= vec![3, 9, 2]
}

/// `mvn -B <args>` in `cwd` against the local repository `m2`, with the
/// user settings file `settings`.
pub fn run(&self, cwd: &Path, m2: &Path, settings: &Path, args: &[&str]) -> Output {
Expand Down
6 changes: 5 additions & 1 deletion crates/socket-patch-cli/tests/scan_rollout_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,14 +966,18 @@ async fn a_cap_of_zero_with_a_maven_config_to_heal_writes_nothing_but_the_heal()
let names9: Vec<&str> = PACKAGES.iter().map(|(n, _)| *n).collect();
write_project(tmp.path(), &names9);
// The six Trusted Checksums settings as releases up to 5.1.0 wrote
// them for every project.
// them for every project, and the repository filter's two lines with
// their directory named through the same property: both directory
// lines are healed, and they are all the run writes.
let earlier = [
"-Daether.artifactResolver.postProcessor.trustedChecksums=true",
"-Daether.artifactResolver.postProcessor.trustedChecksums.checksumAlgorithms=SHA-256",
"-Daether.artifactResolver.postProcessor.trustedChecksums.failIfMissing=false",
"-Daether.trustedChecksumsSource.summaryFile=true",
"-Daether.trustedChecksumsSource.summaryFile.basedir=${session.rootDirectory}/.mvn/checksums",
"-Daether.trustedChecksumsSource.summaryFile.originAware=false",
"-Daether.remoteRepositoryFilter.prefixes=true",
"-Daether.remoteRepositoryFilter.prefixes.basedir=${session.rootDirectory}/.mvn/socket-patch",
"",
]
.join("\n");
Expand Down
44 changes: 44 additions & 0 deletions crates/socket-patch-core/src/formats/maven/declared_maven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,50 @@ impl RootDirectory {
pub(crate) fn unread_by(self, maven: &DeclaredMaven) -> bool {
self == RootDirectory::Launcher && maven.is_maven_4()
}

/// What the Maven the project declares (`maven`) makes of a
/// `.mvn/maven.config` line that names a directory of the checkout
/// through this property, for a setting Maven acts on from the release
/// `since` on. The one answer for every such line hosted mode writes:
/// the Trusted Checksums directory and the repository filter's.
pub(crate) fn read_by(self, maven: &DeclaredMaven, since: [u32; 3]) -> Reads {
// A wrapper that pins a Maven 3 cannot build a pom only Maven 4
// reads, so its release then says nothing about the Maven that does.
if let Some(version) = maven.release().filter(|_| !maven.maven_4_model()) {
if release(version) < since {
return Reads::TooOld(version.to_string());
}
}
if self.unread_by(maven) {
Reads::UnreadByMaven4
} else if self == RootDirectory::Launcher && maven.release().is_none() {
Reads::Maven3Only
} else {
Reads::Read
}
}
}

/// What the Maven a project declares makes of a `.mvn/maven.config` line
/// that names a directory of the checkout through a root-directory property
/// ([`RootDirectory::read_by`]).
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum Reads {
/// The Maven Wrapper pins this Apache Maven release, which is older
/// than the first that acts on the setting.
TooOld(String),
/// The project declares Maven 4 and the line names the directory
/// through [`RootDirectory::Launcher`], which Maven 4 does not
/// interpolate.
UnreadByMaven4,
/// The project declares no Maven and the line names the directory
/// through [`RootDirectory::Launcher`]: Maven 3 reads it, a Maven 4
/// build does not, and nothing in the checkout says which builds it.
Maven3Only,
/// The Maven the project declares reads the line; or it declares none,
/// and the line is spelled so that every Maven that acts on the
/// setting at all finds the directory.
Read,
}

#[cfg(test)]
Expand Down
35 changes: 34 additions & 1 deletion crates/socket-patch-core/src/formats/maven/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ pub(crate) use properties::{

use super::xml::{blank_non_markup, child_text, elements, open_tags, Element};

pub(crate) mod mirror;
pub(crate) mod declared_maven;
pub(crate) mod mirror;
pub(crate) mod repository_filter;
pub(crate) mod trusted_checksums;
pub(crate) mod version;

Expand Down Expand Up @@ -1005,6 +1006,38 @@ pub(crate) fn maven_config_properties(config: &str) -> BTreeMap<String, String>
props
}

/// `config` (a `.mvn/maven.config`) with `args` appended, one per line:
/// the one way hosted mode adds settings to that file. With `keep_ending`
/// a file that ends without a line break still does, so the lines can be
/// taken out again byte for byte ([`repository_filter`]); without it the
/// result always ends with one, as the Trusted Checksums settings have
/// always been written (and as the rewriter's other implementation
/// writes them).
pub(crate) fn append_config_args(config: &str, args: &[&str], keep_ending: bool) -> String {
let block = args.join("\n");
if config.is_empty() {
format!("{block}\n")
} else if config.ends_with('\n') {
format!("{config}{block}\n")
} else if keep_ending {
format!("{config}\n{block}")
} else {
format!("{config}\n{block}\n")
}
}

/// Whether `config` (a `.mvn/maven.config`) holds lines hosted mode wrote
/// that name a directory of the checkout through a root-directory
/// property, in either spelling: the Trusted Checksums block
/// ([`trusted_checksums::holds_written_block`]) or the repository filter's
/// directory line ([`repository_filter::holds_written_line`]). Such lines
/// are respelled for the Maven the project declares, so a caller asks this
/// (a substring test for nearly every config) before it reads the Maven
/// Wrapper and the root pom to find out which spelling the project takes.
pub(crate) fn holds_respellable_lines(config: &str) -> bool {
trusted_checksums::holds_written_block(config) || repository_filter::holds_written_line(config)
}

/// Java's `String.trim`: every char up to U+0020, nothing beyond.
fn java_trim(s: &str) -> &str {
s.trim_matches(|c: char| c <= ' ')
Expand Down
Loading