|
1 | 1 | package io.quarkus.devtools.commands.handlers; |
2 | 2 |
|
3 | | -import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.DATA; |
4 | | -import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.EXAMPLE; |
5 | | -import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.EXTENSIONS; |
6 | | -import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.EXTRA_CODESTARTS; |
7 | | -import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.NO_BUILDTOOL_WRAPPER; |
8 | | -import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.NO_CODE; |
9 | | -import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.NO_DOCKERFILES; |
10 | | -import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.PACKAGE_NAME; |
11 | | -import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.PROJECT_GROUP_ID; |
12 | | -import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.QUARKUS_VERSION; |
13 | | -import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.RESOURCE_CLASS_NAME; |
| 3 | +import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.*; |
14 | 4 | import static io.quarkus.devtools.commands.handlers.CreateProjectCodestartDataConverter.toCodestartData; |
15 | 5 | import static io.quarkus.devtools.commands.handlers.QuarkusCommandHandlers.computeExtensionsFromQuery; |
16 | | -import static io.quarkus.devtools.messagewriter.MessageIcons.ERROR_ICON; |
| 6 | +import static io.quarkus.platform.catalog.processor.ExtensionProcessor.getMinimumJavaVersion; |
17 | 7 |
|
18 | 8 | import java.io.IOException; |
19 | 9 | import java.util.ArrayList; |
|
30 | 20 | import io.quarkus.devtools.codestarts.CodestartType; |
31 | 21 | import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog; |
32 | 22 | import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartProjectInput; |
| 23 | +import io.quarkus.devtools.commands.CreateProjectHelper; |
33 | 24 | import io.quarkus.devtools.commands.data.QuarkusCommandException; |
34 | 25 | import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; |
35 | 26 | import io.quarkus.devtools.commands.data.QuarkusCommandOutcome; |
@@ -74,15 +65,14 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws |
74 | 65 |
|
75 | 66 | List<Extension> extensionsToAdd = computeRequiredExtensions(invocation.getExtensionsCatalog(), extensionsQuery, |
76 | 67 | invocation.log()); |
77 | | - |
78 | | - ExtensionCatalog mainCatalog = invocation.getExtensionsCatalog(); // legacy platform initialization |
79 | 68 | final List<ExtensionCatalog> extensionOrigins; |
| 69 | + ExtensionCatalog mainCatalog = invocation.getExtensionsCatalog(); // legacy platform initialization |
| 70 | + final String javaVersion = invocation.getStringValue(JAVA_VERSION); |
80 | 71 | try { |
| 72 | + checkMinimumJavaVersion(javaVersion, extensionsToAdd); |
81 | 73 | extensionOrigins = getExtensionOrigins(mainCatalog, extensionsToAdd); |
82 | 74 | } catch (QuarkusCommandException e) { |
83 | | - final StringBuilder buf = new StringBuilder(); |
84 | | - buf.append(ERROR_ICON).append(' ').append(e.getLocalizedMessage()); |
85 | | - invocation.log().info(buf.toString()); |
| 75 | + invocation.log().error(e.getLocalizedMessage()); |
86 | 76 | return QuarkusCommandOutcome.failure(); |
87 | 77 | } |
88 | 78 |
|
@@ -244,4 +234,24 @@ private static void addOrigins(final List<ExtensionOrigins> extOrigins, Extensio |
244 | 234 | extOrigins.add(eoBuilder.build()); |
245 | 235 | } |
246 | 236 | } |
| 237 | + |
| 238 | + private void checkMinimumJavaVersion(String javaVersionString, List<Extension> extensions) throws QuarkusCommandException { |
| 239 | + final List<Extension> incompatibleExtensions = new ArrayList<>(); |
| 240 | + final int javaVersion = javaVersionString == null ? CreateProjectHelper.DEFAULT_JAVA_VERSION |
| 241 | + : Integer.parseInt(javaVersionString); |
| 242 | + for (Extension extension : extensions) { |
| 243 | + Integer extMinJavaVersion = getMinimumJavaVersion(extension); |
| 244 | + if (extMinJavaVersion != null |
| 245 | + && javaVersion < extMinJavaVersion) { |
| 246 | + incompatibleExtensions.add(extension); |
| 247 | + } |
| 248 | + } |
| 249 | + if (!incompatibleExtensions.isEmpty()) { |
| 250 | + final String list = incompatibleExtensions.stream() |
| 251 | + .map(e -> String.format("- %s (min: %s)", e.managementKey(), getMinimumJavaVersion(e))) |
| 252 | + .collect(Collectors.joining("\n ")); |
| 253 | + throw new QuarkusCommandException(String |
| 254 | + .format("Some extensions are not compatible with the selected Java version (%s):\n %s", javaVersion, list)); |
| 255 | + } |
| 256 | + } |
247 | 257 | } |
0 commit comments