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
52 changes: 37 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,40 @@ concurrency:

jobs:
build:
uses: openrewrite/gh-automation/.github/workflows/ci-gradle.yml@main
with:
java_version: |
25
21
secrets:
gradle_enterprise_access_key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
sonatype_username: ${{ secrets.SONATYPE_USERNAME }}
sonatype_token: ${{ secrets.SONATYPE_TOKEN}}
ossrh_signing_key: ${{ secrets.OSSRH_SIGNING_KEY }}
ossrh_signing_password: ${{ secrets.OSSRH_SIGNING_PASSWORD }}
OPS_GITHUB_ACTIONS_WEBHOOK: ${{ secrets.OPS_GITHUB_ACTIONS_WEBHOOK }}
node_auth_token: ${{ secrets.NPM_TOKEN }}
pypi_token: ${{ secrets.PYPI_OPENREWRITE_PUBLISH }}
nuget_api_key: ${{ secrets.NUGET_API_KEY }}
runs-on: ubuntu-latest
if: github.event_name != 'schedule' || github.repository_owner == 'openrewrite' || github.repository_owner == 'moderneinc'
steps:
- uses: openrewrite/gh-automation/.github/actions/setup@main
with:
java_version: |
25
21
develocity_access_key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}

# Route Maven resolution through Moderne's Artifactory cache to avoid
# Maven Central rate-limiting (HTTP 404 + Retry-After) under parallel
# test load. Picked up by MavenSettingsAutoLoadingExtension at test time.
- uses: s4u/maven-settings-action@v3.1.0
with:
mirrors: '[{"id": "moderne-cache", "name": "Moderne Artifactory Cache", "mirrorOf": "*", "url": "https://artifactory.moderne.ninja/artifactory/moderne-cache-3/"}]'

- uses: openrewrite/gh-automation/.github/actions/build@main

- if: failure() && github.event_name == 'schedule' && (github.repository_owner == 'openrewrite' || github.repository_owner == 'moderneinc')
uses: openrewrite/gh-automation/.github/actions/slack-failure@main
with:
webhook: ${{ secrets.OPS_GITHUB_ACTIONS_WEBHOOK }}

- if: >
github.event_name != 'pull_request' &&
github.ref == 'refs/heads/main' &&
(github.repository_owner == 'openrewrite' || github.repository_owner == 'moderneinc')
uses: openrewrite/gh-automation/.github/actions/publish-snapshots@main
with:
sonatype_username: ${{ secrets.SONATYPE_USERNAME }}
sonatype_token: ${{ secrets.SONATYPE_TOKEN }}
ossrh_signing_key: ${{ secrets.OSSRH_SIGNING_KEY }}
ossrh_signing_password: ${{ secrets.OSSRH_SIGNING_PASSWORD }}
node_auth_token: ${{ secrets.NPM_TOKEN }}
pypi_token: ${{ secrets.PYPI_OPENREWRITE_PUBLISH }}
nuget_api_key: ${{ secrets.NUGET_API_KEY }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2026 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.gradle;

import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.openrewrite.ExecutionContext;
import org.openrewrite.maven.MavenExecutionContextView;
import org.openrewrite.maven.MavenSettings;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.maven.tree.MavenRepository.MAVEN_LOCAL_DEFAULT;

/**
* Loads {@code ~/.m2/settings.xml} (and {@code $M2_HOME/conf/settings.xml}) into the
* default {@link ExecutionContext} for every {@link RewriteTest} in this module, so a
* configured Maven mirror or repository is honored by recipes that resolve artifacts.
* Auto-registered via {@code META-INF/services/org.junit.jupiter.api.extension.Extension};
* Gradle does not normally read the user's Maven settings, so this is opt-in at the
* module test classpath level.
*/
public class MavenSettingsAutoLoadingExtension implements BeforeAllCallback {

@Override
public void beforeAll(ExtensionContext context) {
RewriteTest.defaultExecutionContextCustomizers.putIfAbsent(
MavenSettingsAutoLoadingExtension.class,
MavenSettingsAutoLoadingExtension::loadMavenSettings);
}

private static void loadMavenSettings(ExecutionContext ctx) {
MavenExecutionContextView mctx = MavenExecutionContextView.view(ctx);
boolean nothingConfigured = mctx.getSettings() == null &&
mctx.getLocalRepository().equals(MAVEN_LOCAL_DEFAULT) &&
mctx.getRepositories().isEmpty() &&
mctx.getActiveProfiles().isEmpty() &&
mctx.getMirrors().isEmpty();
if (nothingConfigured) {
mctx.setMavenSettings(MavenSettings.readMavenSettingsFromDisk(mctx));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.openrewrite.gradle.MavenSettingsAutoLoadingExtension
17 changes: 17 additions & 0 deletions rewrite-gradle/src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright 2026 the original author or authors.
# <p>
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# <p>
# https://www.apache.org/licenses/LICENSE-2.0
# <p>
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

junit.jupiter.extensions.autodetection.enabled=true
16 changes: 16 additions & 0 deletions rewrite-test/src/main/java/org/openrewrite/test/RewriteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;
import java.util.function.Function;
Expand All @@ -51,6 +52,18 @@

@SuppressWarnings("unused")
public interface RewriteTest extends SourceSpecs {
/**
* Registry of customizers applied to the {@link ExecutionContext} produced by
* {@link #defaultExecutionContext(SourceSpec[])}. Test framework integrations
* (e.g. a JUnit Jupiter {@code BeforeAllCallback}) can register a customizer
* once at startup without {@code rewrite-test} taking a dependency on the
* framework.
* <p>
* The map is keyed by the integration's class so {@code putIfAbsent(MyExt.class, MyExt::load)}
* is naturally idempotent — callers do not need their own one-shot guard.
*/
Map<Class<?>, Consumer<ExecutionContext>> defaultExecutionContextCustomizers = new ConcurrentHashMap<>();

static AdHocRecipe toRecipe(Supplier<TreeVisitor<?, ExecutionContext>> visitor) {
return new AdHocRecipe(null, null, null, visitor, null, null);
}
Expand Down Expand Up @@ -696,6 +709,9 @@ default ExecutionContext defaultExecutionContext(SourceSpec<?>[] sourceSpecs) {
}
fail("Failed to parse sources or run recipe", t);
});
for (Consumer<ExecutionContext> customizer : defaultExecutionContextCustomizers.values()) {
customizer.accept(ctx);
}
return ParsingExecutionContextView.view(ctx).setCharset(StandardCharsets.UTF_8);
}

Expand Down
Loading