use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-boot-admin by codecentric.
the class ResourcePatternResolvingResourceResolverTest method test_resolveResource.
@Test
public void test_resolveResource() {
ResourceResolver resolver = new ResourcePatternResolvingResourceResolver(new PathMatchingResourcePatternResolver(), "classpath:/t*Resource.txt");
resolver.resolveResource(null, null, null, new ResourceResolverChain() {
@Override
public Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations) {
assertThat(locations.size(), is(1));
assertThat(locations.get(0).getFilename(), is("testResource.txt"));
return null;
}
@Override
public String resolveUrlPath(String resourcePath, List<? extends Resource> locations) {
return null;
}
});
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-boot by spring-projects.
the class ResourceMatcher method findInFolder.
private List<MatchedResource> findInFolder(File folder) throws IOException {
List<MatchedResource> matchedResources = new ArrayList<>();
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(new FolderResourceLoader(folder));
for (String include : this.includes) {
for (Resource candidate : resolver.getResources(include)) {
File file = candidate.getFile();
if (file.isFile()) {
MatchedResource matchedResource = new MatchedResource(folder, file);
if (!isExcluded(matchedResource)) {
matchedResources.add(matchedResource);
}
}
}
}
return matchedResources;
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project littlefisher-system by littlefishercoder.
the class PackageUtil method scanTypePackage.
/**
* 扫描获取指定包路径所有类
*
* @param typePackage 扫描类包路径
* @return Set<Class>
*/
public static Set<Class> scanTypePackage(String typePackage) {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
String pkg = ClassUtils.convertClassNameToResourcePath(typePackage) + ".class";
/*
* 将加载多个绝对匹配的所有Resource
* 将首先通过ClassLoader.getResource("META-INF")加载非模式路径部分,然后进行遍历模式匹配,排除重复包路径
*/
try {
Set<Class> set = Sets.newHashSet();
Resource[] resources = resolver.getResources(pkg);
if (ArrayUtils.isNotEmpty(resources)) {
MetadataReader metadataReader;
for (Resource resource : resources) {
if (resource.isReadable()) {
metadataReader = metadataReaderFactory.getMetadataReader(resource);
set.add(Class.forName(metadataReader.getClassMetadata().getClassName()));
}
}
}
return set;
} catch (Exception e) {
throw new BaseAppException("CORE-000007", null, e);
}
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project midpoint by Evolveum.
the class ActivitiEngine method autoDeploy.
private void autoDeploy() {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
String[] autoDeploymentFrom = wfConfiguration.getAutoDeploymentFrom();
for (String adf : autoDeploymentFrom) {
Resource[] resources;
try {
resources = resolver.getResources(adf);
} catch (IOException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get resources to be automatically deployed from " + adf, e);
continue;
}
LOGGER.info("Auto deployment from " + adf + " yields " + resources.length + " resource(s)");
for (Resource resource : resources) {
try {
autoDeployResource(resource);
} catch (IOException | XPathExpressionException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't deploy the resource " + resource, e);
}
}
}
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project leopard by tanhaichao.
the class ConfigClasspathImpl method find.
@Override
public InputStream find() throws IOException {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources;
try {
resources = resolver.getResources("classpath*:/dev/dns.properties");
} catch (IOException e) {
e.printStackTrace();
throw new FileNotFoundException("classpath*:/dev/dns.properties");
}
for (Resource resource : resources) {
try {
InputStream is = resource.getInputStream();
return is;
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
}
throw new FileNotFoundException("classpath*:/dev/dns.properties");
}
Aggregations