From 6a18ece6a2dd497a5651f6dac009729d359b048c Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 3 Nov 2014 13:12:06 +0100 Subject: [PATCH] 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 --- .../command/init/ProjectGenerationRequest.java | 17 ++++++++++------- .../init/ProjectGenerationRequestTests.java | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerationRequest.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerationRequest.java index b2d7cfaf26..d803e72605 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerationRequest.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerationRequest.java @@ -233,8 +233,9 @@ class ProjectGenerationRequest { throw new ReportableException(("No project type with id '" + this.type + "' - check the service capabilities (--list)")); } + return result; } - if (isDetectType()) { + else if (isDetectType()) { Map types = new HashMap( metadata.getProjectTypes()); if (this.build != null) { @@ -257,13 +258,15 @@ class ProjectGenerationRequest { + "' use --type with a more specific value " + types.keySet()); } } - ProjectType defaultType = metadata.getDefaultType(); - if (defaultType == null) { - throw new ReportableException( - ("No project type is set and no default is defined. " - + "Check the service capabilities (--list)")); + else { + ProjectType defaultType = metadata.getDefaultType(); + if (defaultType == null) { + throw new ReportableException( + ("No project type is set and no default is defined. " + + "Check the service capabilities (--list)")); + } + return defaultType; } - return defaultType; } private static void filter(Map projects, String tag, diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/ProjectGenerationRequestTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/ProjectGenerationRequestTests.java index 96c6631e98..6e80d30b34 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/ProjectGenerationRequestTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/ProjectGenerationRequestTests.java @@ -138,6 +138,15 @@ public class ProjectGenerationRequestTests { 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 public void invalidType() throws URISyntaxException { this.request.setType("does-not-exist"); @@ -152,16 +161,19 @@ public class ProjectGenerationRequestTests { this.request.generateUrl(readMetadata("types-conflict")); } - private static URI createDefaultUrl(String param) { + private static URI createUrl(String actionAndParam) { try { - return new URI(ProjectGenerationRequest.DEFAULT_SERVICE_URL + "/starter.zip" - + param); + return new URI(ProjectGenerationRequest.DEFAULT_SERVICE_URL + actionAndParam); } catch (URISyntaxException ex) { throw new IllegalStateException(ex); } } + private static URI createDefaultUrl(String param) { + return createUrl("/starter.zip" + param); + } + public void setBuildAndFormat(String build, String format) { this.request.setBuild(build != null ? build : "maven"); this.request.setFormat(format != null ? format : "project");