use of org.mule.runtime.config.internal.dsl.model.ConfigurationDependencyResolver in project mule by mulesoft.
the class LazyMuleArtifactContext method createComponents.
private List<String> createComponents(Optional<Predicate> predicateOptional, Optional<Location> locationOptional, Optional<ComponentModelInitializerAdapter> parentComponentModelInitializerAdapter) {
checkState(predicateOptional.isPresent() != locationOptional.isPresent(), "predicate or location has to be passed");
List<String> alreadyCreatedApplicationComponents = new ArrayList<>();
alreadyCreatedApplicationComponents.addAll(trackingPostProcessor.getBeansTracked());
reverse(alreadyCreatedApplicationComponents);
trackingPostProcessor.startTracking();
Reference<List<String>> createdComponents = new Reference<>();
withContextClassLoader(muleContext.getExecutionClassLoader(), () -> {
applicationModel.executeOnEveryMuleComponentTree(componentModel -> componentModel.setEnabled(false));
ConfigurationDependencyResolver dependencyResolver = new ConfigurationDependencyResolver(this.applicationModel, componentBuildingDefinitionRegistry);
MinimalApplicationModelGenerator minimalApplicationModelGenerator = new MinimalApplicationModelGenerator(dependencyResolver);
Reference<ApplicationModel> minimalApplicationModel = new Reference<>();
predicateOptional.ifPresent(predicate -> minimalApplicationModel.set(minimalApplicationModelGenerator.getMinimalModel(predicate)));
locationOptional.ifPresent(location -> minimalApplicationModel.set(minimalApplicationModelGenerator.getMinimalModel(location)));
// First unregister any already initialized/started component
unregisterBeans(alreadyCreatedApplicationComponents);
objectProviders.clear();
if (parentComponentModelInitializerAdapter.isPresent()) {
List<String> missingComponentNames = dependencyResolver.getMissingDependencies().stream().filter(dependencyNode -> dependencyNode.isTopLevel()).map(dependencyNode -> dependencyNode.getComponentName()).collect(toList());
parentComponentModelInitializerAdapter.get().initializeComponents(componentModel -> {
if (componentModel.getNameAttribute() != null) {
return missingComponentNames.contains(componentModel.getNameAttribute());
}
return false;
});
} else {
dependencyResolver.getMissingDependencies().stream().forEach(globalElementName -> {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Ignoring dependency %s because it does not exists", globalElementName));
}
});
}
List<String> applicationComponents = createApplicationComponents((DefaultListableBeanFactory) this.getBeanFactory(), minimalApplicationModel.get(), false);
createdComponents.set(applicationComponents);
super.prepareObjectProviders();
// This is required to force the execution of postProcessAfterInitialization() for each created component
applicationComponents.forEach(component -> getRegistry().lookupByName(component).get());
});
trackingPostProcessor.stopTracking();
List<String> createdComponentNames = createdComponents.get();
trackingPostProcessor.intersection(createdComponentNames);
return createdComponentNames;
}
Aggregations