Skip to content

Commit f70aad1

Browse files
authored
Fix resolution of dated snapshots as input (#6788)
1 parent d4ddbd6 commit f70aad1

2 files changed

Lines changed: 48 additions & 5 deletions

File tree

rewrite-maven/src/main/java/org/openrewrite/maven/internal/MavenPomDownloader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,16 +534,16 @@ public Pom download(GroupArtifactVersion gav,
534534
}
535535
}
536536

537+
GroupArtifactVersion originalGav = gav;
538+
gav = resolveNamedVersion(gav, containingPom, repositories, ctx);
539+
String versionMaybeDatedSnapshot = datedSnapshotVersion(gav, containingPom, repositories, ctx);
540+
gav = handleSnapshotTimestampVersion(gav);
537541
Iterable<MavenRepository> normalizedRepos = distinctNormalizedRepositories(repositories, containingPom, gav.getVersion());
538542

539543
Timer.Sample sample = Timer.start();
540544
Timer.Builder timer = Timer.builder("rewrite.maven.download").tag("type", "pom");
541545

542546
Map<MavenRepository, String> repositoryResponses = new LinkedHashMap<>();
543-
GroupArtifactVersion originalGav = gav;
544-
gav = resolveNamedVersion(gav, containingPom, repositories, ctx);
545-
String versionMaybeDatedSnapshot = datedSnapshotVersion(gav, containingPom, repositories, ctx);
546-
gav = handleSnapshotTimestampVersion(gav);
547547
List<String> uris = new ArrayList<>();
548548

549549
// Keep the repo and resolved GAV of the found JAR to avoid throwing if JAR is found

rewrite-maven/src/test/java/org/openrewrite/maven/internal/MavenPomDownloaderTest.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ void useHttpWhenHttpsFails() throws Exception {
356356
}
357357
}
358358

359-
@Disabled
360359
@Test
361360
void dontFetchSnapshotsFromReleaseRepos() throws Exception {
362361
try (MockWebServer snapshotRepo = new MockWebServer();
@@ -464,6 +463,50 @@ public MockResponse dispatch(RecordedRequest request) {
464463
}
465464
}
466465

466+
@Test
467+
void datedSnapshotVersionIncludesSnapshotRepositories() throws Exception {
468+
try (MockWebServer snapshotRepo = new MockWebServer()) {
469+
snapshotRepo.setDispatcher(new Dispatcher() {
470+
@Override
471+
public MockResponse dispatch(RecordedRequest request) {
472+
MockResponse response = new MockResponse().setResponseCode(200);
473+
if (request.getPath() != null && request.getPath().endsWith(".pom")) {
474+
//language=xml
475+
response.setBody(
476+
"""
477+
<project>
478+
<groupId>com.example</groupId>
479+
<artifactId>my-lib</artifactId>
480+
<version>3.28.0-SNAPSHOT</version>
481+
</project>
482+
"""
483+
);
484+
}
485+
return response;
486+
}
487+
});
488+
489+
snapshotRepo.start();
490+
491+
var downloader = new MavenPomDownloader(emptyMap(), ctx);
492+
var snapshotRepoModel = MavenRepository.builder()
493+
.id("snapshots")
494+
.uri("http://%s:%d".formatted(snapshotRepo.getHostName(), snapshotRepo.getPort()))
495+
.releases("false")
496+
.snapshots(true)
497+
.build();
498+
499+
// A dated snapshot version should be recognized as a snapshot so that
500+
// snapshot-only repositories are not excluded.
501+
Pom pom = downloader.download(
502+
new GroupArtifactVersion("com.example", "my-lib", "3.28.0-20260220.175218-20"),
503+
null, null, List.of(snapshotRepoModel));
504+
505+
assertThat(pom).isNotNull();
506+
assertThat(snapshotRepo.getRequestCount()).isGreaterThan(0);
507+
}
508+
}
509+
467510
@Issue("https://github.com/openrewrite/rewrite-maven-plugin/issues/862")
468511
@Test
469512
void fetchSnapshotWithCorrectClassifier() throws Exception {

0 commit comments

Comments
 (0)