diff --git a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/buildtool/maven/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/buildtool/maven/codestart.yml index ae576d6afef19..771dc4777802e 100644 --- a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/buildtool/maven/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/buildtool/maven/codestart.yml @@ -1,4 +1,3 @@ ---- name: maven type: buildtool fallback: true diff --git a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/config/properties/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/config/properties/codestart.yml index b7de311e246fa..be1598706f732 100644 --- a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/config/properties/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/config/properties/codestart.yml @@ -1,4 +1,3 @@ ---- name: config-properties type: config fallback: true diff --git a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/config/yaml/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/config/yaml/codestart.yml index e3829b28166eb..81a6305eeef41 100644 --- a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/config/yaml/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/config/yaml/codestart.yml @@ -1,4 +1,3 @@ ---- name: config-yaml type: config language: diff --git a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/example/commandmode-example/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/example/commandmode-example/codestart.yml index 5ea3705898e07..077c82077d285 100644 --- a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/example/commandmode-example/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/example/commandmode-example/codestart.yml @@ -1,4 +1,3 @@ ---- name: commandmode-example ref: commandmode type: example diff --git a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/language/java/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/language/java/codestart.yml index b38cc805f7c39..2846850c7f356 100644 --- a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/language/java/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/language/java/codestart.yml @@ -1,4 +1,3 @@ ---- name: java type: language fallback: true diff --git a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/language/kotlin/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/language/kotlin/codestart.yml index 08bf10c7a76e3..3f129e8d8241e 100644 --- a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/language/kotlin/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/language/kotlin/codestart.yml @@ -1,4 +1,3 @@ ---- name: kotlin type: language language: diff --git a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/language/scala/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/language/scala/codestart.yml index a277a1ae483c4..2d73b61569390 100644 --- a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/language/scala/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/language/scala/codestart.yml @@ -1,4 +1,3 @@ ---- name: scala type: language language: diff --git a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/project/quarkus/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/project/quarkus/codestart.yml index 95462524e44f0..2b446266ae26e 100644 --- a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/project/quarkus/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/project/quarkus/codestart.yml @@ -1,4 +1,3 @@ ---- name: quarkus type: project fallback: true diff --git a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/tooling/dockerfiles/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/tooling/dockerfiles/codestart.yml index bc6fc87e03fa9..027afa4eecffc 100644 --- a/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/tooling/dockerfiles/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/bundled-codestarts/tooling/dockerfiles/codestart.yml @@ -1,4 +1,3 @@ ---- name: dockerfiles type: tooling preselected: true diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/qute-example/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/codestarts/qute-example/codestart.yml index f4017f84aac56..f4de5208a01cb 100644 --- a/devtools/platform-descriptor-json/src/main/resources/codestarts/qute-example/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/qute-example/codestart.yml @@ -1,4 +1,3 @@ ---- name: qute-example ref: qute type: example diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/resteasy-example/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/codestarts/resteasy-example/codestart.yml index 7dac00948f2f9..85a7d80b3cb6c 100644 --- a/devtools/platform-descriptor-json/src/main/resources/codestarts/resteasy-example/codestart.yml +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/resteasy-example/codestart.yml @@ -1,4 +1,3 @@ ---- name: resteasy-example ref: resteasy type: example diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartException.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartException.java index 8264f53aee205..a13c1d924f99e 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartException.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartException.java @@ -2,6 +2,10 @@ public class CodestartException extends RuntimeException { + public CodestartException(String message, Throwable cause) { + super(message, cause); + } + public CodestartException(Throwable cause) { super(null, cause); } diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProcessor.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProcessor.java index 6ff7d33c00460..79884c03f715a 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProcessor.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProcessor.java @@ -6,18 +6,19 @@ import io.quarkus.devtools.codestarts.reader.CodestartFileReader; import io.quarkus.devtools.codestarts.strategy.CodestartFileStrategy; import io.quarkus.devtools.codestarts.strategy.CodestartFileStrategyHandler; +import io.quarkus.devtools.codestarts.strategy.DefaultCodestartFileStrategyHandler; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -82,9 +83,8 @@ void processCodestartDir(final Path sourceDirectory, final Map f final boolean hasFileStrategyHandler = getStrategy(relativeTargetPath.toString()).isPresent(); try { if (!possibleReader.isPresent() && !hasFileStrategyHandler) { - // Copy static files final Path targetPath = targetDirectory.resolve(relativeTargetPath.toString()); - processStaticFile(sourcePath, targetPath); + getSelectedDefaultStrategy().copyStaticFile(sourcePath, targetPath); continue; } final Optional content = reader.read(sourceDirectory, relativeSourcePath, @@ -111,11 +111,6 @@ private List findSources(Path sourceDirectory) { } } - private static void processStaticFile(Path path, Path targetPath) throws IOException { - Files.createDirectories(targetPath.getParent()); - Files.copy(path, targetPath, StandardCopyOption.REPLACE_EXISTING); - } - void checkTargetDir() throws IOException { if (!Files.exists(targetDirectory)) { boolean mkdirStatus = targetDirectory.toFile().mkdirs(); @@ -137,12 +132,25 @@ public void writeFiles() throws IOException { for (Map.Entry> e : files.entrySet()) { final String relativePath = e.getKey(); Files.createDirectories(targetDirectory.resolve(relativePath).getParent()); - getStrategy(relativePath).orElse(CodestartFileStrategyHandler.DEFAULT_STRATEGY) + getStrategy(relativePath).orElse(getSelectedDefaultStrategy()) .process(targetDirectory, relativePath, e.getValue(), data); } } - private Optional getStrategy(final String key) { + DefaultCodestartFileStrategyHandler getSelectedDefaultStrategy() { + for (CodestartFileStrategy codestartFileStrategy : strategies) { + if (Objects.equals(codestartFileStrategy.getFilter(), "*")) { + if (codestartFileStrategy.getHandler() instanceof DefaultCodestartFileStrategyHandler) { + return (DefaultCodestartFileStrategyHandler) codestartFileStrategy.getHandler(); + } + throw new CodestartDefinitionException( + codestartFileStrategy.getHandler().name() + " can't be used as '*' file strategy"); + } + } + return CodestartFileStrategyHandler.DEFAULT_STRATEGY; + } + + Optional getStrategy(final String key) { for (CodestartFileStrategy codestartFileStrategy : strategies) { if (codestartFileStrategy.test(key)) { return Optional.of(codestartFileStrategy.getHandler()); diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/Codestarts.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/Codestarts.java index da1be1c65fe20..8ae671904ac20 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/Codestarts.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/Codestarts.java @@ -19,10 +19,11 @@ public class Codestarts { public static CodestartProject prepareProject(final CodestartInput input) throws IOException { - final Set selectedCodestartNames = new HashSet<>(input.getCodestarts()); - - final List allCodestarts = loadAllCodestarts(input); + return prepareProject(input, loadAllCodestarts(input)); + } + public static CodestartProject prepareProject(final CodestartInput input, final List allCodestarts) { + final Set selectedCodestartNames = new HashSet<>(input.getCodestarts()); final Collection baseCodestarts = resolveSelectedBaseCodestarts(allCodestarts, selectedCodestartNames); final String languageName = baseCodestarts.stream().filter(c -> c.getType() == LANGUAGE).findFirst() .orElseThrow(() -> new CodestartDefinitionException("Language codestart is required")).getName(); diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/reader/QuteCodestartFileReader.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/reader/QuteCodestartFileReader.java index a0392ccaa2ffd..d404ec98083f5 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/reader/QuteCodestartFileReader.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/reader/QuteCodestartFileReader.java @@ -55,7 +55,7 @@ public static String readQuteFile(Path sourceDirectory, Path relativeSourcePath, try { return engine.parse(content).render(data); } catch (TemplateException e) { - throw new IOException("Error while rendering template: " + sourcePath.toString(), e); + throw new CodestartException("Error while rendering template: " + sourcePath.toString(), e); } } @@ -103,7 +103,7 @@ public boolean appliesTo(TemplateNode.Origin origin, Object result) { } public String map(Object result, Expression expression) { - throw new CodestartException("Missing required data: {" + expression.toOriginalString() + "}"); + throw new TemplateException("Missing required data: {" + expression.toOriginalString() + "}"); } } diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/CodestartFileStrategy.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/CodestartFileStrategy.java index 48f264b05ef0f..c5cb2a302fb27 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/CodestartFileStrategy.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/CodestartFileStrategy.java @@ -13,14 +13,15 @@ public CodestartFileStrategy(String filter, CodestartFileStrategyHandler handler this.handler = handler; } + public String getFilter() { + return filter; + } + @Override public boolean test(String t) { if (Objects.equals(filter, t)) { return true; } - if (Objects.equals("*", t)) { - return true; - } // TODO SUPPORT FOR GLOB return false; } diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/CodestartFileStrategyHandler.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/CodestartFileStrategyHandler.java index f09ab828d5df6..36fb7b997e753 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/CodestartFileStrategyHandler.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/CodestartFileStrategyHandler.java @@ -13,7 +13,7 @@ public interface CodestartFileStrategyHandler { - FailOnDuplicateCodestartFileStrategyHandler DEFAULT_STRATEGY = new FailOnDuplicateCodestartFileStrategyHandler(); + DefaultCodestartFileStrategyHandler DEFAULT_STRATEGY = new FailOnDuplicateCodestartFileStrategyHandler(); Map BY_NAME = Stream .of(DEFAULT_STRATEGY, diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/DefaultCodestartFileStrategyHandler.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/DefaultCodestartFileStrategyHandler.java new file mode 100644 index 0000000000000..4fa37a5cb0465 --- /dev/null +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/DefaultCodestartFileStrategyHandler.java @@ -0,0 +1,9 @@ +package io.quarkus.devtools.codestarts.strategy; + +import java.io.IOException; +import java.nio.file.Path; + +public interface DefaultCodestartFileStrategyHandler extends CodestartFileStrategyHandler { + + void copyStaticFile(Path sourcePath, Path targetPath) throws IOException; +} diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/FailOnDuplicateCodestartFileStrategyHandler.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/FailOnDuplicateCodestartFileStrategyHandler.java index 8d47640d19b61..39df6348a3d77 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/FailOnDuplicateCodestartFileStrategyHandler.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/FailOnDuplicateCodestartFileStrategyHandler.java @@ -8,7 +8,7 @@ import java.util.List; import java.util.Map; -final class FailOnDuplicateCodestartFileStrategyHandler implements CodestartFileStrategyHandler { +final class FailOnDuplicateCodestartFileStrategyHandler implements DefaultCodestartFileStrategyHandler { @Override public String name() { return "fail-on-duplicate"; @@ -18,12 +18,21 @@ public String name() { public void process(Path targetDirectory, String relativePath, List codestartFiles, Map data) throws IOException { checkNotEmptyCodestartFiles(codestartFiles); - if (codestartFiles.size() > 1) { + final Path targetPath = targetDirectory.resolve(relativePath); + if (codestartFiles.size() > 1 || Files.exists(targetPath)) { throw new CodestartDefinitionException( "Multiple files found for path with 'fail-on-duplicate' FileStrategy: " + relativePath); } - final Path targetPath = targetDirectory.resolve(relativePath); - checkTargetDoesNotExist(targetPath); Files.write(targetPath, codestartFiles.get(0).getContent().getBytes()); } + + @Override + public void copyStaticFile(Path sourcePath, Path targetPath) throws IOException { + if (Files.exists(targetPath)) { + throw new CodestartDefinitionException( + "Multiple files found for path with 'fail-on-duplicate' FileStrategy: " + targetPath); + } + Files.createDirectories(targetPath.getParent()); + Files.copy(sourcePath, targetPath); + } } diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/ReplaceCodestartFileStrategyHandler.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/ReplaceCodestartFileStrategyHandler.java index be59bfadaa686..b0084537bce9b 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/ReplaceCodestartFileStrategyHandler.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/ReplaceCodestartFileStrategyHandler.java @@ -4,16 +4,23 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.StandardCopyOption; import java.util.List; import java.util.Map; -final class ReplaceCodestartFileStrategyHandler implements CodestartFileStrategyHandler { +final class ReplaceCodestartFileStrategyHandler implements DefaultCodestartFileStrategyHandler { @Override public String name() { return "replace"; } + @Override + public void copyStaticFile(Path sourcePath, Path targetPath) throws IOException { + Files.createDirectories(targetPath.getParent()); + Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); + } + @Override public void process(Path targetDirectory, String relativePath, List codestartFiles, Map data) throws IOException { diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/SmartConfigMergeCodestartFileStrategyHandler.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/SmartConfigMergeCodestartFileStrategyHandler.java index 440d76ef4d533..6dc0ffe27667a 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/SmartConfigMergeCodestartFileStrategyHandler.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/strategy/SmartConfigMergeCodestartFileStrategyHandler.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; import io.quarkus.devtools.codestarts.CodestartException; import io.quarkus.devtools.codestarts.NestedMaps; import io.quarkus.devtools.codestarts.reader.CodestartFile; @@ -16,7 +17,8 @@ final class SmartConfigMergeCodestartFileStrategyHandler implements CodestartFileStrategyHandler { - private static final ObjectMapper YAML_MAPPER = new ObjectMapper(new YAMLFactory()); + private static final ObjectMapper YAML_MAPPER = new ObjectMapper( + new YAMLFactory().configure(YAMLGenerator.Feature.WRITE_DOC_START_MARKER, false)); @Override public String name() { diff --git a/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartLoaderTest.java b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartLoaderTest.java index 214f02141335b..9614e147647a1 100644 --- a/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartLoaderTest.java +++ b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartLoaderTest.java @@ -3,13 +3,17 @@ import static io.quarkus.devtools.codestarts.CodestartSpec.Type.EXAMPLE; import static io.quarkus.devtools.codestarts.CodestartSpec.Type.PROJECT; import static org.apache.commons.io.IOUtils.resourceToString; +import static org.assertj.core.api.Assertions.as; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Collection; +import java.util.Set; +import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.Test; +import org.mockito.internal.util.collections.Sets; class CodestartLoaderTest { @@ -62,24 +66,46 @@ void testReadCodestartSpecDefault() throws IOException { void testLoadBundledCodestarts() throws IOException { final CodestartInput input = CodestartInput.builder(new TestCodestartResourceLoader()).build(); final Collection codestarts = CodestartLoader.loadBundledCodestarts(input); - assertThat(codestarts).extracting(Codestart::getSpec).extracting(CodestartSpec::getName) - .containsExactlyInAnyOrder("y", "z", "config-properties", "config-yaml", "foo", "a", "b", "replace", "t"); + assertThat(codestarts).extracting(Codestart::getName) + .containsExactlyInAnyOrder("y", "maven", "config-properties", "config-yaml", "foo", "a", "b", "replace", "t", + "example-with-b"); + + checkLanguages(codestarts, Sets.newSet("y", "z"), "a", "b"); + checkLanguages(codestarts, Sets.newSet("config-properties", "config-yaml", "foo", "a", "b", "replace")); + checkLanguages(codestarts, Sets.newSet("t"), "a"); + } + + private void checkLanguages(Collection codestarts, Set names, String... languages) { + assertThat(codestarts) + .filteredOn(c -> names.contains(c.getName())) + .allSatisfy((c) -> assertThat(c) + .extracting(Codestart::getImplementedLanguages, as(InstanceOfAssertFactories.ITERABLE)) + .containsExactlyInAnyOrder(languages)); } @Test void testLoadCodestartsFromExtensions() throws IOException { final CodestartInput input = CodestartInput.builder(new TestCodestartResourceLoader()).build(); final Collection codestarts = CodestartLoader.loadCodestartsFromExtensions(input); - assertThat(codestarts).extracting(Codestart::getSpec).extracting(CodestartSpec::getName) + assertThat(codestarts).extracting(Codestart::getName) .containsExactlyInAnyOrder("example1", "example2", "example-forbidden"); + checkLanguages(codestarts, Sets.newSet("example1"), "a"); + checkLanguages(codestarts, Sets.newSet("example2"), "b"); + checkLanguages(codestarts, Sets.newSet("example-forbidden")); } @Test void testLoadCodestartsFail() throws IOException { final CodestartInput input = CodestartInput.builder(new TestCodestartResourceLoader()).build(); assertThatExceptionOfType(CodestartDefinitionException.class) - .isThrownBy(() -> CodestartLoader.loadCodestarts(input.getResourceLoader(), "codestarts-with-error")) + .isThrownBy(() -> CodestartLoader.loadCodestarts(input.getResourceLoader(), "codestarts-with-error-1")) .withMessageContaining("codestart-1"); + assertThatExceptionOfType(CodestartDefinitionException.class) + .isThrownBy(() -> CodestartLoader.loadCodestarts(input.getResourceLoader(), "codestarts-with-error-2")) + .withMessageContaining("codestart-2"); + assertThatExceptionOfType(CodestartDefinitionException.class) + .isThrownBy(() -> CodestartLoader.loadCodestarts(input.getResourceLoader(), "codestarts-with-error-3")) + .withMessageContaining("codestart-3"); } } diff --git a/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartProcessorTest.java b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartProcessorTest.java new file mode 100644 index 0000000000000..125544ab1c606 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartProcessorTest.java @@ -0,0 +1,48 @@ +package io.quarkus.devtools.codestarts; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.quarkus.devtools.codestarts.strategy.CodestartFileStrategyHandler; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +class CodestartProcessorTest { + + @Test + void checkSelectedDefaultStrategy() { + Map spec = new HashMap<>(); + spec.put("test/foo.tt", "forbidden"); + spec.put("*", "replace"); + + final CodestartProcessor processor = new CodestartProcessor( + Mockito.mock(CodestartResourceLoader.class), + "a", + Paths.get("test"), + CodestartProcessor.buildStrategies(spec), + Collections.emptyMap()); + + assertThat(processor.getSelectedDefaultStrategy()).isEqualTo(CodestartFileStrategyHandler.BY_NAME.get("replace")); + assertThat(processor.getStrategy("test/foo.tt")).hasValue(CodestartFileStrategyHandler.BY_NAME.get("forbidden")); + } + + @Test + void checkDefaultStrategy() { + Map spec = new HashMap<>(); + spec.put("test/foo.tt", "forbidden"); + + final CodestartProcessor processor = new CodestartProcessor( + Mockito.mock(CodestartResourceLoader.class), + "a", + Paths.get("test"), + CodestartProcessor.buildStrategies(spec), + Collections.emptyMap()); + + assertThat(processor.getSelectedDefaultStrategy()) + .isEqualTo(CodestartFileStrategyHandler.BY_NAME.get("fail-on-duplicate")); + assertThat(processor.getStrategy("test/foo.tt")).hasValue(CodestartFileStrategyHandler.BY_NAME.get("forbidden")); + } +} diff --git a/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartsTest.java b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartsTest.java new file mode 100644 index 0000000000000..48c5f144385a2 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/CodestartsTest.java @@ -0,0 +1,130 @@ +package io.quarkus.devtools.codestarts; + +import static io.quarkus.devtools.codestarts.TestCodestartResourceLoader.getResource; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.commons.io.FileUtils; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class CodestartsTest { + + private final Path projectPath = Paths.get("target/codestarts-test"); + + @BeforeEach + void setUp() { + FileUtils.deleteQuietly(projectPath.toFile()); + assertThat(projectPath).doesNotExist(); + } + + @Test + void checkStaticConflictFail() throws IOException { + final CodestartInput input = CodestartInput.builder(new TestCodestartResourceLoader()) + .build(); + final List allCodestarts = loadSpecific(input, "static-conflicting-file"); + + final CodestartProject codestartProject = Codestarts.prepareProject(input, allCodestarts); + Assertions.assertThatExceptionOfType(CodestartDefinitionException.class) + .isThrownBy(() -> Codestarts.generateProject(codestartProject, + Files.createTempDirectory("checkStaticConflictFail"))) + .withMessageContaining("Multiple files found for path with 'fail-on-duplicate' FileStrategy:") + .withMessageContaining(".tooling-t"); + } + + @Test + void checkConflictFail() throws IOException { + final CodestartInput input = CodestartInput.builder(new TestCodestartResourceLoader()) + .build(); + final List allCodestarts = loadSpecific(input, "conflicting-file"); + + final CodestartProject codestartProject = Codestarts.prepareProject(input, allCodestarts); + Assertions.assertThatExceptionOfType(CodestartDefinitionException.class) + .isThrownBy(() -> Codestarts.generateProject(codestartProject, Files.createTempDirectory("checkConflictFail"))) + .withMessageContaining("Multiple files found for path with 'fail-on-duplicate' FileStrategy:") + .withMessageContaining(".tooling-t"); + } + + @Test + void checkConflictingFallbackProjectFail() throws IOException { + final CodestartInput input = CodestartInput.builder(new TestCodestartResourceLoader()) + .build(); + final List allCodestarts = loadSpecific(input, "conflicting-fallback-project"); + + Assertions.assertThatExceptionOfType(CodestartDefinitionException.class) + .isThrownBy(() -> Codestarts.prepareProject(input, allCodestarts)) + .withMessageContaining("Multiple fallback found for a base codestart of type: 'PROJECT'"); + } + + @Test + void checkDefaultProject() throws IOException { + final CodestartInput input = CodestartInput.builder(new TestCodestartResourceLoader()) + .build(); + final CodestartProject codestartProject = Codestarts.prepareProject(input); + + assertThat(codestartProject.getRequiredCodestart(CodestartSpec.Type.PROJECT).getName()).isEqualTo("foo"); + assertThat(codestartProject.getRequiredCodestart(CodestartSpec.Type.LANGUAGE).getName()).isEqualTo("a"); + assertThat(codestartProject.getRequiredCodestart(CodestartSpec.Type.BUILDTOOL).getName()).isEqualTo("y"); + assertThat(codestartProject.getRequiredCodestart(CodestartSpec.Type.CONFIG).getName()).isEqualTo("config-properties"); + + assertThat(codestartProject.getExtraCodestarts()).extracting(Codestart::getResourceDir) + .containsExactlyInAnyOrder("bundled-codestarts/tooling-t"); + + final Path targetDirectory = projectPath.resolve("default-project"); + Codestarts.generateProject(codestartProject, targetDirectory); + + assertThat(targetDirectory.resolve("README.md")).hasContent("Base readme world y"); + assertThat(targetDirectory.resolve("config.properties")).hasContent("foo.bar=baz\nfoo.foo=bar\n"); + assertThat(targetDirectory.resolve(".gitignore")).hasContent("base-ignore1\nbase-ignore2\n"); + assertThat(targetDirectory.resolve("a/.tooling-t")).hasContent("a/.tooling-t"); + assertThat(targetDirectory.resolve(".tooling-t")).hasContent(".tooling-t"); + assertThat(targetDirectory.resolve("ybuild.build")).hasContent("fooa\n\nbara\n\nappend test"); + } + + @Test + void checkSpecificProject() throws IOException { + final TestCodestartResourceLoader resourceLoader = new TestCodestartResourceLoader(); + final CodestartInput input = CodestartInput.builder(resourceLoader) + .includeExamples() + .addCodestart("b") + .addCodestart("example-with-b") + .addCodestart("maven") + .addCodestart("config-yaml") + .putData("project.version", "1.2.3") + .build(); + final CodestartProject codestartProject = Codestarts.prepareProject(input); + + assertThat(codestartProject.getRequiredCodestart(CodestartSpec.Type.PROJECT).getName()).isEqualTo("foo"); + assertThat(codestartProject.getRequiredCodestart(CodestartSpec.Type.LANGUAGE).getName()).isEqualTo("b"); + assertThat(codestartProject.getRequiredCodestart(CodestartSpec.Type.BUILDTOOL).getName()).isEqualTo("maven"); + assertThat(codestartProject.getRequiredCodestart(CodestartSpec.Type.CONFIG).getName()).isEqualTo("config-yaml"); + + assertThat(codestartProject.getExtraCodestarts()).extracting(Codestart::getResourceDir) + .containsExactlyInAnyOrder("bundled-codestarts/example-with-b"); + + final Path targetDirectory = projectPath.resolve("specific-project"); + Codestarts.generateProject(codestartProject, targetDirectory); + + assertThat(targetDirectory.resolve("README.md")).hasContent("Base readme world maven"); + assertThat(targetDirectory.resolve("config.yml")).hasContent("example: \"code\""); + assertThat(targetDirectory.resolve(".gitignore")).hasContent("base-ignore1\nbase-ignore2\n"); + assertThat(targetDirectory.resolve("b/example-code")).hasContent("example-code"); + assertThat(targetDirectory.resolve("pom.xml")) + .hasSameTextualContentAs(getResource("expected-pom-maven-merge.xml")); + } + + private List loadSpecific(CodestartInput input, String s) throws IOException { + return Stream.concat( + CodestartLoader.loadBundledCodestarts(input).stream(), + CodestartLoader.loadCodestarts(input.getResourceLoader(), s).stream()) + .collect(Collectors.toList()); + } + +} diff --git a/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/TestCodestartResourceLoader.java b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/TestCodestartResourceLoader.java index 889861c21debe..88d58831a2cc6 100644 --- a/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/TestCodestartResourceLoader.java +++ b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/TestCodestartResourceLoader.java @@ -4,16 +4,21 @@ import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import java.nio.file.Path; public class TestCodestartResourceLoader implements CodestartResourceLoader { @Override public T loadResourceAsPath(String name, Consumer consumer) throws IOException { + return consumer.consume(getResource(name)); + } + + public static Path getResource(String name) throws IOException { final URL url = Thread.currentThread().getContextClassLoader().getResource(name); if (url == null) { throw new IOException("Failed to locate " + name + " on the classpath"); } try { - return consumer.consume(new File(url.toURI()).toPath()); + return new File(url.toURI()).toPath(); } catch (URISyntaxException e) { throw new IOException(e); } diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-z/a/pom.qute.xml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-maven/a/pom.tpl.qute.xml similarity index 100% rename from independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-z/a/pom.qute.xml rename to independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-maven/a/pom.tpl.qute.xml diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-z/b/pom.qute.xml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-maven/b/pom.tpl.qute.xml similarity index 100% rename from independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-z/b/pom.qute.xml rename to independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-maven/b/pom.tpl.qute.xml diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-z/base/pom.qute.xml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-maven/base/pom.tpl.qute.xml similarity index 100% rename from independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-z/base/pom.qute.xml rename to independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-maven/base/pom.tpl.qute.xml diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-maven/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-maven/codestart.yml new file mode 100644 index 0000000000000..805106ab23052 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-maven/codestart.yml @@ -0,0 +1,12 @@ +name: maven +type: buildtool +language: + base: + data: + prop1: proppp + project: + group-id: org.acme + artifact-id: andy + shared-data: + buildtool: + foo: world maven \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/a/ybuild.qute.build b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/a/ybuild.tpl.qute.build similarity index 85% rename from independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/a/ybuild.qute.build rename to independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/a/ybuild.tpl.qute.build index c3924c6dada11..126fc42f648b7 100644 --- a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/a/ybuild.qute.build +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/a/ybuild.tpl.qute.build @@ -7,4 +7,4 @@ bara {/bar} {/include} -append \ No newline at end of file +append {test} \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/b/ybuild.qute.build b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/b/ybuild.tpl.qute.build similarity index 100% rename from independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/b/ybuild.qute.build rename to independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/b/ybuild.tpl.qute.build diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/base/config.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/base/config.yml new file mode 100644 index 0000000000000..56d108a001731 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/base/config.yml @@ -0,0 +1,2 @@ +foo: + bar: bar \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/codestart.yml index 19968f88c35df..821cc24a4dbcf 100644 --- a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-y/codestart.yml @@ -1,4 +1,3 @@ ---- name: y type: buildtool fallback: true @@ -8,4 +7,7 @@ language: test: test shared-data: buildtool: - foo: world y \ No newline at end of file + foo: world y + b: + data: + test: b \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-z/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-z/codestart.yml deleted file mode 100644 index b7692cd1c79b9..0000000000000 --- a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/buildtool-z/codestart.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: z -type: buildtool -language: - base: - shared-data: - buildtool: - foo: world z \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/config-properties/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/config-properties/codestart.yml index b7de311e246fa..be1598706f732 100644 --- a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/config-properties/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/config-properties/codestart.yml @@ -1,4 +1,3 @@ ---- name: config-properties type: config fallback: true diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/config-yaml/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/config-yaml/codestart.yml index e3829b28166eb..81a6305eeef41 100644 --- a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/config-yaml/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/config-yaml/codestart.yml @@ -1,4 +1,3 @@ ---- name: config-yaml type: config language: diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/example-with-b/b/b/example-code b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/example-with-b/b/b/example-code new file mode 100644 index 0000000000000..09735013574a1 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/example-with-b/b/b/example-code @@ -0,0 +1 @@ +example-code \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/example-with-b/b/config.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/example-with-b/b/config.yml new file mode 100644 index 0000000000000..dc77f555ee0de --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/example-with-b/b/config.yml @@ -0,0 +1 @@ +example: code \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/example-with-b/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/example-with-b/codestart.yml new file mode 100644 index 0000000000000..62eaa6f8c8915 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/example-with-b/codestart.yml @@ -0,0 +1,2 @@ +name: example-with-b +type: example \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/foo-project/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/foo-project/codestart.yml index ae687a3b25404..6c93dece2b673 100644 --- a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/foo-project/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/foo-project/codestart.yml @@ -1,4 +1,3 @@ ---- name: foo type: project fallback: true diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/language-a/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/language-a/codestart.yml index 89449a1d2ac74..9f619b7dbb38a 100644 --- a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/language-a/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/language-a/codestart.yml @@ -1,4 +1,3 @@ ---- name: a type: language fallback: true \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/language-b/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/language-b/codestart.yml index 06b368a26d86c..787bbdadaff59 100644 --- a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/language-b/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/language-b/codestart.yml @@ -1,3 +1,2 @@ ---- name: b type: language \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/replace-project/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/replace-project/codestart.yml index 5d01c0dea64d7..37b2368b457ff 100644 --- a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/replace-project/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/replace-project/codestart.yml @@ -1,4 +1,3 @@ ---- name: replace type: project output-strategy: diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/a/a/.tooling-t b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/a/a/.tooling-t index e69de29bb2d1d..0e7c74fbde636 100644 --- a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/a/a/.tooling-t +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/a/a/.tooling-t @@ -0,0 +1 @@ +a/.tooling-t \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/a/config.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/a/config.yml new file mode 100644 index 0000000000000..07e63c29e75ae --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/a/config.yml @@ -0,0 +1,3 @@ +foo: + bar: baz + foo: bar \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/base/.tooling-t b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/base/.tooling-t index 4ce93be9774db..f9d7114d80597 100644 --- a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/base/.tooling-t +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/base/.tooling-t @@ -1 +1 @@ -tooling-t \ No newline at end of file +.tooling-t \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/codestart.yml index 03e3caa0b9e05..1b8dcb447f88c 100644 --- a/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/bundled-codestarts/tooling-t/codestart.yml @@ -1,4 +1,3 @@ ---- name: t type: tooling preselected: true \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/codestarts-with-error-1/codestart-1/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/codestarts-with-error-1/codestart-1/codestart.yml new file mode 100644 index 0000000000000..f8709e335b052 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/codestarts-with-error-1/codestart-1/codestart.yml @@ -0,0 +1 @@ +no-name: nonono \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/codestarts-with-error-2/codestart-2/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/codestarts-with-error-2/codestart-2/codestart.yml new file mode 100644 index 0000000000000..44140b300a192 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/codestarts-with-error-2/codestart-2/codestart.yml @@ -0,0 +1,2 @@ +name: namename +type: wrong-type \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/codestarts-with-error-3/codestart-3/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/codestarts-with-error-3/codestart-3/codestart.yml new file mode 100644 index 0000000000000..d2dbdd5e246d9 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/codestarts-with-error-3/codestart-3/codestart.yml @@ -0,0 +1,2 @@ +name: namenamename +fallback: not-bool \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/codestarts-with-error/codestart-1/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/codestarts-with-error/codestart-1/codestart.yml deleted file mode 100644 index 95f455c0ab8c0..0000000000000 --- a/independent-projects/tools/codestarts/src/test/resources/codestarts-with-error/codestart-1/codestart.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -foo: bar \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/conflicting-codestart/bar-project/base/src/main/resources/application.yml b/independent-projects/tools/codestarts/src/test/resources/codestarts/example-forbidden/base/README.adoc similarity index 100% rename from independent-projects/tools/codestarts/src/test/resources/conflicting-codestart/bar-project/base/src/main/resources/application.yml rename to independent-projects/tools/codestarts/src/test/resources/codestarts/example-forbidden/base/README.adoc diff --git a/independent-projects/tools/codestarts/src/test/resources/codestarts/example-forbidden/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/codestarts/example-forbidden/codestart.yml index 8db16c7da8aae..f45cd0d6f9e3e 100644 --- a/independent-projects/tools/codestarts/src/test/resources/codestarts/example-forbidden/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/codestarts/example-forbidden/codestart.yml @@ -1,2 +1 @@ ---- name: example-forbidden \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/codestarts/example1/a/.gitkeep b/independent-projects/tools/codestarts/src/test/resources/codestarts/example1/a/.gitkeep new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/independent-projects/tools/codestarts/src/test/resources/codestarts/example1/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/codestarts/example1/codestart.yml index 6a2798e86ccbe..48072a02cfc17 100644 --- a/independent-projects/tools/codestarts/src/test/resources/codestarts/example1/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/codestarts/example1/codestart.yml @@ -1,2 +1 @@ ---- name: example1 \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/codestarts/example2/b/.gitkeep b/independent-projects/tools/codestarts/src/test/resources/codestarts/example2/b/.gitkeep new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/independent-projects/tools/codestarts/src/test/resources/codestarts/example2/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/codestarts/example2/codestart.yml index 7bb259e7ca255..b6c7450f004d1 100644 --- a/independent-projects/tools/codestarts/src/test/resources/codestarts/example2/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/codestarts/example2/codestart.yml @@ -1,2 +1 @@ ---- name: example2 \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/conflicting-codestart/bar-project/base/..gitignore b/independent-projects/tools/codestarts/src/test/resources/conflicting-fallback-project/bar-project/base/..gitignore similarity index 100% rename from independent-projects/tools/codestarts/src/test/resources/conflicting-codestart/bar-project/base/..gitignore rename to independent-projects/tools/codestarts/src/test/resources/conflicting-fallback-project/bar-project/base/..gitignore diff --git a/independent-projects/tools/codestarts/src/test/resources/conflicting-codestart/bar-project/base/README.tpl.qute.md b/independent-projects/tools/codestarts/src/test/resources/conflicting-fallback-project/bar-project/base/README.tpl.qute.md similarity index 100% rename from independent-projects/tools/codestarts/src/test/resources/conflicting-codestart/bar-project/base/README.tpl.qute.md rename to independent-projects/tools/codestarts/src/test/resources/conflicting-fallback-project/bar-project/base/README.tpl.qute.md diff --git a/independent-projects/tools/codestarts/src/test/resources/conflicting-fallback-project/bar-project/base/src/main/resources/application.yml b/independent-projects/tools/codestarts/src/test/resources/conflicting-fallback-project/bar-project/base/src/main/resources/application.yml new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/independent-projects/tools/codestarts/src/test/resources/conflicting-codestart/bar-project/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/conflicting-fallback-project/bar-project/codestart.yml similarity index 90% rename from independent-projects/tools/codestarts/src/test/resources/conflicting-codestart/bar-project/codestart.yml rename to independent-projects/tools/codestarts/src/test/resources/conflicting-fallback-project/bar-project/codestart.yml index e9d3bb81372c6..046af2d42e39b 100644 --- a/independent-projects/tools/codestarts/src/test/resources/conflicting-codestart/bar-project/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/conflicting-fallback-project/bar-project/codestart.yml @@ -1,4 +1,3 @@ ---- name: bar type: project fallback: true \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/conflicting-file/tooling-tt/base/.tooling-t b/independent-projects/tools/codestarts/src/test/resources/conflicting-file/tooling-tt/base/.tooling-t.tpl.qute similarity index 100% rename from independent-projects/tools/codestarts/src/test/resources/conflicting-file/tooling-tt/base/.tooling-t rename to independent-projects/tools/codestarts/src/test/resources/conflicting-file/tooling-tt/base/.tooling-t.tpl.qute diff --git a/independent-projects/tools/codestarts/src/test/resources/conflicting-file/tooling-tt/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/conflicting-file/tooling-tt/codestart.yml index 36d7125d65623..b763b3a3187c7 100644 --- a/independent-projects/tools/codestarts/src/test/resources/conflicting-file/tooling-tt/codestart.yml +++ b/independent-projects/tools/codestarts/src/test/resources/conflicting-file/tooling-tt/codestart.yml @@ -1,4 +1,3 @@ ---- name: tt type: tooling preselected: true \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/example-fallback/example-fallback/a/.gitkeep b/independent-projects/tools/codestarts/src/test/resources/example-fallback/example-fallback/a/.gitkeep new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/independent-projects/tools/codestarts/src/test/resources/example-fallback/example-fallback/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/example-fallback/example-fallback/codestart.yml new file mode 100644 index 0000000000000..7ecaa8b08a820 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/example-fallback/example-fallback/codestart.yml @@ -0,0 +1,2 @@ +name: example-fallback +fallback: true \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/expected-pom-maven-merge.xml b/independent-projects/tools/codestarts/src/test/resources/expected-pom-maven-merge.xml new file mode 100644 index 0000000000000..f34f4b93cfb5d --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/expected-pom-maven-merge.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + org.acme + quarkus-project + 1.2.3 + + proppp + + + + io.b + b + 0.1 + + + diff --git a/independent-projects/tools/codestarts/src/test/resources/fallback-example/fb-example/a/fallback.a b/independent-projects/tools/codestarts/src/test/resources/fallback-example/fb-example/a/fallback.a deleted file mode 100644 index 2e65efe2a145d..0000000000000 --- a/independent-projects/tools/codestarts/src/test/resources/fallback-example/fb-example/a/fallback.a +++ /dev/null @@ -1 +0,0 @@ -a \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/fallback-example/fb-example/b/fallback.b b/independent-projects/tools/codestarts/src/test/resources/fallback-example/fb-example/b/fallback.b deleted file mode 100644 index 63d8dbd40c235..0000000000000 --- a/independent-projects/tools/codestarts/src/test/resources/fallback-example/fb-example/b/fallback.b +++ /dev/null @@ -1 +0,0 @@ -b \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/fallback-example/fb-example/base/fallback.base b/independent-projects/tools/codestarts/src/test/resources/fallback-example/fb-example/base/fallback.base deleted file mode 100644 index 8681f8b8f3261..0000000000000 --- a/independent-projects/tools/codestarts/src/test/resources/fallback-example/fb-example/base/fallback.base +++ /dev/null @@ -1 +0,0 @@ -base \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/fallback-example/fb-example/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/fallback-example/fb-example/codestart.yml deleted file mode 100644 index 4f3ace1bbf9c0..0000000000000 --- a/independent-projects/tools/codestarts/src/test/resources/fallback-example/fb-example/codestart.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -name: fb-example -type: example -fallback: true -language: - base: - data: - greeting: - message: "hello" - default-name: "commando" diff --git a/independent-projects/tools/codestarts/src/test/resources/static-conflicting-file/tooling-tt/base/.tooling-t b/independent-projects/tools/codestarts/src/test/resources/static-conflicting-file/tooling-tt/base/.tooling-t new file mode 100644 index 0000000000000..2114c2f755763 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/static-conflicting-file/tooling-tt/base/.tooling-t @@ -0,0 +1 @@ +tooling-tt \ No newline at end of file diff --git a/independent-projects/tools/codestarts/src/test/resources/static-conflicting-file/tooling-tt/codestart.yml b/independent-projects/tools/codestarts/src/test/resources/static-conflicting-file/tooling-tt/codestart.yml new file mode 100644 index 0000000000000..b763b3a3187c7 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/resources/static-conflicting-file/tooling-tt/codestart.yml @@ -0,0 +1,3 @@ +name: tt +type: tooling +preselected: true \ No newline at end of file diff --git a/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/ProjectTestUtil.java b/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/ProjectTestUtil.java deleted file mode 100644 index d6b2d9503ad54..0000000000000 --- a/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/ProjectTestUtil.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.quarkus.devtools; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Comparator; -import java.util.stream.Stream; -import org.junit.jupiter.api.Assertions; - -public final class ProjectTestUtil { - - private ProjectTestUtil() { - } - - public static void delete(final File file) throws IOException { - - if (file.exists()) { - try (Stream stream = Files.walk(file.toPath())) { - stream.sorted(Comparator.reverseOrder()) - .map(Path::toFile) - .forEach(File::delete); - } - } - - Assertions.assertFalse( - Files.exists(file.toPath()), "Directory still exists"); - } -} diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectGenerationTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectGenerationIT.java similarity index 98% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectGenerationTest.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectGenerationIT.java index f45726f42db39..f2f4acbc5c64c 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectGenerationTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectGenerationIT.java @@ -21,7 +21,7 @@ import io.quarkus.devtools.ProjectTestUtil; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; -class CodestartProjectGenerationTest extends PlatformAwareTestBase { +class CodestartProjectGenerationIT extends PlatformAwareTestBase { private static final Path testDirPath = Paths.get("target/codestarts-test"); @@ -35,7 +35,7 @@ private Map getTestInputData() { } private Map getTestInputData(final Map override) { - return CodestartProjectGenerationTest.getTestInputData(getPlatformDescriptor(), override); + return CodestartProjectGenerationIT.getTestInputData(getPlatformDescriptor(), override); } static Map getTestInputData(final QuarkusPlatformDescriptor descriptor, diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectRunTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectRunIT.java similarity index 96% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectRunTest.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectRunIT.java index b13bd7daeae93..e4efe5960c835 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectRunTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartProjectRunIT.java @@ -26,7 +26,7 @@ import io.quarkus.devtools.ProjectTestUtil; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -class CodestartProjectRunTest extends PlatformAwareTestBase { +class CodestartProjectRunIT extends PlatformAwareTestBase { private static final Path testDirPath = Paths.get("target/codestarts-run-test"); @@ -47,7 +47,7 @@ private Map getTestInputData() { } private Map getTestInputData(final Map override) { - return CodestartProjectGenerationTest.getTestInputData(getPlatformDescriptor(), override); + return CodestartProjectGenerationIT.getTestInputData(getPlatformDescriptor(), override); } private Stream provideGenerateCombinations() throws IOException { diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartsTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartsIT.java similarity index 99% rename from integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartsTest.java rename to integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartsIT.java index bdf6cf7090a70..8bc62dc6698ad 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartsTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/CodestartsIT.java @@ -16,7 +16,7 @@ import io.quarkus.devtools.ProjectTestUtil; import io.quarkus.devtools.codestarts.CodestartSpec.Type; -class CodestartsTest extends PlatformAwareTestBase { +class CodestartsIT extends PlatformAwareTestBase { private final Path projectPath = Paths.get("target/codestarts-test");