Skip to content

Commit

Permalink
Simplify and fix default codestart selection code
Browse files Browse the repository at this point in the history
(cherry picked from commit 6484be5)
  • Loading branch information
ia3andy authored and gsmet committed Mar 19, 2024
1 parent 34ef25e commit 7d30d09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import io.quarkus.platform.descriptor.loader.json.ResourceLoader;
import io.quarkus.registry.catalog.Extension;
import io.quarkus.registry.catalog.ExtensionCatalog;
import io.smallrye.common.version.VersionScheme;

public final class QuarkusCodestartCatalog extends GenericCodestartCatalog<QuarkusCodestartProjectInput> {

Expand Down Expand Up @@ -138,13 +137,17 @@ protected Collection<Codestart> select(QuarkusCodestartProjectInput projectInput
.filter(c -> !isExample(c) || projectInput.getExample() == null || c.matches(projectInput.getExample()))
.collect(Collectors.toCollection(ArrayList::new));

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

// if there is no extension selected or only language extensions, we should add the default code start
// this has been settled in https://github.com/quarkusio/quarkus/pull/39467
final boolean shouldAddDefaultCodeStart = projectInput.getExtensions().isEmpty() ||
(projectInput.getExtensions().size() == 1
&& isLanguageExtension(projectInput.getExtensions().iterator().next()));
if (projectInput.getAppContent().contains(CODE)
&& selectedDefaultCodeStart.isPresent()
&& projectCodestarts.stream()
.noneMatch(c -> c.getType() == CodestartType.CODE && !c.getSpec().isPreselected())) {
&& shouldAddDefaultCodeStart) {
final Codestart defaultCodestart = codestarts.stream()
.filter(c -> c.matches(selectedDefaultCodeStart.get()))
.findFirst().orElseThrow(() -> new CodestartStructureException(
Expand Down Expand Up @@ -178,36 +181,6 @@ protected Collection<Codestart> select(QuarkusCodestartProjectInput projectInput
return projectCodestarts;
}

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)
.filter(b -> isCoreBom(b) || isPlatformBom(b) || isUniverseBom(b))
.findFirst();

String bomVersion = null;

if (quarkusBom.isPresent()) {
bomVersion = quarkusBom.get().getVersion();
}

if (bomVersion == null || VersionScheme.MAVEN.compare(bomVersion, "2.8") >= 0) {
if (projectInput.getExtensions().isEmpty() ||
(projectInput.getExtensions().size() == 1
&& isLanguageExtension(projectInput.getExtensions().iterator().next()))) {
var defaultCodestart = projectInput.getDefaultCodestart();
if (defaultCodestart == null) {
defaultCodestart = QuarkusCodestartCatalog.ExtensionCodestart.REST.key();
}
return Optional.of(defaultCodestart);
}

return Optional.empty();
}

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

private boolean isCoreBom(ArtifactCoords artifactCoords) {
return IO_QUARKUS_GROUP_ID.equals(artifactCoords.getGroupId()) && QUARKUS_BOM.equals(artifactCoords.getArtifactId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ private void checkMinimumJavaVersion(String javaVersionString, List<Extension> e
}

private static String getDefaultCodestart(ExtensionCatalog catalog) {
// Recent versions of the catalog have a default-codestart in the project metadata (2.10+)
var map = catalog.getMetadata();
if (map != null && !map.isEmpty()) {
var projectMetadata = map.get("project");
Expand All @@ -264,6 +265,7 @@ private static String getDefaultCodestart(ExtensionCatalog catalog) {
}
}
}
return null;
// Let's use resteasy-reactive for older versions
return "resteasy-reactive";
}
}

0 comments on commit 7d30d09

Please sign in to comment.