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 e1d0e2e4bad54c..2a9322d5c903f1 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 @@ -35,6 +35,7 @@ public enum QuarkusExtensionData implements DataKey { QUARKUS_BOM_GROUP_ID("quarkus.bom.group-id"), QUARKUS_BOM_ARTIFACT_ID("quarkus.bom.artifact-id"), QUARKUS_BOM_VERSION("quarkus.bom.version"), + PROPERTIES_FROM_PARENT("properties.from-parent"), PARENT_GROUP_ID("parent.group-id"), PARENT_ARTIFACT_ID("parent.artifact-id"), PARENT_VERSION("parent.version"), 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 72fb23044a1ffd..396acee4f53e85 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 @@ -187,14 +187,14 @@ public CreateExtension extensionsRelativeDir(String extensionsRelativeDir) { } public QuarkusCommandOutcome execute() throws QuarkusCommandException { - final String extensionId = data.getRequiredStringValue(EXTENSION_ID); - final Path workingDir = resolveWorkingDir(baseDir); final Model baseModel = resolveModel(baseDir); final LayoutType layoutType = detectLayoutType(baseModel, data.getStringValue(GROUP_ID).orElse(null)); - data.putIfAbsent(EXTENSION_NAME, toCapWords(extensionId)); data.putIfAbsent(NAMESPACE_ID, getDefaultNamespaceId(layoutType)); + final String extensionId = normalizeExtensionId(data.getRequiredStringValue(EXTENSION_ID), + data.getRequiredStringValue(NAMESPACE_ID)); + data.putIfAbsent(EXTENSION_NAME, toCapWords(extensionId)); data.putIfAbsent(NAMESPACE_NAME, computeDefaultNamespaceName(data.getRequiredStringValue(NAMESPACE_ID))); data.putIfAbsent(CLASS_NAME_BASE, toCapCamelCase(extensionId)); @@ -212,13 +212,14 @@ public QuarkusCommandOutcome execute() throws QuarkusCommandException { case QUARKUS_CORE: case OTHER_PLATFORM: extensionDirName = extensionId; - final Model extensionsParentModel = readPom(baseDir.resolve(extensionsRelativeDir)); + final Model extensionsParentModel = readPom(workingDir.resolve(extensionsRelativeDir)); + data.putIfAbsent(PROPERTIES_FROM_PARENT, true); ensureRequiredStringData(PARENT_GROUP_ID, resolveGroupId(extensionsParentModel)); ensureRequiredStringData(PARENT_ARTIFACT_ID, resolveArtifactId(extensionsParentModel)); ensureRequiredStringData(PARENT_VERSION, resolveVersion(extensionsParentModel)); data.putIfAbsent(PARENT_RELATIVE_PATH, "../pom.xml"); - itTestModel = readPom(baseDir.resolve(itTestRelativeDir)); + itTestModel = readPom(workingDir.resolve(itTestRelativeDir)); break; case QUARKIVERSE: data.putIfAbsent(PARENT_GROUP_ID, DEFAULT_QUARKIVERSE_PARENT_GROUP_ID); @@ -266,7 +267,14 @@ public QuarkusCommandOutcome execute() throws QuarkusCommandException { extensionsDir, itTestDir, bomDir); } - return handler.execute(log, groupId, runtimeArtifactId, builder.build(), baseDir.resolve(extensionDirName)); + return handler.execute(log, groupId, runtimeArtifactId, builder.build(), workingDir.resolve(extensionDirName)); + } + + private String normalizeExtensionId(String extensionId, String namespaceId) { + if (extensionId.startsWith(namespaceId)) { + return extensionId.substring(namespaceId.length()); + } + return extensionId; } private String getDefaultNamespaceId(LayoutType layoutType) { @@ -315,7 +323,8 @@ private String getRuntimeArtifactIdFromData() { } private static Path resolveWorkingDir(Path dir) { - return dir.endsWith("extensions/") ? dir.resolve("..") : dir; + System.out.println(dir.getFileName().toString()); + return "extensions".equals(dir.getFileName().toString()) ? dir.resolve("..") : dir; } public static LayoutType detectLayoutType(Model basePom, String groupId) { @@ -430,10 +439,8 @@ public Optional getStringValue(QuarkusExtensionData key) { return Optional.ofNullable((o instanceof String) ? (String) o : null); } - public void putIfAbsent(QuarkusExtensionData dataKey, String defaultValue) { - if (!containsKey(dataKey)) { - this.put(dataKey.key(), defaultValue); - } + public void putIfAbsent(QuarkusExtensionData dataKey, Object value) { + this.putIfAbsent(dataKey.key(), value); } public void putIfNonEmptyString(QuarkusExtensionData dataKey, String value) { diff --git a/independent-projects/tools/devtools-common/src/main/resources/codestarts/quarkus-extension/code/extension-base/java/pom.tpl.qute.xml b/independent-projects/tools/devtools-common/src/main/resources/codestarts/quarkus-extension/code/extension-base/java/pom.tpl.qute.xml index 0e3773d53d95b5..7fa5990949f0fb 100644 --- a/independent-projects/tools/devtools-common/src/main/resources/codestarts/quarkus-extension/code/extension-base/java/pom.tpl.qute.xml +++ b/independent-projects/tools/devtools-common/src/main/resources/codestarts/quarkus-extension/code/extension-base/java/pom.tpl.qute.xml @@ -22,14 +22,13 @@ {group-id} {version} {/if} - {namespace.id}{extension.id}-parent {#if extension.name} {namespace.name}{extension.name} - Parent {/if} - pom + {#if !properties.from-parent} UTF-8 UTF-8 @@ -44,6 +43,7 @@ {/if} + {/if} deployment runtime diff --git a/independent-projects/tools/devtools-common/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/devtools-common/src/main/resources/codestarts/quarkus-extension/code/extension-base/java/runtime/src/main/resources/META-INF/quarkus-extension.tpl.qute.yaml index 4f9a5585912bb1..8b03027cd8ae12 100644 --- a/independent-projects/tools/devtools-common/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/devtools-common/src/main/resources/codestarts/quarkus-extension/code/extension-base/java/runtime/src/main/resources/META-INF/quarkus-extension.tpl.qute.yaml @@ -1,5 +1,5 @@ -name: {namespace.name}{extension.name} -#description: {namespace.name}{extension.name} ... +name: {extension.name} +#description: {extension.name} ... metadata: # keywords: # - {extension.id} 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 7fa0339261b7cc..a6fe8f18a97540 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 @@ -45,9 +45,40 @@ public void testCreateCoreExtension(TestInfo testInfo) throws Throwable { assertThatDirectoryTreeMatchSnapshots(testInfo, testDirPath) .contains( "extensions/my-ext/pom.xml", + "extensions/my-ext/runtime/src/main/resources/META-INF/quarkus-extension.yaml", "extensions/my-ext/deployment/src/main/java/org/acme/my/ext/deployment/MyExtProcessor.java", "integration-tests/my-ext/pom.xml", "integration-tests/my-ext/src/test/java/org/acme/my/ext/it/MyExtResourceTest.java"); + assertThatMatchSnapshot(testInfo, testDirPath, "extensions/my-ext/pom.xml"); + assertThatMatchSnapshot(testInfo, testDirPath, + "extensions/my-ext/runtime/src/main/resources/META-INF/quarkus-extension.yaml"); + assertThatMatchSnapshot(testInfo, testDirPath, "bom/application/pom.xml"); + assertThatMatchSnapshot(testInfo, testDirPath, "integration-tests/pom.xml"); + assertThatMatchSnapshot(testInfo, testDirPath, "extensions/pom.xml"); + } + + @Test + public void testCreateCoreExtensionFromExtensionsDir(TestInfo testInfo) throws Throwable { + testDir = initProject("projects/create-extension-quarkus-core", "output/create-extension-quarkus-core-extensions-dir"); + assertThat(testDir).isDirectory(); + invoker = initInvoker(testDir.toPath().resolve("extensions/").toFile()); + + Properties properties = new Properties(); + properties.put("extensionId", "my-ext"); + InvocationResult result = setup(properties); + + assertThat(result.getExitCode()).isZero(); + + final Path testDirPath = testDir.toPath(); + assertThatDirectoryTreeMatchSnapshots(testInfo, testDirPath) + .contains( + "extensions/my-ext/pom.xml", + "extensions/my-ext/deployment/src/main/java/org/acme/my/ext/deployment/MyExtProcessor.java", + "integration-tests/my-ext/pom.xml", + "integration-tests/my-ext/src/test/java/org/acme/my/ext/it/MyExtResourceTest.java"); + assertThatMatchSnapshot(testInfo, testDirPath, "extensions/my-ext/pom.xml"); + assertThatMatchSnapshot(testInfo, testDirPath, + "extensions/my-ext/runtime/src/main/resources/META-INF/quarkus-extension.yaml"); assertThatMatchSnapshot(testInfo, testDirPath, "bom/application/pom.xml"); assertThatMatchSnapshot(testInfo, testDirPath, "integration-tests/pom.xml"); assertThatMatchSnapshot(testInfo, testDirPath, "extensions/pom.xml"); diff --git a/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtension/extensions_my-ext_pom.xml b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtension/extensions_my-ext_pom.xml new file mode 100644 index 00000000000000..91238b55c01577 --- /dev/null +++ b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtension/extensions_my-ext_pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.acme + extensions-parent + 0.1-SNAPSHOT + + quarkus-my-ext-parent + pom + Quarkus - My Ext - Parent + + deployment + runtime + + diff --git a/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtension/extensions_my-ext_runtime_src_main_resources_META-INF_quarkus-extension.yaml b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtension/extensions_my-ext_runtime_src_main_resources_META-INF_quarkus-extension.yaml new file mode 100644 index 00000000000000..899448c057d6cc --- /dev/null +++ b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtension/extensions_my-ext_runtime_src_main_resources_META-INF_quarkus-extension.yaml @@ -0,0 +1,9 @@ +name: My Ext +#description: My Ext ... +metadata: +# keywords: +# - my-ext +# guide: ... +# categories: +# - "miscellaneous" +# status: "preview" \ No newline at end of file diff --git a/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/bom_application_pom.xml b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/bom_application_pom.xml new file mode 100644 index 00000000000000..963e10748ca88b --- /dev/null +++ b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/bom_application_pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + org.acme + fake-quarkus-parent + 0.1-SNAPSHOT + ../../pom.xml + + fake-quarkus-bom + pom + + + + + org.acme + quarkus-my-ext + ${project.version} + + + org.acme + quarkus-my-ext-deployment + ${project.version} + + + + diff --git a/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/dir-tree.snapshot b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/dir-tree.snapshot new file mode 100644 index 00000000000000..00914409beef8f --- /dev/null +++ b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/dir-tree.snapshot @@ -0,0 +1,60 @@ +/ +bom/ +bom/application/ +bom/application/pom.xml +integration-tests/ +integration-tests/my-ext/ +integration-tests/my-ext/pom.xml +integration-tests/my-ext/src/ +integration-tests/my-ext/src/test/ +integration-tests/my-ext/src/test/java/ +integration-tests/my-ext/src/test/java/org/ +integration-tests/my-ext/src/test/java/org/acme/ +integration-tests/my-ext/src/test/java/org/acme/my/ +integration-tests/my-ext/src/test/java/org/acme/my/ext/ +integration-tests/my-ext/src/test/java/org/acme/my/ext/it/ +integration-tests/my-ext/src/test/java/org/acme/my/ext/it/NativeMyExtResourceIT.java +integration-tests/my-ext/src/test/java/org/acme/my/ext/it/MyExtResourceTest.java +integration-tests/my-ext/src/main/ +integration-tests/my-ext/src/main/resources/ +integration-tests/my-ext/src/main/resources/application.properties +integration-tests/my-ext/src/main/java/ +integration-tests/my-ext/src/main/java/org/ +integration-tests/my-ext/src/main/java/org/acme/ +integration-tests/my-ext/src/main/java/org/acme/my/ +integration-tests/my-ext/src/main/java/org/acme/my/ext/ +integration-tests/my-ext/src/main/java/org/acme/my/ext/it/ +integration-tests/my-ext/src/main/java/org/acme/my/ext/it/MyExtResource.java +integration-tests/pom.xml +pom.xml +extensions/ +extensions/my-ext/ +extensions/my-ext/runtime/ +extensions/my-ext/runtime/pom.xml +extensions/my-ext/runtime/src/ +extensions/my-ext/runtime/src/main/ +extensions/my-ext/runtime/src/main/resources/ +extensions/my-ext/runtime/src/main/resources/META-INF/ +extensions/my-ext/runtime/src/main/resources/META-INF/quarkus-extension.yaml +extensions/my-ext/pom.xml +extensions/my-ext/deployment/ +extensions/my-ext/deployment/pom.xml +extensions/my-ext/deployment/src/ +extensions/my-ext/deployment/src/test/ +extensions/my-ext/deployment/src/test/java/ +extensions/my-ext/deployment/src/test/java/org/ +extensions/my-ext/deployment/src/test/java/org/acme/ +extensions/my-ext/deployment/src/test/java/org/acme/my/ +extensions/my-ext/deployment/src/test/java/org/acme/my/ext/ +extensions/my-ext/deployment/src/test/java/org/acme/my/ext/test/ +extensions/my-ext/deployment/src/test/java/org/acme/my/ext/test/MyExtTest.java +extensions/my-ext/deployment/src/test/java/org/acme/my/ext/test/MyExtDevModeTest.java +extensions/my-ext/deployment/src/main/ +extensions/my-ext/deployment/src/main/java/ +extensions/my-ext/deployment/src/main/java/org/ +extensions/my-ext/deployment/src/main/java/org/acme/ +extensions/my-ext/deployment/src/main/java/org/acme/my/ +extensions/my-ext/deployment/src/main/java/org/acme/my/ext/ +extensions/my-ext/deployment/src/main/java/org/acme/my/ext/deployment/ +extensions/my-ext/deployment/src/main/java/org/acme/my/ext/deployment/MyExtProcessor.java +extensions/pom.xml \ No newline at end of file diff --git a/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/extensions_my-ext_pom.xml b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/extensions_my-ext_pom.xml new file mode 100644 index 00000000000000..91238b55c01577 --- /dev/null +++ b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/extensions_my-ext_pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.acme + extensions-parent + 0.1-SNAPSHOT + + quarkus-my-ext-parent + pom + Quarkus - My Ext - Parent + + deployment + runtime + + diff --git a/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/extensions_my-ext_runtime_src_main_resources_META-INF_quarkus-extension.yaml b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/extensions_my-ext_runtime_src_main_resources_META-INF_quarkus-extension.yaml new file mode 100644 index 00000000000000..899448c057d6cc --- /dev/null +++ b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/extensions_my-ext_runtime_src_main_resources_META-INF_quarkus-extension.yaml @@ -0,0 +1,9 @@ +name: My Ext +#description: My Ext ... +metadata: +# keywords: +# - my-ext +# guide: ... +# categories: +# - "miscellaneous" +# status: "preview" \ No newline at end of file diff --git a/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/extensions_pom.xml b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/extensions_pom.xml new file mode 100644 index 00000000000000..5e79f7f310a9a1 --- /dev/null +++ b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/extensions_pom.xml @@ -0,0 +1,20 @@ + + + + org.acme + fake-quarkus-parent + 0.1-SNAPSHOT + ../pom.xml + + 4.0.0 + + extensions-parent + + pom + + my-ext + + + diff --git a/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/integration-tests_pom.xml b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/integration-tests_pom.xml new file mode 100644 index 00000000000000..290f8d60bff9c8 --- /dev/null +++ b/integration-tests/maven/src/test/resources/__snapshots__/CreateExtensionMojoIT/testCreateCoreExtensionFromExtensionsDir/integration-tests_pom.xml @@ -0,0 +1,20 @@ + + + + org.acme + fake-quarkus-parent + 0.1-SNAPSHOT + ../pom.xml + + 4.0.0 + + integration-tests-parent + + pom + + my-ext + + +