Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class MavenPomDownloader {
private static final String RELEASE = "RELEASE";
private static final List<String> NAMED_VERSIONS = Arrays.asList(LATEST, RELEASE);

private static final String NEGATIVE_RESULT_MESSAGES = "org.openrewrite.maven.internal.MavenPomDownloader.negativeResultMessages";


private final MavenPomCache mavenCache;
private final Map<Path, Pom> projectPoms;
Expand Down Expand Up @@ -172,6 +174,15 @@ byte[] sendRequest(HttpSender.Request request) throws IOException, HttpSenderRes
}
}

@SuppressWarnings("unchecked")
private Map<String, String> negativeResultMessages() {
return (Map<String, String>) ctx.getMessages().computeIfAbsent(NEGATIVE_RESULT_MESSAGES, k -> new HashMap<String, String>());
}

private static String negativeResultKey(MavenRepository repo, GroupArtifactVersion gav) {
return repo.getUri() + '|' + gav.getGroupId() + ':' + gav.getArtifactId() + ':' + gav.getVersion();
}

private Map<GroupArtifactVersion, Pom> projectPomsByGav(Map<Path, Pom> projectPoms) {
Map<GroupArtifactVersion, Pom> result = new HashMap<>();
for (Pom projectPom : projectPoms.values()) {
Expand Down Expand Up @@ -326,9 +337,15 @@ public MavenMetadata downloadMetadata(GroupArtifactVersion gav, @Nullable Resolv
// If there was no fatal failure while attempting to find metadata and there was no metadata retrieved
// from the current repo, cache an empty result.
mavenCache.putMavenMetadata(URI.create(repo.getUri()), gav, null);
String originalResponse = repositoryResponses.get(repo);
if (originalResponse != null) {
negativeResultMessages().put(negativeResultKey(repo, gav), originalResponse);
}
}
} else if (!result.isPresent()) {
repositoryResponses.put(repo, "Did not attempt to download because of a previous failure to retrieve from this repository.");
String originalResponse = negativeResultMessages().get(negativeResultKey(repo, gav));
repositoryResponses.put(repo, originalResponse != null ? originalResponse :
"Did not attempt to download because of a previous failure to retrieve from this repository.");
}

// Merge metadata from repository and cache metadata result.
Expand Down Expand Up @@ -718,6 +735,7 @@ public Pom download(GroupArtifactVersion gav,
if (e.isClientSideException()) {
//If the exception is a common, client-side exception, cache an empty result.
mavenCache.putPom(resolvedGav, null);
negativeResultMessages().put(negativeResultKey(repo, gav), e.getMessage());
}
} catch (IOException | UncheckedIOException e) {
repositoryResponses.put(repo, e.getMessage());
Expand All @@ -727,7 +745,9 @@ public Pom download(GroupArtifactVersion gav,
sample.stop(timer.tags("outcome", "cached").register(Metrics.globalRegistry));
return result.get();
} else {
repositoryResponses.put(repo, "Did not attempt to download because of a previous failure to retrieve from this repository.");
String originalResponse = negativeResultMessages().get(negativeResultKey(repo, gav));
repositoryResponses.put(repo, originalResponse != null ? originalResponse :
"Did not attempt to download because of a previous failure to retrieve from this repository.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import org.intellij.lang.annotations.Language;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand Down Expand Up @@ -80,7 +79,6 @@ void addDependenciesOnEmptyProject() {
}

@Test
@Disabled("2026-05-04 temporarily disabled after Artifactory introduction")
void dontAddDuplicateIfUpdateModelOnPriorRecipeCycleFailed() {
rewriteRun(
spec -> spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.openrewrite.maven;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.openrewrite.*;
Expand All @@ -42,7 +41,6 @@ class MavenDependencyFailuresTest implements RewriteTest {

@DocumentExample
@Test
@Disabled("2026-05-04 temporarily disabled after Artifactory introduction")
void unresolvableParent() { // Dad said he was heading to the corner store for cigarettes, and hasn't been resolvable for the past 20 years :'(
rewriteRun(
spec -> spec
Expand Down Expand Up @@ -81,7 +79,6 @@ void unresolvableParent() { // Dad said he was heading to the corner store for c
}

@Test
@Disabled("2026-05-04 temporarily disabled after Artifactory introduction")
void unresolvableMavenMetadata() {
rewriteRun(
spec -> spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,6 @@ void deriveFromNexus() {
}

@Test
@Disabled("2026-05-04 temporarily disabled after Artifactory introduction")
void deriveFromNexusUpgrade() {
rewriteRun(
spec -> spec.recipe(new UpgradeDependencyVersion("*", "*", "latest.patch", null, null, null)),
Expand Down Expand Up @@ -1827,7 +1826,6 @@ void noManagedVersion() {
}

@Test
@Disabled("2026-05-04 temporarily disabled after Artifactory introduction")
void badManagedVersion() {
rewriteRun(
spec -> spec.recipe(new UpgradeDependencyVersion("*", "*", "latest.patch", null, null, null)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ void update() {

@Issue("https://github.com/openrewrite/rewrite/issues/5065")
@Test
@Disabled("2026-05-04 temporarily disabled after Artifactory introduction")
void repoUnreachable() {
rewriteRun(
spec -> spec.recipe(new UpgradePluginVersion(
Expand Down Expand Up @@ -248,7 +247,6 @@ void repoUnreachable() {

@Issue("https://github.com/openrewrite/rewrite/issues/5065")
@Test
@Disabled("2026-05-04 temporarily disabled after Artifactory introduction")
void noNewerVersion() {
rewriteRun(
spec -> spec.recipe(new UpgradePluginVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,74 @@ public MockResponse dispatch(RecordedRequest request) {
}
}

@Test
void replayOriginalMetadataFailureOnSubsequentCall() throws Exception {
try (var server = new MockWebServer()) {
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) {
return new MockResponse().setResponseCode(404).setBody("not found");
}
});
server.start();

// given a repository that always 404s for metadata, and a downloader that shares an ExecutionContext
MavenRepository repository = MavenRepository.builder()
.id("flaky")
.uri("http://%s:%d/".formatted(server.getHostName(), server.getPort()))
.knownToExist(true)
.build();
var downloader = new MavenPomDownloader(emptyMap(), ctx);
var ga = new GroupArtifact("does.not", "exist");

// when downloadMetadata is invoked twice with the same context
String firstMessage = assertThrows(MavenDownloadingException.class,
() -> downloader.downloadMetadata(ga, null, List.of(repository))).getMessage();
String secondMessage = assertThrows(MavenDownloadingException.class,
() -> downloader.downloadMetadata(ga, null, List.of(repository))).getMessage();

// then the second failure replays the original 404, not a generic "did not attempt" notice
assertThat(firstMessage).contains("404");
assertThat(secondMessage)
.contains("404")
.doesNotContain("Did not attempt to download");
}
}

@Test
void replayOriginalPomFailureOnSubsequentCall() throws Exception {
try (var server = new MockWebServer()) {
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) {
return new MockResponse().setResponseCode(404).setBody("");
}
});
server.start();

// given a repository that 404s for both POM and JAR, and a downloader that shares an ExecutionContext
MavenRepository repository = MavenRepository.builder()
.id("flaky")
.uri("http://%s:%d/".formatted(server.getHostName(), server.getPort()))
.knownToExist(true)
.build();
var downloader = new MavenPomDownloader(emptyMap(), ctx);
var gav = new GroupArtifactVersion("does.not", "exist", "1.0.0");

// when download is invoked twice with the same context
String firstMessage = assertThrows(MavenDownloadingException.class,
() -> downloader.download(gav, null, null, List.of(repository))).getMessage();
String secondMessage = assertThrows(MavenDownloadingException.class,
() -> downloader.download(gav, null, null, List.of(repository))).getMessage();

// then the second failure replays the original 404, not a generic "did not attempt" notice
assertThat(firstMessage).contains("404");
assertThat(secondMessage)
.contains("404")
.doesNotContain("Did not attempt to download");
}
}

@SuppressWarnings("ConstantConditions")
@Test
void mergeMetadata() throws Exception {
Expand Down
Loading