use of org.springframework.core.io.ResourceLoader in project spring-boot by spring-projects.
the class ConfigDataEnvironmentPostProcessorTests method postProcessEnvironmentWhenCustomLoaderUsesSpecifiedLoaderInstance.
@Test
void postProcessEnvironmentWhenCustomLoaderUsesSpecifiedLoaderInstance() {
ResourceLoader resourceLoader = mock(ResourceLoader.class);
this.application.setResourceLoader(resourceLoader);
willReturn(this.configDataEnvironment).given(this.postProcessor).getConfigDataEnvironment(any(), any(), any());
this.postProcessor.postProcessEnvironment(this.environment, this.application);
then(this.postProcessor).should().getConfigDataEnvironment(any(), this.resourceLoaderCaptor.capture(), any());
then(this.configDataEnvironment).should().processAndApply();
assertThat(this.resourceLoaderCaptor.getValue()).isSameAs(resourceLoader);
}
use of org.springframework.core.io.ResourceLoader in project spring-framework by spring-projects.
the class TestPropertySourceUtilsTests method addPropertiesFilesToEnvironmentWithSinglePropertyFromVirtualFile.
@Test
void addPropertiesFilesToEnvironmentWithSinglePropertyFromVirtualFile() {
ConfigurableEnvironment environment = new MockEnvironment();
MutablePropertySources propertySources = environment.getPropertySources();
propertySources.remove(MockPropertySource.MOCK_PROPERTIES_PROPERTY_SOURCE_NAME);
assertThat(propertySources.size()).isEqualTo(0);
String pair = "key = value";
ByteArrayResource resource = new ByteArrayResource(pair.getBytes(), "from inlined property: " + pair);
ResourceLoader resourceLoader = mock(ResourceLoader.class);
given(resourceLoader.getResource(anyString())).willReturn(resource);
addPropertiesFilesToEnvironment(environment, resourceLoader, FOO_LOCATIONS);
assertThat(propertySources.size()).isEqualTo(1);
assertThat(environment.getProperty("key")).isEqualTo("value");
}
use of org.springframework.core.io.ResourceLoader in project engine by craftercms.
the class SiteContextFactory method createContext.
public SiteContext createContext(String siteName) {
Map<String, String> macroValues = new HashMap<>();
macroValues.put(siteNameMacroName, siteName);
if (publishingTargetResolver instanceof SiteAwarePublishingTargetResolver) {
String target = ((SiteAwarePublishingTargetResolver) publishingTargetResolver).getPublishingTarget(siteName);
macroValues.put(publishingTargetMacroName, target);
}
String resolvedRootFolderPath = macroResolver.resolveMacros(rootFolderPath, macroValues);
Context context = storeService.getContext(UUID.randomUUID().toString(), storeType, resolvedRootFolderPath, mergingOn, cacheOn, maxAllowedItemsInCache, ignoreHiddenFiles);
try {
SiteContext siteContext = new SiteContext();
siteContext.setInitTimeout(initTimeout);
siteContext.setStoreService(storeService);
siteContext.setCacheTemplate(cacheTemplate);
siteContext.setSiteName(siteName);
siteContext.setContext(context);
siteContext.setStaticAssetsPath(staticAssetsPath);
siteContext.setTemplatesPath(templatesPath);
siteContext.setInitScriptPath(initScriptPath);
siteContext.setFreeMarkerConfig(freeMarkerConfigFactory.getObject());
siteContext.setUrlTransformationEngine(urlTransformationEngine);
siteContext.setRestScriptsPath(restScriptsPath);
siteContext.setControllerScriptsPath(controllerScriptsPath);
siteContext.setGraphQLFactory(graphQLFactory);
siteContext.setShutdownTimeout(shutdownTimeout);
if (disableVariableRestrictions) {
siteContext.setServletContext(servletContext);
}
if (cacheWarmUpEnabled) {
siteContext.setCacheWarmer(cacheWarmer);
}
String[] resolvedConfigPaths = new String[configPaths.length];
for (int i = 0; i < configPaths.length; i++) {
resolvedConfigPaths[i] = macroResolver.resolveMacros(configPaths[i], macroValues);
}
String[] resolvedAppContextPaths = new String[applicationContextPaths.length];
for (int i = 0; i < applicationContextPaths.length; i++) {
resolvedAppContextPaths[i] = macroResolver.resolveMacros(applicationContextPaths[i], macroValues);
}
String[] resolvedUrlRewriteConfPaths = new String[urlRewriteConfPaths.length];
for (int i = 0; i < urlRewriteConfPaths.length; i++) {
resolvedUrlRewriteConfPaths[i] = macroResolver.resolveMacros(urlRewriteConfPaths[i], macroValues);
}
List<String> resolvedProxyConfPaths = Stream.of(proxyConfigPaths).map(path -> macroResolver.resolveMacros(path, macroValues)).collect(toList());
ResourceLoader resourceLoader = new ContentStoreResourceLoader(siteContext);
HierarchicalConfiguration<?> config = getConfig(siteContext, resolvedConfigPaths, resourceLoader);
configureScriptSandbox(siteContext, resourceLoader);
URLClassLoader classLoader = getClassLoader(siteContext);
ScriptFactory scriptFactory = getScriptFactory(siteContext, classLoader);
ConfigurableApplicationContext appContext = getApplicationContext(siteContext, classLoader, config, resolvedAppContextPaths, resourceLoader);
UrlRewriter urlRewriter = getUrlRewriter(siteContext, resolvedUrlRewriteConfPaths, resourceLoader);
HierarchicalConfiguration proxyConfig = getProxyConfig(siteContext, resolvedProxyConfPaths, resourceLoader);
siteContext.setScriptFactory(scriptFactory);
siteContext.setConfig(config);
siteContext.setGlobalApplicationContext(globalApplicationContext);
siteContext.setApplicationContext(appContext);
siteContext.setClassLoader(classLoader);
siteContext.setUrlRewriter(urlRewriter);
siteContext.setProxyConfig(proxyConfig);
if (config != null) {
siteContext.setAllowedTemplatePaths(config.getStringArray(CONFIG_KEY_ALLOWED_TEMPLATE_PATHS));
}
Scheduler scheduler = scheduleJobs(siteContext);
siteContext.setScheduler(scheduler);
return siteContext;
} catch (Exception e) {
logger.error("Error creating context for site '" + siteName + "'", e);
// Destroy context if the site context creation failed
storeService.destroyContext(context);
throw e;
}
}
use of org.springframework.core.io.ResourceLoader in project cas by apereo.
the class DefaultCasConfigurationPropertiesSourceLocator method loadEmbeddedYamlOverriddenProperties.
private PropertySource<?> loadEmbeddedYamlOverriddenProperties(final ResourceLoader resourceLoader, final Environment environment) {
val profiles = ConfigurationPropertiesLoaderFactory.getApplicationProfiles(environment);
val yamlFiles = profiles.stream().map(profile -> String.format("classpath:/application-%s.yml", profile)).sorted().map(resourceLoader::getResource).collect(Collectors.toList());
yamlFiles.add(resourceLoader.getResource("classpath:/application.yml"));
LOGGER.debug("Loading embedded YAML configuration files [{}]", yamlFiles);
val composite = new CompositePropertySource("embeddedYamlOverriddenCompositeProperties");
yamlFiles.forEach(resource -> {
LOGGER.trace("Loading YAML properties from [{}]", resource);
val source = configurationPropertiesLoaderFactory.getLoader(resource, String.format("embeddedYamlOverriddenProperties-%s", resource.getFilename())).load();
composite.addPropertySource(source);
});
return composite;
}
use of org.springframework.core.io.ResourceLoader in project grails-core by grails.
the class DefaultResourceLocator method setSearchLocation.
public void setSearchLocation(String searchLocation) {
ResourceLoader resourceLoader = getDefaultResourceLoader();
patchMatchingResolver = new CachingPathMatchingResourcePatternResolver(resourceLoader);
initializeForSearchLocation(searchLocation);
}
Aggregations