From 00bb1c2813fd8bfdd222541e0c0052ec448e882a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=BCger?= Date: Mon, 9 Oct 2023 17:10:37 +0200 Subject: [PATCH 1/5] Fix test JavaParser parses sources with compile error --- .../sbm/java/impl/ProjectJavaSourcesImplTest.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/ProjectJavaSourcesImplTest.java b/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/ProjectJavaSourcesImplTest.java index 3b421dc5a..df39557e7 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/ProjectJavaSourcesImplTest.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/ProjectJavaSourcesImplTest.java @@ -17,8 +17,11 @@ import org.intellij.lang.annotations.Language; import org.junit.jupiter.api.Test; +import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.JavaType; import org.springframework.beans.factory.UnsatisfiedDependencyException; import org.springframework.sbm.engine.context.ProjectContext; +import org.springframework.sbm.java.api.JavaSource; import org.springframework.sbm.java.api.JavaSourceAndType; import org.springframework.sbm.project.resource.TestProjectContext; @@ -109,9 +112,9 @@ interface SomeClass extends K { """; - assertThrows(UnsatisfiedDependencyException.class, () -> - TestProjectContext.buildProjectContext().withJavaSources(sourceCode).build() - ).getMessage().contains("src/main/java/a/b/c/SomeClass.java:[2,13] cannot find symbol"); - + ProjectContext projectContext = TestProjectContext.buildProjectContext().withJavaSources(sourceCode).build(); + J.ClassDeclaration javaSource = projectContext.getProjectJavaSources().list().get(0).getResource().getSourceFile().getClasses().get(0); + assertThat(javaSource.getImplements()).hasSize(1); + assertThat(javaSource.getImplements().get(0).getType()).isEqualTo(JavaType.Unknown.getInstance()); } } From b030a9b2a39c8cb61093b2ca9c50d6ea698cf592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=BCger?= Date: Mon, 9 Oct 2023 17:19:27 +0200 Subject: [PATCH 2/5] Revert "Fix test JavaParser parses sources with compile error" This reverts commit 541b2443a4ece053d57f4a85e480367ce7b277ee. --- .../sbm/java/impl/ProjectJavaSourcesImplTest.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/ProjectJavaSourcesImplTest.java b/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/ProjectJavaSourcesImplTest.java index df39557e7..3b421dc5a 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/ProjectJavaSourcesImplTest.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/ProjectJavaSourcesImplTest.java @@ -17,11 +17,8 @@ import org.intellij.lang.annotations.Language; import org.junit.jupiter.api.Test; -import org.openrewrite.java.tree.J; -import org.openrewrite.java.tree.JavaType; import org.springframework.beans.factory.UnsatisfiedDependencyException; import org.springframework.sbm.engine.context.ProjectContext; -import org.springframework.sbm.java.api.JavaSource; import org.springframework.sbm.java.api.JavaSourceAndType; import org.springframework.sbm.project.resource.TestProjectContext; @@ -112,9 +109,9 @@ interface SomeClass extends K { """; - ProjectContext projectContext = TestProjectContext.buildProjectContext().withJavaSources(sourceCode).build(); - J.ClassDeclaration javaSource = projectContext.getProjectJavaSources().list().get(0).getResource().getSourceFile().getClasses().get(0); - assertThat(javaSource.getImplements()).hasSize(1); - assertThat(javaSource.getImplements().get(0).getType()).isEqualTo(JavaType.Unknown.getInstance()); + assertThrows(UnsatisfiedDependencyException.class, () -> + TestProjectContext.buildProjectContext().withJavaSources(sourceCode).build() + ).getMessage().contains("src/main/java/a/b/c/SomeClass.java:[2,13] cannot find symbol"); + } } From 15e4231cc68f5ec4be84e4ca119786b52be4df9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=BCger?= Date: Mon, 9 Oct 2023 17:19:54 +0200 Subject: [PATCH 3/5] Add missing bean --- .../autoconfigure/ProjectResourceSetConfiguration.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/boot/autoconfigure/ProjectResourceSetConfiguration.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/boot/autoconfigure/ProjectResourceSetConfiguration.java index 5020736f7..b27690d78 100644 --- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/boot/autoconfigure/ProjectResourceSetConfiguration.java +++ b/sbm-support-rewrite/src/main/java/org/springframework/sbm/boot/autoconfigure/ProjectResourceSetConfiguration.java @@ -19,10 +19,7 @@ import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.sbm.project.RewriteSourceFileWrapper; -import org.springframework.sbm.project.resource.ProjectResourceSerializer; -import org.springframework.sbm.project.resource.ProjectResourceSetFactory; -import org.springframework.sbm.project.resource.ProjectResourceSetSerializer; -import org.springframework.sbm.project.resource.RewriteMigrationResultMerger; +import org.springframework.sbm.project.resource.*; /** * @author Fabian Krüger @@ -49,6 +46,11 @@ ProjectResourceSetSerializer projectResourceSetSerializer(ProjectResourceSeriali return new ProjectResourceSetSerializer(resourceSerializer); } + @Bean + public ProjectResourceSetHolder projectResourceSetHolder(ExecutionContext executionContext, RewriteMigrationResultMerger rewriteMigrationResultMerger) { + return new ProjectResourceSetHolder(executionContext, rewriteMigrationResultMerger); + } + @Bean ProjectResourceSetFactory projectResourceSetFactory(RewriteMigrationResultMerger rewriteMigrationResultMerger, RewriteSourceFileWrapper sourceFileWrapper, ExecutionContext executionContext) { return new ProjectResourceSetFactory(rewriteMigrationResultMerger, sourceFileWrapper, executionContext); From 5368730c37c9f793b21847c57c270dd68145d4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=BCger?= Date: Mon, 9 Oct 2023 17:20:05 +0200 Subject: [PATCH 4/5] Implement empty method --- .../java/org/springframework/sbm/project/TestDummyResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/project/TestDummyResource.java b/components/sbm-core/src/test/java/org/springframework/sbm/project/TestDummyResource.java index ff0e60835..fadcad3a9 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/project/TestDummyResource.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/project/TestDummyResource.java @@ -62,7 +62,7 @@ private File getFile(TestDummyResource testDummyResource) { @Override public long contentLength() { - throw new UnsupportedOperationException(); + return content.length(); } @Override From 62ab54e3752553ac5033c4c648dee2fbef61e0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=BCger?= Date: Mon, 9 Oct 2023 17:21:55 +0200 Subject: [PATCH 5/5] Expect passing tests in build --- .github/workflows/build-sbm-revamp.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-sbm-revamp.yml b/.github/workflows/build-sbm-revamp.yml index 30599208f..3a8f57fd5 100644 --- a/.github/workflows/build-sbm-revamp.yml +++ b/.github/workflows/build-sbm-revamp.yml @@ -37,8 +37,8 @@ jobs: - name: sbm-openrewrite (build + test) run: mvn --batch-mode install --projects :sbm-openrewrite - - name: sbm-core (build) - run: mvn -DskipTests --batch-mode install --projects :sbm-core + - name: sbm-core (build + test) + run: mvn --batch-mode install --projects :sbm-core - name: recipe-test-support (build) run: mvn -DskipTests --batch-mode install --projects :recipe-test-support