From 808daa54e59643d6669df6b85339021d937b0934 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Sun, 22 Dec 2013 11:02:38 +0000 Subject: [PATCH] Make SpringApplication.getSources() do what it says on the can We still need the distinction internally between initial and additional sources, but the SpringApplication API (getSources()) itself doen't need to reflect that. --- .../springframework/boot/SpringApplication.java | 15 +++------------ .../boot/SpringApplicationTests.java | 5 +---- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index 8848afb081..366273cd09 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -155,8 +155,6 @@ public class SpringApplication { private Set sources = new LinkedHashSet(); - private Set initialSources = new LinkedHashSet(); - private Class mainApplicationClass; private boolean showBanner = true; @@ -211,7 +209,7 @@ public class SpringApplication { private void initialize(Object[] sources) { if (sources != null && sources.length > 0) { - this.initialSources.addAll(Arrays.asList(sources)); + this.sources.addAll(Arrays.asList(sources)); } this.webEnvironment = deduceWebEnvironment(); this.initializers = new LinkedHashSet>(); @@ -301,7 +299,7 @@ public class SpringApplication { // Call all remaining initializers callEnvironmentAwareSpringApplicationInitializers(args, environment); - Set sources = assembleSources(); + Set sources = getSources(); Assert.notEmpty(sources, "Sources must not be empty"); if (this.showBanner) { printBanner(); @@ -366,13 +364,6 @@ public class SpringApplication { } } - private Set assembleSources() { - LinkedHashSet sources = new LinkedHashSet(); - sources.addAll(this.sources); - sources.addAll(this.initialSources); - return sources; - } - private void callNonEnvironmentAwareSpringApplicationInitializers(String[] args) { for (ApplicationContextInitializer initializer : getInitializers()) { if (initializer instanceof SpringApplicationInitializer @@ -727,7 +718,7 @@ public class SpringApplication { */ public void setSources(Set sources) { Assert.notNull(sources, "Sources must not be null"); - this.sources = new LinkedHashSet(sources); + this.sources.addAll(sources); } /** diff --git a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index e2d8f57f8a..0805c09138 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -52,7 +52,6 @@ import org.springframework.core.env.PropertySource; import org.springframework.core.env.StandardEnvironment; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.ResourceLoader; -import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.StringUtils; import static org.hamcrest.Matchers.equalTo; @@ -322,9 +321,7 @@ public class SpringApplicationTests { application.setWebEnvironment(false); application.setUseMockLoader(true); application.run(); - @SuppressWarnings("unchecked") - Set initialSources = (Set) ReflectionTestUtils.getField( - application, "initialSources"); + Set initialSources = application.getSources(); assertThat(initialSources.toArray(), equalTo(sources)); }