diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/DependencyChangeHandlerTest.java b/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/DependencyChangeHandlerTest.java index a6750ce95..c47f66c7b 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/DependencyChangeHandlerTest.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/DependencyChangeHandlerTest.java @@ -27,8 +27,6 @@ import org.springframework.sbm.parsers.JavaParserBuilder; import org.springframework.sbm.project.resource.TestProjectContext; -import static org.junit.jupiter.api.Assertions.*; - /** * @author Fabian Krüger */ diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/project/buildfile/OpenRewriteMavenBuildFileTest.java b/components/sbm-core/src/test/java/org/springframework/sbm/project/buildfile/OpenRewriteMavenBuildFileTest.java index 5242a80b4..e5f4da830 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/project/buildfile/OpenRewriteMavenBuildFileTest.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/project/buildfile/OpenRewriteMavenBuildFileTest.java @@ -35,10 +35,8 @@ import org.springframework.sbm.java.api.Member; import org.springframework.sbm.java.impl.DependenciesChangedEventHandler; import org.springframework.sbm.java.impl.DependencyChangeHandler; -import org.springframework.sbm.java.impl.RewriteJavaParser; import org.springframework.sbm.parsers.RewriteExecutionContext; import org.springframework.sbm.parsers.JavaParserBuilder; -import org.springframework.sbm.project.resource.SbmApplicationProperties; import org.springframework.sbm.project.resource.TestProjectContext; import java.nio.file.Path; diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ActuatorEndpointsSanitizationHelperTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ActuatorEndpointsSanitizationHelperTest.java index 3867150e1..773cf24cb 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ActuatorEndpointsSanitizationHelperTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ActuatorEndpointsSanitizationHelperTest.java @@ -15,15 +15,12 @@ */ package org.springframework.sbm.boot.upgrade_27_30.report.helper; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.sbm.build.util.PomBuilder; import org.springframework.sbm.engine.context.ProjectContext; import org.springframework.sbm.project.resource.TestProjectContext; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; /** * @author Fabian Krüger diff --git a/sbm-support-rewrite/src/test/java/org/openrewrite/maven/MavenParserTest.java b/sbm-support-rewrite/src/test/java/org/openrewrite/maven/MavenParserTest.java index 758cbec33..0ba773d8e 100644 --- a/sbm-support-rewrite/src/test/java/org/openrewrite/maven/MavenParserTest.java +++ b/sbm-support-rewrite/src/test/java/org/openrewrite/maven/MavenParserTest.java @@ -15,14 +15,26 @@ */ package org.openrewrite.maven; +import org.intellij.lang.annotations.Language; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.SourceFile; +import org.openrewrite.maven.cache.LocalMavenArtifactCache; +import org.openrewrite.maven.cache.ReadOnlyLocalMavenArtifactCache; +import org.openrewrite.maven.internal.MavenPomDownloader; +import org.openrewrite.maven.tree.MavenResolutionResult; +import org.openrewrite.maven.tree.ResolvedDependency; +import org.openrewrite.maven.tree.Scope; +import org.openrewrite.maven.utilities.MavenArtifactDownloader; +import org.springframework.sbm.parsers.maven.RewriteMavenArtifactDownloader; import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -33,6 +45,63 @@ * @author Fabian Krüger */ public class MavenParserTest { + + @Test + @DisplayName("parse pom with relocated dependency") + void parsePomWithRelocatedDependency() { + @Language("xml") + String pom = """ + + + 4.0.0 + + com.acme + app + 0.1.0-SNAPSHOT + + + + mysql + mysql-connector-java + 8.0.33 + + + + """; + + List parse = MavenParser.builder().build().parse(pom).toList(); + assertThat(parse).isNotNull(); + +// MavenArtifactDownloader mavenArtifactDownloader = new MavenArtifactDownloader(new ReadOnlyLocalMavenArtifactCache(Path.of(System.getProperty("user.home")).resolve(".m2/repository")), null, e -> { +// throw new RuntimeException(e); +// }); + + MavenResolutionResult mavenResolutionResult = parse.get(0).getMarkers().findFirst(MavenResolutionResult.class).get(); + List resolvedDependencies = mavenResolutionResult.getDependencies().get(Scope.Compile); + + MavenArtifactDownloader mavenArtifactDownloader = new RewriteMavenArtifactDownloader( + new LocalMavenArtifactCache(Paths.get(System.getProperty("user.home"), ".m2", "repository")) + .orElse( + new LocalMavenArtifactCache(Paths.get(System.getProperty("user.home"), ".rewrite", "cache", "artifacts") + ) + ), + null, + t -> {throw new RuntimeException(t);} + ); + List list = resolvedDependencies + // FIXME: 945 - deal with dependencies to projects in reactor + // + .stream() + .filter(rd -> rd.getRepository() != null) + .map(rd -> mavenArtifactDownloader.downloadArtifact(rd)) + .filter(Objects::nonNull) + .distinct() + .toList(); + + assertThat(list).isNotNull(); + } + @Test @DisplayName("Should Read .mvn/maven.config") @ExpectedToFail("See https://github.com/openrewrite/rewrite/issues/3409") diff --git a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserParityTest.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserParityTest.java index fe30cc39e..143073a8f 100644 --- a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserParityTest.java +++ b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserParityTest.java @@ -59,6 +59,38 @@ */ class RewriteProjectParserParityTest { + @Test + @DisplayName("pom") + void pom(@TempDir Path tempDir) { + + @Language("xml") + String pom = """ + + + 4.0.0 + + com.acme + app + 0.1.0-SNAPSHOT + + + + mysql + mysql-connector-java + 8.0.33 + + + + """; + TestProjectHelper.createTestProject(tempDir).withResources(new DummyResource(tempDir.resolve("pom.xml"), pom)).writeToFilesystem(); + ParserParityTestHelper + .scanProjectDir(tempDir) + .parseSequentially() + .verifyParity(); + + } + @Test @DisplayName("Parsing Simplistic Maven Project ") void parsingSimplisticMavenProject(@TempDir Path tempDir) throws GitAPIException { diff --git a/sbm-support-rewrite/src/test/java/org/springframework/sbm/test/util/ParserParityTestHelper.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/test/util/ParserParityTestHelper.java index 447b3920c..817f6ba93 100644 --- a/sbm-support-rewrite/src/test/java/org/springframework/sbm/test/util/ParserParityTestHelper.java +++ b/sbm-support-rewrite/src/test/java/org/springframework/sbm/test/util/ParserParityTestHelper.java @@ -30,6 +30,7 @@ import org.openrewrite.style.Style; import org.springframework.sbm.parsers.ParserProperties; import org.springframework.sbm.parsers.RewriteProjectParsingResult; +import org.springframework.util.StopWatch; import java.net.URI; import java.net.URISyntaxException; @@ -100,7 +101,15 @@ public void verifyParity(CustomParserResultParityChecker customParserResultParit expectedParserResult = result.expectedParsingResult(); actualParserResult = result.actualParsingResult(); } else { + StopWatch sw1 = new StopWatch("Parsers"); + sw1.start("actual"); actualParserResult = parserExecutionHelper.parseWithRewriteProjectParser(baseDir, parserProperties); + sw1.stop(); + System.out.println(sw1.shortSummary()); + + sw1.start("expectd"); + sw1.stop(); + System.out.println(sw1.shortSummary()); expectedParserResult = parserExecutionHelper.parseWithComparingParser(baseDir, parserProperties, executionContext); }