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.
This commit is contained in:
Dave Syer 2013-12-22 11:02:38 +00:00
parent 2a10503167
commit 808daa54e5
2 changed files with 4 additions and 16 deletions

View File

@ -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);
}
/**

View File

@ -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));
}