Commit 808daa54 authored by Dave Syer's avatar Dave Syer

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.
parent 2a105031
......@@ -155,8 +155,6 @@ public class SpringApplication {
private Set<Object> sources = new LinkedHashSet<Object>();
private Set<Object> initialSources = new LinkedHashSet<Object>();
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<ApplicationContextInitializer<?>>();
......@@ -301,7 +299,7 @@ public class SpringApplication {
// Call all remaining initializers
callEnvironmentAwareSpringApplicationInitializers(args, environment);
Set<Object> sources = assembleSources();
Set<Object> sources = getSources();
Assert.notEmpty(sources, "Sources must not be empty");
if (this.showBanner) {
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) {
for (ApplicationContextInitializer<?> initializer : getInitializers()) {
if (initializer instanceof SpringApplicationInitializer
......@@ -727,7 +718,7 @@ public class SpringApplication {
*/
public void setSources(Set<Object> sources) {
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.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<Object> initialSources = (Set<Object>) ReflectionTestUtils.getField(
application, "initialSources");
Set<Object> initialSources = application.getSources();
assertThat(initialSources.toArray(), equalTo(sources));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment