diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartData.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartData.java index 7332137ed3b99..9fd9d3d380c65 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartData.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartData.java @@ -59,18 +59,18 @@ public static Map buildDependenciesData(Stream codest final Set boms = new LinkedHashSet<>(); final Set dependencies = new LinkedHashSet<>(); final Set testDependencies = new LinkedHashSet<>(); - codestartsStream - .flatMap(s -> Stream.of(s.getBaseLanguageSpec(), s.getLanguageSpec(languageName))) - .forEach(d -> { - dependencies.addAll(d.getDependencies()); - testDependencies.addAll(d.getTestDependencies()); - }); platforms.stream() .map(CodestartDep::new) .forEach(boms::add); extensions.stream() .map(CodestartDep::new) .forEach(dependencies::add); + codestartsStream + .flatMap(s -> Stream.of(s.getBaseLanguageSpec(), s.getLanguageSpec(languageName))) + .forEach(d -> { + dependencies.addAll(d.getDependencies()); + testDependencies.addAll(d.getTestDependencies()); + }); depsData.put("dependencies", dependencies); depsData.put("boms", boms); depsData.put("test-dependencies", testDependencies); diff --git a/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectGenerationTest.java b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectGenerationTest.java index 6b7df9d97d384..855fd44371411 100644 --- a/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectGenerationTest.java +++ b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectGenerationTest.java @@ -12,10 +12,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class CodestartProjectGenerationTest { +public class CodestartProjectGenerationTest { + private static final TestCodestartResourceLoader RESOURCE_LOADER = new TestCodestartResourceLoader(); private final Path projectPath = Paths.get("target/codestarts-test"); - private TestCodestartResourceLoader resourceLoader = new TestCodestartResourceLoader(); @BeforeEach void setUp() { @@ -119,12 +119,12 @@ void checkSpecificProject() throws IOException { .hasSameTextualContentAs(getResource("expected-pom-maven-merge.xml")); } - private CodestartCatalog load() throws IOException { - return CodestartCatalogLoader.loadDefaultCatalog(resourceLoader, "codestarts/core", "codestarts/examples"); + public static CodestartCatalog load() throws IOException { + return CodestartCatalogLoader.loadDefaultCatalog(RESOURCE_LOADER, "codestarts/core", "codestarts/examples"); } - private CodestartCatalog loadSpecific(String s) throws IOException { - return CodestartCatalogLoader.loadDefaultCatalog(resourceLoader, "codestarts/core", "codestarts/examples", + public static CodestartCatalog loadSpecific(String s) throws IOException { + return CodestartCatalogLoader.loadDefaultCatalog(RESOURCE_LOADER, "codestarts/core", "codestarts/examples", "codestarts/" + s); } diff --git a/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/core/CodestartDataTest.java b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/core/CodestartDataTest.java new file mode 100644 index 0000000000000..30b4f79142c79 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/core/CodestartDataTest.java @@ -0,0 +1,66 @@ +package io.quarkus.devtools.codestarts.core; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +import io.quarkus.devtools.codestarts.CodestartCatalog; +import io.quarkus.devtools.codestarts.CodestartProjectGenerationTest; +import io.quarkus.devtools.codestarts.CodestartProjectInput; +import java.io.IOException; +import java.util.Map; +import java.util.Set; +import org.assertj.core.util.Lists; +import org.assertj.core.util.Sets; +import org.junit.jupiter.api.Test; + +class CodestartDataTest { + @Test + @SuppressWarnings("unchecked") + void testDependenciesOverrideWithVersion() throws IOException { + final CodestartCatalog catalog = CodestartProjectGenerationTest.loadSpecific("deps"); + final Map dependenciesData = CodestartData.buildDependenciesData(catalog.getCodestarts().stream() + .filter(c -> c.isSelected(Sets.newLinkedHashSet("codestart-dep1", "codestart-dep2"))), + "a", + Lists.list("input.group:some-dep:1.2", "my.group:base-dep1", "my.group:a-dep1:1.1"), + Lists.list("input.group:some-bom")); + assertThat((Set>) dependenciesData.get("dependencies")) + .isNotNull() + .map(m -> m.get("formatted-gav")) + .containsExactlyInAnyOrder( + "input.group:some-dep:1.2", + "my.group:base-dep1", + "my.group:a-dep1:1.1", + "my.group:base-depversion:1.10", + "my.group:base-dep2", + "my.group:a-dep2"); + assertThat((Set>) dependenciesData.get("test-dependencies")) + .isNotNull() + .map(m -> m.get("formatted-gav")) + .containsExactlyInAnyOrder( + "my.group:base-test-dep1", + "my.group:a-test-dep1", + "my.group:base-test-dep2"); + assertThat((Set>) dependenciesData.get("boms")) + .isNotNull() + .map(m -> m.get("formatted-gav")) + .containsExactly("input.group:some-bom"); + } + + @Test + @SuppressWarnings("unchecked") + void testDependenciesOverrideNoVersion() throws IOException { + final CodestartCatalog catalog = CodestartProjectGenerationTest.loadSpecific("deps"); + final Map dependenciesData = CodestartData.buildDependenciesData(catalog.getCodestarts().stream() + .filter(c -> c.isSelected(Sets.newLinkedHashSet("codestart-dep1"))), + "a", + Lists.list("my.group:base-depversion"), + Lists.newArrayList()); + assertThat((Set>) dependenciesData.get("dependencies")) + .isNotNull() + .map(m -> m.get("formatted-gav")) + .containsExactlyInAnyOrder( + "my.group:base-dep1", + "my.group:a-dep1", + "my.group:base-depversion"); + } +} diff --git a/independent-projects/tools/codestarts/src/test/resources/codestarts/deps/dep1/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/codestarts/deps/dep1/codestart.yml new file mode 100644 index 0000000000000..0389daae4c4b8 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/codestarts/deps/dep1/codestart.yml @@ -0,0 +1,17 @@ +--- +name: codestart-dep1 +ref: codestart-dep1 +language: + base: + dependencies: + - my.group:base-dep1 + - my.group:base-depversion:1.10 + test-dependencies: + - my.group:base-test-dep1 + a: + data: + foo: bar + dependencies: + - my.group:a-dep1 + test-dependencies: + - my.group:a-test-dep1 \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/codestarts/deps/dep2/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/codestarts/deps/dep2/codestart.yml new file mode 100644 index 0000000000000..0ee8c2d80bb89 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/codestarts/deps/dep2/codestart.yml @@ -0,0 +1,14 @@ +--- +name: codestart-dep2 +ref: codestart-dep2 +language: + base: + dependencies: + - my.group:base-dep2 + test-dependencies: + - my.group:base-test-dep2 + a: + data: + foo: bar2 + dependencies: + - my.group:a-dep2 \ No newline at end of file diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java index c39afd3b76026..e2e14b2015808 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java @@ -85,7 +85,7 @@ void generateMavenWithCustomDep(TestInfo testInfo) throws Throwable { final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder() .addData(getGenerationTestInputData()) .addBoms(QuarkusCodestartTesting.getPlatformBoms()) - .addExtension(ArtifactKey.fromString("io.quarkus:quarkus-resteasy")) + .addExtension(ArtifactCoords.fromString("io.quarkus:quarkus-resteasy:1.8")) .addExtension(ArtifactCoords.fromString("commons-io:commons-io:2.5")) .build(); @@ -102,6 +102,7 @@ void generateMavenWithCustomDep(TestInfo testInfo) throws Throwable { .satisfies(checkContains("\n" + " io.quarkus\n" + " quarkus-resteasy\n" + + " 1.8\n" + " \n")); } diff --git a/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateMavenWithCustomDep/pom.xml b/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateMavenWithCustomDep/pom.xml index e8915a9efed98..d72ec15811dd9 100644 --- a/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateMavenWithCustomDep/pom.xml +++ b/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateMavenWithCustomDep/pom.xml @@ -29,19 +29,20 @@ - - io.quarkus - quarkus-arc - io.quarkus quarkus-resteasy + 1.8 commons-io commons-io 2.5 + + io.quarkus + quarkus-arc + io.quarkus quarkus-junit5