Skip to content

RewriteTest: framework-agnostic ExecutionContext customizer registry#7559

Merged
jkschneider merged 5 commits intomainfrom
rewrite-test-default-ctx-customizers
May 4, 2026
Merged

RewriteTest: framework-agnostic ExecutionContext customizer registry#7559
jkschneider merged 5 commits intomainfrom
rewrite-test-default-ctx-customizers

Conversation

@jkschneider
Copy link
Copy Markdown
Member

@jkschneider jkschneider commented May 4, 2026

Summary

  • Adds RewriteTest.defaultExecutionContextCustomizers — a Map<Class<?>, Consumer<ExecutionContext>> applied to every default ExecutionContext. Test-framework integrations (JUnit, TestNG, Spock, etc.) register a customizer keyed by their own class without rewrite-test taking a dependency on the framework; putIfAbsent makes registration naturally idempotent.
  • First consumer: a JUnit Jupiter BeforeAllCallback in rewrite-gradle/src/test, auto-detected via service loader, that loads ~/.m2/settings.xml into the ExecutionContext so Gradle tests honor any configured mirror.
  • CI workflow now uses the finer-grained composite actions from openrewrite/gh-automation (added in ci-gradle: extract composite actions for finer-grained reuse gh-automation#94) so that s4u/maven-settings-action can be slotted between setup and build and write a ~/.m2/settings.xml whose wildcard mirror points at Moderne's Artifactory cache.

Why

Recent rewrite-gradle:test failures on main were MavenPomDownloader requests being throttled by Maven Central / Cloudflare with HTTP 404 + Retry-After under parallel test load. Routing artifact resolution through a configured mirror via ~/.m2/settings.xml bypasses the rate limit.

Gradle does not normally read the user's Maven settings, so the loader is opt-in at the rewrite-gradle test classpath only — nothing changes for downstream consumers of org.openrewrite.gradle.Assertions.

Test plan

  • ./gradlew :rewrite-gradle:test --tests org.openrewrite.gradle.AddPlatformDependencyTest — 20/20 green locally with ~/.m2/settings.xml configured (was 8/20 failing without).
  • CI on this PR: confirm the broader rewrite-gradle:test and rewrite-java-test:test failures clear with the workflow change.
  • Sanity-check that no existing test relies on defaultExecutionContext being free of customizations (registry is empty until a framework integration opts in).

Adds `RewriteTest.defaultExecutionContextCustomizers`, a `Map<Class<?>, Consumer<ExecutionContext>>`
applied to the context built by `defaultExecutionContext`. Test framework integrations
(JUnit, TestNG, Spock, …) can register a customizer keyed by their own class without
`rewrite-test` taking a dependency on any framework; `putIfAbsent` makes registration
naturally idempotent.

First consumer: a JUnit Jupiter `BeforeAllCallback` in rewrite-gradle's test sources,
auto-detected via service loader, that loads `~/.m2/settings.xml` into the ExecutionContext.
Recipes resolving Maven artifacts during rewrite-gradle tests then honor any configured
mirror, sidestepping Maven Central rate limits (HTTP 404 + Retry-After) under parallel load.
Gradle does not normally read the user's Maven settings, so this opt-in lives entirely in
test sources of openrewrite/rewrite — not in any published API surface.
…imits

Inlines the build job that previously delegated to openrewrite/gh-automation's
reusable ci-gradle workflow, and adds an `s4u/maven-settings-action` step that
writes a `~/.m2/settings.xml` with a wildcard mirror pointing at Moderne's
Artifactory cache. The MavenSettingsAutoLoadingExtension introduced earlier in
this PR loads that file into the test ExecutionContext, so recipes resolving
Maven artifacts during rewrite-gradle tests no longer hit Maven Central directly
and avoid the HTTP 404 + Retry-After throttling that's been failing CI under
parallel load.

The reusable workflow had no hook to inject extra setup steps, and inlining
keeps everything in this PR. Functionality (build, scheduled-failure Slack
notification, snapshot publish on main) is preserved.
Switches from the gh-automation reusable workflow (`ci-gradle.yml`) to its
finer-grained composite-action form, so we can inject `s4u/maven-settings-action`
between `setup` and `build`. The action writes a `~/.m2/settings.xml` whose
wildcard mirror points at Moderne's Artifactory cache; the
MavenSettingsAutoLoadingExtension introduced earlier in this PR loads it into
the test ExecutionContext, avoiding Maven Central's HTTP 404 + Retry-After
throttling under parallel test load.

The composite actions land in openrewrite/gh-automation#94.
@jkschneider jkschneider marked this pull request as ready for review May 4, 2026 11:33
@jkschneider jkschneider merged commit 4864a79 into main May 4, 2026
1 check failed
@jkschneider jkschneider deleted the rewrite-test-default-ctx-customizers branch May 4, 2026 12:13
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant