Skip to content

Commit

Permalink
Merge pull request quarkusio#26806 from ia3andy/with-codestart
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy authored Jul 25, 2022
2 parents c08ba74 + fe352b9 commit 2b615b8
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 19 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/ci-actions-incremental.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions devtools/cli/src/main/java/io/quarkus/cli/CreateExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -156,9 +157,10 @@ public void dryRun(BuildTool buildTool, CreateExtensionCommandHandler invocation
for (Map.Entry<String, Object> 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());
}

Expand All @@ -167,7 +169,7 @@ public String toString() {
return "CreateExtension{" + "gav=" + gav
+ ", quarkusVersion=" + targetQuarkusVersion
+ ", nameGeneration=" + nameGeneration
+ ", testGeneration=" + testGeneration
+ ", testGeneration=" + codeGeneration
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,6 +24,10 @@ public class ExtensionTestGenerationGroup {
"--without-tests" }, description = "Do not generate any tests (disable all)")
Optional<Boolean> withoutTests;

public boolean withCodestart() {
return codestart;
}

public boolean skipUnitTest() {
return withoutTests.orElse(!unitTest);
}
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ metadata:
# guide: {extension.guide ?: '...'}
# categories:
# - "miscellaneous"
# status: "preview"
# 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}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: extension-codestart
type: code
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{#if input.extra-codestarts.contains("integration-tests")}
package {package-name}.it;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language;
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;

public class {class-name-base}CodestartTest {

@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
.languages(Language.JAVA)
.setupStandaloneExtensionTest("{group-id}:{namespace.id}{extension.id}")
.build();

/**
* Make sure the generated code meets the expectations.
* <br>
* The generated code uses mocked data to be immutable and allow snapshot testing.
* <br><br>
*
* Read the doc: <br>
* {@link https://quarkus.io/guides/extension-codestart#integration-test}
*/
@Test
void testContent() throws Throwable {
//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();
}
}

{#else}
<SKIP>
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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">
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>generate-codestart-jar</id>
<phase>generate-resources</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>$\{project.basedir}/src/main</classesDirectory>
<includes>
<include>codestarts/**</include>
</includes>
<classifier>codestarts</classifier>
<skipIfEmpty>true</skipIfEmpty>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{#include readme-header /}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{#include index-entry /}
Original file line number Diff line number Diff line change
@@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
{#if input.extra-codestarts.contains("extension-codestart")}
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devtools-testing</artifactId>
<scope>test</scope>
</dependency>
{/if}
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<SKIP>";

@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
Expand All @@ -45,7 +50,11 @@ public Optional<String> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 2b615b8

Please sign in to comment.