From 89922551ccbb105c4121974ff0e3fca13c0e02b4 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Thu, 22 Jun 2023 10:51:49 +0200 Subject: [PATCH] Fix create app exception min java version not thrown up --- .../cli/src/main/java/io/quarkus/cli/CreateApp.java | 2 +- .../SmartPomMergeCodestartFileStrategyHandler.java | 4 ++-- .../handlers/CreateProjectCommandHandler.java | 11 +++-------- ...AppearingInPlatformAndNonPlatformCatalogsTest.java | 5 ++++- ...ctImportingMultipleBomsFromSinglePlatformTest.java | 5 ++++- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java b/devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java index 6752ac38c4786..b2f307e9aff95 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java @@ -101,7 +101,7 @@ public Integer call() throws Exception { return CommandLine.ExitCode.SOFTWARE; } catch (Exception e) { return output.handleCommandException(e, - "Unable to create project: " + e.getMessage()); + "Unable to create project: " + e.getLocalizedMessage()); } } diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/SmartPomMergeCodestartFileStrategyHandler.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/SmartPomMergeCodestartFileStrategyHandler.java index 288b86af36d9a..393e198361cbb 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/SmartPomMergeCodestartFileStrategyHandler.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/SmartPomMergeCodestartFileStrategyHandler.java @@ -12,7 +12,7 @@ import io.fabric8.maven.Maven; import io.fabric8.maven.merge.SmartModelMerger; -import io.quarkus.devtools.codestarts.CodestartStructureException; +import io.quarkus.devtools.codestarts.CodestartException; import io.quarkus.devtools.codestarts.core.CodestartData; import io.quarkus.devtools.codestarts.core.reader.TargetFile; @@ -32,7 +32,7 @@ public void process(Path targetDirectory, String relativePath, List createDirectories(targetPath); CodestartData.getBuildtool(data) .filter(b -> Objects.equals(b, "maven")) - .orElseThrow(() -> new CodestartStructureException( + .orElseThrow(() -> new CodestartException( "something is wrong, smart-pom-merge file strategy must only be used on maven projects")); final SmartModelMerger merger = new SmartModelMerger(); diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java index 47e7db1140ab3..33ed3c0048ca3 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java @@ -65,16 +65,11 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws List extensionsToAdd = computeRequiredExtensions(invocation.getExtensionsCatalog(), extensionsQuery, invocation.log()); - final List extensionOrigins; ExtensionCatalog mainCatalog = invocation.getExtensionsCatalog(); // legacy platform initialization + final String javaVersion = invocation.getStringValue(JAVA_VERSION); - try { - checkMinimumJavaVersion(javaVersion, extensionsToAdd); - extensionOrigins = getExtensionOrigins(mainCatalog, extensionsToAdd); - } catch (QuarkusCommandException e) { - invocation.log().error(e.getLocalizedMessage()); - return QuarkusCommandOutcome.failure(); - } + checkMinimumJavaVersion(javaVersion, extensionsToAdd); + final List extensionOrigins = getExtensionOrigins(mainCatalog, extensionsToAdd); final List platformBoms = new ArrayList<>(Math.max(extensionOrigins.size(), 1)); if (extensionOrigins.size() > 0) { diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/project/create/ExtensionsAppearingInPlatformAndNonPlatformCatalogsTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/project/create/ExtensionsAppearingInPlatformAndNonPlatformCatalogsTest.java index 43aff9a5c4224..9ed389c3d6582 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/project/create/ExtensionsAppearingInPlatformAndNonPlatformCatalogsTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/project/create/ExtensionsAppearingInPlatformAndNonPlatformCatalogsTest.java @@ -1,6 +1,7 @@ package io.quarkus.devtools.project.create; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.nio.file.Path; import java.util.ArrayList; @@ -13,6 +14,7 @@ import org.junit.jupiter.api.Test; import io.quarkus.devtools.commands.CreateProject; +import io.quarkus.devtools.commands.data.QuarkusCommandException; import io.quarkus.devtools.project.BuildTool; import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.devtools.project.QuarkusProjectHelper; @@ -222,7 +224,8 @@ public void addNonPlatformExtensionWithGA() throws Exception { @Test public void attemptCreateWithIncompatibleExtensions() throws Exception { final Path projectDir = newProjectDir("create-with-incompatible-extensions"); - assertThat(createProject(projectDir, Arrays.asList("acme-bar", "other-five-one")).isSuccess()).isFalse(); + assertThatExceptionOfType(QuarkusCommandException.class) + .isThrownBy(() -> createProject(projectDir, Arrays.asList("acme-bar", "other-five-one"))); } @Test diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/project/create/MavenProjectImportingMultipleBomsFromSinglePlatformTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/project/create/MavenProjectImportingMultipleBomsFromSinglePlatformTest.java index 52e337e57c4b8..003ef71903793 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/project/create/MavenProjectImportingMultipleBomsFromSinglePlatformTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/project/create/MavenProjectImportingMultipleBomsFromSinglePlatformTest.java @@ -1,6 +1,7 @@ package io.quarkus.devtools.project.create; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.nio.file.Path; import java.util.ArrayList; @@ -13,6 +14,7 @@ import org.junit.jupiter.api.Test; import io.quarkus.devtools.commands.CreateProject; +import io.quarkus.devtools.commands.data.QuarkusCommandException; import io.quarkus.devtools.project.BuildTool; import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.devtools.project.QuarkusProjectHelper; @@ -200,7 +202,8 @@ public void addExtensionAndImportMemberBom() throws Exception { @Test public void attemptCreateWithIncompatibleExtensions() throws Exception { final Path projectDir = newProjectDir("create-with-incompatible-extensions"); - assertThat(createProject(projectDir, Arrays.asList("acme-bar", "other-five-one")).isSuccess()).isFalse(); + assertThatExceptionOfType(QuarkusCommandException.class) + .isThrownBy(() -> createProject(projectDir, Arrays.asList("acme-bar", "other-five-one"))); } @Test