Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Commit

Permalink
Static boolean to allow build time initializtion
Browse files Browse the repository at this point in the history
A native image can be built with 0 support for XML now, as long as
spring.xml.ignored=true.
  • Loading branch information
dsyer committed Aug 26, 2020
1 parent bc12b2d commit e62f1ce
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.SpringProperties;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReaderFactory;
Expand All @@ -58,6 +59,8 @@ public class FunctionalInstallerPostProcessor implements BeanDefinitionRegistryP

private MetadataReaderFactory metadataReaderFactory;

private static final boolean shouldIgnoreXml = SpringProperties.getFlag("spring.xml.ignore");

private enum Phase {

USER, DEFERRED;
Expand Down Expand Up @@ -170,17 +173,21 @@ private Set<Imported> findAdded(Set<Imported> seen, BeanDefinitionRegistry regis
.getOrCreate(context, initializerType);
configs.put(clazz, initializer);
}
} else if (ImportBeanDefinitionRegistrar.class.isAssignableFrom(clazz)) {
}
else if (ImportBeanDefinitionRegistrar.class.isAssignableFrom(clazz)) {
added.add(new Imported(imported.getSource(), clazz));
} else {
}
else {
context.registerBean(clazz);
}
}
}
}
} else if (ImportBeanDefinitionRegistrar.class.isAssignableFrom(type)) {
}
else if (ImportBeanDefinitionRegistrar.class.isAssignableFrom(type)) {
importRegistrar(registry, imported);
} else {
}
else {
try {
if (getMetaData(type).isAnnotated(Configuration.class.getName())) {
// recurse?
Expand All @@ -189,20 +196,24 @@ private Set<Imported> findAdded(Set<Imported> seen, BeanDefinitionRegistry regis
ApplicationContextInitializer<GenericApplicationContext> initializer = (ApplicationContextInitializer<GenericApplicationContext>) InfrastructureUtils
.getOrCreate(context, initializerType);
configs.put(type, initializer);
} else {
}
else {
context.registerBean(type);
}
} catch (ArrayStoreException e) {
}
catch (ArrayStoreException e) {
// ignore
}
}
} else if (imported.getResources() != null) {
}
else if (!shouldIgnoreXml && imported.getResources() != null) {
initializers.add(new XmlInitializer(imported.getResources()));
}
}
if (phase == Phase.USER) {
initializers.addAll(configs.values());
} else {
}
else {
for (Class<?> config : AutoConfigurations
.getClasses(AutoConfigurations.of(configs.keySet().toArray(new Class<?>[0])))) {
initializers.add(configs.get(config));
Expand Down Expand Up @@ -261,7 +272,8 @@ public void importRegistrar(BeanDefinitionRegistry registry, Imported imported)
private AnnotationMetadata getMetaData(Class<?> imported) {
try {
return this.metadataReaderFactory.getMetadataReader(imported.getName()).getAnnotationMetadata();
} catch (IOException e) {
}
catch (IOException e) {
throw new IllegalStateException("Cannot find metadata for " + imported, e);
}
}
Expand Down

0 comments on commit e62f1ce

Please sign in to comment.