use of io.micronaut.core.io.ResourceLoader in project micronaut-core by micronaut-projects.
the class RequiresCondition method matchesPresenceOfResources.
private boolean matchesPresenceOfResources(ConditionContext context, AnnotationValue<Requires> requirements) {
if (requirements.contains(MEMBER_RESOURCES)) {
final String[] resourcePaths = requirements.stringValues(MEMBER_RESOURCES);
if (ArrayUtils.isNotEmpty(resourcePaths)) {
final BeanContext beanContext = context.getBeanContext();
ResourceResolver resolver;
final List<ResourceLoader> resourceLoaders;
if (beanContext instanceof ApplicationContext) {
ResourceLoader resourceLoader = ((ApplicationContext) beanContext).getEnvironment();
resourceLoaders = Arrays.asList(resourceLoader, FileSystemResourceLoader.defaultLoader());
} else {
resourceLoaders = Arrays.asList(ClassPathResourceLoader.defaultLoader(beanContext.getClassLoader()), FileSystemResourceLoader.defaultLoader());
}
resolver = new ResourceResolver(resourceLoaders);
for (String resourcePath : resourcePaths) {
if (!resolver.getResource(resourcePath).isPresent()) {
context.fail("Resource [" + resourcePath + "] does not exist");
return false;
}
}
}
}
return true;
}
Aggregations