Explicit type takes precedence over build and format

Prior to this commit, specifying the --format and/or --build options
alongside --type did not use the explicit type as it should. This commit
ignores the --build and --format options if a type is explicitly set.

Fixes gh-1807
This commit is contained in:
Stephane Nicoll 2014-11-03 13:12:06 +01:00
parent a85e02fbb9
commit 6a18ece6a2
2 changed files with 25 additions and 10 deletions

View File

@ -233,8 +233,9 @@ class ProjectGenerationRequest {
throw new ReportableException(("No project type with id '" throw new ReportableException(("No project type with id '"
+ this.type + "' - check the service capabilities (--list)")); + this.type + "' - check the service capabilities (--list)"));
} }
return result;
} }
if (isDetectType()) { else if (isDetectType()) {
Map<String, ProjectType> types = new HashMap<String, ProjectType>( Map<String, ProjectType> types = new HashMap<String, ProjectType>(
metadata.getProjectTypes()); metadata.getProjectTypes());
if (this.build != null) { if (this.build != null) {
@ -257,6 +258,7 @@ class ProjectGenerationRequest {
+ "' use --type with a more specific value " + types.keySet()); + "' use --type with a more specific value " + types.keySet());
} }
} }
else {
ProjectType defaultType = metadata.getDefaultType(); ProjectType defaultType = metadata.getDefaultType();
if (defaultType == null) { if (defaultType == null) {
throw new ReportableException( throw new ReportableException(
@ -265,6 +267,7 @@ class ProjectGenerationRequest {
} }
return defaultType; return defaultType;
} }
}
private static void filter(Map<String, ProjectType> projects, String tag, private static void filter(Map<String, ProjectType> projects, String tag,
String tagValue) { String tagValue) {

View File

@ -138,6 +138,15 @@ public class ProjectGenerationRequestTests {
this.request.generateUrl(metadata)); this.request.generateUrl(metadata));
} }
@Test
public void typeAndBuildAndFormat() {
InitializrServiceMetadata metadata = readMetadata();
setBuildAndFormat("gradle", "project");
request.setType("maven-build");
assertEquals(createUrl("/pom.xml?type=maven-build"),
this.request.generateUrl(metadata));
}
@Test @Test
public void invalidType() throws URISyntaxException { public void invalidType() throws URISyntaxException {
this.request.setType("does-not-exist"); this.request.setType("does-not-exist");
@ -152,16 +161,19 @@ public class ProjectGenerationRequestTests {
this.request.generateUrl(readMetadata("types-conflict")); this.request.generateUrl(readMetadata("types-conflict"));
} }
private static URI createDefaultUrl(String param) { private static URI createUrl(String actionAndParam) {
try { try {
return new URI(ProjectGenerationRequest.DEFAULT_SERVICE_URL + "/starter.zip" return new URI(ProjectGenerationRequest.DEFAULT_SERVICE_URL + actionAndParam);
+ param);
} }
catch (URISyntaxException ex) { catch (URISyntaxException ex) {
throw new IllegalStateException(ex); throw new IllegalStateException(ex);
} }
} }
private static URI createDefaultUrl(String param) {
return createUrl("/starter.zip" + param);
}
public void setBuildAndFormat(String build, String format) { public void setBuildAndFormat(String build, String format) {
this.request.setBuild(build != null ? build : "maven"); this.request.setBuild(build != null ? build : "maven");
this.request.setFormat(format != null ? format : "project"); this.request.setFormat(format != null ? format : "project");