use of org.springframework.core.io.support.ResourcePatternResolver in project head by mifos.
the class MifosViewerServletContextListener method copyFromClassPathToDirectory.
private void copyFromClassPathToDirectory(String directoryToScan, File rootDirectory) throws IOException {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources(LOCATION_PATTERN);
LOGGER.info("Found " + resources.length + " Resources on " + LOCATION_PATTERN);
for (Resource resource : resources) {
if (resource.exists() & resource.isReadable() && resource.contentLength() > 0) {
URL url = resource.getURL();
String urlString = url.toExternalForm();
String targetName = urlString.substring(urlString.indexOf(directoryToScan));
File destination = new File(rootDirectory, targetName);
FileUtils.copyURLToFile(url, destination);
LOGGER.info("Copied " + url + " to " + destination.getAbsolutePath());
} else {
LOGGER.debug("Did not copy, seems to be directory: " + resource.getDescription());
}
}
}
use of org.springframework.core.io.support.ResourcePatternResolver in project spring-boot by spring-projects.
the class SpringPackageScanClassResolver method scan.
private Resource[] scan(ClassLoader loader, String packageName) throws IOException {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(loader);
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(packageName) + "/**/*.class";
Resource[] resources = resolver.getResources(pattern);
return resources;
}
use of org.springframework.core.io.support.ResourcePatternResolver in project jaffa-framework by jaffa-projects.
the class ConfigApiHelper method registerResources.
/**
* Register configuration files in IManager implementationss, based on the source of the method call
* @param file The configuration file to be registered or unregistered
* @return Success or failure of the operation
*/
public static boolean registerResources(File file, FileContentsHelper fileContents) {
boolean isSuccess = true;
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
for (IManager manager : ManagerRepositoryService.getInstance().getManagerMap().values()) {
Resource resource = getMetaInfResource(file, resolver, manager);
try {
if (resource.getFile().exists()) {
if (manager instanceof RoleManager) {
PolicyManager.clearCache();
}
manager.registerResource(resource, fileContents.getContextSalience(), fileContents.getVariationSalience());
ManagerRepositoryService.getInstance().add(manager.getClass().getSimpleName(), manager);
log.debug(resource.getFilename() + " was successfully registered to " + manager);
}
} catch (Exception e) {
isSuccess = false;
log.error("The resource " + resource.getFilename() + " failed to register", e);
}
}
return isSuccess;
}
use of org.springframework.core.io.support.ResourcePatternResolver in project commons-dao by reportportal.
the class CriteriaMapFactory method findNeededTypes.
/**
* Find Classes into specified package
*/
private List<Class<?>> findNeededTypes(String basePackage) {
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
List<Class<?>> candidates = new LinkedList<>();
try {
String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolveBasePackage(basePackage) + "/" + "**/*.class";
Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
if (isCandidate(metadataReader)) {
candidates.add(Class.forName(metadataReader.getClassMetadata().getClassName()));
}
}
}
return candidates;
} catch (Exception e) {
throw new IllegalArgumentException("Unable to scan base package '" + basePackage + "'", e);
}
}
use of org.springframework.core.io.support.ResourcePatternResolver in project molgenis by molgenis.
the class SchemaLoader method getSchema.
private Resource getSchema(String schemaName) throws IOException {
if (schemaName.contains("/")) {
schemaName = schemaName.substring(schemaName.lastIndexOf('/'));
}
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
String searchPattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "/**/" + schemaName;
Resource[] resources = resourcePatternResolver.getResources(searchPattern);
if ((resources == null) || (resources.length == 0)) {
throw new RuntimeException("Could not find schema [" + schemaName + "]");
}
return resources[0];
}
Aggregations