Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 12 additions & 5 deletions crates/socket-patch-cli/tests/e2e_redirect_maven_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,19 @@ fn socket(cwd: &Path, m2: &Path, args: &[&str]) -> (Option<i32>, serde_json::Val
(out.status.code(), env, stderr)
}

/// Purge every copy of the fixture GAV (base + suffixed) from `m2` so the
/// next resolve must fetch it.
/// Purge every suffixed copy of the fixture from `m2` so the next resolve
/// must fetch it. The base version stays: the project only asks for the
/// suffixed one, and `maven-dependency-plugin` itself depends on
/// commons-text 1.10.0, so purging it sends every later resolve back to
/// Central (CI run 37909555148).
fn purge(m2: &Path) {
let dir = m2.join(GROUP_PATH).join(ARTIFACT);
if dir.exists() {
std::fs::remove_dir_all(&dir).unwrap();
let Ok(versions) = std::fs::read_dir(m2.join(GROUP_PATH).join(ARTIFACT)) else {
return;
};
for entry in versions.flatten() {
if entry.file_name() != VERSION && entry.path().is_dir() {
std::fs::remove_dir_all(entry.path()).unwrap();
}
}
}

Expand Down
11 changes: 9 additions & 2 deletions crates/socket-patch-cli/tests/e2e_vendor_maven_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,17 @@ fn maven_vendor_fresh_checkout_install_and_manifestless_vex() {
.is_file(),
"the local repository stays warm"
);
// The mirror keeps the id `central` so the warm plugin closure (cached
// under that id) is reused instead of re-fetched from Central (CI run
// 37909555148).
let mirrored = root.join("mirrored-settings.xml");
write_settings(
write_settings_with_ids(
&mirrored,
&[("external:*", "https://repo.maven.apache.org/maven2")],
&[(
"central",
"external:*",
"https://repo.maven.apache.org/maven2",
)],
);
for (label, settings) in [("warm", &settings), ("mirrorOf external:*", &mirrored)] {
let out = mvn.copy_dependencies(&fresh, &m2, settings, "target/dep");
Expand Down
21 changes: 19 additions & 2 deletions crates/socket-patch-cli/tests/maven_build_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,28 @@ fn is_resolution_failure(out: &Output) -> bool {
/// A user `settings.xml` with the given `(mirrorOf, url)` mirrors (none =
/// an empty settings file that just shields the run from `~/.m2`).
pub fn write_settings(path: &Path, mirrors: &[(&str, &str)]) {
let ids: Vec<String> = (0..mirrors.len())
.map(|i| format!("e2e-mirror-{i}"))
.collect();
let mirrors: Vec<(&str, &str, &str)> = ids
.iter()
.zip(mirrors)
.map(|(id, (of, url))| (id.as_str(), *of, *url))
.collect();
write_settings_with_ids(path, &mirrors);
}

/// [`write_settings`] with explicit `(id, mirrorOf, url)` mirrors. A mirror
/// that serves Central's content should keep the id `central`: the local
/// repository records which repository id each artifact came from and
/// re-fetches anything cached under another id, so a differently named
/// mirror re-downloads the whole warm plugin closure from Central.
pub fn write_settings_with_ids(path: &Path, mirrors: &[(&str, &str, &str)]) {
let mut body =
String::from("<settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\">\n <mirrors>\n");
for (i, (of, url)) in mirrors.iter().enumerate() {
for (id, of, url) in mirrors {
body.push_str(&format!(
" <mirror>\n <id>e2e-mirror-{i}</id>\n <mirrorOf>{of}</mirrorOf>\n \
" <mirror>\n <id>{id}</id>\n <mirrorOf>{of}</mirrorOf>\n \
<url>{url}</url>\n </mirror>\n"
));
}
Expand Down
Loading