diff --git a/.github/workflows/mvn-build.yml b/.github/workflows/mvn-build.yml index 7cb090905..80c0405c7 100644 --- a/.github/workflows/mvn-build.yml +++ b/.github/workflows/mvn-build.yml @@ -16,5 +16,6 @@ jobs: with: java-version: '11' distribution: 'adopt' + cache: 'maven' - name: Build with Maven run: mvn --update-snapshots -DtrimStackTrace=false -Dsurefire.useFile=false -DskipITs verify \ No newline at end of file diff --git a/components/sbm-core/pom.xml b/components/sbm-core/pom.xml index 6f05a8e1f..a2591f3b4 100644 --- a/components/sbm-core/pom.xml +++ b/components/sbm-core/pom.xml @@ -138,6 +138,10 @@ com.fasterxml.jackson.dataformat jackson-dataformat-yaml + + com.squareup.okhttp3 + okhttp + org.springframework.sbm diff --git a/components/sbm-core/src/main/java/org/springframework/sbm/build/impl/RewriteMavenArtifactDownloader.java b/components/sbm-core/src/main/java/org/springframework/sbm/build/impl/RewriteMavenArtifactDownloader.java index 9b59a4a1d..6d4e772fa 100644 --- a/components/sbm-core/src/main/java/org/springframework/sbm/build/impl/RewriteMavenArtifactDownloader.java +++ b/components/sbm-core/src/main/java/org/springframework/sbm/build/impl/RewriteMavenArtifactDownloader.java @@ -17,8 +17,12 @@ import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.XSlf4j; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; import org.openrewrite.internal.lang.Nullable; import org.openrewrite.ipc.http.HttpSender; +import org.openrewrite.ipc.http.OkHttpSender; import org.openrewrite.maven.MavenSettings; import org.openrewrite.maven.cache.LocalMavenArtifactCache; import org.openrewrite.maven.cache.MavenArtifactCache; @@ -27,6 +31,7 @@ import org.springframework.stereotype.Component; import java.nio.file.Paths; +import java.util.concurrent.TimeUnit; import java.util.function.Consumer; @Slf4j @@ -40,6 +45,13 @@ public RewriteMavenArtifactDownloader() { new LocalMavenArtifactCache(Paths.get(System.getProperty("user.home"), ".rewrite", "cache", "artifacts")) ), null, + new OkHttpSender( + new OkHttpClient.Builder() + .retryOnConnectionFailure(true) + .connectTimeout(1, TimeUnit.SECONDS) + .readTimeout(2, TimeUnit.SECONDS) + .build() + ), (t) -> log.error("Error while downloading dependencies", t) ); diff --git a/components/sbm-core/src/main/java/org/springframework/sbm/project/parser/MavenProjectParser.java b/components/sbm-core/src/main/java/org/springframework/sbm/project/parser/MavenProjectParser.java index ae3c41e50..a398cbe0a 100644 --- a/components/sbm-core/src/main/java/org/springframework/sbm/project/parser/MavenProjectParser.java +++ b/components/sbm-core/src/main/java/org/springframework/sbm/project/parser/MavenProjectParser.java @@ -147,14 +147,20 @@ public List parse(Path projectDirectory, List resources) { Path.of("src/main/mule") ); - // FIXME: mainSourceSetMarker and provenance marker needs to be a dde to all resources + // FIXME: mainSourceSetMarker and provenance marker must be added to all resources + List resourceList = resourceParser.filter(projectDirectory, mainResourcePaths, resources, relativeModuleDir); - List mainResources = resourceParser.parse(projectDirectory, mainResourcePaths, resources); + List resourceMarker = new ArrayList(javaProvenanceMarkers); + resourceMarker.add(mainSourceSet); + resourceMarker.add(gitProvenance); + List mainResources = resourceParser.parse(projectDirectory, resourceList, resourceMarker); sourceFiles.addAll(mainResources); // ------- // Test Java sources - List testJavaSources = parseTestJavaSources(projectDirectory, resources, ctx, javaParser, pomXml, mavenWithMarkers, mavenProjectDirectory, javaProvenanceMarkers); + ArrayList markers = new ArrayList<>(javaProvenanceMarkers); + markers.add(mainSourceSet); + List testJavaSources = parseTestJavaSources(projectDirectory, resources, ctx, javaParser, pomXml, mavenWithMarkers, mavenProjectDirectory, markers); JavaSourceSet testSourceSet = javaParser.getSourceSet(ctx); sourceFiles.addAll(testJavaSources); @@ -166,9 +172,11 @@ public List parse(Path projectDirectory, List resources) { Path.of("src/test/mule") ); - // FIXME: mainSourceSetMarker and provenance marker needs to be a dde to all resources - - List testResources = resourceParser.parse(projectDirectory, testResourcePaths, resources); + List filteredResources = resourceParser.filter(projectDirectory, testResourcePaths, resources, relativeModuleDir); + List testResourceMarker = new ArrayList(javaProvenanceMarkers); + testResourceMarker.add(testSourceSet); + testResourceMarker.add(gitProvenance); + List testResources = resourceParser.parse(projectDirectory, filteredResources, testResourceMarker); sourceFiles.addAll(testResources); // @@ -270,8 +278,7 @@ private List parseTestJavaSources(Path projectDirectory, List }).collect(Collectors.toList()); List testCompilationUnits = javaParser.parseInputs(testJavaSourcesInput, projectDirectory, ctx); // FIXME: #7 JavaParser and adding markers is required when adding java sources and should go into dedicated component - testCompilationUnits.stream() - .forEach(cu -> cu.getMarkers().getMarkers().addAll(javaProvenanceMarkers)); + testCompilationUnits.forEach(cu -> cu.getMarkers().getMarkers().addAll(javaProvenanceMarkers)); return testCompilationUnits; } diff --git a/components/sbm-core/src/main/java/org/springframework/sbm/project/parser/ResourceParser.java b/components/sbm-core/src/main/java/org/springframework/sbm/project/parser/ResourceParser.java index 5c9cecb26..1a6627710 100644 --- a/components/sbm-core/src/main/java/org/springframework/sbm/project/parser/ResourceParser.java +++ b/components/sbm-core/src/main/java/org/springframework/sbm/project/parser/ResourceParser.java @@ -21,11 +21,14 @@ import org.openrewrite.SourceFile; import org.openrewrite.hcl.HclParser; import org.openrewrite.json.JsonParser; +import org.openrewrite.marker.Marker; +import org.openrewrite.marker.Markers; import org.openrewrite.properties.PropertiesParser; import org.openrewrite.protobuf.ProtoParser; import org.openrewrite.text.PlainTextParser; import org.openrewrite.tree.ParsingExecutionContextView; import org.openrewrite.xml.XmlParser; +import org.openrewrite.xml.tree.Xml; import org.openrewrite.yaml.YamlParser; import org.springframework.context.ApplicationEventPublisher; import org.springframework.core.io.Resource; @@ -52,37 +55,10 @@ public class ResourceParser { private final ResourceFilter resourceFilter; private final ApplicationEventPublisher eventPublisher; - public List parse(Path baseDir, Set resourcePaths, List resources) { - ParsingExecutionContextView ctx = ParsingExecutionContextView.view(new RewriteExecutionContext(eventPublisher)); - ctx.setParsingListener((input, sourceFile) -> eventPublisher.publishEvent(new StartedScanningProjectResourceEvent(sourceFile.getSourcePath()))); - - List relevantResources = resourceFilter.filter(resources, baseDir, resourcePaths); - - HashMap, List> parserAndParserInputMappings = new LinkedHashMap(); - parserAndParserInputMappings.put(jsonParser, new ArrayList<>()); - parserAndParserInputMappings.put(xmlParser, new ArrayList<>()); - parserAndParserInputMappings.put(yamlParser, new ArrayList<>()); - parserAndParserInputMappings.put(propertiesParser, new ArrayList<>()); - parserAndParserInputMappings.put(new ProtoParser(), new ArrayList<>()); - parserAndParserInputMappings.put(HclParser.builder().build(), new ArrayList<>()); - parserAndParserInputMappings.put(plainTextParser, new ArrayList<>()); - - List parserInputs = createParserInputs(relevantResources); - - parserInputs.forEach(r -> { - Parser parser = parserAndParserInputMappings.keySet().stream() - .filter(p -> p.accept(r)) - .findFirst() - .orElseThrow(() -> new RuntimeException("Could not find matching parser for " + r.getPath())); - - parserAndParserInputMappings.get(parser).add(r); - }); - - return parserAndParserInputMappings.entrySet().stream() - .map(e -> e.getKey().parseInputs(e.getValue(), baseDir, ctx)) - .flatMap(List::stream) - .collect(Collectors.toList()); - + List filter(Path projectDirectory, Set resourcePaths, List resources, Path relativeModuleDir) { + Path comparingPath = relativeModuleDir != null ? projectDirectory.resolve(relativeModuleDir) : projectDirectory; + List relevantResources = resourceFilter.filter(resources, comparingPath, resourcePaths); + return relevantResources; } private List createParserInputs(List relevantResources) { @@ -114,6 +90,42 @@ private InputStream getInputStream(Resource r) { } } + public List parse(Path baseDir, List relevantResources, List markers) { + List parserInputs = createParserInputs(relevantResources); + + HashMap, List> parserAndParserInputMappings = new LinkedHashMap(); + parserAndParserInputMappings.put(jsonParser, new ArrayList<>()); + parserAndParserInputMappings.put(xmlParser, new ArrayList<>()); + parserAndParserInputMappings.put(yamlParser, new ArrayList<>()); + parserAndParserInputMappings.put(propertiesParser, new ArrayList<>()); + parserAndParserInputMappings.put(new ProtoParser(), new ArrayList<>()); + parserAndParserInputMappings.put(HclParser.builder().build(), new ArrayList<>()); + parserAndParserInputMappings.put(plainTextParser, new ArrayList<>()); + + parserInputs.forEach(r -> { + Parser parser = parserAndParserInputMappings.keySet().stream() + .filter(p -> p.accept(r)) + .findFirst() + .orElseThrow(() -> new RuntimeException("Could not find matching parser for " + r.getPath())); + + parserAndParserInputMappings.get(parser).add(r); + }); + + ParsingExecutionContextView ctx = ParsingExecutionContextView.view(new RewriteExecutionContext(eventPublisher)); + ctx.setParsingListener((input, sourceFile) -> eventPublisher.publishEvent(new StartedScanningProjectResourceEvent(sourceFile.getSourcePath()))); + + return parserAndParserInputMappings.entrySet().stream() + .map(e -> e.getKey().parseInputs(e.getValue(), baseDir, ctx)) + .flatMap(List::stream) + .map(e -> addMarkers(e, markers)) + .collect(Collectors.toList()); + + } + + private SourceFile addMarkers(SourceFile e, List markers) { + return e.withMarkers(Markers.build(markers)); + } + @Component public static class ResourceFilter { private List filter(List resources, Path moduleDir, Set searchDirs) { diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/OpenRewriteMethodTest.java b/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/OpenRewriteMethodTest.java index 2270ee95d..9aa64e717 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/OpenRewriteMethodTest.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/OpenRewriteMethodTest.java @@ -144,19 +144,19 @@ void testRemoveAnnotation() { void removeMethodAnnotationsFromDependency() { String given = "import javax.ejb.*;\n" + - "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + - "public class TransactionalService {\n" + - " @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + - " public void notSupported() {}\n" + - "}"; + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class TransactionalService {\n" + + " @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + " public void notSupported() {}\n" + + "}"; String expected = "import javax.ejb.*;\n" + - "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + - "public class TransactionalService {\n" + - " \n" + - " public void notSupported() {}\n" + - "}"; + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class TransactionalService {\n" + + " \n" + + " public void notSupported() {}\n" + + "}"; JavaSource javaSource = TestProjectContext.buildProjectContext() .withBuildFileHavingDependencies("javax.ejb:javax.ejb-api:3.2", "org.springframework.data:spring-data-jpa:2.6.1") diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/project/parser/ProjectContextInitializerTest.java b/components/sbm-core/src/test/java/org/springframework/sbm/project/parser/ProjectContextInitializerTest.java index 1b43bfaa9..db2fc1a02 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/project/parser/ProjectContextInitializerTest.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/project/parser/ProjectContextInitializerTest.java @@ -42,10 +42,12 @@ import org.springframework.sbm.engine.context.ProjectRootPathResolver; import org.springframework.sbm.engine.git.GitSupport; import org.springframework.sbm.engine.precondition.PreconditionVerifier; +import org.springframework.sbm.java.impl.RewriteJavaParser; import org.springframework.sbm.java.refactoring.JavaRefactoringFactoryImpl; import org.springframework.sbm.java.util.BasePackageCalculator; import org.springframework.sbm.openrewrite.RewriteExecutionContext; import org.springframework.sbm.project.resource.*; +import org.springframework.sbm.properties.parser.RewritePropertiesParser; import org.springframework.sbm.xml.parser.RewriteXmlParser; import org.springframework.util.FileSystemUtils; @@ -58,12 +60,8 @@ import static org.mockito.Mockito.mock; import static org.springframework.sbm.project.parser.ResourceVerifierTestHelper.*; - @SpringBootTest(classes = { - ResourceParser.class, ProjectContextInitializer.class, - MavenProjectParser.class, - RewriteMavenParser.class, RewriteMavenArtifactDownloader.class, JavaProvenanceMarkerFactory.class, BasePackageCalculator.class, @@ -73,8 +71,16 @@ ProjectContextFactory.class, RewriteMavenParserFactory.class, // FIXME: #7 remove class MavenPomCacheProvider.class, - PathScanner.class, SbmApplicationProperties.class, + PathScanner.class, + RewriteJavaParser.class, + RewritePlainTextParser.class, + RewriteYamlParser.class, + RewriteJsonParser.class, + ResourceParser.class, + RewritePropertiesParser.class, + MavenProjectParser.class, + RewriteMavenParser.class, RewriteXmlParser.class, ResourceHelper.class, ResourceLoader.class, @@ -118,13 +124,13 @@ void test() { assertThat(projectDirectory.toAbsolutePath().resolve(".git")).exists(); - assertThat(projectResources).hasSize(18); + assertThat(projectResources).hasSize(19); verifyResource("testcode/pom.xml").wrapsInstanceOf(Xml.Document.class); verifyIgnored(projectResources, "testcode/path-scanner/.git"); verifyResource("testcode/path-scanner/pom.xml") - .wrapsInstanceOf(Maven.class) + .wrapsInstanceOf(Xml.Document.class) .havingMarkers( mavenResolutionResult(null, "com.example:example-project-parent:1.0.0-SNAPSHOT", List.of( @@ -140,7 +146,7 @@ void test() { .isContainedIn(projectResources); verifyResource("testcode/path-scanner/module1/pom.xml") - .wrapsInstanceOf(Maven.class) + .wrapsInstanceOf(Xml.Document.class) .havingMarkers( mavenResolutionResult( "com.example:example-project-parent:1.0.0-SNAPSHOT", @@ -166,7 +172,6 @@ void test() { buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), gitProvenanceMarker("master") ) .isContainedIn(projectResources); @@ -177,10 +182,10 @@ void test() { buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), + javaSourceSetMarker("main", 1903), gitProvenanceMarker("master") ) - .isContainedIn(projectResources); + .isContainedIn(projectResources); verifyResource("testcode/path-scanner/module1/src/main/resources/some.xml") .wrapsInstanceOf(Xml.Document.class) @@ -188,7 +193,7 @@ void test() { buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), + javaSourceSetMarker("main", 1903), gitProvenanceMarker("master") ) .isContainedIn(projectResources); @@ -199,7 +204,7 @@ void test() { buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), + javaSourceSetMarker("main", 1903), gitProvenanceMarker("master") ) .isContainedIn(projectResources); @@ -210,7 +215,7 @@ void test() { buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), + javaSourceSetMarker("main", 1903), gitProvenanceMarker("master") ) .isContainedIn(projectResources); @@ -221,7 +226,7 @@ void test() { buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), + javaSourceSetMarker("main", 1903), gitProvenanceMarker("master") ) .isContainedIn(projectResources); @@ -232,7 +237,7 @@ void test() { buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), + javaSourceSetMarker("main", 1903), gitProvenanceMarker("master") ) .isContainedIn(projectResources); @@ -242,7 +247,7 @@ void test() { .havingMarkers(buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), + javaSourceSetMarker("main", 1903), gitProvenanceMarker("master") ) .isContainedIn(projectResources); @@ -253,7 +258,7 @@ void test() { buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), + javaSourceSetMarker("main", 1903), gitProvenanceMarker("master") ) .isContainedIn(projectResources); @@ -264,7 +269,7 @@ void test() { buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), + javaSourceSetMarker("main", 1903), gitProvenanceMarker("master") ) .isContainedIn(projectResources); @@ -275,7 +280,7 @@ void test() { buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), + javaSourceSetMarker("main", 1903), gitProvenanceMarker("master") ) .isContainedIn(projectResources); @@ -285,7 +290,7 @@ void test() { .havingMarkers(buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), + javaSourceSetMarker("main", 1903), gitProvenanceMarker("master") ) .isContainedIn(projectResources); @@ -296,14 +301,14 @@ void test() { buildToolMarker("Maven", "3.6"), javaVersionMarker(11, "11", "11"), javaProjectMarker(null, "com.example:module1:1.0.0-SNAPSHOT"), - javaSourceSetMarker("main", ""), + javaSourceSetMarker("main", 1903), gitProvenanceMarker("master") ) .isContainedIn(projectResources); // module2 verifyResource("testcode/path-scanner/module2/pom.xml") - .wrapsInstanceOf(Maven.class) + .wrapsInstanceOf(Xml.Document.class) .havingMarkers( mavenResolutionResult( "com.example:example-project-parent:1.0.0-SNAPSHOT", @@ -355,10 +360,13 @@ private void verifyIgnored(List> p @NotNull private Map> noDependencies() { return Map.of( - Scope.Compile, List.of(), - Scope.Provided, List.of(), - Scope.Test, List.of(), - Scope.Runtime, List.of() + Scope.Compile, List.of(), + Scope.Provided, List.of(), + Scope.Test, List.of(), + Scope.Runtime, List.of() ); } -} \ No newline at end of file +} + + + diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/project/parser/ResourceParserTest.java b/components/sbm-core/src/test/java/org/springframework/sbm/project/parser/ResourceParserTest.java index 7c11bffdd..a740b7995 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/project/parser/ResourceParserTest.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/project/parser/ResourceParserTest.java @@ -26,7 +26,6 @@ import org.openrewrite.SourceFile; import org.openrewrite.text.PlainText; import org.openrewrite.text.PlainTextParser; -import org.openrewrite.tree.ParsingEventListener; import org.openrewrite.tree.ParsingExecutionContextView; import org.springframework.context.ApplicationEventPublisher; import org.springframework.core.io.Resource; @@ -37,9 +36,9 @@ import org.springframework.sbm.xml.parser.RewriteXmlParser; import java.io.ByteArrayInputStream; -import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.concurrent.CountDownLatch; @@ -82,9 +81,9 @@ void beforeEach() { "some.xml,,org.openrewrite.xml.tree.Xml$Document", "some.yaml2,foo:bar,org.openrewrite.text.PlainText", }) - void test(String filename, String content, String className) throws ClassNotFoundException { + void picksMatchingParser(String filename, String content, String className) throws ClassNotFoundException { List resources = getResourceAsList(filename, content); - List parsedResources = sut.parse(baseDir, resourcePaths, resources); + List parsedResources = sut.parse(baseDir, resources, new ArrayList<>()); assertCorrectParsing(filename, content, Class.forName(className), parsedResources); } diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/project/parser/ResourceVerifierTestHelper.java b/components/sbm-core/src/test/java/org/springframework/sbm/project/parser/ResourceVerifierTestHelper.java index 37ea4bc33..991539af7 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/project/parser/ResourceVerifierTestHelper.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/project/parser/ResourceVerifierTestHelper.java @@ -85,6 +85,10 @@ public static MarkerVerifier javaSourceSetMarker(String name, String classpath) return new JavaSourceSetMarkersVerifier(name, classpath); } + public static MarkerVerifier javaSourceSetMarker(String name, int numTypes) { + return new JavaSourceSetMarkersVerifier(name, numTypes); + } + public static MarkerVerifier gitProvenanceMarker(String branch) { return new GitProvenanceMarkerVerifier(branch); } @@ -109,9 +113,16 @@ void isContainedIn(List> projectRe this.markerVerifer.forEach(v -> v.check(rewriteSourceFileHolder)); - assertThat(rewriteSourceFileHolder.getSourceFile().getMarkers().getMarkers()) - .as("Invalid number of markers for resource '%s'. Expected '%s' but found '%s'", rewriteSourceFileHolder, markerVerifer.size(), rewriteSourceFileHolder.getSourceFile().getMarkers().getMarkers().size()) - .hasSize(markerVerifer.size()); + List markers = rewriteSourceFileHolder.getSourceFile().getMarkers().getMarkers(); + int size = markerVerifer.size(); + int actualSize = markers.size(); + assertThat(markers.size()) + .as(() -> + { + String format = String.format("Invalid number of markers for resource '%s'. Expected '%d' but found '%d', '%s'", rewriteSourceFileHolder.getAbsolutePath().toString(), size, actualSize, markers.stream().map(m -> m.getClass().getName()).collect(Collectors.joining("', \n'"))); + return format; + }) + .isSameAs(markerVerifer.size()); } @@ -146,11 +157,11 @@ public void check(RewriteSourceFileHolder rewriteSourceFileHolder) { @Override public void assertMarker(SourceFile sourceFile, BuildTool marker) { assertThat(marker.getType().name()) - .as("Invalid marker [BuildTool] for resource '%s'. Expected name to be '%s' but was '%s'", sourceFile, name, marker.getType().name()) + .as("Invalid marker [BuildTool] for resource '%s'. Expected name to be '%s' but was '%s'", sourceFile.getSourcePath().toString(), name, marker.getType().name()) .isEqualTo(name); assertThat(marker.getVersion()) - .as("Invalid marker [BuildTool] for resource '%s'. Expected version to be '%s' but was '%s'", sourceFile, version, marker.getVersion()) + .as("Invalid marker [BuildTool] for resource '%s'. Expected version to be '%s' but was '%s'", sourceFile.getSourcePath().toString(), version, marker.getVersion()) .isEqualTo(version); } @@ -181,15 +192,15 @@ public void check(RewriteSourceFileHolder rewriteSourceFileHolder) { @Override public void assertMarker(SourceFile sourceFile, JavaVersion marker) { assertThat(marker.getCreatedBy()) - .as("Invalid marker [JavaVersion] for resource '%s'. Expected targetCompatibility to be '%s' but was '%s'", sourceFile, version, marker.getSourceCompatibility()) + .as("Invalid marker [JavaVersion] for resource '%s'. Expected targetCompatibility to be '%s' but was '%s'", sourceFile.getSourcePath().toString(), version, marker.getSourceCompatibility()) .startsWith(Integer.toString(version)); assertThat(marker.getSourceCompatibility()) - .as("Invalid marker [JavaVersion] for resource '%s'. Expected sourceCompatibility to be '%s' but was '%s'", sourceFile, source, marker.getSourceCompatibility()) + .as("Invalid marker [JavaVersion] for resource '%s'. Expected sourceCompatibility to be '%s' but was '%s'", sourceFile.getSourcePath().toString(), source, marker.getSourceCompatibility()) .isEqualTo(source); assertThat(marker.getTargetCompatibility()) - .as("Invalid marker [JavaVersion] for resource '%s'. Expected targetCompatibility to be '%s' but was '%s'", sourceFile, target, marker.getSourceCompatibility()) + .as("Invalid marker [JavaVersion] for resource '%s'. Expected targetCompatibility to be '%s' but was '%s'", sourceFile.getSourcePath().toString(), target, marker.getSourceCompatibility()) .isEqualTo(target); } @@ -230,12 +241,20 @@ public void assertMarkers(SourceFile rewriteSourceFileHolder, List private static class JavaSourceSetMarkersVerifier implements MarkerVerifier { private final String name; private final String classpath; + private final Integer numTypes; public JavaSourceSetMarkersVerifier(String name, String classpathPattern) { this.name = name; + this.numTypes = null; this.classpath = classpathPattern; } + public JavaSourceSetMarkersVerifier(String name, int numTypes) { + this.name = name; + this.numTypes = numTypes; + this.classpath = null; + } + @Override public void check(RewriteSourceFileHolder rewriteSourceFileHolder) { List javaSourceSetMarker = getMarkers(rewriteSourceFileHolder, JavaSourceSet.class); @@ -250,22 +269,25 @@ public void assertMarker(SourceFile sourceFile, JavaSourceSet marker) { @Override public void assertMarkers(SourceFile rewriteSourceFileHolder, List javaSourceSetMarker) { assertThat(javaSourceSetMarker).filteredOn(js -> name.equals(js.getName())) - .as("Invalid marker [JavaSourceSet] for resource '%s'. Expected name to be '%s' but no Marker with this name was found.", rewriteSourceFileHolder, name) + .as("Invalid marker [JavaSourceSet] for resource '%s'. Expected name to be '%s' but no Marker with this name was found.", rewriteSourceFileHolder.getSourcePath().toString(), name) .isNotEmpty(); - List dependencies = javaSourceSetMarker.stream().filter(js -> "main".equals(js.getName())) + List dependencies = javaSourceSetMarker.stream().filter(js -> name.equals(js.getName())) .flatMap(js -> js.getClasspath().stream()) .map(fq -> fq.getFullyQualifiedName()) .collect(Collectors.toList()); - String[] split = classpath.split(", "); - if (classpath.equals("")) { - dependencies.add(""); + if(classpath != null && !classpath.isEmpty()) { + String[] split = classpath.split(", "); + assertThat(dependencies) + .as("Invalid marker [JavaSourceSet] for resource '%s'. Expected dependencies to be '%s' but was '%s'", rewriteSourceFileHolder.getSourcePath().toString(), classpath, dependencies) + .contains(split); + } else if(numTypes != null) { + assertThat(dependencies) + .as("Invalid marker [JavaSourceSet] for resource '%s'. Expected dependencies to be of size '%d' but was '%d'", rewriteSourceFileHolder.getSourcePath().toString(), numTypes, dependencies.size()) + .hasSize(numTypes); } - assertThat(dependencies) - .as("Invalid marker [JavaSourceSet] for resource '%s'. Expected dependencies to be '%s' but was '%s'", rewriteSourceFileHolder, classpath, dependencies) - .contains(split); } } @@ -280,14 +302,13 @@ public GitProvenanceMarkerVerifier(String branch) { @Override public void check(RewriteSourceFileHolder rewriteSourceFileHolder) { GitProvenance gitProvenanceMarker = getFirstMarker(rewriteSourceFileHolder, GitProvenance.class); - - + assertMarker(rewriteSourceFileHolder.getSourceFile(), gitProvenanceMarker); } @Override public void assertMarker(SourceFile sourceFile, GitProvenance marker) { assertThat(marker.getBranch()) - .as("Invalid marker [GitProvenance] for resource '%s'. Expected branch to be '%s' but was '%s'", sourceFile, branch, marker.getBranch()) + .as("Invalid marker [GitProvenance] for resource '%s'. Expected branch to be '%s' but was '%s'", sourceFile.getSourcePath().toString(), branch, marker.getBranch()) .isEqualTo(branch); } @@ -335,8 +356,8 @@ public void assertMarker(Xml.Document mavenModel, MavenResolutionResult marker) ) ); - assertThat(dependenciesGav).containsExactlyInAnyOrderEntriesOf(dependencies); - assertThat(coordinate).isEqualTo(coordinate); + assertThat(dependenciesGav).containsExactlyInAnyOrderEntriesOf(this.dependencies); + assertThat(coordinate).isEqualTo(this.coordinate); } @Override @@ -364,7 +385,7 @@ public void assertMarker(Xml.Document sourceFile, MavenResolutionResult marker) List modulesList = marker.getModules().stream().map(m -> m.getPom().getGav().toString()).collect(Collectors.toList()); assertThat(modulesList) - .as("Invalid marker [Modules] for resource '%s'. Expected modules to be '%s' but was '%s'", sourceFile, modules, modulesList) + .as("Invalid marker [Modules] for resource '%s'. Expected modules to be '%s' but was '%s'", sourceFile.getSourcePath().toString(), modules, modulesList) .containsExactlyInAnyOrder(modules); } diff --git a/components/sbm-core/testcode/path-scanner/module1/pom.xml b/components/sbm-core/testcode/path-scanner/module1/pom.xml index 36b4aa9cb..7a3dbcf85 100644 --- a/components/sbm-core/testcode/path-scanner/module1/pom.xml +++ b/components/sbm-core/testcode/path-scanner/module1/pom.xml @@ -31,4 +31,13 @@ 11 + + + org.jetbrains + annotations + 23.0.0 + test + + + \ No newline at end of file diff --git a/components/sbm-core/testcode/path-scanner/module1/src/main/resources/META-INF/spring.factories b/components/sbm-core/testcode/path-scanner/module1/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..67d9b2715 --- /dev/null +++ b/components/sbm-core/testcode/path-scanner/module1/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +a.b.c.Foo=a.ba.c.FooImpl \ No newline at end of file diff --git a/components/sbm-recipes-mule-to-boot/src/test/java/org/springframework/sbm/mule/actions/wmq/MuleToJavaDSLWmqTest.java b/components/sbm-recipes-mule-to-boot/src/test/java/org/springframework/sbm/mule/actions/wmq/MuleToJavaDSLWmqTest.java index 449122887..02e7a216e 100644 --- a/components/sbm-recipes-mule-to-boot/src/test/java/org/springframework/sbm/mule/actions/wmq/MuleToJavaDSLWmqTest.java +++ b/components/sbm-recipes-mule-to-boot/src/test/java/org/springframework/sbm/mule/actions/wmq/MuleToJavaDSLWmqTest.java @@ -16,6 +16,7 @@ package org.springframework.sbm.mule.actions.wmq; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openrewrite.SourceFile; import org.springframework.sbm.build.api.Dependency; @@ -27,6 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat; +@Disabled("FIXME: https://github.com/spring-projects-experimental/spring-boot-migrator/issues/195") public class MuleToJavaDSLWmqTest extends JavaDSLActionBaseTest { private final static String muleXml = "\n" +