Skip to content

Commit 6563405

Browse files
committed
ImportRegistry as a package-visible top-level interface which can easily be shared within the package
Issue: SPR-12128
1 parent 125ae99 commit 6563405

File tree

5 files changed

+38
-22
lines changed

5 files changed

+38
-22
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.springframework.beans.factory.support.BeanNameGenerator;
4545
import org.springframework.beans.factory.support.RootBeanDefinition;
4646
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
47-
import org.springframework.context.annotation.ConfigurationClassParser.ImportRegistry;
4847
import org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase;
4948
import org.springframework.core.annotation.AnnotationAttributes;
5049
import org.springframework.core.env.Environment;
@@ -96,7 +95,7 @@ class ConfigurationClassBeanDefinitionReader {
9695
* Create a new {@link ConfigurationClassBeanDefinitionReader} instance that will be used
9796
* to populate the given {@link BeanDefinitionRegistry}.
9897
*/
99-
public ConfigurationClassBeanDefinitionReader(BeanDefinitionRegistry registry, SourceExtractor sourceExtractor,
98+
ConfigurationClassBeanDefinitionReader(BeanDefinitionRegistry registry, SourceExtractor sourceExtractor,
10099
ProblemReporter problemReporter, MetadataReaderFactory metadataReaderFactory,
101100
ResourceLoader resourceLoader, Environment environment, BeanNameGenerator importBeanNameGenerator,
102101
ImportRegistry importRegistry) {
@@ -132,8 +131,11 @@ private void loadBeanDefinitionsForConfigurationClass(ConfigurationClass configC
132131
TrackedConditionEvaluator trackedConditionEvaluator) {
133132

134133
if (trackedConditionEvaluator.shouldSkip(configClass)) {
135-
removeBeanDefinition(configClass);
136-
importRegistry.removeImportingClassFor(configClass.getMetadata().getClassName());
134+
String beanName = configClass.getBeanName();
135+
if (StringUtils.hasLength(beanName) && this.registry.containsBeanDefinition(beanName)) {
136+
this.registry.removeBeanDefinition(beanName);
137+
}
138+
this.importRegistry.removeImportingClassFor(configClass.getMetadata().getClassName());
137139
return;
138140
}
139141

@@ -147,13 +149,6 @@ private void loadBeanDefinitionsForConfigurationClass(ConfigurationClass configC
147149
loadBeanDefinitionsFromRegistrars(configClass.getImportBeanDefinitionRegistrars());
148150
}
149151

150-
private void removeBeanDefinition(ConfigurationClass configClass) {
151-
String beanName = configClass.getBeanName();
152-
if (StringUtils.hasLength(beanName) && this.registry.containsBeanDefinition(beanName)) {
153-
this.registry.removeBeanDefinition(beanName);
154-
}
155-
}
156-
157152
/**
158153
* Register the {@link Configuration} class itself as a bean definition.
159154
*/

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

-8
Original file line numberDiff line numberDiff line change
@@ -588,14 +588,6 @@ public SourceClass asSourceClass(String className) throws IOException {
588588
}
589589

590590

591-
interface ImportRegistry {
592-
593-
AnnotationMetadata getImportingClassFor(String importedClass);
594-
595-
void removeImportingClassFor(String importedClass);
596-
}
597-
598-
599591
@SuppressWarnings("serial")
600592
private static class ImportStack extends Stack<ConfigurationClass> implements ImportRegistry {
601593

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import org.springframework.context.EnvironmentAware;
5454
import org.springframework.context.ResourceLoaderAware;
5555
import org.springframework.context.annotation.ConfigurationClassEnhancer.EnhancedConfiguration;
56-
import org.springframework.context.annotation.ConfigurationClassParser.ImportRegistry;
5756
import org.springframework.core.Ordered;
5857
import org.springframework.core.PriorityOrdered;
5958
import org.springframework.core.env.Environment;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2002-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.context.annotation;
18+
19+
import org.springframework.core.type.AnnotationMetadata;
20+
21+
/**
22+
* @author Juergen Hoeller
23+
* @author Phil Webb
24+
*/
25+
interface ImportRegistry {
26+
27+
AnnotationMetadata getImportingClassFor(String importedClass);
28+
29+
void removeImportingClassFor(String importedClass);
30+
31+
}

spring-context/src/test/java/org/springframework/context/annotation/ImportAwareTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ private static final class OnMissingBeanCondition implements ConfigurationCondit
281281

282282
@Override
283283
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
284-
return context.getBeanFactory().getBeanNamesForType(MetadataHolder.class,
285-
true, false).length == 0;
284+
return (context.getBeanFactory().getBeanNamesForType(MetadataHolder.class, true, false).length == 0);
286285
}
287286

288287
@Override

0 commit comments

Comments
 (0)