Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple fixes for create-extension in Quarkus core #15860

Merged
merged 1 commit into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public enum LayoutType {
private final EnhancedDataMap data = new EnhancedDataMap();

private MessageWriter log = MessageWriter.info();
private String extensionId;
private String itTestRelativeDir = "integration-tests";
private String bomRelativeDir = "bom/application";
private String extensionsRelativeDir = "extensions";
Expand All @@ -76,7 +77,9 @@ public CreateExtension groupId(String groupId) {
}

public CreateExtension extensionId(String extensionId) {
data.putIfNonEmptyString(EXTENSION_ID, extensionId);
if (!StringUtils.isEmpty(extensionId)) {
this.extensionId = extensionId;
}
return this;
}

Expand Down Expand Up @@ -187,14 +190,13 @@ 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));
ensureRequiredStringData(EXTENSION_ID, resolveExtensionId());
data.putIfAbsent(EXTENSION_NAME, toCapWords(extensionId));
data.putIfAbsent(NAMESPACE_NAME, computeDefaultNamespaceName(data.getRequiredStringValue(NAMESPACE_ID)));
data.putIfAbsent(CLASS_NAME_BASE, toCapCamelCase(extensionId));

Expand All @@ -212,13 +214,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);
Expand Down Expand Up @@ -266,7 +269,15 @@ 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 resolveExtensionId() {
String namespaceId = data.getRequiredStringValue(NAMESPACE_ID);
if (extensionId.startsWith(namespaceId)) {
extensionId = extensionId.substring(namespaceId.length());
}
return extensionId;
}

private String getDefaultNamespaceId(LayoutType layoutType) {
Expand Down Expand Up @@ -315,7 +326,7 @@ private String getRuntimeArtifactIdFromData() {
}

private static Path resolveWorkingDir(Path dir) {
return dir.endsWith("extensions/") ? dir.resolve("..") : dir;
return "extensions".equals(dir.getFileName().toString()) ? dir.resolve("..") : dir;
}

public static LayoutType detectLayoutType(Model basePom, String groupId) {
Expand Down Expand Up @@ -430,10 +441,8 @@ public Optional<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
<groupId>{group-id}</groupId>
<version>{version}</version>
{/if}

<artifactId>{namespace.id}{extension.id}-parent</artifactId>
{#if extension.name}
<name>{namespace.name}{extension.name} - Parent</name>
{/if}

<packaging>pom</packaging>

{#if !properties.from-parent}
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand All @@ -44,6 +43,7 @@
{/if}
</properties>

{/if}
<modules>
<module>deployment</module>
<module>runtime</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: {namespace.name}{extension.name}
#description: {namespace.name}{extension.name} ...
name: {extension.name}
#description: {extension.name} ...
metadata:
# keywords:
# - {extension.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "quarkus-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");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.acme</groupId>
<artifactId>extensions-parent</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<artifactId>quarkus-my-ext-parent</artifactId>
<packaging>pom</packaging>
<name>Quarkus - My Ext - Parent</name>
<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: My Ext
#description: My Ext ...
metadata:
# keywords:
# - my-ext
# guide: ...
# categories:
# - "miscellaneous"
# status: "preview"
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.acme</groupId>
<artifactId>fake-quarkus-parent</artifactId>
<version>0.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>fake-quarkus-bom</artifactId>
<packaging>pom</packaging>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.acme</groupId>
<artifactId>quarkus-my-ext</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.acme</groupId>
<artifactId>quarkus-my-ext-deployment</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.acme</groupId>
<artifactId>extensions-parent</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<artifactId>quarkus-my-ext-parent</artifactId>
<packaging>pom</packaging>
<name>Quarkus - My Ext - Parent</name>
<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: My Ext
#description: My Ext ...
metadata:
# keywords:
# - my-ext
# guide: ...
# categories:
# - "miscellaneous"
# status: "preview"
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.acme</groupId>
<artifactId>fake-quarkus-parent</artifactId>
<version>0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>extensions-parent</artifactId>

<packaging>pom</packaging>
<modules>
<module>my-ext</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.acme</groupId>
<artifactId>fake-quarkus-parent</artifactId>
<version>0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>integration-tests-parent</artifactId>

<packaging>pom</packaging>
<modules>
<module>my-ext</module>
</modules>

</project>