From b35508d5a6ee2fca2c2f30871e1f95790aea65d1 Mon Sep 17 00:00:00 2001 From: vignesh1992 Date: Mon, 27 Sep 2021 15:38:37 +0200 Subject: [PATCH 1/4] Support both kebab-case and camelCase as Spring init CLI Options --- .../boot/cli/command/init/InitCommand.java | 18 ++++++++----- .../cli/command/init/InitCommandTests.java | 26 +++++++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java index 0c62b487f42a..33d315be6e8e 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java @@ -128,16 +128,20 @@ protected void options() { otherOptions(); } + /** + * Supports both kebab-case and camelCase as project CLI Options camelCase to be + * deprecated in future releases + */ private void projectGenerationOptions() { - this.groupId = option(Arrays.asList("groupId", "g"), "Project coordinates (for example 'org.test')") - .withRequiredArg(); - this.artifactId = option(Arrays.asList("artifactId", "a"), + this.groupId = option(Arrays.asList("groupId", "group-id", "g"), + "Project coordinates (for example 'org.test')").withRequiredArg(); + this.artifactId = option(Arrays.asList("artifactId", "artifact-id", "a"), "Project coordinates; infer archive name (for example 'test')").withRequiredArg(); this.version = option(Arrays.asList("version", "v"), "Project version (for example '0.0.1-SNAPSHOT')") .withRequiredArg(); this.name = option(Arrays.asList("name", "n"), "Project name; infer application name").withRequiredArg(); this.description = option("description", "Project description").withRequiredArg(); - this.packageName = option("package-name", "Package name").withRequiredArg(); + this.packageName = option(Arrays.asList("packageName", "package-name"), "Package name").withRequiredArg(); this.type = option(Arrays.asList("type", "t"), "Project type. Not normally needed if you use --build " + "and/or --format. Check the capabilities of the service (--list) for more details") @@ -148,11 +152,11 @@ private void projectGenerationOptions() { .defaultsTo("maven"); this.format = option("format", "Format of the generated content (for example 'build' for a build file, " + "'project' for a project archive)").withRequiredArg().defaultsTo("project"); - this.javaVersion = option(Arrays.asList("java-version", "j"), "Language level (for example '1.8')") - .withRequiredArg(); + this.javaVersion = option(Arrays.asList("javaVersion", "java-version", "j"), + "Language level (for example '1.8')").withRequiredArg(); this.language = option(Arrays.asList("language", "l"), "Programming language (for example 'java')") .withRequiredArg(); - this.bootVersion = option(Arrays.asList("boot-version", "b"), + this.bootVersion = option(Arrays.asList("bootVersion", "boot-version", "b"), "Spring Boot version (for example '1.2.0.RELEASE')").withRequiredArg(); this.dependencies = option(Arrays.asList("dependencies", "d"), "Comma-separated list of dependency identifiers to include in the generated project") diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java index cbdfb1664f14..5931714d8303 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java @@ -272,6 +272,32 @@ void parseProjectOptions() throws Exception { assertThat(dependencies.contains("data-jpa")).isTrue(); } + @Test + void parseProjectWithKebabCaseCLIOptions() throws Exception { + this.handler.disableProjectGeneration(); + this.command.run("--group-id=org.demo", "--artifact-id=acme", "--version=1.2.3-SNAPSHOT", "--name=acme-sample", + "--description=Acme sample project", "--package-name=demo.foo", "--type=ant-project", "--build=grunt", + "--format=web", "--packaging=war", "--java-version=1.9", "--language=groovy", + "--boot-version=1.2.0.RELEASE", "--dependencies=web,data-jpa"); + assertThat(this.handler.lastRequest.getGroupId()).isEqualTo("org.demo"); + assertThat(this.handler.lastRequest.getArtifactId()).isEqualTo("acme"); + assertThat(this.handler.lastRequest.getVersion()).isEqualTo("1.2.3-SNAPSHOT"); + assertThat(this.handler.lastRequest.getName()).isEqualTo("acme-sample"); + assertThat(this.handler.lastRequest.getDescription()).isEqualTo("Acme sample project"); + assertThat(this.handler.lastRequest.getPackageName()).isEqualTo("demo.foo"); + assertThat(this.handler.lastRequest.getType()).isEqualTo("ant-project"); + assertThat(this.handler.lastRequest.getBuild()).isEqualTo("grunt"); + assertThat(this.handler.lastRequest.getFormat()).isEqualTo("web"); + assertThat(this.handler.lastRequest.getPackaging()).isEqualTo("war"); + assertThat(this.handler.lastRequest.getJavaVersion()).isEqualTo("1.9"); + assertThat(this.handler.lastRequest.getLanguage()).isEqualTo("groovy"); + assertThat(this.handler.lastRequest.getBootVersion()).isEqualTo("1.2.0.RELEASE"); + List dependencies = this.handler.lastRequest.getDependencies(); + assertThat(dependencies).hasSize(2); + assertThat(dependencies.contains("web")).isTrue(); + assertThat(dependencies.contains("data-jpa")).isTrue(); + } + @Test void overwriteFileInArchive(@TempDir File tempDir) throws Exception { File conflict = new File(tempDir, "test.txt"); From de0f46d975f69f0995e3bc2770904ebfc5942c67 Mon Sep 17 00:00:00 2001 From: vignesh1992 Date: Mon, 27 Sep 2021 15:47:15 +0200 Subject: [PATCH 2/4] Format comment for projectGenerationOptions method --- .../springframework/boot/cli/command/init/InitCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java index 33d315be6e8e..1e44f020cb94 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java @@ -129,8 +129,8 @@ protected void options() { } /** - * Supports both kebab-case and camelCase as project CLI Options camelCase to be - * deprecated in future releases + * Supports both kebab-case and camelCase as project CLI Options. camelCase to be + * deprecated as part of future releases */ private void projectGenerationOptions() { this.groupId = option(Arrays.asList("groupId", "group-id", "g"), From 11bb419b453a8629b4c55dca826aa5b892281675 Mon Sep 17 00:00:00 2001 From: vignesh1992 Date: Mon, 27 Sep 2021 15:51:34 +0200 Subject: [PATCH 3/4] Add name to Authors of the file --- .../org/springframework/boot/cli/command/init/InitCommand.java | 1 + .../springframework/boot/cli/command/init/InitCommandTests.java | 1 + 2 files changed, 2 insertions(+) diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java index 1e44f020cb94..aa83a8dcecfc 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java @@ -38,6 +38,7 @@ * * @author Stephane Nicoll * @author Eddú Meléndez + * @author vigneshti * @since 1.2.0 */ public class InitCommand extends OptionParsingCommand { diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java index 5931714d8303..7c7cfc9bca59 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java @@ -44,6 +44,7 @@ * * @author Stephane Nicoll * @author Eddú Meléndez + * @author vigneshti */ @ExtendWith(MockitoExtension.class) class InitCommandTests extends AbstractHttpClientMockTests { From fa94c43bd1d02b59a11169ca273427f0e5dd1436 Mon Sep 17 00:00:00 2001 From: vignesh1992 Date: Mon, 27 Sep 2021 16:20:29 +0200 Subject: [PATCH 4/4] Add name to Authors of the file --- .../org/springframework/boot/cli/command/init/InitCommand.java | 2 +- .../springframework/boot/cli/command/init/InitCommandTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java index aa83a8dcecfc..d21712890a45 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java @@ -38,7 +38,7 @@ * * @author Stephane Nicoll * @author Eddú Meléndez - * @author vigneshti + * @author Vignesh Thangavel Ilangovan * @since 1.2.0 */ public class InitCommand extends OptionParsingCommand { diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java index 7c7cfc9bca59..7e4a7f208450 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java @@ -44,7 +44,7 @@ * * @author Stephane Nicoll * @author Eddú Meléndez - * @author vigneshti + * @author Vignesh Thangavel Ilangovan */ @ExtendWith(MockitoExtension.class) class InitCommandTests extends AbstractHttpClientMockTests {