Skip to content

Commit

Permalink
Allow passing name and description for CLI and Maven project
Browse files Browse the repository at this point in the history
This does not modify the Gradle setup.
  • Loading branch information
gsmet authored and igorregis committed Oct 16, 2022
1 parent bcfcd51 commit dd7cc0a
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 1 deletion.
12 changes: 12 additions & 0 deletions devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.quarkus.cli.create.TargetBuildToolGroup;
import io.quarkus.cli.create.TargetGAVGroup;
import io.quarkus.cli.create.TargetLanguageGroup;
import io.quarkus.devtools.commands.CreateProject.CreateProjectKey;
import io.quarkus.devtools.commands.SourceType;
import io.quarkus.devtools.commands.data.QuarkusCommandInvocation;
import io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler;
Expand All @@ -30,6 +31,13 @@ public class CreateApp extends BaseCreateCommand {
"--extension", "--extensions" }, description = "Extension(s) to add to the project.", split = ",")
Set<String> extensions = new HashSet<>();

@CommandLine.Option(paramLabel = "NAME", names = { "--name" }, description = "Name of the project.")
String name;

@CommandLine.Option(paramLabel = "DESCRIPTION", names = {
"--description" }, description = "Description of the project.")
String description;

@CommandLine.ArgGroup(order = 2, heading = "%nQuarkus version:%n")
TargetQuarkusVersionGroup targetQuarkusVersion = new TargetQuarkusVersionGroup();

Expand Down Expand Up @@ -62,6 +70,8 @@ public Integer call() throws Exception {
setJavaVersion(sourceType, targetLanguage.getJavaVersion());
setSourceTypeExtensions(extensions, sourceType);
setCodegenOptions(codeGeneration);
setValue(CreateProjectKey.PROJECT_NAME, name);
setValue(CreateProjectKey.PROJECT_DESCRIPTION, description);

QuarkusCommandInvocation invocation = build(buildTool, targetQuarkusVersion,
propertiesOptions.properties, extensions);
Expand Down Expand Up @@ -99,6 +109,8 @@ public String toString() {
+ ", targetLanguage=" + targetLanguage
+ ", codeGeneration=" + codeGeneration
+ ", extensions=" + extensions
+ ", name=" + name
+ ", description=" + description
+ ", project=" + super.toString()
+ ", properties=" + propertiesOptions.properties
+ '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void setCodegenOptions(CodeGenerationGroup codeGeneration) {
setValue(CreateProjectKey.NO_BUILDTOOL_WRAPPER, !codeGeneration.includeWrapper);
}

private void setValue(String name, Object value) {
protected void setValue(String name, Object value) {
if (value != null) {
values.put(name, value);
}
Expand Down
25 changes: 25 additions & 0 deletions devtools/cli/src/test/java/io/quarkus/cli/CliProjectMavenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public void testCreateAppDefaults() throws Exception {
Assertions.assertTrue(pomContent.contains("<artifactId>quarkus-resteasy-reactive</artifactId>"),
"pom.xml should contain quarkus-resteasy-reactive:\n" + pomContent);

// check that the project doesn't have a <description> (a <name> is defined in the profile, it's harder to test)
Assertions.assertFalse(pomContent.contains("<description>"),
"pom.xml should not contain a description:\n" + pomContent);

CliDriver.valdiateGeneratedSourcePackage(project, "org/acme");

result = CliDriver.invokeValidateDryRunBuild(project);
Expand Down Expand Up @@ -341,6 +345,27 @@ public void testCreateArgJava17() throws Exception {
"Java 17 should be used when specified. Found:\n" + pomContent);
}

@Test
public void testCreateNameDescription() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "--name", "My name", "--description",
"My description");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
Assertions.assertTrue(result.stdout.contains("SUCCESS"),
"Expected confirmation that the project has been created." + result);

String pomContent = validateBasicIdentifiers(CreateProjectHelper.DEFAULT_GROUP_ID,
CreateProjectHelper.DEFAULT_ARTIFACT_ID,
CreateProjectHelper.DEFAULT_VERSION);
Assertions.assertTrue(pomContent.contains("<name>My name</name>"),
"pom.xml should contain a name:\n" + pomContent);
Assertions.assertTrue(pomContent.contains("<description>My description</description>"),
"pom.xml should contain a description:\n" + pomContent);

result = CliDriver.invokeValidateDryRunBuild(project);

CliDriver.invokeValidateBuild(project);
}

String validateBasicIdentifiers(String group, String artifact, String version) throws Exception {
Path pom = project.resolve("pom.xml");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public class CreateProjectMojo extends AbstractMojo {
@Parameter(property = "projectVersion")
private String projectVersion;

@Parameter(property = "projectName")
private String projectName;

@Parameter(property = "projectDescription")
private String projectDescription;

/**
* When true, do not include any code in the generated Quarkus project.
*/
Expand Down Expand Up @@ -279,6 +285,8 @@ public void execute() throws MojoExecutionException {
.groupId(projectGroupId)
.artifactId(projectArtifactId)
.version(projectVersion)
.name(projectName)
.description(projectDescription)
.javaVersion(javaVersion)
.resourceClassName(className)
.packageName(packageName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
<groupId>{project.group-id}</groupId>
<artifactId>{project.artifact-id}</artifactId>
<version>{project.version}</version>
{#if project.name }
<name>{project.name}</name>
{/if}
{#if project.description }
<description>{project.description}</description>
{/if}

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public enum QuarkusDataKey implements DataKey {
PROJECT_GROUP_ID("project.group-id"),
PROJECT_ARTIFACT_ID("project.artifact-id"),
PROJECT_VERSION("project.version"),
PROJECT_NAME("project.name"),
PROJECT_DESCRIPTION("project.description"),
PROJECT_PACKAGE_NAME("project.package-name"),
QUARKUS_MAVEN_PLUGIN_GROUP_ID("quarkus.maven-plugin.group-id"),
QUARKUS_MAVEN_PLUGIN_ARTIFACT_ID("quarkus.maven-plugin.artifact-id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public interface CreateProjectKey {
String PROJECT_GROUP_ID = "project.group-id";
String PROJECT_ARTIFACT_ID = "project.artifact-id";
String PROJECT_VERSION = "project.version";
String PROJECT_NAME = "project.name";
String PROJECT_DESCRIPTION = "project.description";
String PACKAGE_NAME = "project.package-name";
String EXTENSIONS = "project.extensions";
String RESOURCE_CLASS_NAME = "project.resource.class-name";
Expand Down Expand Up @@ -73,6 +75,22 @@ public CreateProject version(String version) {
return this;
}

public CreateProject name(String name) {
if (name == null || name.isBlank()) {
return this;
}
setValue(PROJECT_NAME, name);
return this;
}

public CreateProject description(String description) {
if (description == null || description.isBlank()) {
return this;
}
setValue(PROJECT_DESCRIPTION, description);
return this;
}

@Deprecated
public CreateProject quarkusMavenPluginVersion(String version) {
setValue(QUARKUS_MAVEN_PLUGIN_VERSION, version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ 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_NAME(CreateProjectKey.PROJECT_NAME),
PROJECT_DESCRIPTION(CreateProjectKey.PROJECT_DESCRIPTION),
PROJECT_PACKAGE_NAME(CreateProjectKey.PACKAGE_NAME),
QUARKUS_VERSION(CreateProjectKey.QUARKUS_VERSION),
JAVA_VERSION(CreateProjectKey.JAVA_VERSION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public void testProjectGenerationFromScratch() throws MavenInvocationException,
assertThat(new File(testDir, "src/main/docker/Dockerfile.jvm")).isFile();

Model model = loadPom(testDir);

assertThat(model.getName()).isNull();
assertThat(model.getDescription()).isNull();

final DependencyManagement dependencyManagement = model.getDependencyManagement();
final List<Dependency> dependencies = dependencyManagement.getDependencies();
assertThat(dependencies.stream()
Expand Down Expand Up @@ -115,6 +119,34 @@ public void testProjectGenerationFromScratch() throws MavenInvocationException,
.returns("${maven.home}", from(Xpp3Dom::getValue));
}

@Test
public void testProjectGenerationFromScratchWithNameAndDescription() throws MavenInvocationException, IOException {
testDir = initEmptyProject("projects/project-generation-name-description");
assertThat(testDir).isDirectory();
invoker = initInvoker(testDir);

Properties properties = new Properties();
properties.put("projectGroupId", "org.acme");
properties.put("projectArtifactId", "acme");
properties.put("projectVersion", "1.0.0-SNAPSHOT");
properties.put("projectName", "My name");
properties.put("projectDescription", "My description");

InvocationResult result = setup(properties);

assertThat(result.getExitCode()).isZero();

// As the directory is not empty (log) navigate to the artifactID directory
testDir = new File(testDir, "acme");

assertThat(new File(testDir, "pom.xml")).isFile();

Model model = loadPom(testDir);

assertThat(model.getName()).isEqualTo("My name");
assertThat(model.getDescription()).isEqualTo("My description");
}

@Test
public void testProjectGenerationWithExistingPomFileWithPackagingJarShouldFail() throws Exception {
testDir = initProject("projects/simple-pom-it", "projects/project-generation-from-empty-pom");
Expand Down

0 comments on commit dd7cc0a

Please sign in to comment.