Package org.openrewrite.test
Class ModwRunner
java.lang.Object
org.openrewrite.test.ModwRunner
- All Implemented Interfaces:
RewriteRunner
A
RewriteRunner that drives recipe execution through the moderne-cli
(mod). Stages the test's source files to a temp directory, invokes the
pinned CLI version via its active.recipe hook (the same path the
Moderne IntelliJ plugin uses for in-IDE recipe development), then translates
the CLI's output back into a RecipeRun so the surrounding
rewriteRun validation works unchanged.
The test case is responsible for providing whatever build files (pom.xml,
settings.xml, build.gradle, etc.) the CLI needs to load the staged project.
Source files are written at their declared sourcePath.
Construction
Built with the generated Lombok builder; every field is optional and defaulted, so the common case is simplyModwRunner.builder().build(). Defaults live
in one place (DEFAULT_CLI_VERSION, DEFAULT_ORIGIN_URL) so the
same values apply across every recipe library; bump them there to move all
consumers at once, or override per runner via the builder
(ModwRunner.builder().cliVersion("4.3.0").build()).
Choosing the CLI version
The effective version resolves as: themoderne.cli.regression.version
system property > the MODERNE_CLI_REGRESSION_VERSION environment
variable > the builder's cliVersion (default DEFAULT_CLI_VERSION).
Local developers leave the overrides unset and get the committed default; CI sets
the env var once to bump the regression target across all recipe modules.
Silencing known failures
Setting the version to one that is not yet published on Maven Central is treated as a deliberate skip: when themodw wrapper download returns
HTTP 404 the test is aborted (reported skipped) rather than failed. This is
the "look-ahead bump" workflow — point the version at the not-yet-released CLI
that will carry the fix to silence a known compatibility break; once that CLI
ships, the check resumes automatically.
Artifact sourcing
Themodw wrapper and the heavy platform distribution are fetched from
Moderne's Artifactory cache ("https://artifactory.moderne.ninja/artifactory/moderne-cache-3") in preference to Maven
Central, which rate-limits parallel CI downloads. Provide credentials via
WRAPPER_DIST_USERNAME_ENV/WRAPPER_DIST_PASSWORD_ENV (or
WRAPPER_DIST_TOKEN_ENV); these are also read by the wrapper for the
distribution download. Authenticated, Artifactory proxies on demand and is
authoritative (a 404 means "not published" → skip). Unauthenticated access only
reads already-cached artifacts, so a 401 (or 5xx / I/O error) falls back to Maven
Central, whose 404 is then the authoritative "not published" signal.
V1 limitations
- Modified files are re-parsed using the original
SourceSpec's parser. If the parser can't be invoked standalone (no JVM dep, RPC-based, etc.), the run fails. - The recipe's runtime classpath is taken from the test JVM's
java.class.path. Tests run from a JVM whose classpath doesn't include the recipe (extreme edge case) need to override.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.openrewrite.test.RewriteRunner
RewriteRunner.Context -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault moderne-cli version every recipe library tests against.static final StringOrigin URL given to the staged fixture repo by default.static final StringEnvironment variable holding a moderne-cli license key.static final StringEnvironment variable CI sets to override the committed default CLI version.static final StringSystem property equivalent ofVERSION_ENV; takes precedence over it.static final Stringstatic final Stringstatic final StringCredentials for the Artifactory cache.Fields inherited from interface org.openrewrite.test.RewriteRunner
IN_PROCESS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.openrewrite.RecipeRunrun(org.openrewrite.Recipe recipe, RewriteRunner.Context context) Default in-JVM behavior.
-
Field Details
-
WRAPPER_DIST_USERNAME_ENV
Credentials for the Artifactory cache. Shared with themodwwrapper's own distribution download (it reads the same variables), so a single set covers both the wrapper fetch and the heavy platform distribution. When set, Artifactory proxies on demand and becomes authoritative (a real 404 for missing artifacts); when unset, access is anonymous (cached artifacts only) and a 401 falls back to Maven Central. A token takes precedence over username/password.- See Also:
-
WRAPPER_DIST_PASSWORD_ENV
- See Also:
-
WRAPPER_DIST_TOKEN_ENV
- See Also:
-
VERSION_ENV
Environment variable CI sets to override the committed default CLI version.- See Also:
-
VERSION_PROPERTY
System property equivalent ofVERSION_ENV; takes precedence over it.- See Also:
-
DEFAULT_CLI_VERSION
Default moderne-cli version every recipe library tests against. The single place to bump the floor for all consumers; override per runner via the builder or at runtime viaVERSION_ENV/VERSION_PROPERTY.- See Also:
-
LICENSE_KEY_ENV
Environment variable holding a moderne-cli license key. When set, the runner configures it viamodw config license editbefore building, which lets the CLI run recipes on private repositories without a Moderne tenant. When unset, the runner proceeds without a license — recipes still run against the open-source fixture repositories these tests use.- See Also:
-
DEFAULT_ORIGIN_URL
Origin URL given to the staged fixture repo by default.- See Also:
-
-
Constructor Details
-
ModwRunner
public ModwRunner()
-
-
Method Details
-
run
Description copied from interface:RewriteRunnerDefault in-JVM behavior. Out-of-process runners override this.- Specified by:
runin interfaceRewriteRunner
-