diff --git a/build.gradle.kts b/build.gradle.kts index b40100b..5f9c899 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,14 +7,22 @@ group = "org.openrewrite.recipe" description = "Apache Migration" recipeDependencies { - parserClasspath("org.apache.httpcomponents.core5:httpcore5:5.1.+") - parserClasspath("org.apache.httpcomponents.client5:httpclient5:5.1.+") + parserClasspath("commons-io:commons-io:2.+") parserClasspath("org.apache.commons:commons-collections4:4.4") - parserClasspath("org.apache.poi:poi:3.16") + parserClasspath("org.apache.commons:commons-lang3:3.+") + + parserClasspath("org.apache.httpcomponents.client5:httpclient5:5.1.+") + parserClasspath("org.apache.httpcomponents.core5:httpcore5:5.1.+") parserClasspath("org.apache.httpcomponents:httpclient:4.5.14") - parserClasspath("org.apache.httpcomponents:httpmime:4.5.14") parserClasspath("org.apache.httpcomponents:httpcore-nio:4.4.16") parserClasspath("org.apache.httpcomponents:httpcore:4.4.16") + parserClasspath("org.apache.httpcomponents:httpmime:4.5.14") + + parserClasspath("org.apache.maven.shared:maven-shared-utils:3.+") + + parserClasspath("org.apache.poi:poi:3.16") + + parserClasspath("org.codehaus.plexus:plexus-utils:3.+") } val rewriteVersion = rewriteRecipe.rewriteVersion.get() @@ -32,12 +40,13 @@ dependencies { exclude("io.github.eisop","dataflow-errorprone") } - implementation("commons-io:commons-io:2.+") - implementation("org.apache.commons:commons-lang3:3.+") - implementation("org.apache.maven.shared:maven-shared-utils:3.+") - implementation("org.codehaus.plexus:plexus-utils:3.+") + compileOnly("commons-io:commons-io:2.+") + compileOnly("org.apache.commons:commons-lang3:3.+") + compileOnly("org.apache.maven.shared:maven-shared-utils:3.+") + compileOnly("org.codehaus.plexus:plexus-utils:3.+") implementation("org.jspecify:jspecify:1.0.0") + testImplementation("org.openrewrite:rewrite-java-17") testImplementation("org.openrewrite:rewrite-test") testImplementation("org.openrewrite:rewrite-maven") @@ -58,3 +67,7 @@ dependencies { testImplementation("org.junit.jupiter:junit-jupiter-engine:5.13.3") } + +tasks.withType { + options.compilerArgs.add("-Arewrite.javaParserClasspathFrom=resources") +} diff --git a/src/main/java/org/openrewrite/apache/commons/io/ApacheIOUtilsUseExplicitCharset.java b/src/main/java/org/openrewrite/apache/commons/io/ApacheIOUtilsUseExplicitCharset.java index dcf6e3a..44bb0af 100644 --- a/src/main/java/org/openrewrite/apache/commons/io/ApacheIOUtilsUseExplicitCharset.java +++ b/src/main/java/org/openrewrite/apache/commons/io/ApacheIOUtilsUseExplicitCharset.java @@ -86,8 +86,6 @@ public Validated validate() { @Override public TreeVisitor getVisitor() { return Preconditions.check(new UsesType<>("org.apache.commons.io.IOUtils", false), new JavaIsoVisitor() { - private final JavaParser.Builder javaParser = JavaParser.fromJavaVersion().classpath("commons-io"); - @Override public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { J.MethodInvocation mi = super.visitMethodInvocation(method, ctx); @@ -95,26 +93,26 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu mi = mi.withSelect(method.getArguments().get(0)); //noinspection ConstantConditions mi = mi.withMethodType(mi.getMethodType().withName("getBytes")); - mi = JavaTemplate.builder("#{any(String)}.getBytes(StandardCharsets.#{})") - .javaParser(javaParser) + maybeAddImport("java.nio.charset.StandardCharsets"); + return JavaTemplate.builder("#{any(String)}.getBytes(StandardCharsets.#{})") + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "commons-io")) .imports("java.nio.charset.StandardCharsets") .build() .apply(updateCursor(mi), mi.getCoordinates().replaceMethod(), mi.getArguments().get(0), encoding == null ? "UTF_8" : encoding); - } else { - for (Map.Entry entry : MATCHER_TEMPLATES.entrySet()) { - if (entry.getKey().matches(mi)) { - List args = new ArrayList<>(mi.getArguments()); - args.add(encoding == null ? "UTF_8" : encoding); - mi = JavaTemplate.builder(entry.getValue()) - .contextSensitive() - .javaParser(javaParser) - .imports("java.nio.charset.StandardCharsets") - .build() - .apply(updateCursor(mi), - mi.getCoordinates().replaceMethod(), args.toArray()); - } + } + + for (Map.Entry entry : MATCHER_TEMPLATES.entrySet()) { + if (entry.getKey().matches(mi)) { + List args = new ArrayList<>(mi.getArguments()); + args.add(encoding == null ? "UTF_8" : encoding); + mi = JavaTemplate.builder(entry.getValue()) + .contextSensitive() + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "commons-io")) + .imports("java.nio.charset.StandardCharsets") + .build() + .apply(updateCursor(mi), mi.getCoordinates().replaceMethod(), args.toArray()); } } if (method != mi) { diff --git a/src/main/java/org/openrewrite/apache/commons/lang/IsNotEmptyToJdk.java b/src/main/java/org/openrewrite/apache/commons/lang/IsNotEmptyToJdk.java index 9f33752..0b5cef7 100644 --- a/src/main/java/org/openrewrite/apache/commons/lang/IsNotEmptyToJdk.java +++ b/src/main/java/org/openrewrite/apache/commons/lang/IsNotEmptyToJdk.java @@ -15,6 +15,7 @@ */ package org.openrewrite.apache.commons.lang; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.Recipe; @@ -71,8 +72,9 @@ public TreeVisitor getVisitor() { private final MethodMatcher isNotEmptyMatcher = new MethodMatcher("*..StringUtils isNotEmpty(..)"); private final MethodMatcher trimMatcher = new MethodMatcher("java.lang.String trim()"); - private final JavaTemplate isEmptyReplacement = Semantics.expression(this, "IsEmpty", (String s) -> (s == null || s.isEmpty())).build(); - private final JavaTemplate isNotEmptyReplacement = Semantics.expression(this, "IsNotEmpty", (String s) -> (s != null && !s.isEmpty())).build(); + // No need to use context here, as there are no classpath dependencies needed for these replacements + private final JavaTemplate isEmptyReplacement = Semantics.expression(this, "IsEmpty", (@Nullable String s) -> (s == null || s.isEmpty())).build(); + private final JavaTemplate isNotEmptyReplacement = Semantics.expression(this, "IsNotEmpty", (@Nullable String s) -> (s != null && !s.isEmpty())).build(); private final JavaTemplate isEmptyTrimmed = Semantics.expression(this, "IsEmptyTrimmed", (String s) -> s.trim().isEmpty()).build(); private final JavaTemplate isNotEmptyTrimmed = Semantics.expression(this, "IsNotEmptyTrimmed", (String s) -> !s.trim().isEmpty()).build(); diff --git a/src/main/resources/META-INF/rewrite/classpath.tsv.zip b/src/main/resources/META-INF/rewrite/classpath.tsv.zip index e9aa4b1..64efc23 100644 Binary files a/src/main/resources/META-INF/rewrite/classpath.tsv.zip and b/src/main/resources/META-INF/rewrite/classpath.tsv.zip differ diff --git a/src/test/java/org/openrewrite/apache/commons/codec/ApacheBase64ToJavaBase64Test.java b/src/test/java/org/openrewrite/apache/commons/codec/ApacheBase64ToJavaBase64Test.java index 7696eaa..c2e4ce3 100644 --- a/src/test/java/org/openrewrite/apache/commons/codec/ApacheBase64ToJavaBase64Test.java +++ b/src/test/java/org/openrewrite/apache/commons/codec/ApacheBase64ToJavaBase64Test.java @@ -40,7 +40,7 @@ void toJavaBase64() { java( """ import org.apache.commons.codec.binary.Base64; - + class Test { static byte[] decodeBytes(byte[] encodedBytes) { return Base64.decodeBase64(encodedBytes); diff --git a/src/test/java/org/openrewrite/apache/commons/io/ApacheCommonsFileUtilsTest.java b/src/test/java/org/openrewrite/apache/commons/io/ApacheCommonsFileUtilsTest.java index 921c08a..4941140 100644 --- a/src/test/java/org/openrewrite/apache/commons/io/ApacheCommonsFileUtilsTest.java +++ b/src/test/java/org/openrewrite/apache/commons/io/ApacheCommonsFileUtilsTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; +import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -26,7 +27,7 @@ class ApacheCommonsFileUtilsTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.parser(JavaParser.fromJavaVersion().classpath("commons-io")) + spec.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(),"commons-io")) .recipe(new ApacheCommonsFileUtilsRecipes()); } diff --git a/src/test/java/org/openrewrite/apache/commons/io/ApacheFileUtilsToJavaFilesTest.java b/src/test/java/org/openrewrite/apache/commons/io/ApacheFileUtilsToJavaFilesTest.java index b9062ff..49f305e 100644 --- a/src/test/java/org/openrewrite/apache/commons/io/ApacheFileUtilsToJavaFilesTest.java +++ b/src/test/java/org/openrewrite/apache/commons/io/ApacheFileUtilsToJavaFilesTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; +import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -28,7 +29,7 @@ class ApacheFileUtilsToJavaFilesTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .recipe(new ApacheFileUtilsToJavaFiles()) - .parser(JavaParser.fromJavaVersion().classpath("commons-io")); + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "commons-io")); } @DocumentExample @@ -42,7 +43,7 @@ void convertTest() { import java.nio.charset.Charset; import org.apache.commons.io.FileUtils; import java.util.List; - + class A { byte[] readFileBytes(File file) { return FileUtils.readFileToByteArray(file); @@ -62,9 +63,9 @@ List readLinesWithCharsetId(File file) { import java.io.File; import java.nio.charset.Charset; import java.nio.file.Files; - + import java.util.List; - + class A { byte[] readFileBytes(File file) { return Files.readAllBytes(file.toPath()); diff --git a/src/test/java/org/openrewrite/apache/commons/io/ApacheIOUtilsUseExplicitCharsetTest.java b/src/test/java/org/openrewrite/apache/commons/io/ApacheIOUtilsUseExplicitCharsetTest.java index 15978ef..faaa088 100644 --- a/src/test/java/org/openrewrite/apache/commons/io/ApacheIOUtilsUseExplicitCharsetTest.java +++ b/src/test/java/org/openrewrite/apache/commons/io/ApacheIOUtilsUseExplicitCharsetTest.java @@ -16,6 +16,7 @@ package org.openrewrite.apache.commons.io; import org.junit.jupiter.api.Test; +import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -29,7 +30,7 @@ class ApacheIOUtilsUseExplicitCharsetTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .recipe(new ApacheIOUtilsUseExplicitCharset(null)) - .parser(JavaParser.fromJavaVersion().classpath("commons-io")); + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "commons-io")); } @Test diff --git a/src/test/java/org/openrewrite/apache/commons/io/UseJavaStandardCharsetsTest.java b/src/test/java/org/openrewrite/apache/commons/io/UseJavaStandardCharsetsTest.java index 2b3df78..397735b 100644 --- a/src/test/java/org/openrewrite/apache/commons/io/UseJavaStandardCharsetsTest.java +++ b/src/test/java/org/openrewrite/apache/commons/io/UseJavaStandardCharsetsTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; +import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -28,7 +29,7 @@ class UseJavaStandardCharsetsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .recipeFromResources("org.openrewrite.apache.commons.io.UseStandardCharsets") - .parser(JavaParser.fromJavaVersion().classpath("commons-io")); + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "commons-io")); } @DocumentExample @@ -41,7 +42,7 @@ void toStandardCharsets() { """ import java.nio.charset.Charset; import org.apache.commons.io.Charsets; - + class A { Charset iso88591 = Charsets.ISO_8859_1; Charset usAscii = Charsets.US_ASCII; @@ -54,7 +55,7 @@ class A { """ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; - + class A { Charset iso88591 = StandardCharsets.ISO_8859_1; Charset usAscii = StandardCharsets.US_ASCII; diff --git a/src/test/java/org/openrewrite/apache/commons/io/UseSystemLineSeparatorTest.java b/src/test/java/org/openrewrite/apache/commons/io/UseSystemLineSeparatorTest.java index 7366db2..207605c 100644 --- a/src/test/java/org/openrewrite/apache/commons/io/UseSystemLineSeparatorTest.java +++ b/src/test/java/org/openrewrite/apache/commons/io/UseSystemLineSeparatorTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; +import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.Issue; import org.openrewrite.config.Environment; import org.openrewrite.java.JavaParser; @@ -34,7 +35,7 @@ public void defaults(RecipeSpec spec) { .scanRuntimeClasspath("org.openrewrite.apache.commons.io") .build() .activateRecipes("org.openrewrite.apache.commons.io.UseSystemLineSeparator")) - .parser(JavaParser.fromJavaVersion().classpath("commons-io")); + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "commons-io")); } diff --git a/src/test/java/org/openrewrite/apache/commons/lang/ApacheCommonsStringUtilsTest.java b/src/test/java/org/openrewrite/apache/commons/lang/ApacheCommonsStringUtilsTest.java index 2120847..b98cadf 100644 --- a/src/test/java/org/openrewrite/apache/commons/lang/ApacheCommonsStringUtilsTest.java +++ b/src/test/java/org/openrewrite/apache/commons/lang/ApacheCommonsStringUtilsTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; +import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.Issue; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; @@ -30,7 +31,7 @@ class ApacheCommonsStringUtilsTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.parser(JavaParser.fromJavaVersion().classpath("commons-lang3")) + spec.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "commons-lang3")) .recipe(new ApacheCommonsStringUtilsRecipes()); } diff --git a/src/test/java/org/openrewrite/apache/commons/lang/IsNotEmptyToJdkTest.java b/src/test/java/org/openrewrite/apache/commons/lang/IsNotEmptyToJdkTest.java index 6321e4a..1737305 100644 --- a/src/test/java/org/openrewrite/apache/commons/lang/IsNotEmptyToJdkTest.java +++ b/src/test/java/org/openrewrite/apache/commons/lang/IsNotEmptyToJdkTest.java @@ -20,6 +20,7 @@ import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; import org.openrewrite.DocumentExample; +import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -30,7 +31,7 @@ class IsNotEmptyToJdkTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.parser(JavaParser.fromJavaVersion().classpath("commons-lang3", "plexus-utils", "maven-shared-utils")) + spec.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "commons-lang3", "plexus-utils", "maven-shared-utils")) .recipe(new IsNotEmptyToJdk()); } @@ -71,7 +72,7 @@ void trim(String import_) { java( """ import %s; - + class A { boolean test(String first) { boolean a = StringUtils.isEmpty(first.trim()); @@ -87,7 +88,7 @@ String foo() { """.formatted(import_), """ import %s; - + class A { boolean test(String first) { boolean a = first.trim().isEmpty(); @@ -190,7 +191,7 @@ String getField() { java( """ import org.apache.commons.lang3.StringUtils; - + class A { boolean test(B b) { return StringUtils.isEmpty(b.getField()); diff --git a/src/test/java/org/openrewrite/apache/maven/shared/MavenSharedStringUtilsTest.java b/src/test/java/org/openrewrite/apache/maven/shared/MavenSharedStringUtilsTest.java index 8bc5cb3..2a57391 100644 --- a/src/test/java/org/openrewrite/apache/maven/shared/MavenSharedStringUtilsTest.java +++ b/src/test/java/org/openrewrite/apache/maven/shared/MavenSharedStringUtilsTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; +import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -28,7 +29,7 @@ class MavenSharedStringUtilsTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.parser(JavaParser.fromJavaVersion().classpath("maven-shared-utils")) + spec.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "maven-shared-utils")) .recipe(new MavenSharedStringUtilsRecipes()); } @@ -81,19 +82,19 @@ void bar(String in, CharSequence cs) { String[] array; boolean bool; String string; - + // Test all methods in alphabetical order to only execute the slow recipes once string = in.length() <= 10 ? in : in.substring(0, 10 - 3) + "..."; string = in == null || in.isEmpty() ? in : Character.toTitleCase(in.charAt(0)) + in.substring(1); string = Objects.toString(in, ""); string = Objects.toString(in, "nil"); string = in.replaceAll("\\\\s+", ""); - + bool = in == null ? false : in.equalsIgnoreCase("other"); bool = Objects.equals(in, "other"); //bool = StringUtils.equals(cs, "other"); bool = StringUtils.isEmpty(in); - + string = in == null ? null : in.toLowerCase(); string = in == null || in.isEmpty() ? in : in.replace("search", "replacement"); string = in == null ? null : new StringBuffer(in).reverse().toString(); diff --git a/src/test/java/org/openrewrite/codehaus/plexus/PlexusFileUtilsTest.java b/src/test/java/org/openrewrite/codehaus/plexus/PlexusFileUtilsTest.java index a87fe7b..2c3d69c 100644 --- a/src/test/java/org/openrewrite/codehaus/plexus/PlexusFileUtilsTest.java +++ b/src/test/java/org/openrewrite/codehaus/plexus/PlexusFileUtilsTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -28,7 +29,7 @@ class PlexusFileUtilsTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpath("commons-io", "plexus-utils")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(),"commons-io", "plexus-utils")) .recipe(new PlexusFileUtilsRecipes()); } @@ -42,7 +43,7 @@ void deleteDirectoryFullyQualified() { java( """ import java.io.File; - + class Test { void test() throws Exception { org.codehaus.plexus.util.FileUtils.deleteDirectory("test"); @@ -53,9 +54,9 @@ void test() throws Exception { """, """ import org.apache.commons.io.FileUtils; - + import java.io.File; - + class Test { void test() throws Exception { FileUtils.deleteDirectory(new File("test")); @@ -75,9 +76,9 @@ void deleteDirectorySimpleImport() { java( """ import org.codehaus.plexus.util.FileUtils; - + import java.io.File; - + class Test { void test() throws Exception { FileUtils.deleteDirectory("test"); @@ -86,9 +87,9 @@ void test() throws Exception { """, """ import org.apache.commons.io.FileUtils; - + import java.io.File; - + class Test { void test() throws Exception { FileUtils.deleteDirectory(new File("test")); @@ -106,9 +107,9 @@ void deleteDirectoryRetainedImport() { java( """ import org.codehaus.plexus.util.FileUtils; - + import java.io.File; - + class Test { void test() throws Exception { FileUtils.deleteDirectory("test"); @@ -118,9 +119,9 @@ void test() throws Exception { """, """ import org.codehaus.plexus.util.FileUtils; - + import java.io.File; - + class Test { void test() throws Exception { org.apache.commons.io.FileUtils.deleteDirectory(new File("test")); @@ -142,7 +143,7 @@ void fileExists() { java( """ import org.codehaus.plexus.util.FileUtils; - + class Test { boolean test(String fileName) throws Exception { return FileUtils.fileExists(fileName); @@ -151,7 +152,7 @@ boolean test(String fileName) throws Exception { """, """ import java.io.File; - + class Test { boolean test(String fileName) throws Exception { return new File(fileName).exists(); @@ -172,9 +173,9 @@ void getFile() { java( """ import org.codehaus.plexus.util.FileUtils; - + import java.io.File; - + class Test { File test(String fileName) throws Exception { return FileUtils.getFile(fileName); @@ -183,7 +184,7 @@ File test(String fileName) throws Exception { """, """ import java.io.File; - + class Test { File test(String fileName) throws Exception { return new File(fileName); diff --git a/src/test/java/org/openrewrite/codehaus/plexus/PlexusStringUtilsTest.java b/src/test/java/org/openrewrite/codehaus/plexus/PlexusStringUtilsTest.java index 13a26c3..2b54a73 100644 --- a/src/test/java/org/openrewrite/codehaus/plexus/PlexusStringUtilsTest.java +++ b/src/test/java/org/openrewrite/codehaus/plexus/PlexusStringUtilsTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; +import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -28,7 +29,8 @@ class PlexusStringUtilsTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.parser(JavaParser.fromJavaVersion().classpath("plexus-utils")) + spec + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "plexus-utils")) .recipe(new PlexusStringUtilsRecipes()); } @@ -84,22 +86,22 @@ void bar(String in, CharSequence cs) { String[] array; boolean bool; String string; - + // Test all methods in alphabetical order to only execute the slow recipes once string = in.length() <= 10 ? in : in.substring(0, 10 - 3) + "..."; string = in == null || in.isEmpty() ? in : Character.toTitleCase(in.charAt(0)) + in.substring(1); string = Objects.toString(in, ""); string = Objects.toString(in, "nil"); string = in.replaceAll("\\\\s+", ""); - + bool = in == null ? false : in.equalsIgnoreCase("other"); bool = Objects.equals(in, "other"); //bool = StringUtils.equals(cs, "other"); - + bool = StringUtils.isAlphanumeric(in); bool = StringUtils.isAlpha(in); bool = StringUtils.isEmpty(in); - + string = in == null ? null : in.toLowerCase(); string = in == null || in.isEmpty() ? in : in.replace("search", "replacement"); string = in == null ? null : new StringBuilder(in).reverse().toString();