Add package-name option for spring init

For some reason, we forgot to add an attribute to customize the package
name when using spring init. This is now the case.

Closes gh-3716
pull/3721/head
Stephane Nicoll 9 years ago
parent 25ac258d22
commit 04b1de2d1d

@ -89,10 +89,12 @@ public class InitCommand extends OptionParsingCommand {
private OptionSpec<String> description; private OptionSpec<String> description;
private OptionSpec<String> packaging; private OptionSpec<String> packageName;
private OptionSpec<String> type; private OptionSpec<String> type;
private OptionSpec<String> packaging;
private OptionSpec<String> build; private OptionSpec<String> build;
private OptionSpec<String> format; private OptionSpec<String> format;
@ -140,13 +142,14 @@ public class InitCommand extends OptionParsingCommand {
"Project name; infer application name").withRequiredArg(); "Project name; infer application name").withRequiredArg();
this.description = option("description", "Project description") this.description = option("description", "Project description")
.withRequiredArg(); .withRequiredArg();
this.packaging = option(Arrays.asList("packaging", "p"), this.packageName = option("package-name", "Package name").withRequiredArg();
"Project packaging (for example 'jar')").withRequiredArg();
this.type = option( this.type = option(
Arrays.asList("type", "t"), Arrays.asList("type", "t"),
"Project type. Not normally needed if you use --build " "Project type. Not normally needed if you use --build "
+ "and/or --format. Check the capabilities of the service " + "and/or --format. Check the capabilities of the service "
+ "(--list) for more details").withRequiredArg(); + "(--list) for more details").withRequiredArg();
this.packaging = option(Arrays.asList("packaging", "p"),
"Project packaging (for example 'jar')").withRequiredArg();
this.build = option("build", this.build = option("build",
"Build system to use (for example 'maven' or 'gradle')") "Build system to use (for example 'maven' or 'gradle')")
.withRequiredArg().defaultsTo("maven"); .withRequiredArg().defaultsTo("maven");
@ -226,8 +229,8 @@ public class InitCommand extends OptionParsingCommand {
if (options.has(this.javaVersion)) { if (options.has(this.javaVersion)) {
request.setJavaVersion(options.valueOf(this.javaVersion)); request.setJavaVersion(options.valueOf(this.javaVersion));
} }
if (options.has(this.packaging)) { if (options.has(this.packageName)) {
request.setPackaging(options.valueOf(this.packaging)); request.setPackageName(options.valueOf(this.packageName));
} }
request.setBuild(options.valueOf(this.build)); request.setBuild(options.valueOf(this.build));
request.setFormat(options.valueOf(this.format)); request.setFormat(options.valueOf(this.format));
@ -235,6 +238,9 @@ public class InitCommand extends OptionParsingCommand {
if (options.has(this.type)) { if (options.has(this.type)) {
request.setType(options.valueOf(this.type)); request.setType(options.valueOf(this.type));
} }
if (options.has(this.packaging)) {
request.setPackaging(options.valueOf(this.packaging));
}
if (options.has(this.language)) { if (options.has(this.language)) {
request.setLanguage(options.valueOf(this.language)); request.setLanguage(options.valueOf(this.language));
} }

@ -54,10 +54,12 @@ class ProjectGenerationRequest {
private String description; private String description;
private String packaging; private String packageName;
private String type; private String type;
private String packaging;
private String build; private String build;
private String format; private String format;
@ -178,15 +180,15 @@ class ProjectGenerationRequest {
} }
/** /**
* The packaging type or {@code null} if it should not be customized. * Return the package name or {@code null} if it should not be customized.
* @return the packaging type or {@code null} * @return the package name or {@code null}
*/ */
public String getPackaging() { public String getPackageName() {
return this.packaging; return packageName;
} }
public void setPackaging(String packaging) { public void setPackageName(String packageName) {
this.packaging = packaging; this.packageName = packageName;
} }
/** /**
@ -202,6 +204,18 @@ class ProjectGenerationRequest {
this.type = type; this.type = type;
} }
/**
* The packaging type or {@code null} if it should not be customized.
* @return the packaging type or {@code null}
*/
public String getPackaging() {
return this.packaging;
}
public void setPackaging(String packaging) {
this.packaging = packaging;
}
/** /**
* The build type to use. Ignored if a type is set. Can be used alongside the * The build type to use. Ignored if a type is set. Can be used alongside the
* {@link #getFormat() format} to identify the type to use. * {@link #getFormat() format} to identify the type to use.
@ -322,12 +336,15 @@ class ProjectGenerationRequest {
if (this.description != null) { if (this.description != null) {
builder.setParameter("description", this.description); builder.setParameter("description", this.description);
} }
if (this.packaging != null) { if (this.packageName != null) {
builder.setParameter("packaging", this.packaging); builder.setParameter("packageName", this.packageName);
} }
if (this.type != null) { if (this.type != null) {
builder.setParameter("type", projectType.getId()); builder.setParameter("type", projectType.getId());
} }
if (this.packaging != null) {
builder.setParameter("packaging", this.packaging);
}
if (this.javaVersion != null) { if (this.javaVersion != null) {
builder.setParameter("javaVersion", this.javaVersion); builder.setParameter("javaVersion", this.javaVersion);
} }

@ -266,18 +266,19 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
public void parseProjectOptions() throws Exception { public void parseProjectOptions() throws Exception {
this.handler.disableProjectGeneration(); this.handler.disableProjectGeneration();
this.command.run("-g=org.demo", "-a=acme", "-v=1.2.3-SNAPSHOT", "-n=acme-sample", this.command.run("-g=org.demo", "-a=acme", "-v=1.2.3-SNAPSHOT", "-n=acme-sample",
"--description=Acme sample project", "-p=war", "-t=ant-project", "--description=Acme sample project", "--package-name=demo.foo", "-t=ant-project",
"--build=grunt", "--format=web", "-j=1.9", "-l=groovy", "--build=grunt", "--format=web", "-p=war", "-j=1.9", "-l=groovy",
"-b=1.2.0.RELEASE", "-d=web,data-jpa"); "-b=1.2.0.RELEASE", "-d=web,data-jpa");
assertEquals("org.demo", this.handler.lastRequest.getGroupId()); assertEquals("org.demo", this.handler.lastRequest.getGroupId());
assertEquals("acme", this.handler.lastRequest.getArtifactId()); assertEquals("acme", this.handler.lastRequest.getArtifactId());
assertEquals("1.2.3-SNAPSHOT", this.handler.lastRequest.getVersion()); assertEquals("1.2.3-SNAPSHOT", this.handler.lastRequest.getVersion());
assertEquals("acme-sample", this.handler.lastRequest.getName()); assertEquals("acme-sample", this.handler.lastRequest.getName());
assertEquals("Acme sample project", this.handler.lastRequest.getDescription()); assertEquals("Acme sample project", this.handler.lastRequest.getDescription());
assertEquals("war", this.handler.lastRequest.getPackaging()); assertEquals("demo.foo", this.handler.lastRequest.getPackageName());
assertEquals("ant-project", this.handler.lastRequest.getType()); assertEquals("ant-project", this.handler.lastRequest.getType());
assertEquals("grunt", this.handler.lastRequest.getBuild()); assertEquals("grunt", this.handler.lastRequest.getBuild());
assertEquals("web", this.handler.lastRequest.getFormat()); assertEquals("web", this.handler.lastRequest.getFormat());
assertEquals("war", this.handler.lastRequest.getPackaging());
assertEquals("1.9", this.handler.lastRequest.getJavaVersion()); assertEquals("1.9", this.handler.lastRequest.getJavaVersion());
assertEquals("groovy", this.handler.lastRequest.getLanguage()); assertEquals("groovy", this.handler.lastRequest.getLanguage());
assertEquals("1.2.0.RELEASE", this.handler.lastRequest.getBootVersion()); assertEquals("1.2.0.RELEASE", this.handler.lastRequest.getBootVersion());

@ -95,9 +95,9 @@ public class ProjectGenerationRequestTests {
} }
@Test @Test
public void customPackaging() { public void customPackageName() {
this.request.setPackaging("war"); this.request.setPackageName("demo.foo");
assertEquals(createDefaultUrl("?packaging=war&type=test-type"), assertEquals(createDefaultUrl("?packageName=demo.foo&type=test-type"),
this.request.generateUrl(createDefaultMetadata())); this.request.generateUrl(createDefaultMetadata()));
} }
@ -113,6 +113,13 @@ public class ProjectGenerationRequestTests {
this.request.generateUrl(metadata)); this.request.generateUrl(metadata));
} }
@Test
public void customPackaging() {
this.request.setPackaging("war");
assertEquals(createDefaultUrl("?type=test-type&packaging=war"),
this.request.generateUrl(createDefaultMetadata()));
}
@Test @Test
public void customLanguage() { public void customLanguage() {
this.request.setLanguage("groovy"); this.request.setLanguage("groovy");

Loading…
Cancel
Save