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.
pull/184/head
Dave Syer 11 years ago
parent 2a10503167
commit 808daa54e5

@ -155,8 +155,6 @@ public class SpringApplication {
private Set<Object> sources = new LinkedHashSet<Object>(); private Set<Object> sources = new LinkedHashSet<Object>();
private Set<Object> initialSources = new LinkedHashSet<Object>();
private Class<?> mainApplicationClass; private Class<?> mainApplicationClass;
private boolean showBanner = true; private boolean showBanner = true;
@ -211,7 +209,7 @@ public class SpringApplication {
private void initialize(Object[] sources) { private void initialize(Object[] sources) {
if (sources != null && sources.length > 0) { if (sources != null && sources.length > 0) {
this.initialSources.addAll(Arrays.asList(sources)); this.sources.addAll(Arrays.asList(sources));
} }
this.webEnvironment = deduceWebEnvironment(); this.webEnvironment = deduceWebEnvironment();
this.initializers = new LinkedHashSet<ApplicationContextInitializer<?>>(); this.initializers = new LinkedHashSet<ApplicationContextInitializer<?>>();
@ -301,7 +299,7 @@ public class SpringApplication {
// Call all remaining initializers // Call all remaining initializers
callEnvironmentAwareSpringApplicationInitializers(args, environment); callEnvironmentAwareSpringApplicationInitializers(args, environment);
Set<Object> sources = assembleSources(); Set<Object> sources = getSources();
Assert.notEmpty(sources, "Sources must not be empty"); Assert.notEmpty(sources, "Sources must not be empty");
if (this.showBanner) { if (this.showBanner) {
printBanner(); printBanner();
@ -366,13 +364,6 @@ public class SpringApplication {
} }
} }
private Set<Object> assembleSources() {
LinkedHashSet<Object> sources = new LinkedHashSet<Object>();
sources.addAll(this.sources);
sources.addAll(this.initialSources);
return sources;
}
private void callNonEnvironmentAwareSpringApplicationInitializers(String[] args) { private void callNonEnvironmentAwareSpringApplicationInitializers(String[] args) {
for (ApplicationContextInitializer<?> initializer : getInitializers()) { for (ApplicationContextInitializer<?> initializer : getInitializers()) {
if (initializer instanceof SpringApplicationInitializer if (initializer instanceof SpringApplicationInitializer
@ -727,7 +718,7 @@ public class SpringApplication {
*/ */
public void setSources(Set<Object> sources) { public void setSources(Set<Object> sources) {
Assert.notNull(sources, "Sources must not be null"); Assert.notNull(sources, "Sources must not be null");
this.sources = new LinkedHashSet<Object>(sources); this.sources.addAll(sources);
} }
/** /**

@ -52,7 +52,6 @@ import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment; import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -322,9 +321,7 @@ public class SpringApplicationTests {
application.setWebEnvironment(false); application.setWebEnvironment(false);
application.setUseMockLoader(true); application.setUseMockLoader(true);
application.run(); application.run();
@SuppressWarnings("unchecked") Set<Object> initialSources = application.getSources();
Set<Object> initialSources = (Set<Object>) ReflectionTestUtils.getField(
application, "initialSources");
assertThat(initialSources.toArray(), equalTo(sources)); assertThat(initialSources.toArray(), equalTo(sources));
} }

Loading…
Cancel
Save