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

Fix picocli codestart readme with gradle #15770

Merged
merged 1 commit into from Mar 17, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -45,17 +45,17 @@ You can then execute your native executable with: `./{buildtool.build-dir}/{proj

If you want to learn more about building native executables, please consult {buildtool.guide}.

{#if selected-extensions}
{#if input.selected-extensions}
## Related guides

{#for ext in selected-extensions}
{#for ext in input.selected-extensions}
{#if ext.guide}
- {ext.name} ([guide]({ext.guide})): {ext.description}
{/if}
{/for}

{/if}
{#if selected-examples}
{#if input.selected-examples}
## Provided examples
{/if}

Expand Up @@ -149,11 +149,11 @@ <h3>Do you like Quarkus?</h3>
<li>Go give it a star on <a href="https://github.com/quarkusio/quarkus">GitHub</a>.</li>
</ul>
</div>
{#if selected-extensions}
{#if input.selected-extensions}
<div class="right-section">
<h3>Selected extensions guides</h3>
<ul>
{#for ext in selected-extensions}
{#for ext in input.selected-extensions}
{#if ext.guide}
<li title="{ext.description}"><a href="{ext.guide}" target="_blank">{ext.name} guide</a></li>
{/if}
Expand Down
Expand Up @@ -4,6 +4,5 @@ Also for picocli applications the dev mode is supported. When running dev mode,

As picocli applications will often require arguments to be passed on the commandline, this is also possible in dev mode via:
```shell script
{buildtool.cli} {buildtool.cmd.dev} {#if buildtool.cli == 'gradle'}--quarkus-args{#else}-Dquarkus.args={/if}='help'
{buildtool.cli} {buildtool.cmd.dev} {#if input.base-codestart.buildtool == 'gradle' || input.base-codestart.buildtool == 'gradle-kotlin-dsl'}--quarkus-args{#else}-Dquarkus.args{/if}='hello --first-name=Quarky'
```

@@ -1,6 +1,7 @@
package io.quarkus.devtools.codestarts.core;

import io.quarkus.devtools.codestarts.Codestart;
import io.quarkus.devtools.codestarts.CodestartType;
import io.quarkus.devtools.codestarts.core.CodestartSpec.CodestartDep;
import io.quarkus.devtools.codestarts.utils.NestedMaps;
import java.util.Collection;
Expand All @@ -15,11 +16,19 @@

public final class CodestartData {

public static final String INPUT_BASE_CODESTART_KEY_PREFIX = "input.base-codestart.";
public static final String INPUT_BASE_CODESTARTS_KEY = "input.base-codestarts";
public static final String INPUT_EXTRA_CODESTARTS_KEY = "input.extra-codestarts";

private CodestartData() {
}

public static Optional<String> getInputCodestartForType(final Map<String, Object> data, final CodestartType type) {
return NestedMaps.getValue(data, INPUT_BASE_CODESTART_KEY_PREFIX + type.toString().toLowerCase());
}

public static Optional<String> getBuildtool(final Map<String, Object> data) {
return NestedMaps.getValue(data, "codestart-project.buildtool.name");
return getInputCodestartForType(data, CodestartType.BUILDTOOL);
}

public static Map<String, Object> buildCodestartData(final Codestart codestart, final String languageName,
Expand All @@ -35,11 +44,11 @@ public static Map<String, Object> buildCodestartData(final Codestart codestart,
public static Map<String, Object> buildCodestartProjectData(Collection<Codestart> baseCodestarts,
Collection<Codestart> extraCodestarts) {
final HashMap<String, Object> data = new HashMap<>();
baseCodestarts.forEach((c) -> data.put("codestart-project." + c.getSpec().getType().toString().toLowerCase() + ".name",
baseCodestarts.forEach((c) -> data.put(INPUT_BASE_CODESTART_KEY_PREFIX + c.getSpec().getType().toString().toLowerCase(),
c.getName()));
data.put("codestart-project.base-codestarts",
data.put(INPUT_BASE_CODESTARTS_KEY,
baseCodestarts.stream().map(Codestart::getName).collect(Collectors.toList()));
data.put("codestart-project.extra-codestarts",
data.put(INPUT_EXTRA_CODESTARTS_KEY,
extraCodestarts.stream().map(Codestart::getName).collect(Collectors.toList()));
return NestedMaps.unflatten(data);
}
Expand Down
Expand Up @@ -4,6 +4,8 @@
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.CodestartType;
import io.quarkus.devtools.codestarts.core.CodestartData;
import io.quarkus.devtools.codestarts.core.reader.TargetFile;
import io.quarkus.devtools.codestarts.utils.NestedMaps;
import java.io.IOException;
Expand Down Expand Up @@ -82,8 +84,7 @@ static void flatten(String prefix, Map<String, String> target, Map<String, ?> ma
}

private static String getConfigType(Map<String, Object> data) {
final Optional<String> config = NestedMaps.getValue(data, "codestart-project.config.name");
final Optional<String> config = CodestartData.getInputCodestartForType(data, CodestartType.CONFIG);
return config.orElseThrow(() -> new CodestartException("Config type is required"));
}

}
Expand Up @@ -37,6 +37,9 @@
public final class QuarkusCodestartCatalog extends GenericCodestartCatalog<QuarkusCodestartProjectInput> {

public static final String QUARKUS_CODESTARTS_DIR = "codestarts/quarkus";
public static final String INPUT_SELECTED_EXTENSIONS_KEY = "selected-extensions";
public static final String INPUT_SELECTED_EXTENSIONS_GA_KEY = "selected-extensions-ga";
public static final String INPUT_SELECTED_EXAMPLES_KEY = "selected-examples";
private final Map<String, Extension> extensionsMapping;

public enum Tag implements DataKey {
Expand Down Expand Up @@ -101,8 +104,6 @@ protected Collection<Codestart> select(QuarkusCodestartProjectInput projectInput
projectInput.getSelection().addNames(getToolingCodestarts(projectInput));
projectInput.getSelection().addNames(projectInput.getOverrideExamples());

projectInput.getData().putAll(generateSelectedExtensionsData(projectInput));

// Filter out examples if noExamples
final List<Codestart> projectCodestarts = super.select(projectInput).stream()
.filter(c -> !isExample(c) || !projectInput.noExamples())
Expand Down Expand Up @@ -143,7 +144,7 @@ protected Collection<Codestart> select(QuarkusCodestartProjectInput projectInput
"Only one extension with singleton example can be selected at a time (you can always use 'noExamples' if needed)");
}

projectInput.getData().putAll(generateSelectedExamplesData(projectCodestarts));
projectInput.getData().putAll(generateSelectionData(projectInput, projectCodestarts));

return projectCodestarts;
}
Expand Down Expand Up @@ -184,29 +185,28 @@ private List<String> getToolingCodestarts(QuarkusCodestartProjectInput projectIn
return codestarts;
}

private Map<String, Object> generateSelectedExamplesData(List<Codestart> projectCodestarts) {
Map<String, Object> data = new HashMap<>();
data.put("selected-examples", projectCodestarts.stream().filter(QuarkusCodestartCatalog::isExample).map(c -> {
Map<String, Object> eData = new HashMap<>();
eData.put("name", c.getName());
eData.put("tags", c.getTags());
eData.putAll(c.getMetadata());
return eData;
}).collect(Collectors.toList()));
return data;
}

private Map<String, Object> generateSelectedExtensionsData(QuarkusCodestartProjectInput projectInput) {
private Map<String, Object> generateSelectionData(QuarkusCodestartProjectInput projectInput,
List<Codestart> projectCodestarts) {
Map<String, Object> data = new HashMap<>();
data.put("selected-extensions-ga",
final Map<String, Object> inputData = new HashMap<>();
inputData.put(INPUT_SELECTED_EXAMPLES_KEY,
projectCodestarts.stream().filter(QuarkusCodestartCatalog::isExample).map(c -> {
Map<String, Object> eData = new HashMap<>();
eData.put("name", c.getName());
eData.put("tags", c.getTags());
eData.putAll(c.getMetadata());
return eData;
}).collect(Collectors.toList()));
inputData.put(INPUT_SELECTED_EXTENSIONS_GA_KEY,
getSelectedExtensionsAsStream(projectInput).map(Extension::managementKey).collect(Collectors.toSet()));
data.put("selected-extensions", getSelectedExtensionsAsStream(projectInput).map(e -> {
inputData.put(INPUT_SELECTED_EXTENSIONS_KEY, getSelectedExtensionsAsStream(projectInput).map(e -> {
Map<String, Object> eData = new HashMap<>();
eData.put("name", e.getName());
eData.put("description", e.getDescription());
eData.put("guide", getGuide(e));
return eData;
}).collect(Collectors.toList()));
data.put("input", inputData);
return data;
}

Expand Down
Expand Up @@ -320,6 +320,9 @@ void generateMavenPicocliJava(TestInfo testInfo) throws Throwable {
assertThatMatchSnapshot(testInfo, projectDir, "src/main/java/org/acme/picocli/GoodbyeCommand.java");
assertThatMatchSnapshot(testInfo, projectDir, "src/main/java/org/acme/picocli/HelloCommand.java");
assertThatMatchSnapshot(testInfo, projectDir, "src/main/java/org/acme/picocli/GreetingService.java");

assertThat(projectDir.resolve("README.md"))
.satisfies(checkContains("./mvnw compile quarkus:dev -Dquarkus.args='hello --first-name=Quarky"));
}

@Test
Expand All @@ -343,6 +346,25 @@ void generateMavenPicocliKotlin(TestInfo testInfo) throws Throwable {
assertThatMatchSnapshot(testInfo, projectDir, "src/main/kotlin/org/acme/picocli/GreetingService.kt");
}

@Test
void generateMavenPicocliGradle(TestInfo testInfo) throws Throwable {
final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder()
.addExtension(AppArtifactKey.fromString("io.quarkus:quarkus-picocli"))
.buildTool(BuildTool.GRADLE)
.addData(getGenerationTestInputData())
.build();
final Path projectDir = testDirPath.resolve("maven-picocli-gradle");
getCatalog().createProject(input).generate(projectDir);

checkGradle(projectDir);
checkReadme(projectDir);
checkDockerfiles(projectDir, BuildTool.GRADLE);
checkConfigProperties(projectDir);

assertThat(projectDir.resolve("README.md"))
.satisfies(checkContains("./gradlew quarkusDev --quarkus-args='hello --first-name=Quarky'"));
}

@Test
void generateMavenConfigYamlJava(TestInfo testInfo) throws Throwable {
final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder()
Expand Down