Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor & Remove legacy codegen #26659

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -163,14 +164,12 @@ public Path projectRoot() {
public void setSourceTypeExtensions(Set<String> 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));
}

/**
Expand All @@ -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) {
Expand Down Expand Up @@ -269,15 +268,16 @@ 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";
}

key = key.substring(0, 1).toUpperCase() + key.substring(1);
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))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,7 +49,7 @@ public SourceType getSourceType(CommandSpec spec, BuildTool buildTool, Set<Strin
} else if (scala) {
sourceType = SourceType.SCALA;
} else {
sourceType = CreateProjectHelper.determineSourceType(extensions);
sourceType = SourceType.resolve(extensions);
}
}
return sourceType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import io.quarkus.cli.Version;
import io.quarkus.cli.common.OutputOptionMixin;
import io.quarkus.cli.common.TargetQuarkusVersionGroup;
import io.quarkus.devtools.commands.CreateProjectHelper;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.devtools.project.codegen.CreateProjectHelper;
import io.quarkus.maven.ArtifactCoords;
import io.quarkus.platform.tools.ToolsConstants;
import io.quarkus.platform.tools.ToolsUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import io.quarkus.cli.build.ExecuteUtil;
import io.quarkus.cli.build.GradleRunner;
import io.quarkus.devtools.project.codegen.CreateProjectHelper;
import io.quarkus.devtools.commands.CreateProjectHelper;
import io.quarkus.devtools.testing.RegistryClientTestHelper;
import picocli.CommandLine;

Expand Down Expand Up @@ -367,8 +367,6 @@ public void testCreateArgPassthrough() throws Exception {
"Output should contain 'Project ArtifactId my-project', found: " + result.stdout);
Assertions.assertTrue(noSpaces.contains("ProjectGroupIdsilly"),
"Output should contain 'Project GroupId silly', found: " + result.stdout);
Assertions.assertTrue(result.stdout.contains("JAVA"),
"Should contain JAVA, found: " + result.stdout);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import io.quarkus.devtools.project.codegen.CreateProjectHelper;
import io.quarkus.devtools.commands.CreateProjectHelper;
import io.quarkus.devtools.testing.RegistryClientTestHelper;
import picocli.CommandLine;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import io.quarkus.devtools.project.codegen.CreateProjectHelper;
import io.quarkus.devtools.commands.CreateProjectHelper;
import io.quarkus.devtools.testing.RegistryClientTestHelper;
import picocli.CommandLine;

Expand Down Expand Up @@ -307,8 +307,6 @@ public void testCreateArgPassthrough() throws Exception {
"Output should contain 'Project ArtifactId my-project', found: " + result.stdout);
Assertions.assertTrue(noSpaces.contains("ProjectGroupIdsilly"),
"Output should contain 'Project GroupId silly', found: " + result.stdout);
Assertions.assertTrue(result.stdout.contains("JAVA"),
"Should contain JAVA, found: " + result.stdout);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.quarkus.devtools.project.codegen.CreateProjectHelper;
import io.quarkus.devtools.commands.CreateProjectHelper;

public class TargetGAVGroupTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.maven;

import static io.quarkus.devtools.commands.CreateJBangProject.CreateJBangProjectKey.NO_JBANG_WRAPPER;
import static io.quarkus.devtools.project.CodestartResourceLoadersBuilder.codestartLoadersBuilder;
import static org.fusesource.jansi.Ansi.ansi;

Expand Down Expand Up @@ -118,8 +119,8 @@ public void execute() throws MojoExecutionException {
final CreateJBangProject createJBangProject = new CreateJBangProject(QuarkusProject.of(projectDirPath, catalog,
codestartsResourceLoader, log, BuildTool.MAVEN))
.extensions(extensions)
.javaTarget(javaVersion)
.setValue("noJBangWrapper", noJBangWrapper);
.javaVersion(javaVersion)
.setValue(NO_JBANG_WRAPPER, noJBangWrapper);

boolean success;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@

import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.devtools.commands.CreateProject;
import io.quarkus.devtools.commands.CreateProjectHelper;
import io.quarkus.devtools.messagewriter.MessageWriter;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.devtools.project.codegen.CreateProjectHelper;
import io.quarkus.devtools.project.codegen.SourceType;
import io.quarkus.maven.components.MavenVersionEnforcer;
import io.quarkus.maven.components.Prompter;
import io.quarkus.maven.utilities.MojoUtils;
Expand Down Expand Up @@ -109,14 +108,11 @@ public class CreateProjectMojo extends AbstractMojo {
* <br />
* If more than one of those extensions are picked, this parameter will be ignored.
* <br />
* 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
* <br />
* {@code className}
*/
@Parameter(property = "path")
@Deprecated
private String path;

/**
Expand All @@ -125,8 +121,6 @@ public class CreateProjectMojo extends AbstractMojo {
* <br />
* If more than one of those extensions are picked, then only the package name part will be used as {@link #packageName}
* <br />
* 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
* <br />
* By default, the {@link #projectGroupId} is used as package for generated classes (you can also use {@link #packageName}
Expand All @@ -135,7 +129,6 @@ public class CreateProjectMojo extends AbstractMojo {
* {@code className}
*/
@Parameter(property = "className")
@Deprecated
private String className;

/**
Expand Down Expand Up @@ -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<ResourceLoader> codestartsResourceLoader = codestartLoadersBuilder()
.catalog(catalog)
Expand All @@ -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)) {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down