Skip to content

Commit

Permalink
Use the value of project/default-codestart from the platform descript…
Browse files Browse the repository at this point in the history
…or as the default codestart instead of a hardcoded value
  • Loading branch information
aloubyansky committed Mar 13, 2024
1 parent 61aaf1f commit 467901f
Show file tree
Hide file tree
Showing 20 changed files with 109 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: rest-codestart
ref: rest
name: resteasy-reactive-codestart
ref: resteasy-reactive
type: code
tags: extension-codestart
metadata:
title: REST
description: Easily start your REST Web Services
title: RESTEasy Reactive
description: Easily start your Reactive RESTful Web Services
related-guide-section: https://quarkus.io/guides/getting-started-reactive#reactive-jax-rs-resources
language:
base:
Expand All @@ -14,6 +14,6 @@ language:
path: "/hello"
response: "Hello from Quarkus REST"
dependencies:
- io.quarkus:quarkus-rest
- io.quarkus:quarkus-resteasy-reactive
test-dependencies:
- io.rest-assured:rest-assured
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,16 @@ protected Collection<Codestart> select(QuarkusCodestartProjectInput projectInput
.collect(Collectors.toCollection(ArrayList::new));

// include default codestarts depending on the versions and the extensions being chosen or not
Optional<ExtensionCodestart> selectedDefaultCodeStart = getSelectedDefaultCodeStart(projectInput);
Optional<String> selectedDefaultCodeStart = getSelectedDefaultCodeStart(projectInput);

if (projectInput.getAppContent().contains(CODE)
&& selectedDefaultCodeStart.isPresent()
&& projectCodestarts.stream()
.noneMatch(c -> c.getType() == CodestartType.CODE && !c.getSpec().isPreselected())) {
final Codestart defaultCodestart = codestarts.stream()
.filter(c -> c.matches(selectedDefaultCodeStart.get().key()))
.filter(c -> c.matches(selectedDefaultCodeStart.get()))
.findFirst().orElseThrow(() -> new CodestartStructureException(
selectedDefaultCodeStart.get().key() + " codestart not found"));
selectedDefaultCodeStart.get() + " codestart not found"));
final String languageName = findLanguageName(projectCodestarts);
if (defaultCodestart.implementsLanguage(languageName)) {
projectCodestarts.add(defaultCodestart);
Expand Down Expand Up @@ -178,7 +178,7 @@ protected Collection<Codestart> select(QuarkusCodestartProjectInput projectInput
return projectCodestarts;
}

private Optional<ExtensionCodestart> getSelectedDefaultCodeStart(QuarkusCodestartProjectInput projectInput) {
private Optional<String> getSelectedDefaultCodeStart(QuarkusCodestartProjectInput projectInput) {
// This is very hackyish, we need a better data structure to do better
Optional<ArtifactCoords> quarkusBom = projectInput.getBoms().stream()
.map(ArtifactCoords::fromString)
Expand All @@ -195,13 +195,17 @@ private Optional<ExtensionCodestart> getSelectedDefaultCodeStart(QuarkusCodestar
if (projectInput.getExtensions().isEmpty() ||
(projectInput.getExtensions().size() == 1
&& isLanguageExtension(projectInput.getExtensions().iterator().next()))) {
return Optional.of(ExtensionCodestart.REST);
var defaultCodestart = projectInput.getDefaultCodestart();
if (defaultCodestart == null) {
defaultCodestart = QuarkusCodestartCatalog.ExtensionCodestart.REST.key();
}
return Optional.of(defaultCodestart);
}

return Optional.empty();
}

return Optional.of(ExtensionCodestart.RESTEASY);
return Optional.of(ExtensionCodestart.RESTEASY.key());
}

private boolean isCoreBom(ArtifactCoords artifactCoords) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public final class QuarkusCodestartProjectInput extends CodestartProjectInput {
private final Collection<ArtifactCoords> extensions;
private final Collection<ArtifactCoords> platforms;
private final String example;
private Set<AppContent> appContent;
private final Set<AppContent> appContent;
private final String defaultCodestart;

public QuarkusCodestartProjectInput(QuarkusCodestartProjectInputBuilder builder) {
super(builder);
Expand All @@ -24,6 +25,7 @@ public QuarkusCodestartProjectInput(QuarkusCodestartProjectInputBuilder builder)
this.example = builder.example;
this.buildTool = requireNonNull(builder.buildTool, "buildTool is required");
this.appContent = builder.appContent;
this.defaultCodestart = builder.defaultCodestart;
}

public static QuarkusCodestartProjectInputBuilder builder() {
Expand All @@ -49,4 +51,8 @@ public Set<AppContent> getAppContent() {
public BuildTool getBuildTool() {
return buildTool;
}

public String getDefaultCodestart() {
return defaultCodestart;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class QuarkusCodestartProjectInputBuilder extends CodestartProjectInputBu
Set<AppContent> appContent = new HashSet<>(FULL_CONTENT);
String example;
BuildTool buildTool = BuildTool.MAVEN;
String defaultCodestart;

QuarkusCodestartProjectInputBuilder() {
super();
Expand Down Expand Up @@ -146,6 +147,13 @@ public QuarkusCodestartProjectInputBuilder buildTool(BuildTool buildTool) {
return this;
}

public QuarkusCodestartProjectInputBuilder defaultCodestart(String defaultCodestart) {
if (defaultCodestart != null) {
this.defaultCodestart = defaultCodestart;
}
return this;
}

public QuarkusCodestartProjectInput build() {
return new QuarkusCodestartProjectInput(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
.addData(toCodestartData(invocation.getValues()))
.addData(invocation.getValue(DATA, Collections.emptyMap()))
.messageWriter(invocation.log())
.defaultCodestart(getDefaultCodestart(mainCatalog))
.build();
invocation.log().info("-----------");
if (!extensionsToAdd.isEmpty()) {
Expand Down Expand Up @@ -249,4 +250,20 @@ private void checkMinimumJavaVersion(String javaVersionString, List<Extension> e
.format("Some extensions are not compatible with the selected Java version (%s):\n %s", javaVersion, list));
}
}

private static String getDefaultCodestart(ExtensionCatalog catalog) {
var map = catalog.getMetadata();
if (map != null && !map.isEmpty()) {
var projectMetadata = map.get("project");
if (projectMetadata instanceof Map) {
var defaultCodestart = ((Map<?, ?>) projectMetadata).get("default-codestart");
if (defaultCodestart != null) {
if (defaultCodestart instanceof String) {
return defaultCodestart.toString();
}
}
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.Map;

import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog;
import io.quarkus.registry.catalog.ExtensionCatalog;
Expand Down Expand Up @@ -36,4 +37,17 @@ public static ExtensionCatalog newFakeExtensionCatalog() {
throw new UncheckedIOException(e);
}
}

public static String getDefaultCodestart() {
var map = FAKE_EXTENSION_CATALOG.getMetadata().get("project");
if (map != null) {
if (map instanceof Map) {
var defaultCodestart = ((Map<?, ?>) map).get("default-codestart");
if (defaultCodestart instanceof String) {
return defaultCodestart.toString();
}
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@
],
"metadata": {
"project": {
"default-codestart": "resteasy-reactive",
"properties": {
"doc-root": "https://quarkus.io",
"rest-assured-version": "4.3.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.quarkus.devtools.codestarts.CodestartProjectDefinition;
import io.quarkus.devtools.codestarts.CodestartType;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.testing.FakeExtensionCatalog;
import io.quarkus.devtools.testing.SnapshotTesting;
import io.quarkus.maven.dependency.ArtifactKey;

Expand All @@ -34,7 +35,7 @@ void loadTest() throws IOException {
.extracting(Codestart::getImplementedLanguages)
.allSatisfy(s -> assertThat(s.isEmpty() || s.size() == 3).isTrue());

assertThat(catalog.getCodestarts()).filteredOn("ref", "rest")
assertThat(catalog.getCodestarts()).filteredOn("ref", "resteasy-reactive")
.extracting(Codestart::getImplementedLanguages)
.hasSize(1)
.allSatisfy(s -> assertThat(s).containsExactlyInAnyOrder("java", "kotlin", "scala"));
Expand All @@ -47,7 +48,7 @@ void loadTest() throws IOException {

@Test
void createProjectTestEmpty() throws IOException {
final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder()
final QuarkusCodestartProjectInput input = newInputBuilder()
.noCode()
.noBuildToolWrapper()
.noDockerfiles()
Expand All @@ -68,7 +69,7 @@ void createProjectTestEmpty() throws IOException {

@Test
void createProjectTestNoExample() throws IOException {
final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder()
final QuarkusCodestartProjectInput input = newInputBuilder()
.noCode()
.build();
final CodestartProjectDefinition projectDefinition = getCatalog().createProject(input);
Expand All @@ -88,7 +89,7 @@ void createProjectTestNoExample() throws IOException {

@Test
void createProjectTestGradle() throws IOException {
final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder()
final QuarkusCodestartProjectInput input = newInputBuilder()
.buildTool(BuildTool.GRADLE)
.build();
final CodestartProjectDefinition projectDefinition = getCatalog().createProject(input);
Expand All @@ -98,7 +99,7 @@ void createProjectTestGradle() throws IOException {

@Test
void createProjectTestKotlin() throws IOException {
final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder()
final QuarkusCodestartProjectInput input = newInputBuilder()
.addExtension(ArtifactKey.fromString("io.quarkus:quarkus-kotlin"))
.build();
final CodestartProjectDefinition projectDefinition = getCatalog().createProject(input);
Expand All @@ -108,7 +109,7 @@ void createProjectTestKotlin() throws IOException {

@Test
void prepareProjectTestScala() throws IOException {
final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder()
final QuarkusCodestartProjectInput input = newInputBuilder()
.addExtension(ArtifactKey.fromString("io.quarkus:quarkus-scala"))
.build();
final CodestartProjectDefinition projectDefinition = getCatalog().createProject(input);
Expand All @@ -118,7 +119,7 @@ void prepareProjectTestScala() throws IOException {

@Test
void prepareProjectTestConfigYaml() throws IOException {
final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder()
final QuarkusCodestartProjectInput input = newInputBuilder()
.addExtension(ArtifactKey.fromString("io.quarkus:quarkus-config-yaml"))
.build();
final CodestartProjectDefinition projectDefinition = getCatalog().createProject(input);
Expand All @@ -128,7 +129,7 @@ void prepareProjectTestConfigYaml() throws IOException {

@Test
void prepareProjectTestResteasy() throws IOException {
final QuarkusCodestartProjectInput input = QuarkusCodestartProjectInput.builder()
final QuarkusCodestartProjectInput input = newInputBuilder()
.addExtension(ArtifactKey.fromString("io.quarkus:quarkus-resteasy"))
.build();
final CodestartProjectDefinition projectDefinition = getCatalog().createProject(input);
Expand All @@ -141,6 +142,10 @@ void prepareProjectTestResteasy() throws IOException {
"resteasy-codestart");
}

private static QuarkusCodestartProjectInputBuilder newInputBuilder() {
return QuarkusCodestartProjectInput.builder().defaultCodestart(FakeExtensionCatalog.getDefaultCodestart());
}

private QuarkusCodestartCatalog getCatalog() throws IOException {
return FAKE_QUARKUS_CODESTART_CATALOG;
}
Expand Down
Loading

0 comments on commit 467901f

Please sign in to comment.