From 2bf0c5a5d4229186b03a9b5214f5d588cbbb97c4 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Mon, 11 Jul 2022 14:44:49 +0200 Subject: [PATCH] Refactor & Remove legacy codegen --- .../main/java/io/quarkus/cli/CreateApp.java | 4 +- .../main/java/io/quarkus/cli/CreateCli.java | 4 +- .../quarkus/cli/create/BaseCreateCommand.java | 36 +++--- .../cli/create/CodeGenerationGroup.java | 2 +- .../create/ExtensionNameGenerationGroup.java | 2 +- .../io/quarkus/cli/create/TargetGAVGroup.java | 2 +- .../cli/create/TargetLanguageGroup.java | 6 +- .../cli/registry/RegistryClientMixin.java | 2 +- .../io/quarkus/cli/CliProjectGradleTest.java | 4 +- .../io/quarkus/cli/CliProjectJBangTest.java | 2 +- .../io/quarkus/cli/CliProjectMavenTest.java | 4 +- .../cli/create/TargetGAVGroupTest.java | 2 +- .../io/quarkus/maven/CreateJBangMojo.java | 5 +- .../io/quarkus/maven/CreateProjectMojo.java | 26 ++--- ...rkusJBangCodestartProjectInputBuilder.java | 2 +- .../quarkus/QuarkusCodestartData.java | 76 ------------- .../devtools/commands/CreateJBangProject.java | 15 ++- .../devtools/commands/CreateProject.java | 78 ++++++------- .../CreateProjectHelper.java | 33 ++---- .../quarkus/devtools/commands/SourceType.java | 25 +++++ .../CreateJBangProjectCommandHandler.java | 17 +-- .../CreateProjectCodestartDataConverter.java | 106 ++++++++++++++++++ .../handlers/CreateProjectCommandHandler.java | 44 ++++---- .../project/codegen/ProjectGenerator.java | 27 ----- .../devtools/project/codegen/SourceType.java | 90 --------------- .../codegen/writer/FileProjectWriter.java | 82 -------------- .../project/codegen/writer/ProjectWriter.java | 28 ----- .../commands/CreateProjectHelperTest.java | 53 +++++++++ .../codegen/CreateProjectHelperTest.java | 74 ------------ .../codestarts/QuarkusCodestartTest.java | 2 +- .../commands/CreateJBangProjectTest.java | 7 +- .../devtools/commands/CreateProjectTest.java | 40 +++++-- .../gradle/QuarkusPluginFunctionalTest.java | 36 +++--- 33 files changed, 372 insertions(+), 564 deletions(-) rename independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/{project/codegen => commands}/CreateProjectHelper.java (89%) create mode 100644 independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/SourceType.java create mode 100644 independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCodestartDataConverter.java delete mode 100644 independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/ProjectGenerator.java delete mode 100644 independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/SourceType.java delete mode 100644 independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/writer/FileProjectWriter.java delete mode 100644 independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/writer/ProjectWriter.java create mode 100644 independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/commands/CreateProjectHelperTest.java delete mode 100644 independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/project/codegen/CreateProjectHelperTest.java 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 3000a3da18a37..e45733c788919 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java @@ -10,11 +10,11 @@ import io.quarkus.cli.create.TargetBuildToolGroup; import io.quarkus.cli.create.TargetGAVGroup; import io.quarkus.cli.create.TargetLanguageGroup; +import io.quarkus.devtools.commands.SourceType; import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; import io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler; import io.quarkus.devtools.commands.handlers.CreateProjectCommandHandler; import io.quarkus.devtools.project.BuildTool; -import io.quarkus.devtools.project.codegen.SourceType; import picocli.CommandLine; @CommandLine.Command(name = "app", header = "Create a Quarkus application project.", description = "%n" @@ -59,7 +59,7 @@ public Integer call() throws Exception { BuildTool buildTool = targetBuildTool.getBuildTool(BuildTool.MAVEN); SourceType sourceType = targetLanguage.getSourceType(spec, buildTool, extensions, output); - setJavaVersion(targetLanguage.getJavaVersion()); + setJavaVersion(sourceType, targetLanguage.getJavaVersion()); setSourceTypeExtensions(extensions, sourceType); setCodegenOptions(codeGeneration); diff --git a/devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java b/devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java index f570cf1137ebd..4c5788b6d3968 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java @@ -10,11 +10,11 @@ import io.quarkus.cli.create.TargetBuildToolGroup; import io.quarkus.cli.create.TargetGAVGroup; import io.quarkus.cli.create.TargetLanguageGroup; +import io.quarkus.devtools.commands.SourceType; import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; import io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler; import io.quarkus.devtools.commands.handlers.CreateProjectCommandHandler; import io.quarkus.devtools.project.BuildTool; -import io.quarkus.devtools.project.codegen.SourceType; import picocli.CommandLine; @CommandLine.Command(name = "cli", header = "Create a Quarkus command-line project.", description = "%n" @@ -61,7 +61,7 @@ public Integer call() throws Exception { BuildTool buildTool = targetBuildTool.getBuildTool(BuildTool.MAVEN); SourceType sourceType = targetLanguage.getSourceType(spec, buildTool, extensions, output); - setJavaVersion(targetLanguage.getJavaVersion()); + setJavaVersion(sourceType, targetLanguage.getJavaVersion()); setSourceTypeExtensions(extensions, sourceType); setCodegenOptions(codeGeneration); diff --git a/devtools/cli/src/main/java/io/quarkus/cli/create/BaseCreateCommand.java b/devtools/cli/src/main/java/io/quarkus/cli/create/BaseCreateCommand.java index a13c2e3c5f0e9..4922d09d5542c 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/create/BaseCreateCommand.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/create/BaseCreateCommand.java @@ -1,5 +1,7 @@ package io.quarkus.cli.create; +import static io.quarkus.devtools.commands.CreateProjectHelper.computeJavaVersion; + import java.nio.file.Path; import java.util.Collection; import java.util.HashMap; @@ -13,13 +15,12 @@ import io.quarkus.cli.common.RunModeOption; import io.quarkus.cli.common.TargetQuarkusVersionGroup; import io.quarkus.cli.registry.ToggleRegistryClientMixin; -import io.quarkus.devtools.commands.CreateProject; +import io.quarkus.devtools.commands.CreateProject.CreateProjectKey; +import io.quarkus.devtools.commands.CreateProjectHelper; +import io.quarkus.devtools.commands.SourceType; import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; import io.quarkus.devtools.project.BuildTool; import io.quarkus.devtools.project.QuarkusProject; -import io.quarkus.devtools.project.codegen.CreateProjectHelper; -import io.quarkus.devtools.project.codegen.ProjectGenerator; -import io.quarkus.devtools.project.codegen.SourceType; import io.quarkus.registry.RegistryResolutionException; import picocli.CommandLine; import picocli.CommandLine.Model.CommandSpec; @@ -104,9 +105,9 @@ public Path outputDirectory() { public void setSingleProjectGAV(TargetGAVGroup targetGav) { projectDirName = targetGav.getArtifactId(); - setValue(ProjectGenerator.PROJECT_GROUP_ID, targetGav.getGroupId()); - setValue(ProjectGenerator.PROJECT_ARTIFACT_ID, targetGav.getArtifactId()); - setValue(ProjectGenerator.PROJECT_VERSION, targetGav.getVersion()); + setValue(CreateProjectKey.PROJECT_GROUP_ID, targetGav.getGroupId()); + setValue(CreateProjectKey.PROJECT_ARTIFACT_ID, targetGav.getArtifactId()); + setValue(CreateProjectKey.PROJECT_VERSION, targetGav.getVersion()); } /** @@ -163,14 +164,12 @@ public Path projectRoot() { public void setSourceTypeExtensions(Set extensions, SourceType sourceType) { extensions = CreateProjectHelper.sanitizeExtensions(extensions); CreateProjectHelper.addSourceTypeExtensions(extensions, sourceType); - - setValue(ProjectGenerator.SOURCE_TYPE, sourceType); - setValue(ProjectGenerator.EXTENSIONS, extensions); + setValue(CreateProjectKey.EXTENSIONS, extensions); } /** Set Java source level */ - public void setJavaVersion(String javaVersion) { - CreateProjectHelper.setJavaVersion(values, javaVersion); + public void setJavaVersion(SourceType sourceType, String javaVersion) { + values.put(CreateProjectKey.JAVA_VERSION, computeJavaVersion(sourceType, javaVersion)); } /** @@ -179,11 +178,11 @@ public void setJavaVersion(String javaVersion) { * @param codeGeneration */ public void setCodegenOptions(CodeGenerationGroup codeGeneration) { - setValue(ProjectGenerator.PACKAGE_NAME, codeGeneration.packageName); - setValue(ProjectGenerator.APP_CONFIG, codeGeneration.getAppConfig()); + setValue(CreateProjectKey.PACKAGE_NAME, codeGeneration.packageName); + setValue(CreateProjectKey.APP_CONFIG, codeGeneration.getAppConfig()); - setValue(CreateProject.NO_CODE, !codeGeneration.includeCode); - setValue(CreateProject.NO_BUILDTOOL_WRAPPER, !codeGeneration.includeWrapper); + setValue(CreateProjectKey.NO_CODE, !codeGeneration.includeCode); + setValue(CreateProjectKey.NO_BUILDTOOL_WRAPPER, !codeGeneration.includeWrapper); } private void setValue(String name, Object value) { @@ -269,7 +268,7 @@ public void dryRun(BuildTool buildTool, QuarkusCommandInvocation invocation, Out } public String prettyName(String key) { - if (CreateProject.NO_BUILDTOOL_WRAPPER.equals(key)) { + if (CreateProjectKey.NO_BUILDTOOL_WRAPPER.equals(key)) { return "Omit build tool wrapper"; } @@ -277,7 +276,8 @@ public String prettyName(String key) { StringBuilder builder = new StringBuilder(key); for (int i = 0; i < builder.length(); i++) { // Check char is underscore - if (builder.charAt(i) == '_') { + final char c = builder.charAt(i); + if (c == '-' || c == '.') { builder.replace(i, i + 1, " "); builder.replace(i + 1, i + 2, String.valueOf(Character.toUpperCase(builder.charAt(i + 1)))); diff --git a/devtools/cli/src/main/java/io/quarkus/cli/create/CodeGenerationGroup.java b/devtools/cli/src/main/java/io/quarkus/cli/create/CodeGenerationGroup.java index cc4807a716622..488bcf9bdad34 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/create/CodeGenerationGroup.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/create/CodeGenerationGroup.java @@ -3,7 +3,7 @@ import java.util.Collections; import java.util.Map; -import io.quarkus.devtools.project.codegen.CreateProjectHelper; +import io.quarkus.devtools.commands.CreateProjectHelper; import io.quarkus.platform.tools.ToolsUtils; import picocli.CommandLine; diff --git a/devtools/cli/src/main/java/io/quarkus/cli/create/ExtensionNameGenerationGroup.java b/devtools/cli/src/main/java/io/quarkus/cli/create/ExtensionNameGenerationGroup.java index a702aa00d096a..8b1928b0fb6f5 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/create/ExtensionNameGenerationGroup.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/create/ExtensionNameGenerationGroup.java @@ -1,6 +1,6 @@ package io.quarkus.cli.create; -import io.quarkus.devtools.project.codegen.CreateProjectHelper; +import io.quarkus.devtools.commands.CreateProjectHelper; import picocli.CommandLine; public class ExtensionNameGenerationGroup { diff --git a/devtools/cli/src/main/java/io/quarkus/cli/create/TargetGAVGroup.java b/devtools/cli/src/main/java/io/quarkus/cli/create/TargetGAVGroup.java index 13a7f6d2e2e26..5c45c4a64254a 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/create/TargetGAVGroup.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/create/TargetGAVGroup.java @@ -1,6 +1,6 @@ package io.quarkus.cli.create; -import io.quarkus.devtools.project.codegen.CreateProjectHelper; +import io.quarkus.devtools.commands.CreateProjectHelper; import picocli.CommandLine; public class TargetGAVGroup { diff --git a/devtools/cli/src/main/java/io/quarkus/cli/create/TargetLanguageGroup.java b/devtools/cli/src/main/java/io/quarkus/cli/create/TargetLanguageGroup.java index 4248ba04c6c86..c889f156f8f0a 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/create/TargetLanguageGroup.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/create/TargetLanguageGroup.java @@ -5,9 +5,9 @@ import java.util.stream.Collectors; import io.quarkus.cli.common.OutputOptionMixin; +import io.quarkus.devtools.commands.CreateProjectHelper; +import io.quarkus.devtools.commands.SourceType; import io.quarkus.devtools.project.BuildTool; -import io.quarkus.devtools.project.codegen.CreateProjectHelper; -import io.quarkus.devtools.project.codegen.SourceType; import picocli.CommandLine; import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.ParameterException; @@ -49,7 +49,7 @@ public SourceType getSourceType(CommandSpec spec, BuildTool buildTool, Set * If more than one of those extensions are picked, this parameter will be ignored. *
- * This is @Deprecated because using a generic path parameters with multiple example does not make sense and lead to - * confusion. * More info: https://github.com/quarkusio/quarkus/issues/14437 *
* {@code className} */ @Parameter(property = "path") - @Deprecated private String path; /** @@ -125,8 +121,6 @@ public class CreateProjectMojo extends AbstractMojo { *
* If more than one of those extensions are picked, then only the package name part will be used as {@link #packageName} *
- * This is @Deprecated because using a generic className parameters with multiple example does not make sense and lead to - * confusion. * More info: https://github.com/quarkusio/quarkus/issues/14437 *
* By default, the {@link #projectGroupId} is used as package for generated classes (you can also use {@link #packageName} @@ -135,7 +129,6 @@ public class CreateProjectMojo extends AbstractMojo { * {@code className} */ @Parameter(property = "className") - @Deprecated private String className; /** @@ -273,8 +266,7 @@ public void execute() throws MojoExecutionException { try { extensions = CreateProjectHelper.sanitizeExtensions(extensions); catalog = CreateProjectHelper.completeCatalog(catalog, extensions, mvn); - final SourceType sourceType = CreateProjectHelper.determineSourceType(extensions); - sanitizeOptions(sourceType); + sanitizeOptions(); final List codestartsResourceLoader = codestartLoadersBuilder() .catalog(catalog) @@ -286,17 +278,14 @@ public void execute() throws MojoExecutionException { .groupId(projectGroupId) .artifactId(projectArtifactId) .version(projectVersion) - .sourceType(sourceType) - .javaTarget(javaVersion) - .className(className) + .javaVersion(javaVersion) + .resourceClassName(className) .packageName(packageName) .extensions(extensions) + .resourcePath(path) .example(example) .noCode(noCode) .appConfig(appConfig); - if (path != null) { - createProject.setValue("path", path); - } success = createProject.execute().isSuccess(); if (success && parentPomModel != null && BuildTool.MAVEN.equals(buildToolEnum)) { @@ -419,10 +408,9 @@ private boolean shouldUseDefaults() { } - private void sanitizeOptions(SourceType sourceType) { + private void sanitizeOptions() { if (className != null) { - className = sourceType.stripExtensionFrom(className); - + className = className.replaceAll("\\.(java|kotlin|scala)$", ""); int idx = className.lastIndexOf('.'); if (idx >= 0 && isBlank(packageName)) { // if it's a full qualified class name, we use the package name part (only if the packageName wasn't already defined) diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartProjectInputBuilder.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartProjectInputBuilder.java index e9018cdfc9324..1ea5c4bc2fc8f 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartProjectInputBuilder.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartProjectInputBuilder.java @@ -3,8 +3,8 @@ import io.quarkus.devtools.codestarts.CodestartProjectInputBuilder; import io.quarkus.devtools.codestarts.DataKey; import io.quarkus.devtools.codestarts.utils.NestedMaps; +import io.quarkus.devtools.commands.CreateProjectHelper; import io.quarkus.devtools.messagewriter.MessageWriter; -import io.quarkus.devtools.project.codegen.CreateProjectHelper; import io.quarkus.devtools.project.extensions.Extensions; import io.quarkus.maven.ArtifactCoords; import io.quarkus.maven.ArtifactKey; diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartData.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartData.java index ecd29e08dcb55..ea7fb8ac7622a 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartData.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartData.java @@ -1,13 +1,6 @@ package io.quarkus.devtools.codestarts.quarkus; import io.quarkus.devtools.codestarts.DataKey; -import io.quarkus.devtools.codestarts.utils.NestedMaps; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; public final class QuarkusCodestartData { @@ -59,73 +52,4 @@ public String key() { } } - public enum LegacySupport implements DataKey { - BOM_GROUP_ID("bom_groupId"), - BOM_ARTIFACT_ID("bom_artifactId"), - BOM_VERSION("bom_version"), - PROJECT_GROUP_ID("project_groupId"), - PROJECT_ARTIFACT_ID("project_artifactId"), - PROJECT_VERSION("project_version"), - PROJECT_PACKAGE_NAME("package_name"), - QUARKUS_MAVEN_PLUGIN_GROUP_ID("maven_plugin_groupId"), - QUARKUS_MAVEN_PLUGIN_ARTIFACT_ID("maven_plugin_artifactId"), - QUARKUS_MAVEN_PLUGIN_VERSION("maven_plugin_version"), - QUARKUS_GRADLE_PLUGIN_ID("gradle_plugin_id"), - QUARKUS_GRADLE_PLUGIN_VERSION("gradle_plugin_version"), - QUARKUS_VERSION("quarkus_version"), - - JAVA_VERSION("java_target"), - KOTLIN_VERSION("kotlin_version"), - SCALA_VERSION("scala_version"), - SCALA_MAVEN_PLUGIN_VERSION("scala_plugin_version"), - MAVEN_COMPILER_PLUGIN_VERSION("compiler_plugin_version"), - MAVEN_SUREFIRE_PLUGIN_VERSION("surefire_plugin_version"), - - RESTEASY_CODESTART_RESOURCE_PATH("path"), - RESTEASY_CODESTART_RESOURCE_CLASS_NAME(QuarkusCodestartData::convertClassName), - - RESTEASY_REACTIVE_CODESTART_RESOURCE_PATH("path"), - RESTEASY_REACTIVE_CODESTART_RESOURCE_CLASS_NAME(QuarkusCodestartData::convertClassName), - - SPRING_WEB_CODESTART_RESOURCE_PATH("path"), - SPRING_WEB_CODESTART_RESOURCE_CLASS_NAME(QuarkusCodestartData::convertClassName); - - private final String key; - private final Function, Object> converter; - - LegacySupport(String legacyKey) { - this((m) -> m.get(legacyKey)); - } - - LegacySupport(Function, Object> converter) { - this.key = QuarkusDataKey.valueOf(this.name()).key(); - this.converter = converter; - } - - @Override - public String key() { - return key; - } - - public static Map convertFromLegacy(Map legacy) { - return NestedMaps.unflatten(Stream.of(values()) - .map(v -> new HashMap.SimpleImmutableEntry<>(v.key(), v.converter.apply(legacy))) - .filter(v -> v.getValue() != null) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); - } - } - - // TODO remove the class_name convertion when its removed - private static String convertClassName(final Map legacyData) { - Optional classNameValue = NestedMaps.getValue(legacyData, "class_name"); - if (classNameValue.isPresent()) { - final String className = classNameValue.get(); - int idx = classNameValue.get().lastIndexOf('.'); - if (idx < 0) { - return className; - } - return className.substring(idx + 1); - } - return null; - } } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateJBangProject.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateJBangProject.java index 7fe8c934b6ea1..2f9ed67d62255 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateJBangProject.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateJBangProject.java @@ -1,20 +1,24 @@ package io.quarkus.devtools.commands; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.EXTENSIONS; +import static io.quarkus.devtools.commands.CreateProjectHelper.computeJavaVersion; import static java.util.Objects.requireNonNull; +import io.quarkus.devtools.commands.CreateProject.CreateProjectKey; import io.quarkus.devtools.commands.data.QuarkusCommandException; import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; import io.quarkus.devtools.commands.data.QuarkusCommandOutcome; import io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler; import io.quarkus.devtools.project.QuarkusProject; -import io.quarkus.devtools.project.codegen.CreateProjectHelper; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; public class CreateJBangProject { + public interface CreateJBangProjectKey { + String NO_JBANG_WRAPPER = "codegen.no-jbang-wrapper"; + } + public static final String NAME = "create-jbang"; private final QuarkusProject quarkusProject; @@ -35,7 +39,7 @@ public CreateJBangProject extensions(Set extensions) { return this; } - public CreateJBangProject javaTarget(String javaVersion) { + public CreateJBangProject javaVersion(String javaVersion) { this.javaVersion = javaVersion; return this; } @@ -48,8 +52,9 @@ public CreateJBangProject setValue(String name, Object value) { } public QuarkusCommandOutcome execute() throws QuarkusCommandException { - setValue(EXTENSIONS, extensions); - CreateProjectHelper.setJavaVersion(values, javaVersion); // default + setValue(CreateProjectKey.EXTENSIONS, extensions); + final SourceType sourceType = SourceType.resolve(extensions); + setValue(CreateProjectKey.JAVA_VERSION, computeJavaVersion(sourceType, javaVersion)); // default final QuarkusCommandInvocation invocation = new QuarkusCommandInvocation(quarkusProject, values); return new CreateJBangProjectCommandHandler().execute(invocation); diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateProject.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateProject.java index 87b383ec65b82..6ee39ddf512ca 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateProject.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateProject.java @@ -1,16 +1,9 @@ package io.quarkus.devtools.commands; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.APP_CONFIG; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.CLASS_NAME; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.EXTENSIONS; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.PACKAGE_NAME; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.PROJECT_ARTIFACT_ID; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.PROJECT_GROUP_ID; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.PROJECT_VERSION; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.QUARKUS_GRADLE_PLUGIN_VERSION; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.QUARKUS_MAVEN_PLUGIN_VERSION; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.RESOURCE_PATH; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.SOURCE_TYPE; +import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.*; +import static io.quarkus.devtools.commands.CreateProjectHelper.computeJavaVersion; +import static io.quarkus.devtools.commands.handlers.CreateProjectCodestartDataConverter.PlatformPropertiesKey.QUARKUS_GRADLE_PLUGIN_VERSION; +import static io.quarkus.devtools.commands.handlers.CreateProjectCodestartDataConverter.PlatformPropertiesKey.QUARKUS_MAVEN_PLUGIN_VERSION; import static java.util.Objects.requireNonNull; import io.quarkus.devtools.commands.data.QuarkusCommandException; @@ -19,8 +12,6 @@ import io.quarkus.devtools.commands.handlers.CreateProjectCommandHandler; import io.quarkus.devtools.project.BuildTool; import io.quarkus.devtools.project.QuarkusProject; -import io.quarkus.devtools.project.codegen.CreateProjectHelper; -import io.quarkus.devtools.project.codegen.SourceType; import io.quarkus.platform.tools.ToolsUtils; import java.util.Collections; import java.util.HashMap; @@ -36,14 +27,27 @@ */ public class CreateProject { - public static final String NO_DOCKERFILES = "quarkus.create-project.no-dockerfiles"; - public static final String NO_BUILDTOOL_WRAPPER = "quarkus.create-project.no-buildtool-wrapper"; - public static final String NO_CODE = "quarkus.create-project.no-code"; - public static final String EXAMPLE = "quarkus.create-project.example"; - public static final String EXTRA_CODESTARTS = "quarkus.create-project.extra-codestarts"; + public interface CreateProjectKey { + String PROJECT_GROUP_ID = "project.group-id"; + String PROJECT_ARTIFACT_ID = "project.artifact-id"; + String PROJECT_VERSION = "project.version"; + String PACKAGE_NAME = "project.package-name"; + String EXTENSIONS = "project.extensions"; + String RESOURCE_CLASS_NAME = "project.resource.class-name"; + String RESOURCE_PATH = "project.resource.path"; + String JAVA_VERSION = "project.java-version"; + String APP_CONFIG = "project.app-config"; + + String QUARKUS_VERSION = "quarkus-version"; + String NO_DOCKERFILES = "codegen.no-dockerfiles"; + String NO_BUILDTOOL_WRAPPER = "codegen.no-buildtool-wrapper"; + String NO_CODE = "codegen.no-code"; + String EXAMPLE = "codegen.example"; + String EXTRA_CODESTARTS = "codegen.extra-codestarts"; + } private QuarkusProject quarkusProject; - private String javaTarget; + private String javaVersion; private Set extensions = new HashSet<>(); private Map values = new HashMap<>(); @@ -88,18 +92,13 @@ public CreateProject quarkusPluginVersion(String version) { return this; } - public CreateProject sourceType(SourceType sourceType) { - setValue(SOURCE_TYPE, sourceType); - return this; - } - public CreateProject extraCodestarts(Set extraCodestarts) { setValue(EXTRA_CODESTARTS, extraCodestarts); return this; } - public CreateProject javaTarget(String javaTarget) { - this.javaTarget = javaTarget; + public CreateProject javaVersion(String javaVersion) { + this.javaVersion = javaVersion; return this; } @@ -108,6 +107,15 @@ public CreateProject resourcePath(String resourcePath) { return this; } + public CreateProject resourceClassName(String resourceClassName) { + if (resourceClassName == null) { + return this; + } + CreateProjectHelper.checkClassName(resourceClassName); + setValue(RESOURCE_CLASS_NAME, resourceClassName); + return this; + } + public CreateProject appConfig(String appConfigAsString) { Map configMap = Collections.emptyMap(); @@ -118,19 +126,6 @@ public CreateProject appConfig(String appConfigAsString) { return this; } - /** - * Use packageName instead as this one is only working with RESTEasy and SpringWeb - */ - @Deprecated - public CreateProject className(String className) { - if (className == null) { - return this; - } - CreateProjectHelper.checkClassName(className); - setValue(CLASS_NAME, className); - return this; - } - public CreateProject packageName(String packageName) { if (packageName == null) { return this; @@ -199,10 +194,11 @@ public boolean doCreateProject(final Map context) throws Quarkus } public QuarkusCommandOutcome execute() throws QuarkusCommandException { - CreateProjectHelper.setJavaVersion(values, javaTarget); + final SourceType sourceType = SourceType.resolve(extensions); + setValue(CreateProjectKey.JAVA_VERSION, computeJavaVersion(sourceType, javaVersion)); + CreateProjectHelper.handleSpringConfiguration(values, extensions); - // TODO: sanitize? handle language extensions? setValue(EXTENSIONS, extensions); final QuarkusCommandInvocation invocation = new QuarkusCommandInvocation(quarkusProject, values); diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/CreateProjectHelper.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateProjectHelper.java similarity index 89% rename from independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/CreateProjectHelper.java rename to independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateProjectHelper.java index cfb7dfecfaff1..a5da02d421ad5 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/CreateProjectHelper.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateProjectHelper.java @@ -1,10 +1,11 @@ -package io.quarkus.devtools.project.codegen; +package io.quarkus.devtools.commands; import static java.util.Objects.requireNonNull; import io.quarkus.bootstrap.BootstrapConstants; import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException; import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; +import io.quarkus.devtools.commands.CreateProject.CreateProjectKey; import io.quarkus.maven.ArtifactCoords; import io.quarkus.paths.PathTree; import io.quarkus.registry.catalog.Extension; @@ -17,7 +18,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -174,23 +174,12 @@ public static Path createOutputDirectory(String targetDirectory) { return outputPath; } - public static SourceType determineSourceType(Set extensions) { - Optional sourceType = extensions.stream() - .map(SourceType::parse) - .filter(Optional::isPresent) - .map(e -> e.orElse(SourceType.JAVA)) - .findAny(); - return sourceType.orElse(SourceType.JAVA); - } - - public static void setJavaVersion(Map values, String javaTarget) { - requireNonNull(values, "Must provide values"); - + public static String computeJavaVersion(SourceType sourceType, String inputJavaVersion) { Integer javaFeatureVersionTarget = null; - if (javaTarget != null && !DETECT_JAVA_RUNTIME_VERSION.equals(javaTarget)) { + if (inputJavaVersion != null && !DETECT_JAVA_RUNTIME_VERSION.equals(inputJavaVersion)) { // Probably too much as we should push only the feature version but let's be as thorough as we used to be - Matcher matcher = JAVA_VERSION_PATTERN.matcher(javaTarget); + Matcher matcher = JAVA_VERSION_PATTERN.matcher(inputJavaVersion); if (matcher.matches()) { javaFeatureVersionTarget = Integer.valueOf(matcher.group(1)); } @@ -202,12 +191,11 @@ public static void setJavaVersion(Map values, String javaTarget) int bestJavaLtsVersion = determineBestJavaLtsVersion(javaFeatureVersionTarget); - if (SourceType.KOTLIN.equals(values.get(ProjectGenerator.SOURCE_TYPE)) + if (SourceType.KOTLIN.equals(sourceType) && bestJavaLtsVersion > MAX_LTS_SUPPORTED_BY_KOTLIN) { bestJavaLtsVersion = MAX_LTS_SUPPORTED_BY_KOTLIN; } - - values.put(ProjectGenerator.JAVA_TARGET, String.valueOf(bestJavaLtsVersion)); + return String.valueOf(bestJavaLtsVersion); } public static int determineBestJavaLtsVersion() { @@ -242,7 +230,7 @@ public static void addSourceTypeExtensions(Set extensions, SourceType so public static void handleSpringConfiguration(Map values) { @SuppressWarnings("unchecked") - Set extensions = (Set) values.get(ProjectGenerator.EXTENSIONS); + Set extensions = (Set) values.get(CreateProjectKey.EXTENSIONS); handleSpringConfiguration(values, extensions); } @@ -252,10 +240,9 @@ public static void handleSpringConfiguration(Map values, Set EXTENSION_SOURCE_TYPE = Map.of( + "kotlin", KOTLIN, + "quarkus-kotlin", KOTLIN, + "scala", SCALA, + "quarkus-scala", SCALA); + + public static SourceType resolve(Collection extensions) { + for (String extension : extensions) { + if (EXTENSION_SOURCE_TYPE.containsKey(extension)) { + return EXTENSION_SOURCE_TYPE.get(extension); + } + } + return JAVA; + } +} diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateJBangProjectCommandHandler.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateJBangProjectCommandHandler.java index 7e3924072b184..4d040f5494344 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateJBangProjectCommandHandler.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateJBangProjectCommandHandler.java @@ -1,18 +1,19 @@ package io.quarkus.devtools.commands.handlers; +import static io.quarkus.devtools.commands.CreateJBangProject.CreateJBangProjectKey.NO_JBANG_WRAPPER; +import static io.quarkus.devtools.commands.handlers.CreateProjectCodestartDataConverter.toCodestartData; import static io.quarkus.devtools.commands.handlers.QuarkusCommandHandlers.computeCoordsFromQuery; import io.quarkus.devtools.codestarts.jbang.QuarkusJBangCodestartCatalog; import io.quarkus.devtools.codestarts.jbang.QuarkusJBangCodestartProjectInput; import io.quarkus.devtools.codestarts.jbang.QuarkusJBangCodestartProjectInputBuilder; -import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.LegacySupport; -import io.quarkus.devtools.commands.CreateProject; +import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.QuarkusDataKey; +import io.quarkus.devtools.commands.CreateProject.CreateProjectKey; import io.quarkus.devtools.commands.data.QuarkusCommandException; import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; import io.quarkus.devtools.commands.data.QuarkusCommandOutcome; import io.quarkus.devtools.messagewriter.MessageIcons; import io.quarkus.devtools.project.QuarkusProject; -import io.quarkus.devtools.project.codegen.ProjectGenerator; import io.quarkus.maven.ArtifactCoords; import io.quarkus.registry.catalog.ExtensionCatalog; import java.io.IOException; @@ -25,7 +26,7 @@ public class CreateJBangProjectCommandHandler implements QuarkusCommandHandler { @Override public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws QuarkusCommandException { - final Set extensionsQuery = invocation.getValue(ProjectGenerator.EXTENSIONS, Collections.emptySet()); + final Set extensionsQuery = invocation.getValue(CreateProjectKey.EXTENSIONS, Collections.emptySet()); final List extensionsToAdd = computeCoordsFromQuery(invocation, extensionsQuery); if (extensionsToAdd == null) { throw new QuarkusCommandException("Failed to create project because of invalid extensions"); @@ -33,14 +34,14 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws final ExtensionCatalog catalog = invocation.getExtensionsCatalog(); - final boolean noWrapper = invocation.getValue("noJBangWrapper", false) || - invocation.getValue(CreateProject.NO_BUILDTOOL_WRAPPER, false); + final boolean noWrapper = invocation.getValue(NO_JBANG_WRAPPER, false) || + invocation.getValue(CreateProjectKey.NO_BUILDTOOL_WRAPPER, false); final QuarkusJBangCodestartProjectInputBuilder builder = QuarkusJBangCodestartProjectInput.builder() .addExtensions(extensionsToAdd) .setNoJBangWrapper(noWrapper) - .addData(LegacySupport.convertFromLegacy(invocation.getValues())) - .putData("quarkus.version", invocation.getExtensionsCatalog().getQuarkusCoreVersion()); + .addData(toCodestartData(invocation.getValues())) + .putData(QuarkusDataKey.QUARKUS_VERSION, invocation.getExtensionsCatalog().getQuarkusCoreVersion()); if (catalog.getBom() != null) { // TODO properly import the BOMs diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCodestartDataConverter.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCodestartDataConverter.java new file mode 100644 index 0000000000000..7230807001235 --- /dev/null +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCodestartDataConverter.java @@ -0,0 +1,106 @@ +package io.quarkus.devtools.commands.handlers; + +import io.quarkus.devtools.codestarts.DataKey; +import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData; +import io.quarkus.devtools.codestarts.utils.NestedMaps; +import io.quarkus.devtools.commands.CreateProject.CreateProjectKey; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public enum CreateProjectCodestartDataConverter implements DataKey { + PROJECT_GROUP_ID(CreateProjectKey.PROJECT_GROUP_ID), + PROJECT_ARTIFACT_ID(CreateProjectKey.PROJECT_ARTIFACT_ID), + PROJECT_VERSION(CreateProjectKey.PROJECT_VERSION), + PROJECT_PACKAGE_NAME(CreateProjectKey.PACKAGE_NAME), + QUARKUS_VERSION(CreateProjectKey.QUARKUS_VERSION), + JAVA_VERSION(CreateProjectKey.JAVA_VERSION), + APP_CONFIG(CreateProjectKey.APP_CONFIG, Collections.emptyMap()), + + QUARKUS_MAVEN_PLUGIN_GROUP_ID(PlatformPropertiesKey.QUARKUS_MAVEN_PLUGIN_GROUP_ID), + QUARKUS_MAVEN_PLUGIN_ARTIFACT_ID(PlatformPropertiesKey.QUARKUS_MAVEN_PLUGIN_ARTIFACT_ID), + QUARKUS_MAVEN_PLUGIN_VERSION(PlatformPropertiesKey.QUARKUS_MAVEN_PLUGIN_VERSION), + QUARKUS_GRADLE_PLUGIN_ID(PlatformPropertiesKey.QUARKUS_GRADLE_PLUGIN_ID), + QUARKUS_GRADLE_PLUGIN_VERSION(PlatformPropertiesKey.QUARKUS_GRADLE_PLUGIN_VERSION), + KOTLIN_VERSION(PlatformPropertiesKey.KOTLIN_VERSION), + SCALA_VERSION(PlatformPropertiesKey.SCALA_VERSION), + SCALA_MAVEN_PLUGIN_VERSION(PlatformPropertiesKey.SCALA_MAVEN_PLUGIN_VERSION), + MAVEN_COMPILER_PLUGIN_VERSION(PlatformPropertiesKey.MAVEN_COMPILER_PLUGIN_VERSION), + MAVEN_SUREFIRE_PLUGIN_VERSION(PlatformPropertiesKey.MAVEN_SUREFIRE_PLUGIN_VERSION), + + BOM_GROUP_ID(CatalogKey.BOM_GROUP_ID), + BOM_ARTIFACT_ID(CatalogKey.BOM_ARTIFACT_ID), + BOM_VERSION(CatalogKey.BOM_VERSION), + + RESTEASY_CODESTART_RESOURCE_PATH(CreateProjectKey.RESOURCE_PATH), + RESTEASY_CODESTART_RESOURCE_CLASS_NAME(CreateProjectCodestartDataConverter::convertClassName), + + RESTEASY_REACTIVE_CODESTART_RESOURCE_PATH(CreateProjectKey.RESOURCE_PATH), + RESTEASY_REACTIVE_CODESTART_RESOURCE_CLASS_NAME(CreateProjectCodestartDataConverter::convertClassName), + + SPRING_WEB_CODESTART_RESOURCE_PATH(CreateProjectKey.RESOURCE_PATH), + SPRING_WEB_CODESTART_RESOURCE_CLASS_NAME(CreateProjectCodestartDataConverter::convertClassName); + + private final String key; + private final Function, Object> converter; + + CreateProjectCodestartDataConverter(String createProjectKey) { + this((m) -> m.get(createProjectKey)); + } + + CreateProjectCodestartDataConverter(String createProjectKey, Object defaultValue) { + this((m) -> m.getOrDefault(createProjectKey, defaultValue)); + } + + CreateProjectCodestartDataConverter(Function, Object> converter) { + this.key = QuarkusCodestartData.QuarkusDataKey.valueOf(this.name()).key(); + this.converter = converter; + } + + @Override + public String key() { + return key; + } + + public static Map toCodestartData(Map createProjectData) { + return NestedMaps.unflatten(Stream.of(values()) + .map(v -> new HashMap.SimpleImmutableEntry<>(v.key(), v.converter.apply(createProjectData))) + .filter(v -> v.getValue() != null) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + } + + private static String convertClassName(final Map createProjectData) { + String className = (String) createProjectData.get(CreateProjectKey.RESOURCE_CLASS_NAME); + if (className != null) { + int idx = className.lastIndexOf('.'); + if (idx < 0) { + return className; + } + return className.substring(idx + 1); + } + return null; + } + + public interface PlatformPropertiesKey { + String QUARKUS_MAVEN_PLUGIN_GROUP_ID = "maven-plugin-groupId"; + String QUARKUS_MAVEN_PLUGIN_ARTIFACT_ID = "maven-plugin-artifactId"; + String QUARKUS_MAVEN_PLUGIN_VERSION = "maven-plugin-version"; + String QUARKUS_GRADLE_PLUGIN_VERSION = "gradle-plugin-version"; + String KOTLIN_VERSION = "kotlin-version"; + String SCALA_VERSION = "scala-version"; + String QUARKUS_GRADLE_PLUGIN_ID = "gradle-plugin-id"; + String SCALA_MAVEN_PLUGIN_VERSION = "scala-plugin-version"; + String MAVEN_COMPILER_PLUGIN_VERSION = "compiler-plugin-version"; + String MAVEN_SUREFIRE_PLUGIN_VERSION = "surefire-plugin-version"; + } + + public interface CatalogKey { + String BOM_GROUP_ID = "bom.group-id"; + String BOM_ARTIFACT_ID = "bom.artifact-id"; + String BOM_VERSION = "bom.version"; + } + +} 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 7fbca27efe1af..00a53f481a80d 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 @@ -1,32 +1,29 @@ package io.quarkus.devtools.commands.handlers; -import static io.quarkus.devtools.commands.CreateProject.EXAMPLE; -import static io.quarkus.devtools.commands.CreateProject.EXTRA_CODESTARTS; -import static io.quarkus.devtools.commands.CreateProject.NO_BUILDTOOL_WRAPPER; -import static io.quarkus.devtools.commands.CreateProject.NO_CODE; -import static io.quarkus.devtools.commands.CreateProject.NO_DOCKERFILES; +import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.EXAMPLE; +import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.EXTENSIONS; +import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.EXTRA_CODESTARTS; +import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.NO_BUILDTOOL_WRAPPER; +import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.NO_CODE; +import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.NO_DOCKERFILES; +import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.PACKAGE_NAME; +import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.PROJECT_GROUP_ID; +import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.QUARKUS_VERSION; +import static io.quarkus.devtools.commands.CreateProject.CreateProjectKey.RESOURCE_CLASS_NAME; +import static io.quarkus.devtools.commands.handlers.CreateProjectCodestartDataConverter.toCodestartData; import static io.quarkus.devtools.commands.handlers.QuarkusCommandHandlers.computeExtensionsFromQuery; import static io.quarkus.devtools.messagewriter.MessageIcons.ERROR_ICON; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.APP_CONFIG; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.BOM_ARTIFACT_ID; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.BOM_GROUP_ID; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.BOM_VERSION; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.CLASS_NAME; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.PACKAGE_NAME; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.PROJECT_GROUP_ID; -import static io.quarkus.devtools.project.codegen.ProjectGenerator.QUARKUS_VERSION; import io.quarkus.devtools.codestarts.CodestartProjectDefinition; import io.quarkus.devtools.codestarts.CodestartType; import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog; -import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.LegacySupport; import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartProjectInput; import io.quarkus.devtools.commands.data.QuarkusCommandException; import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; import io.quarkus.devtools.commands.data.QuarkusCommandOutcome; +import io.quarkus.devtools.commands.handlers.CreateProjectCodestartDataConverter.CatalogKey; import io.quarkus.devtools.messagewriter.MessageIcons; import io.quarkus.devtools.messagewriter.MessageWriter; -import io.quarkus.devtools.project.codegen.ProjectGenerator; import io.quarkus.devtools.project.extensions.Extensions; import io.quarkus.maven.ArtifactCoords; import io.quarkus.platform.tools.ToolsUtils; @@ -57,17 +54,17 @@ public class CreateProjectCommandHandler implements QuarkusCommandHandler { @Override public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws QuarkusCommandException { - final Set extensionsQuery = invocation.getValue(ProjectGenerator.EXTENSIONS, Collections.emptySet()); + final Set extensionsQuery = invocation.getValue(EXTENSIONS, Collections.emptySet()); // Default to cleaned groupId if packageName not set - final String className = invocation.getStringValue(CLASS_NAME); + final String className = invocation.getStringValue(RESOURCE_CLASS_NAME); final String pkgName = invocation.getStringValue(PACKAGE_NAME); final String groupId = invocation.getStringValue(PROJECT_GROUP_ID); if (pkgName == null) { if (className != null && className.contains(".")) { final int idx = className.lastIndexOf('.'); invocation.setValue(PACKAGE_NAME, className.substring(0, idx)); - invocation.setValue(CLASS_NAME, className.substring(idx + 1)); + invocation.setValue(RESOURCE_CLASS_NAME, className.substring(idx + 1)); } else if (groupId != null) { invocation.setValue(PACKAGE_NAME, groupId.replace('-', '.').replace('_', '.')); } @@ -120,13 +117,13 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws extensionCoords.add(coords); } - invocation.setValue(BOM_GROUP_ID, mainCatalog.getBom().getGroupId()); - invocation.setValue(BOM_ARTIFACT_ID, mainCatalog.getBom().getArtifactId()); - invocation.setValue(BOM_VERSION, mainCatalog.getBom().getVersion()); + invocation.setValue(CatalogKey.BOM_GROUP_ID, mainCatalog.getBom().getGroupId()); + invocation.setValue(CatalogKey.BOM_ARTIFACT_ID, mainCatalog.getBom().getArtifactId()); + invocation.setValue(CatalogKey.BOM_VERSION, mainCatalog.getBom().getVersion()); invocation.setValue(QUARKUS_VERSION, mainCatalog.getQuarkusCoreVersion()); final Properties quarkusProps = ToolsUtils.readQuarkusProperties(mainCatalog); quarkusProps.forEach((k, v) -> { - final String name = k.toString().replace('-', '_'); + final String name = k.toString(); if (!invocation.hasValue(name)) { invocation.setValue(name, v.toString()); } @@ -150,8 +147,7 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws .noBuildToolWrapper(invocation.getValue(NO_BUILDTOOL_WRAPPER, false)) .noDockerfiles(invocation.getValue(NO_DOCKERFILES, false)) .addData(platformData) - .addData(LegacySupport.convertFromLegacy(invocation.getValues())) - .putData(APP_CONFIG, invocation.getValue(APP_CONFIG, Collections.emptyMap())) + .addData(toCodestartData(invocation.getValues())) .messageWriter(invocation.log()) .build(); invocation.log().info("-----------"); diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/ProjectGenerator.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/ProjectGenerator.java deleted file mode 100644 index 7446924347397..0000000000000 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/ProjectGenerator.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.quarkus.devtools.project.codegen; - -public interface ProjectGenerator { - String BOM_GROUP_ID = "bom_groupId"; - String BOM_ARTIFACT_ID = "bom_artifactId"; - String BOM_VERSION = "bom_version"; - String PROJECT_GROUP_ID = "project_groupId"; - String PROJECT_ARTIFACT_ID = "project_artifactId"; - String PROJECT_VERSION = "project_version"; - String QUARKUS_MAVEN_PLUGIN_VERSION = "maven_plugin_version"; - String QUARKUS_GRADLE_PLUGIN_VERSION = "gradle_plugin_version"; - String QUARKUS_VERSION = "quarkus_version"; - String PACKAGE_NAME = "package_name"; - String MAVEN_REPOSITORIES = "maven_repositories"; - String MAVEN_PLUGIN_REPOSITORIES = "maven_plugin_repositories"; - String SOURCE_TYPE = "source_type"; - String BUILD_FILE = "build_file"; - String BUILD_DIRECTORY = "build_dir"; - String ADDITIONAL_GITIGNORE_ENTRIES = "additional_gitignore_entries"; - String CLASS_NAME = "class_name"; - String EXTENSIONS = "extensions"; - String IS_SPRING = "is_spring"; - String RESOURCE_PATH = "path"; - String JAVA_TARGET = "java_target"; - String APP_CONFIG = "app-config"; // codestart uses dashes - -} diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/SourceType.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/SourceType.java deleted file mode 100644 index 3044f4992d372..0000000000000 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/SourceType.java +++ /dev/null @@ -1,90 +0,0 @@ -package io.quarkus.devtools.project.codegen; - -import io.quarkus.maven.utilities.MojoUtils; -import java.util.Arrays; -import java.util.Optional; - -public enum SourceType { - JAVA(MojoUtils.JAVA_FILE_EXTENSION, MojoUtils.JAVA_EXTENSION_NAME), - - KOTLIN(MojoUtils.KOTLIN_FILE_EXTENSION, MojoUtils.KOTLIN_EXTENSION_NAME), - - SCALA(MojoUtils.SCALA_FILE_EXTENSION, MojoUtils.SCALA_EXTENSION_NAME); - - private static final String srcDirPrefix = "src/main/"; - private static final String testSrcDirPrefix = "src/test/"; - - private static final String BUILD_FILE_RESOURCE_TEMPLATE = "templates/%s/%s/%s-template.ftl"; - private static final String RESOURCE_TEMPLATE = "templates/%s/%s/resource-template.ftl"; - private static final String SPRING_CONTROLLER_TEMPLATE = "templates/%s/%s/spring-controller-template.ftl"; - private static final String TEST_RESOURCE_TEMPLATE = "templates/%s/%s/test-resource-template.ftl"; - private static final String NATIVE_TEST_RESOURCE_TEMPLATE = "templates/%s/%s/native-test-resource-template.ftl"; - - private final String extension; - private final String name; - - SourceType(String extension, String name) { - this.extension = extension; - this.name = name; - } - - public String getSrcDir() { - return srcDirPrefix + getPathDiscriminator(); - } - - private String getPathDiscriminator() { - return this.name; - } - - public String getTestSrcDir() { - return testSrcDirPrefix + getPathDiscriminator(); - } - - public String getBuildFileResourceTemplate(String templateName, String buildFile) { - return computeTemplateFile(BUILD_FILE_RESOURCE_TEMPLATE, templateName, buildFile); - } - - public String getSrcResourceTemplate(String templateName) { - return computeTemplateFile(RESOURCE_TEMPLATE, templateName); - } - - public String getSrcSpringControllerTemplate(String templateName) { - return computeTemplateFile(SPRING_CONTROLLER_TEMPLATE, templateName); - } - - public String getTestResourceTemplate(String templateName) { - return computeTemplateFile(TEST_RESOURCE_TEMPLATE, templateName); - } - - public String getNativeTestResourceTemplate(String templateName) { - return computeTemplateFile(NATIVE_TEST_RESOURCE_TEMPLATE, templateName); - } - - public String getExtension() { - return extension; - } - - public String getName() { - return name; - } - - public String stripExtensionFrom(String className) { - if (className != null && className.endsWith(extension)) { - return className.substring(0, className.length() - extension.length()); - } else { - return className; - } - } - - private String computeTemplateFile(String genericTemplate, String templateName) { - return computeTemplateFile(genericTemplate, templateName, null); - } - - private String computeTemplateFile(String genericTemplate, String templateName, String fileName) { - return String.format(genericTemplate, templateName, getPathDiscriminator(), fileName); - } - - public static Optional parse(String extension) { - return Arrays.stream(values()).filter(e -> extension.contains(e.name)).findAny(); - } -} diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/writer/FileProjectWriter.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/writer/FileProjectWriter.java deleted file mode 100644 index c5c8fdb5dfcf0..0000000000000 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/writer/FileProjectWriter.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * - */ -package io.quarkus.devtools.project.codegen.writer; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -/** - * ProjectWriter implementation to create direct files in the file system. - */ -public class FileProjectWriter implements ProjectWriter { - private final File root; - - public FileProjectWriter(final File file) { - root = file; - } - - @Override - public void init() throws IOException { - if (!root.exists()) { - boolean mkdirStatus = root.mkdirs(); - if (!mkdirStatus) { - throw new IOException("Failed to create root directory"); - } - return; - } - if (!root.isDirectory()) { - throw new IOException("Project root needs to be a directory"); - } - final String[] files = root.list(); - if (files != null && files.length > 0) { - throw new IOException("You can't create a project when the folder is not empty."); - } - } - - @Override - public String mkdirs(String path) { - File dirToCreate = new File(root, path); - if (!dirToCreate.exists()) { - dirToCreate.mkdirs(); - } - if (path.isEmpty()) { - return ""; - } - return dirToCreate.getPath().substring(root.getPath().length() + 1); - } - - @Override - public void write(String path, String content) throws IOException { - final Path outputPath = root.toPath().resolve(path); - Files.write(outputPath, content.getBytes("UTF-8")); - } - - @Override - public byte[] getContent(String path) throws IOException { - return Files.readAllBytes(root.toPath().resolve(path)); - } - - @Override - public boolean exists(String path) { - return new File(root, path).exists(); - } - - @Override - public void close() throws IOException { - //do nothing - } - - @Override - public File getProjectFolder() { - return root; - } - - @Override - public boolean hasFile() { - return true; - } - -} diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/writer/ProjectWriter.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/writer/ProjectWriter.java deleted file mode 100644 index f1be715adc5aa..0000000000000 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/codegen/writer/ProjectWriter.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - */ -package io.quarkus.devtools.project.codegen.writer; - -import java.io.Closeable; -import java.io.File; -import java.io.IOException; - -/** - * This writer provide a way to write direct a file or inside a zip for project creation. - */ -public interface ProjectWriter extends Closeable { - - void init() throws IOException; - - void write(String path, String content) throws IOException; - - byte[] getContent(String path) throws IOException; - - String mkdirs(String path) throws IOException; - - boolean exists(String path); - - File getProjectFolder(); - - boolean hasFile(); -} diff --git a/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/commands/CreateProjectHelperTest.java b/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/commands/CreateProjectHelperTest.java new file mode 100644 index 0000000000000..bb7a7774ed9c3 --- /dev/null +++ b/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/commands/CreateProjectHelperTest.java @@ -0,0 +1,53 @@ +package io.quarkus.devtools.commands; + +import static io.quarkus.devtools.commands.CreateProjectHelper.DETECT_JAVA_RUNTIME_VERSION; +import static io.quarkus.devtools.commands.CreateProjectHelper.computeJavaVersion; +import static io.quarkus.devtools.commands.CreateProjectHelper.determineBestJavaLtsVersion; +import static io.quarkus.devtools.commands.SourceType.JAVA; +import static io.quarkus.devtools.commands.SourceType.KOTLIN; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class CreateProjectHelperTest { + + @Test + public void givenJavaVersion17ShouldReturn17() { + assertEquals("17", computeJavaVersion(JAVA, "17")); + } + + @Test + public void givenJavaVersion16ShouldReturn11() { + assertEquals("11", computeJavaVersion(JAVA, "16.0.1")); + } + + @Test + public void givenJavaVersion11ShouldReturn11() { + assertEquals("11", computeJavaVersion(JAVA, "11")); + } + + @Test + public void givenJavaVersion18ShouldReturn17() { + assertEquals("17", computeJavaVersion(JAVA, "18")); + } + + @Test + public void givenAutoDetectShouldReturnAppropriateVersion() { + final String bestJavaLtsVersion = String.valueOf(determineBestJavaLtsVersion(Runtime.version().feature())); + assertEquals(bestJavaLtsVersion, computeJavaVersion(JAVA, DETECT_JAVA_RUNTIME_VERSION)); + } + + @Test + public void testDetermineBestLtsVersion() { + assertEquals(11, determineBestJavaLtsVersion(8)); + assertEquals(11, determineBestJavaLtsVersion(11)); + assertEquals(11, determineBestJavaLtsVersion(12)); + assertEquals(17, determineBestJavaLtsVersion(17)); + assertEquals(17, determineBestJavaLtsVersion(18)); + } + + @Test + public void givenKotlinProjectWithVersion18ShouldReturn17() { + assertEquals("17", computeJavaVersion(KOTLIN, "18")); + } +} diff --git a/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/project/codegen/CreateProjectHelperTest.java b/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/project/codegen/CreateProjectHelperTest.java deleted file mode 100644 index 9cacd513b3e15..0000000000000 --- a/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/project/codegen/CreateProjectHelperTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package io.quarkus.devtools.project.codegen; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.HashMap; -import java.util.Map; -import org.junit.jupiter.api.Test; - -class CreateProjectHelperTest { - - @Test - public void givenJavaVersion17ShouldReturn17() { - Map values = new HashMap<>(); - values.put("nonnull", "nonnull"); - - CreateProjectHelper.setJavaVersion(values, "17"); - assertEquals("17", values.get("java_target")); - } - - @Test - public void givenJavaVersion16ShouldReturn11() { - Map values = new HashMap<>(); - values.put("nonnull", "nonnull"); - - CreateProjectHelper.setJavaVersion(values, "16.0.1"); - assertEquals("11", values.get("java_target")); - } - - @Test - public void givenJavaVersion11ShouldReturn11() { - Map values = new HashMap<>(); - values.put("nonnull", "nonnull"); - - CreateProjectHelper.setJavaVersion(values, "11"); - assertEquals("11", values.get("java_target")); - } - - @Test - public void givenJavaVersion18ShouldReturn17() { - Map values = new HashMap<>(); - values.put("nonnull", "nonnull"); - - CreateProjectHelper.setJavaVersion(values, "18"); - assertEquals("17", values.get("java_target")); - } - - @Test - public void givenAutoDetectShouldReturnAppropriateVersion() { - Map values = new HashMap<>(); - values.put("nonnull", "nonnull"); - - CreateProjectHelper.setJavaVersion(values, CreateProjectHelper.DETECT_JAVA_RUNTIME_VERSION); - assertEquals(String.valueOf(CreateProjectHelper.determineBestJavaLtsVersion(Runtime.version().feature())), - values.get("java_target")); - } - - @Test - public void testDetermineBestLtsVersion() { - assertEquals(11, CreateProjectHelper.determineBestJavaLtsVersion(8)); - assertEquals(11, CreateProjectHelper.determineBestJavaLtsVersion(11)); - assertEquals(11, CreateProjectHelper.determineBestJavaLtsVersion(12)); - assertEquals(17, CreateProjectHelper.determineBestJavaLtsVersion(17)); - assertEquals(17, CreateProjectHelper.determineBestJavaLtsVersion(18)); - } - - @Test - public void givenKotlinProjectWithVersion18ShouldReturn17() { - Map values = new HashMap<>(); - values.put(ProjectGenerator.SOURCE_TYPE, SourceType.KOTLIN); - - CreateProjectHelper.setJavaVersion(values, "18"); - assertEquals("17", values.get("java_target")); - } -} diff --git a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java index 26b53bc61a1aa..f186a63604ce6 100644 --- a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java +++ b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java @@ -1,9 +1,9 @@ package io.quarkus.devtools.testing.codestarts; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.QuarkusDataKey.PROJECT_PACKAGE_NAME; +import static io.quarkus.devtools.commands.CreateProjectHelper.completeCatalogWithCoords; import static io.quarkus.devtools.project.CodestartResourceLoadersBuilder.codestartLoadersBuilder; import static io.quarkus.devtools.project.QuarkusProjectHelper.artifactResolver; -import static io.quarkus.devtools.project.codegen.CreateProjectHelper.completeCatalogWithCoords; import static io.quarkus.devtools.testing.RegistryClientTestHelper.disableRegistryClientTestConfig; import static io.quarkus.devtools.testing.RegistryClientTestHelper.enableRegistryClientTestConfig; import static io.quarkus.devtools.testing.SnapshotTesting.checkContains; diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/commands/CreateJBangProjectTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/commands/CreateJBangProjectTest.java index 009b594a48551..4b435a3a5a3e5 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/commands/CreateJBangProjectTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/commands/CreateJBangProjectTest.java @@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test; +import io.quarkus.devtools.commands.CreateJBangProject.CreateJBangProjectKey; import io.quarkus.devtools.commands.data.QuarkusCommandException; import io.quarkus.devtools.commands.data.QuarkusCommandOutcome; import io.quarkus.devtools.project.BuildTool; @@ -25,7 +26,7 @@ public void createRESTEasy() throws Exception { final Path projectDir = file.toPath(); SnapshotTesting.deleteTestDirectory(file); assertCreateJBangProject(newCreateJBangProject(projectDir) - .setValue("noJBangWrapper", false)); + .setValue(CreateJBangProjectKey.NO_JBANG_WRAPPER, false)); assertThat(projectDir.resolve("jbang")).exists(); @@ -41,7 +42,7 @@ public void createRESTEasyWithNoJBangWrapper() throws Exception { final Path projectDir = file.toPath(); SnapshotTesting.deleteTestDirectory(file); assertCreateJBangProject(newCreateJBangProject(projectDir) - .setValue("noJBangWrapper", true)); + .setValue(CreateJBangProjectKey.NO_JBANG_WRAPPER, true)); assertThat(projectDir.resolve("jbang")).doesNotExist(); @@ -61,7 +62,7 @@ public void createRESTEasyWithExtensions() throws Exception { assertCreateJBangProject(newCreateJBangProject(projectDir) .extensions(extensions) - .setValue("noJBangWrapper", false)); + .setValue(CreateJBangProjectKey.NO_JBANG_WRAPPER, false)); assertThat(projectDir.resolve("jbang")).exists(); diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/commands/CreateProjectTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/commands/CreateProjectTest.java index 940be1866d5ab..170c44ca120b7 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/commands/CreateProjectTest.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/commands/CreateProjectTest.java @@ -34,7 +34,6 @@ import io.quarkus.devtools.project.BuildTool; import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.devtools.project.QuarkusProjectHelper; -import io.quarkus.devtools.project.codegen.writer.FileProjectWriter; import io.quarkus.devtools.testing.PlatformAwareTestBase; import io.quarkus.devtools.testing.SnapshotTesting; import io.quarkus.maven.utilities.MojoUtils; @@ -49,7 +48,7 @@ public void createRESTEasy() throws Exception { .groupId("org.acme.foo") .artifactId("resteasy-app") .version("1.0.0-FOO") - .className("org.acme.getting.started.GreetingResource") + .resourceClassName("org.acme.getting.started.GreetingResource") .resourcePath("/foo") .extensions(Collections.singleton("resteasy"))); final Properties quarkusProp = getQuarkusProperties(); @@ -79,6 +78,31 @@ public void createRESTEasy() throws Exception { .satisfies(checkContains("./mvnw")); } + @Test + public void createWithPackage() throws Exception { + final File file = new File("target/with-package"); + final Path projectDir = file.toPath(); + SnapshotTesting.deleteTestDirectory(file); + assertCreateProject(newCreateProject(projectDir) + .groupId("org.acme.foo") + .artifactId("package-app") + .version("1.0.0-FOO") + .resourceClassName("SomeResource") + .packageName("io.aloha") + .resourcePath("/bar") + .extensions(Collections.singleton("resteasy"))); + assertThat(projectDir.resolve("src/main/java/io/aloha/SomeResource.java")) + .exists() + .satisfies(checkContains("package io.aloha;")) + .satisfies(checkContains("class SomeResource")) + .satisfies(checkContains("@Path(\"/bar\")")); + assertThat(projectDir.resolve("pom.xml")) + .exists() + .satisfies(checkContains("org.acme.foo")) + .satisfies(checkContains("package-app")) + .satisfies(checkContains("1.0.0-FOO")); + } + @Test public void createSpringWeb() throws Exception { final File file = new File("target/create-spring"); @@ -89,7 +113,7 @@ public void createSpringWeb() throws Exception { .packageName("org.acme.bar.spr") .artifactId("spring-web-app") .version("1.0.0-BAR") - .className("BarController") + .resourceClassName("BarController") .resourcePath("/bar") .extensions(Collections.singleton("spring-web"))); assertThat(projectDir.resolve("pom.xml")) @@ -114,7 +138,7 @@ public void createRESTEasyAndSpringWeb() throws Exception { SnapshotTesting.deleteTestDirectory(file); assertCreateProject(newCreateProject(projectDir) .artifactId("spring-web-resteasy-app") - .className("BarController") + .resourceClassName("BarController") .packageName("io.test") .resourcePath("/bar") .extensions(new HashSet<>(Arrays.asList("resteasy", "spring-web")))); @@ -148,7 +172,7 @@ public void createGradle() throws Exception { .packageName("my.project") .artifactId("resteasy-app") .version("1.0.0-FOO") - .className("FooResource") + .resourceClassName("FooResource") .resourcePath("/foo") .extensions(Collections.singleton("resteasy"))); @@ -201,7 +225,7 @@ public void createOnTopOfExisting() throws Exception { .groupId("something.is") .artifactId("wrong") .version("1.0.0-SNAPSHOT") - .className("org.foo.MyResource") + .resourceClassName("org.foo.MyResource") .execute(); }).withRootCauseInstanceOf(IOException.class); } @@ -215,17 +239,15 @@ void createMultipleTimes() throws InterruptedException { List> collect = IntStream.range(0, 15).boxed().map(i -> (Callable) () -> { File tempDir = Files.createTempDirectory("test").toFile(); - FileProjectWriter write = new FileProjectWriter(tempDir); final QuarkusProject project = QuarkusProjectHelper.getProject(tempDir.toPath(), BuildTool.MAVEN); final QuarkusCommandOutcome result = new CreateProject(project) .groupId("org.acme") .artifactId("acme") .version("1.0.0-SNAPSHOT") - .className("org.acme.MyResource") + .resourceClassName("org.acme.MyResource") .execute(); assertTrue(result.isSuccess()); latch.countDown(); - write.close(); tempDir.delete(); return null; }).collect(Collectors.toList()); diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java index d049d12f06af3..897849598cb39 100644 --- a/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java @@ -1,12 +1,15 @@ package io.quarkus.gradle; +import static io.quarkus.devtools.commands.SourceType.JAVA; import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -17,9 +20,9 @@ import com.google.common.collect.ImmutableMap; import io.quarkus.devtools.commands.CreateProject; +import io.quarkus.devtools.commands.SourceType; import io.quarkus.devtools.project.BuildTool; import io.quarkus.devtools.project.QuarkusProjectHelper; -import io.quarkus.devtools.project.codegen.SourceType; import io.quarkus.test.devmode.util.DevModeTestUtils; public class QuarkusPluginFunctionalTest extends QuarkusGradleDevToolsTestBase { @@ -34,7 +37,8 @@ void setUp(@TempDir File projectRoot) { @ParameterizedTest(name = "Build {0} project") @EnumSource(SourceType.class) public void canBuild(SourceType sourceType) throws Exception { - createProject(sourceType); + Set extensions = JAVA.equals(sourceType) ? Collections.emptySet() : Set.of(sourceType.toString().toLowerCase()); + createProject(extensions); BuildResult build = runGradleWrapper(projectRoot, "build", "--stacktrace"); @@ -48,7 +52,7 @@ public void canBuild(SourceType sourceType) throws Exception { @Test public void canDetectUpToDateBuild() throws Exception { - createProject(SourceType.JAVA); + createProject(); BuildResult firstBuild = runGradleWrapper(projectRoot, "quarkusBuild", "--stacktrace"); assertThat(BuildResult.isSuccessful(firstBuild.getTasks().get(":quarkusBuild"))).isTrue(); @@ -59,7 +63,7 @@ public void canDetectUpToDateBuild() throws Exception { @Test public void canDetectResourceChangeWhenBuilding() throws Exception { - createProject(SourceType.JAVA); + createProject(); BuildResult firstBuild = runGradleWrapper(projectRoot, "quarkusBuild", "--stacktrace"); assertThat(BuildResult.isSuccessful(firstBuild.getTasks().get(":quarkusBuild"))).isTrue(); @@ -73,7 +77,7 @@ public void canDetectResourceChangeWhenBuilding() throws Exception { @Test public void canDetectClassChangeWhenBuilding() throws Exception { - createProject(SourceType.JAVA); + createProject(); BuildResult firstBuild = runGradleWrapper(projectRoot, "quarkusBuild", "--stacktrace"); assertThat(BuildResult.isSuccessful(firstBuild.getTasks().get(":quarkusBuild"))).isTrue(); @@ -88,7 +92,7 @@ public void canDetectClassChangeWhenBuilding() throws Exception { @Test public void canDetectClasspathChangeWhenBuilding() throws Exception { - createProject(SourceType.JAVA); + createProject(); BuildResult firstBuild = runGradleWrapper(projectRoot, "quarkusBuild", "--stacktrace"); assertThat(BuildResult.isSuccessful(firstBuild.getTasks().get(":quarkusBuild"))).isTrue(); @@ -100,7 +104,7 @@ public void canDetectClasspathChangeWhenBuilding() throws Exception { @Test public void canDetectOutputChangeWhenBuilding() throws Exception { - createProject(SourceType.JAVA); + createProject(); BuildResult firstBuild = runGradleWrapper(projectRoot, "quarkusBuild", "--stacktrace"); @@ -116,7 +120,7 @@ public void canDetectOutputChangeWhenBuilding() throws Exception { @Test public void canDetectUpToDateTests() throws Exception { - createProject(SourceType.JAVA); + createProject(); BuildResult firstBuild = runGradleWrapper(projectRoot, "test"); @@ -129,7 +133,7 @@ public void canDetectUpToDateTests() throws Exception { @Test public void canDetectSystemPropertyChangeWhenBuilding() throws Exception { - createProject(SourceType.JAVA); + createProject(); BuildResult firstBuild = runGradleWrapper(projectRoot, "quarkusBuild", "--stacktrace"); @@ -144,7 +148,7 @@ public void canDetectSystemPropertyChangeWhenBuilding() throws Exception { @Test public void canRunTest() throws Exception { - createProject(SourceType.JAVA); + createProject(); BuildResult buildResult = runGradleWrapper(projectRoot, "test", "--stacktrace"); @@ -153,7 +157,7 @@ public void canRunTest() throws Exception { @Test public void generateCodeBeforeTests() throws Exception { - createProject(SourceType.JAVA); + createProject(); BuildResult firstBuild = runGradleWrapper(projectRoot, "test", "--stacktrace"); assertThat(firstBuild.getOutput()).contains("Task :quarkusGenerateCode"); @@ -161,16 +165,20 @@ public void generateCodeBeforeTests() throws Exception { assertThat(BuildResult.isSuccessful(firstBuild.getTasks().get(":test"))).isTrue(); } - private void createProject(SourceType sourceType) throws Exception { + private void createProject() throws Exception { + createProject(Collections.emptySet()); + } + + private void createProject(Set extensions) throws Exception { Map context = new HashMap<>(); - context.put("path", "/greeting"); assertThat(new CreateProject(QuarkusProjectHelper.getProject(projectRoot.toPath(), BuildTool.GRADLE)) .groupId("com.acme.foo") + .extensions(extensions) + .resourcePath("/greeting") .artifactId("foo") .version("1.0.0-SNAPSHOT") .packageName("org.acme.foo") - .sourceType(sourceType) .doCreateProject(context)) .withFailMessage("Project was not created") .isTrue();