Add extra attributes to the init command

Update the CLI init command to expose additional attributes supported
by Spring Initializr. These are: groupId, artifactId, version, name,
description and language.

Closes gh-2793 and gh-2907
This commit is contained in:
Eddú Meléndez
2015-05-04 09:15:56 -05:00
committed by Stephane Nicoll
parent d4dfa8d979
commit 0b8fd67507
4 changed files with 174 additions and 2 deletions

View File

@@ -37,6 +37,7 @@ import org.springframework.util.Assert;
* {@link Command} that initializes a project using Spring initializr.
*
* @author Stephane Nicoll
* @author Eddú Meléndez
* @since 1.2.0
*/
public class InitCommand extends OptionParsingCommand {
@@ -96,6 +97,18 @@ public class InitCommand extends OptionParsingCommand {
private OptionSpec<Void> force;
private OptionSpec<String> language;
private OptionSpec<String> groupId;
private OptionSpec<String> artifactId;
private OptionSpec<String> name;
private OptionSpec<String> version;
private OptionSpec<String> description;
InitOptionHandler(InitializrService initializrService) {
this.serviceCapabilitiesReport = new ServiceCapabilitiesReportGenerator(
initializrService);
@@ -140,6 +153,24 @@ public class InitCommand extends OptionParsingCommand {
"The project type to use. Not normally needed if you use --build "
+ "and/or --format. Check the capabilities of the service "
+ "(--list) for more details").withRequiredArg();
this.language = option(Arrays.asList("language", "lang"),
"Programming Language to use (for example 'java')")
.withRequiredArg();
this.groupId = option(Arrays.asList("groupId", "g"),
"The project group that produced the dependency (for example 'org.test')")
.withRequiredArg();
this.artifactId = option(Arrays.asList("artifactId", "a"),
"The unique id for an artifact produced by the project group (for example 'test')")
.withRequiredArg();
this.name = option(Arrays.asList("name", "n"),
"The full name of the project.")
.withRequiredArg();
this.version = option(Arrays.asList("version", "v"),
"The version of the dependency (for example '0.0.1-SNAPSHOT')")
.withRequiredArg();
this.description = option(Arrays.asList("description", "des"),
"A detailed description of the project")
.withRequiredArg();
}
private void otherOptions() {
@@ -209,6 +240,24 @@ public class InitCommand extends OptionParsingCommand {
if (options.has(this.type)) {
request.setType(options.valueOf(this.type));
}
if(options.has(this.language)) {
request.setLanguage(options.valueOf(this.language));
}
if(options.has(this.groupId)) {
request.setGroupId(options.valueOf(this.groupId));
}
if (options.has(this.artifactId)) {
request.setArtifactId(options.valueOf(this.artifactId));
}
if(options.has(this.name)) {
request.setName(options.valueOf(this.name));
}
if(options.has(this.version)) {
request.setVersion(options.valueOf(this.version));
}
if(options.has(this.description)) {
request.setDescription(options.valueOf(this.description));
}
request.setExtract(options.has(this.extract));
if (nonOptionArguments.size() == 1) {
String output = (String) nonOptionArguments.get(0);

View File

@@ -59,6 +59,18 @@ class ProjectGenerationRequest {
private String type;
private String language;
private String groupId;
private String artifactId;
private String name;
private String version;
private String description;
/**
* The URL of the service to use.
* @see #DEFAULT_SERVICE_URL
@@ -199,6 +211,72 @@ class ProjectGenerationRequest {
this.type = type;
}
/**
* The programming language to use or {@code null} if it should not be customized.
*/
public String getLanguage() {
return this.language;
}
public void setLanguage(String language) {
this.language = language;
}
/**
* The groupId to use or {@code null} if it should not be customized.
*/
public String getGroupId() {
return this.groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
/**
* The artifactId to use or {@code null} if it should not be customized.
*/
public String getArtifactId() {
return this.artifactId;
}
public void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}
/**
* The name to use or {@code null} if it should not be customized.
*/
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
/**
* The artifact version to use or {@code null} if it should not be customized.
*/
public String getVersion() {
return this.version;
}
public void setVersion(String version) {
this.version = version;
}
/**
*
*/
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
/**
* Generates the URI to use to generate a project represented by this request
* @param metadata the metadata that describes the service
@@ -217,6 +295,9 @@ class ProjectGenerationRequest {
sb.append(projectType.getAction());
builder.setPath(sb.toString());
if (this.artifactId != null) {
builder.setParameter("artifactId", this.artifactId);
}
if (this.bootVersion != null) {
builder.setParameter("bootVersion", this.bootVersion);
}
@@ -225,15 +306,30 @@ class ProjectGenerationRequest {
builder.setParameter("dependencies",
StringUtils.collectionToCommaDelimitedString(this.dependencies));
}
if (this.description != null) {
builder.setParameter("description", this.description);
}
if (this.groupId != null) {
builder.setParameter("groupId", this.groupId);
}
if (this.javaVersion != null) {
builder.setParameter("javaVersion", this.javaVersion);
}
if (this.language != null) {
builder.setParameter("language", this.language);
}
if (this.name != null) {
builder.setParameter("name", this.name);
}
if (this.packaging != null) {
builder.setParameter("packaging", this.packaging);
}
if (this.type != null) {
builder.setParameter("type", projectType.getId());
}
if (this.version != null) {
builder.setParameter("version", this.version);
}
return builder.build();
}