From 42f91e26a55a581739308e5325831f6a2a7c74de Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Mon, 18 Jul 2022 16:20:57 +0200 Subject: [PATCH 1/3] Add --with-codestart option in create extension --- .../java/io/quarkus/cli/CreateExtension.java | 20 ++++++------ ...java => ExtensionCodeGenerationGroup.java} | 20 ++++++++++-- .../io/quarkus/maven/CreateExtensionMojo.java | 7 ++++ .../META-INF/quarkus-extension.tpl.qute.yaml | 9 +++++- .../code/extension-codestart/codestart.yml | 2 ++ ...lass-name-base}CodestartTest.tpl.qute.java | 32 +++++++++++++++++++ .../java/runtime/pom.tpl.qute.xml | 29 +++++++++++++++++ .../base/README.tpl.qute.md | 1 + .../META-INF/resources/index.entry.qute.html | 1 + .../codestart.tpl.qute.yml | 13 ++++++++ .../java/src/main/java/org/acme/.gitkeep | 0 .../java/integration-tests/pom.tpl.qute.xml | 7 ++++ .../core/reader/QuteCodestartFileReader.java | 15 +++++++-- .../QuarkusExtensionCodestartCatalog.java | 3 +- .../devtools/commands/CreateExtension.java | 19 +++++++++++ .../maven/it/CreateExtensionMojoIT.java | 2 ++ .../dir-tree.snapshot | 19 +++++++++++ ...quarkus-my-quarkiverse-ext_runtime_pom.xml | 20 ++++++++++++ 18 files changed, 202 insertions(+), 17 deletions(-) rename devtools/cli/src/main/java/io/quarkus/cli/create/{ExtensionTestGenerationGroup.java => ExtensionCodeGenerationGroup.java} (60%) create mode 100644 independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/codestart.yml create mode 100644 independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/integration-tests/src/test/java/{package-name.dir}/it/{class-name-base}CodestartTest.tpl.qute.java create mode 100644 independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/pom.tpl.qute.xml create mode 100644 independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/base/README.tpl.qute.md create mode 100644 independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/base/src/main/resources/META-INF/resources/index.entry.qute.html create mode 100644 independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/codestart.tpl.qute.yml create mode 100644 independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/java/src/main/java/org/acme/.gitkeep diff --git a/devtools/cli/src/main/java/io/quarkus/cli/CreateExtension.java b/devtools/cli/src/main/java/io/quarkus/cli/CreateExtension.java index 12fd1601e92ee..d5ab9e6769faa 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/CreateExtension.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/CreateExtension.java @@ -7,9 +7,9 @@ import io.quarkus.cli.common.PropertiesOptions; import io.quarkus.cli.common.TargetQuarkusVersionGroup; import io.quarkus.cli.create.BaseCreateCommand; +import io.quarkus.cli.create.ExtensionCodeGenerationGroup; import io.quarkus.cli.create.ExtensionGAVMixin; import io.quarkus.cli.create.ExtensionNameGenerationGroup; -import io.quarkus.cli.create.ExtensionTestGenerationGroup; import io.quarkus.devtools.commands.data.QuarkusCommandOutcome; import io.quarkus.devtools.commands.handlers.CreateExtensionCommandHandler; import io.quarkus.devtools.project.BuildTool; @@ -81,7 +81,7 @@ public class CreateExtension extends BaseCreateCommand { ExtensionNameGenerationGroup nameGeneration = new ExtensionNameGenerationGroup(); @CommandLine.ArgGroup(order = 3, exclusive = false, heading = "%nCode Generation (Optional):%n") - ExtensionTestGenerationGroup testGeneration = new ExtensionTestGenerationGroup(); + ExtensionCodeGenerationGroup codeGeneration = new ExtensionCodeGenerationGroup(); @CommandLine.ArgGroup(order = 4, exclusive = false, validate = false) PropertiesOptions propertiesOptions = new PropertiesOptions(); @@ -117,9 +117,10 @@ public Integer call() throws Exception { .quarkusBomGroupId(quarkusBom.getGroupId()) .quarkusBomArtifactId(quarkusBom.getArtifactId()) .quarkusBomVersion(quarkusBom.getVersion()) - .withoutUnitTest(testGeneration.skipUnitTest()) - .withoutDevModeTest(testGeneration.skipDevModeTest()) - .withoutIntegrationTests(testGeneration.skipIntegrationTests()) + .withCodestart(codeGeneration.withCodestart()) + .withoutUnitTest(codeGeneration.skipUnitTest()) + .withoutDevModeTest(codeGeneration.skipDevModeTest()) + .withoutIntegrationTests(codeGeneration.skipIntegrationTests()) .prepare(); QuarkusCommandOutcome outcome = QuarkusCommandOutcome.success(); @@ -156,9 +157,10 @@ public void dryRun(BuildTool buildTool, CreateExtensionCommandHandler invocation for (Map.Entry entry : invocation.getData().entrySet()) { dryRunOutput.put(prettyName(entry.getKey()), entry.getValue().toString()); } - dryRunOutput.put("Skip Unit Test", "" + testGeneration.skipUnitTest()); - dryRunOutput.put("Skip Dev-mode Test", "" + testGeneration.skipDevModeTest()); - dryRunOutput.put("Skip Integration Test", "" + testGeneration.skipIntegrationTests()); + dryRunOutput.put("Extension Codestart", "" + codeGeneration.withCodestart()); + dryRunOutput.put("Skip Unit Test", "" + codeGeneration.skipUnitTest()); + dryRunOutput.put("Skip Dev-mode Test", "" + codeGeneration.skipDevModeTest()); + dryRunOutput.put("Skip Integration Test", "" + codeGeneration.skipIntegrationTests()); output.info(help.createTextTable(dryRunOutput).toString()); } @@ -167,7 +169,7 @@ public String toString() { return "CreateExtension{" + "gav=" + gav + ", quarkusVersion=" + targetQuarkusVersion + ", nameGeneration=" + nameGeneration - + ", testGeneration=" + testGeneration + + ", testGeneration=" + codeGeneration + '}'; } } diff --git a/devtools/cli/src/main/java/io/quarkus/cli/create/ExtensionTestGenerationGroup.java b/devtools/cli/src/main/java/io/quarkus/cli/create/ExtensionCodeGenerationGroup.java similarity index 60% rename from devtools/cli/src/main/java/io/quarkus/cli/create/ExtensionTestGenerationGroup.java rename to devtools/cli/src/main/java/io/quarkus/cli/create/ExtensionCodeGenerationGroup.java index f2112b43946ce..7764ca68377b4 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/create/ExtensionTestGenerationGroup.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/create/ExtensionCodeGenerationGroup.java @@ -4,7 +4,11 @@ import picocli.CommandLine; -public class ExtensionTestGenerationGroup { +public class ExtensionCodeGenerationGroup { + @CommandLine.Option(names = { "-C", + "--codestart" }, description = "Generate extension codestart", negatable = true) + boolean codestart = false; + @CommandLine.Option(names = { "--no-unit-test" }, description = "Generate unit tests", negatable = true) boolean unitTest = true; @@ -20,6 +24,10 @@ public class ExtensionTestGenerationGroup { "--without-tests" }, description = "Do not generate any tests (disable all)") Optional withoutTests; + public boolean withCodestart() { + return codestart; + } + public boolean skipUnitTest() { return withoutTests.orElse(!unitTest); } @@ -34,7 +42,13 @@ public boolean skipDevModeTest() { @Override public String toString() { - return "ExtensionTestGenerationGroup [devModeTest=" + devModeTest + ", integrationTests=" + integrationTests - + ", unitTest=" + unitTest + ", withoutTests=" + withoutTests + "]"; + final StringBuilder sb = new StringBuilder("ExtensionCodeGenerationGroup{"); + sb.append("codestart=").append(codestart); + sb.append(", unitTest=").append(unitTest); + sb.append(", integrationTests=").append(integrationTests); + sb.append(", devModeTest=").append(devModeTest); + sb.append(", withoutTests=").append(withoutTests); + sb.append('}'); + return sb.toString(); } } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java index db41fca9da326..e877bdbaa98c3 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java @@ -170,6 +170,12 @@ public class CreateExtensionMojo extends AbstractMojo { @Parameter(property = "quarkusBomVersion") String quarkusBomVersion; + /** + * Indicates whether to generate an extension codestart + */ + @Parameter(property = "withCodestart") + boolean withCodestart; + /** * Indicates whether to generate a unit test class for the extension */ @@ -241,6 +247,7 @@ public void execute() throws MojoExecutionException { .quarkusBomGroupId(quarkusBomGroupId) .quarkusBomArtifactId(quarkusBomArtifactId) .quarkusBomGroupId(quarkusBomVersion) + .withCodestart(withCodestart) .withoutUnitTest(withoutTests || withoutUnitTest) .withoutDevModeTest(withoutTests || withoutDevModeTest) .withoutIntegrationTests(withoutTests || withoutIntegrationTests); diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-base/java/runtime/src/main/resources/META-INF/quarkus-extension.tpl.qute.yaml b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-base/java/runtime/src/main/resources/META-INF/quarkus-extension.tpl.qute.yaml index f70fc324fb824..53ae350d7cd6e 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-base/java/runtime/src/main/resources/META-INF/quarkus-extension.tpl.qute.yaml +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-base/java/runtime/src/main/resources/META-INF/quarkus-extension.tpl.qute.yaml @@ -6,4 +6,11 @@ metadata: # guide: {extension.guide ?: '...'} # categories: # - "miscellaneous" -# status: "preview" \ No newline at end of file +# status: "preview" +{#if input.extra-codestarts.contains("extension-codestart")} + codestart: + name: {extension.id} + languages: + - "java" + artifact: "{group-id}:{namespace.id}{extension.id}:codestarts:jar:$\{project.version}" +{/if} \ No newline at end of file diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/codestart.yml b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/codestart.yml new file mode 100644 index 0000000000000..8e3569d7abe0e --- /dev/null +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/codestart.yml @@ -0,0 +1,2 @@ +name: extension-codestart +type: code diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/integration-tests/src/test/java/{package-name.dir}/it/{class-name-base}CodestartTest.tpl.qute.java b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/integration-tests/src/test/java/{package-name.dir}/it/{class-name-base}CodestartTest.tpl.qute.java new file mode 100644 index 0000000000000..e3bb749f046cd --- /dev/null +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/integration-tests/src/test/java/{package-name.dir}/it/{class-name-base}CodestartTest.tpl.qute.java @@ -0,0 +1,32 @@ +{#if input.extra-codestarts.contains("integration-tests")} +package {package-name}.it; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.is; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +public class {class-name-base}CodestartTest { + + @RegisterExtension + public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() + .languages(Language.JAVA) + .setupStandaloneExtensionTest("{group-id}:{namespace.id}{extension.id}") + .build(); + + @Test + void testContent() throws Throwable { + codestartTest.checkGeneratedSource("org.acme.{class-name-base}Resource"); + } + + @Test + void buildAllProjects() throws Throwable { + codestartTest.buildAllProjects(); + } +} + +{#else} + +{/if} \ No newline at end of file diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/pom.tpl.qute.xml b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/pom.tpl.qute.xml new file mode 100644 index 0000000000000..7c16df91f9dc8 --- /dev/null +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/pom.tpl.qute.xml @@ -0,0 +1,29 @@ + + + + + + maven-jar-plugin + + + generate-codestart-jar + generate-resources + + jar + + + $\{project.basedir}/src/main + + codestarts/** + + codestarts + true + + + + + + + diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/base/README.tpl.qute.md b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/base/README.tpl.qute.md new file mode 100644 index 0000000000000..ccb61df404b1e --- /dev/null +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/base/README.tpl.qute.md @@ -0,0 +1 @@ +{#include readme-header /} diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/base/src/main/resources/META-INF/resources/index.entry.qute.html b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/base/src/main/resources/META-INF/resources/index.entry.qute.html new file mode 100644 index 0000000000000..a1768e062a782 --- /dev/null +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/base/src/main/resources/META-INF/resources/index.entry.qute.html @@ -0,0 +1 @@ +{#include index-entry /} \ No newline at end of file diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/codestart.tpl.qute.yml b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/codestart.tpl.qute.yml new file mode 100644 index 0000000000000..62c8578813772 --- /dev/null +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/codestart.tpl.qute.yml @@ -0,0 +1,13 @@ +name: {extension.id}-codestart +ref: {extension.id} +type: code +tags: extension-codestart +metadata: + title: {extension.name} + description: {#if extension.description}{extension.description}{#else}Start coding with {extension.name}{/if} +# path: /some-path +{#if input.extra-codestarts.contains("quarkiverse")} + related-guide-section: https://quarkiverse.github.io/quarkiverse-docs/quarkus-quinoa/dev/index.html +{#else} +# related-guide-section: TBD +{/if} \ No newline at end of file diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/java/src/main/java/org/acme/.gitkeep b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/runtime/src/main/codestarts/quarkus/{extension.id}-codestart/java/src/main/java/org/acme/.gitkeep new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/integration-tests/java/integration-tests/pom.tpl.qute.xml b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/integration-tests/java/integration-tests/pom.tpl.qute.xml index c0ad4a7b30e7f..bd9fbadde6637 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/integration-tests/java/integration-tests/pom.tpl.qute.xml +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/integration-tests/java/integration-tests/pom.tpl.qute.xml @@ -46,6 +46,13 @@ rest-assured test +{#if input.extra-codestarts.contains("extension-codestart")} + + io.quarkus + quarkus-devtools-testing + test + +{/if} diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/reader/QuteCodestartFileReader.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/reader/QuteCodestartFileReader.java index d011a9ea89c5b..f2d6a56d50e3a 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/reader/QuteCodestartFileReader.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/reader/QuteCodestartFileReader.java @@ -27,15 +27,20 @@ final class QuteCodestartFileReader implements CodestartFileReader { private static final String TPL_QUTE_FLAG = ".tpl.qute"; private static final String ENTRY_QUTE_FLAG = ".entry.qute"; public static final String INCLUDE_QUTE_FLAG = ".include.qute"; + public static final String SKIP_TAG = ""; @Override public boolean matches(String fileName) { - return fileName.contains(TPL_QUTE_FLAG) || fileName.contains(ENTRY_QUTE_FLAG) || fileName.contains(INCLUDE_QUTE_FLAG); + return fileName.contains(TPL_QUTE_FLAG) + || fileName.contains(ENTRY_QUTE_FLAG) + || fileName.contains(INCLUDE_QUTE_FLAG); } @Override public String cleanFileName(String fileName) { - return fileName.replaceAll(TPL_QUTE_FLAG, "").replace(ENTRY_QUTE_FLAG, ""); + return fileName + .replaceAll(TPL_QUTE_FLAG, "") + .replace(ENTRY_QUTE_FLAG, ""); } @Override @@ -45,7 +50,11 @@ public Optional read(CodestartResource projectResource, Source source, S if (FilenameUtils.getName(source.path()).contains(INCLUDE_QUTE_FLAG)) { return Optional.empty(); } - return Optional.of(readQuteFile(projectResource, source, languageName, data)); + final String value = readQuteFile(projectResource, source, languageName, data); + if (SKIP_TAG.equals(value)) { + return Optional.empty(); + } + return Optional.of(value); } public static String readQuteFile(CodestartResource projectResource, Source source, String languageName, diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/extension/QuarkusExtensionCodestartCatalog.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/extension/QuarkusExtensionCodestartCatalog.java index d11f9b1c582a5..e8af1d8697dad 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/extension/QuarkusExtensionCodestartCatalog.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/extension/QuarkusExtensionCodestartCatalog.java @@ -67,7 +67,8 @@ public enum Code implements DataKey { QUARKIVERSE, DEVMODE_TEST, INTEGRATION_TESTS, - UNIT_TEST + UNIT_TEST, + EXTENSION_CODESTART } public enum Tooling implements DataKey { diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateExtension.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateExtension.java index 9b0275defdac4..3caffa498d992 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateExtension.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateExtension.java @@ -69,6 +69,7 @@ public enum LayoutType { private String itTestRelativeDir = "integration-tests"; private String bomRelativeDir = "bom/application"; private String extensionsRelativeDir = "extensions"; + private boolean withCodestart; public CreateExtension(final Path baseDir) { this.baseDir = requireNonNull(baseDir, "extensionDirPath is required"); @@ -161,6 +162,11 @@ public CreateExtension quarkusBomVersion(String quarkusBomVersion) { return this; } + public CreateExtension withCodestart(boolean withCodestart) { + this.withCodestart = withCodestart; + return this; + } + public CreateExtension withoutUnitTest(boolean withoutUnitTest) { this.builder.withoutUnitTest(withoutUnitTest); return this; @@ -241,6 +247,12 @@ public CreateExtensionCommandHandler prepare() throws QuarkusCommandException { data.putIfAbsent(PARENT_RELATIVE_PATH, "../pom.xml"); itTestModel = readPom(workingDir.resolve(itTestRelativeDir)); + + if (withCodestart) { + log.warn("\nExtension Codestart is not yet available for '%s' extension (skipped).\n", + layoutType.toString().toLowerCase()); + } + break; case QUARKIVERSE: defaultVersion = DEFAULT_QUARKIVERSE_VERSION; @@ -262,6 +274,9 @@ public CreateExtensionCommandHandler prepare() throws QuarkusCommandException { // TODO: Support Quarkiverse multi extensions repo builder.addCodestart(QuarkusExtensionCodestartCatalog.Code.QUARKIVERSE.key()); builder.addCodestart(QuarkusExtensionCodestartCatalog.Tooling.GIT.key()); + if (withCodestart) { + builder.addCodestart(QuarkusExtensionCodestartCatalog.Code.EXTENSION_CODESTART.key()); + } itTestModel = getStandaloneTempModel(workingDir, runtimeArtifactId, defaultVersion); break; default: @@ -273,6 +288,10 @@ public CreateExtensionCommandHandler prepare() throws QuarkusCommandException { data.putIfAbsent(MAVEN_COMPILER_PLUGIN_VERSION, DEFAULT_COMPILER_PLUGIN_VERSION); ensureRequiredStringData(QUARKUS_VERSION); + if (withCodestart) { + builder.addCodestart(QuarkusExtensionCodestartCatalog.Code.EXTENSION_CODESTART.key()); + } + // In standalone mode, the base pom is used as parent for integration tests itTestModel = getStandaloneTempModel(workingDir, runtimeArtifactId, defaultVersion); break; diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/CreateExtensionMojoIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/CreateExtensionMojoIT.java index a2c9cd30398cf..ba64fbdd9b6cb 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/it/CreateExtensionMojoIT.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/it/CreateExtensionMojoIT.java @@ -96,6 +96,7 @@ public void testCreateQuarkiverseExtension(TestInfo testInfo) throws Throwable { properties.put("quarkusVersion", "2.10.5.Final"); properties.put("extensionName", "My Quarkiverse extension"); properties.put("extensionDescription", "My Quarkiverse extension description"); + properties.put("withCodestart", "true"); InvocationResult result = setup(properties); assertThat(result.getExitCode()).isZero(); @@ -104,6 +105,7 @@ public void testCreateQuarkiverseExtension(TestInfo testInfo) throws Throwable { assertThatDirectoryTreeMatchSnapshots(testInfo, testDirPath) .contains( "quarkus-my-quarkiverse-ext/pom.xml", + "quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/codestart.yml", "quarkus-my-quarkiverse-ext/deployment/src/main/java/io/quarkiverse/my/quarkiverse/ext/deployment/MyQuarkiverseExtProcessor.java", "quarkus-my-quarkiverse-ext/integration-tests/pom.xml", "quarkus-my-quarkiverse-ext/integration-tests/src/test/java/io/quarkiverse/my/quarkiverse/ext/it/MyQuarkiverseExtResourceTest.java"); diff --git a/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateQuarkiverseExtension/dir-tree.snapshot b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateQuarkiverseExtension/dir-tree.snapshot index 9017c2ddd10eb..491997e2044f4 100644 --- a/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateQuarkiverseExtension/dir-tree.snapshot +++ b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateQuarkiverseExtension/dir-tree.snapshot @@ -71,6 +71,7 @@ quarkus-my-quarkiverse-ext/integration-tests/src/test/java/io/quarkiverse/my/ quarkus-my-quarkiverse-ext/integration-tests/src/test/java/io/quarkiverse/my/quarkiverse/ quarkus-my-quarkiverse-ext/integration-tests/src/test/java/io/quarkiverse/my/quarkiverse/ext/ quarkus-my-quarkiverse-ext/integration-tests/src/test/java/io/quarkiverse/my/quarkiverse/ext/it/ +quarkus-my-quarkiverse-ext/integration-tests/src/test/java/io/quarkiverse/my/quarkiverse/ext/it/MyQuarkiverseExtCodestartTest.java quarkus-my-quarkiverse-ext/integration-tests/src/test/java/io/quarkiverse/my/quarkiverse/ext/it/MyQuarkiverseExtResourceIT.java quarkus-my-quarkiverse-ext/integration-tests/src/test/java/io/quarkiverse/my/quarkiverse/ext/it/MyQuarkiverseExtResourceTest.java quarkus-my-quarkiverse-ext/pom.xml @@ -78,6 +79,24 @@ quarkus-my-quarkiverse-ext/runtime/ quarkus-my-quarkiverse-ext/runtime/pom.xml quarkus-my-quarkiverse-ext/runtime/src/ quarkus-my-quarkiverse-ext/runtime/src/main/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/base/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/base/README.md +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/base/src/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/base/src/main/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/base/src/main/resources/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/base/src/main/resources/META-INF/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/base/src/main/resources/META-INF/resources/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/base/src/main/resources/META-INF/resources/index.html +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/codestart.yml +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/java/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/java/src/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/java/src/main/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/java/src/main/java/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/java/src/main/java/org/ +quarkus-my-quarkiverse-ext/runtime/src/main/codestarts/quarkus/my-quarkiverse-ext-codestart/java/src/main/java/org/acme/ quarkus-my-quarkiverse-ext/runtime/src/main/java/ quarkus-my-quarkiverse-ext/runtime/src/main/java/io/ quarkus-my-quarkiverse-ext/runtime/src/main/java/io/quarkiverse/ diff --git a/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateQuarkiverseExtension/quarkus-my-quarkiverse-ext_runtime_pom.xml b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateQuarkiverseExtension/quarkus-my-quarkiverse-ext_runtime_pom.xml index 7ff4e0c8c407d..302ba5212906b 100644 --- a/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateQuarkiverseExtension/quarkus-my-quarkiverse-ext_runtime_pom.xml +++ b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateQuarkiverseExtension/quarkus-my-quarkiverse-ext_runtime_pom.xml @@ -46,6 +46,26 @@ + + maven-jar-plugin + + + generate-codestart-jar + generate-resources + + jar + + + ${project.basedir}/src/main + + codestarts/** + + codestarts + true + + + + From 949723a8eae30d29cbe35a72c25b1eba5eb25730 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Tue, 19 Jul 2022 15:38:52 +0200 Subject: [PATCH 2/3] Add longpath support --- .github/workflows/ci-actions-incremental.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-actions-incremental.yml b/.github/workflows/ci-actions-incremental.yml index 1c3e93777a5ba..757d48bceb6c3 100644 --- a/.github/workflows/ci-actions-incremental.yml +++ b/.github/workflows/ci-actions-incremental.yml @@ -118,7 +118,6 @@ jobs: run: | echo "EXCLUDE_JAKARTA_INCOMPATIBLE_MODULES=-pl "'!'":quarkus-integration-test-infinispan-client -pl "'!'":quarkus-integration-test-kafka-avro" >> $GITHUB_ENV if: github.ref_name == 'jakarta-rewrite' - - uses: actions/checkout@v2 with: fetch-depth: 0 @@ -317,7 +316,9 @@ jobs: run: | ss -ln sudo service mysql stop || true - + - name: Support longpaths on Windows + if: "startsWith(matrix.java.os-name, 'windows')" + run: git config --global core.longpaths true - uses: actions/checkout@v2 with: fetch-depth: 0 @@ -418,6 +419,9 @@ jobs: os-name: "windows-latest" } steps: + - name: Support longpaths on Windows + if: "startsWith(matrix.java.os-name, 'windows')" + run: git config --global core.longpaths true - uses: actions/checkout@v2 - name: Download Maven Repo uses: actions/download-artifact@v1 @@ -490,6 +494,9 @@ jobs: os-name: "windows-latest" } steps: + - name: Support longpaths on Windows + if: "startsWith(matrix.java.os-name, 'windows')" + run: git config --global core.longpaths true - uses: actions/checkout@v2 - name: Download Maven Repo uses: actions/download-artifact@v1 @@ -553,6 +560,9 @@ jobs: os-name: "windows-latest" } steps: + - name: Support longpaths on Windows + if: "startsWith(matrix.java.os-name, 'windows')" + run: git config --global core.longpaths true - uses: actions/checkout@v2 - name: Download Maven Repo uses: actions/download-artifact@v1 From fe352b96a7a832a21f1656d81f8fed22afb6b205 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Mon, 18 Jul 2022 16:20:57 +0200 Subject: [PATCH 3/3] Fix template --- ...lass-name-base}CodestartTest.tpl.qute.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/integration-tests/src/test/java/{package-name.dir}/it/{class-name-base}CodestartTest.tpl.qute.java b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/integration-tests/src/test/java/{package-name.dir}/it/{class-name-base}CodestartTest.tpl.qute.java index e3bb749f046cd..151c47b423257 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/integration-tests/src/test/java/{package-name.dir}/it/{class-name-base}CodestartTest.tpl.qute.java +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus-extension/code/extension-codestart/java/integration-tests/src/test/java/{package-name.dir}/it/{class-name-base}CodestartTest.tpl.qute.java @@ -1,12 +1,11 @@ {#if input.extra-codestarts.contains("integration-tests")} package {package-name}.it; -import static io.restassured.RestAssured.given; -import static org.hamcrest.Matchers.is; - import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; -import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language; +import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; public class {class-name-base}CodestartTest { @@ -16,11 +15,24 @@ public class {class-name-base}CodestartTest { .setupStandaloneExtensionTest("{group-id}:{namespace.id}{extension.id}") .build(); + /** + * Make sure the generated code meets the expectations. + *
+ * The generated code uses mocked data to be immutable and allow snapshot testing. + *

+ * + * Read the doc:
+ * {@link https://quarkus.io/guides/extension-codestart#integration-test} + */ @Test void testContent() throws Throwable { - codestartTest.checkGeneratedSource("org.acme.{class-name-base}Resource"); + //codestartTest.checkGeneratedSource("org.acme.SomeClass"); + //codestartTest.assertThatGeneratedFileMatchSnapshot(Language.JAVA, "\"src/main/resources/some-resource.ext"); } + /** + * This test runs the build (with tests) on generated projects for all selected languages + */ @Test void buildAllProjects() throws Throwable { codestartTest.buildAllProjects();