|
15 | 15 | */
|
16 | 16 | package org.springframework.sbm.java;
|
17 | 17 |
|
18 |
| -import org.jboss.shrinkwrap.resolver.api.maven.Maven; |
| 18 | +import org.assertj.core.api.Assertions; |
19 | 19 | import org.openrewrite.*;
|
20 | 20 | import org.openrewrite.internal.InMemoryLargeSourceSet;
|
21 |
| -import org.springframework.sbm.java.util.JavaSourceUtil; |
22 |
| -import org.springframework.sbm.testhelper.common.utils.TestDiff; |
23 |
| -import org.assertj.core.api.Assertions; |
24 | 21 | import org.openrewrite.java.JavaIsoVisitor;
|
25 | 22 | import org.openrewrite.java.JavaParser;
|
26 | 23 | import org.openrewrite.java.JavaVisitor;
|
27 | 24 | import org.openrewrite.java.tree.J;
|
| 25 | +import org.openrewrite.maven.cache.LocalMavenArtifactCache; |
| 26 | +import org.openrewrite.maven.tree.ResolvedDependency; |
| 27 | +import org.openrewrite.maven.tree.ResolvedGroupArtifactVersion; |
| 28 | +import org.openrewrite.maven.utilities.MavenArtifactDownloader; |
| 29 | +import org.springframework.sbm.java.util.JavaSourceUtil; |
| 30 | +import org.springframework.sbm.testhelper.common.utils.TestDiff; |
28 | 31 |
|
29 | 32 | import java.io.File;
|
30 | 33 | import java.nio.file.Path;
|
|
36 | 39 | import java.util.stream.Collectors;
|
37 | 40 | import java.util.stream.Stream;
|
38 | 41 |
|
39 |
| -import static org.junit.jupiter.api.Assertions.fail; |
| 42 | +import static org.junit.jupiter.api.AssertionsKt.fail; |
40 | 43 |
|
41 | 44 |
|
42 | 45 | public class OpenRewriteTestSupport {
|
@@ -235,16 +238,27 @@ public static JavaParser.Builder getJavaParser(String... classpath) {
|
235 | 238 | }
|
236 | 239 |
|
237 | 240 | /**
|
238 |
| - * Retrieve the <code>Path</code>s of jars for given classpath |
| 241 | + * Retrieve the <code>Path</code>s of jars for given gav |
239 | 242 | *
|
240 |
| - * @param classpath in 'groupId:artifactId:version' format |
| 243 | + * @param gav in 'groupId:artifactId:version' format |
241 | 244 | */
|
242 |
| - public static List<Path> getClasspathFiles(String... classpath) { |
243 |
| - if (classpath.length == 0) return List.of(); |
244 |
| - File[] as = Maven.resolver().resolve(classpath).withTransitivity().as(File.class); |
245 |
| - return Arrays.stream(as) |
246 |
| - .map(File::toPath) |
247 |
| - .collect(Collectors.toList()); |
| 245 | + public static List<Path> getClasspathFiles(String... gav) { |
| 246 | + if (gav.length == 0) return List.of(); |
| 247 | + Path localM2 = Path.of(System.getProperty("user.home")).resolve(".m2/repository").normalize().toAbsolutePath(); |
| 248 | + MavenArtifactDownloader mavenArtifactDownloader = new MavenArtifactDownloader(new LocalMavenArtifactCache(localM2), null, t -> { |
| 249 | + throw new RuntimeException(t); |
| 250 | + }); |
| 251 | + return Arrays.stream(gav) |
| 252 | + .map(g -> g.split(":")) |
| 253 | + .map(g -> new ResolvedGroupArtifactVersion(null, g[0], g[1], g.length == 3 ? g[2] : null, null)) |
| 254 | + .map(g -> ResolvedDependency.builder() |
| 255 | + .gav(g) |
| 256 | + .build() |
| 257 | + ) |
| 258 | + .map(g -> { |
| 259 | + return mavenArtifactDownloader.downloadArtifact(g); |
| 260 | + }) |
| 261 | + .toList(); |
248 | 262 | }
|
249 | 263 |
|
250 | 264 | private static <P> RecipeRun refactor(J.CompilationUnit given, JavaVisitor<ExecutionContext> visitor) {
|
|
0 commit comments