use of org.reflections.scanners.ResourcesScanner in project deeplearning4j by deeplearning4j.
the class DefaultI18N method loadLanguageResources.
private synchronized void loadLanguageResources(String languageCode) {
if (loadedLanguages.contains(languageCode))
return;
//Scan classpath for resources in the /dl4j_i18n/ directory...
URL url = this.getClass().getResource("/" + DEFAULT_I8N_RESOURCES_DIR + "/");
Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new ResourcesScanner()).setUrls(url));
String pattern = ".*" + languageCode;
Set<String> resources = reflections.getResources(Pattern.compile(pattern));
Map<String, String> messages = new HashMap<>();
for (String s : resources) {
if (!s.endsWith(languageCode))
continue;
log.trace("Attempting to parse file: {}", s);
parseFile(s, messages);
}
messagesByLanguage.put(languageCode, messages);
loadedLanguages.add(languageCode);
}
use of org.reflections.scanners.ResourcesScanner in project swagger-core by swagger-api.
the class BeanConfig method classes.
@Override
public Set<Class<?>> classes() {
ConfigurationBuilder config = new ConfigurationBuilder();
Set<String> acceptablePackages = new HashSet<String>();
boolean allowAllPackages = false;
if (resourcePackage != null && !"".equals(resourcePackage)) {
String[] parts = resourcePackage.split(",");
for (String pkg : parts) {
if (!"".equals(pkg)) {
acceptablePackages.add(pkg);
config.addUrls(ClasspathHelper.forPackage(pkg));
}
}
} else {
allowAllPackages = true;
}
config.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new SubTypesScanner());
final Reflections reflections = new Reflections(config);
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(javax.ws.rs.Path.class);
Set<Class<?>> typesAnnotatedWith = reflections.getTypesAnnotatedWith(SwaggerDefinition.class);
classes.addAll(typesAnnotatedWith);
/*
* Find concrete types annotated with @Api, but with a supertype annotated with @Path.
* This would handle split resources where the interface has jax-rs annotations
* and the implementing class has Swagger annotations
*/
for (Class<?> cls : reflections.getTypesAnnotatedWith(Api.class)) {
for (Class<?> intfc : TypeToken.of(cls).getTypes().interfaces().rawTypes()) {
Annotation ann = intfc.getAnnotation(javax.ws.rs.Path.class);
if (ann != null) {
classes.add(cls);
break;
}
}
}
Set<Class<?>> output = new HashSet<Class<?>>();
for (Class<?> cls : classes) {
if (allowAllPackages) {
output.add(cls);
} else {
for (String pkg : acceptablePackages) {
if (cls.getPackage().getName().startsWith(pkg)) {
output.add(cls);
}
}
}
}
return output;
}
use of org.reflections.scanners.ResourcesScanner in project Gaffer by gchq.
the class StreamUtil method openStreams.
public static InputStream[] openStreams(final Class clazz, final String folderPath, final boolean logErrors) {
if (null == folderPath) {
return new InputStream[0];
}
String folderPathChecked = folderPath;
if (!folderPathChecked.endsWith("/")) {
folderPathChecked = folderPathChecked + "/";
}
if (folderPathChecked.startsWith("/")) {
folderPathChecked = folderPathChecked.substring(1);
}
final Set<String> schemaFiles = new Reflections(new ConfigurationBuilder().setScanners(new ResourcesScanner()).setUrls(ClasspathHelper.forClass(clazz))).getResources(Pattern.compile(".*"));
final Iterator<String> itr = schemaFiles.iterator();
while (itr.hasNext()) {
if (!itr.next().startsWith(folderPathChecked)) {
itr.remove();
}
}
int index = 0;
final InputStream[] schemas = new InputStream[schemaFiles.size()];
for (final String schemaFile : schemaFiles) {
schemas[index] = openStream(clazz, schemaFile, logErrors);
index++;
}
return schemas;
}
use of org.reflections.scanners.ResourcesScanner in project swagger-core by swagger-api.
the class ReflectiveJaxrsScanner method getReflections.
protected Reflections getReflections() {
if (reflections == null) {
ConfigurationBuilder config = new ConfigurationBuilder();
acceptablePackages = new HashSet<String>();
if (resourcePackage != "") {
String[] parts = resourcePackage.split(",");
for (String pkg : parts) {
if (!"".equals(pkg)) {
acceptablePackages.add(pkg);
config.addUrls(ClasspathHelper.forPackage(pkg));
}
}
}
config.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new SubTypesScanner());
this.reflections = new Reflections(config);
}
return this.reflections;
}
use of org.reflections.scanners.ResourcesScanner in project sling by apache.
the class OsgiMetadataUtil method initMetadataDocumentCache.
/**
* Reads all SCR metadata XML documents located at OSGI-INF/ and caches them with quick access by implementation class.
* @return Cache map
*/
private static Map<String, Document> initMetadataDocumentCache() {
Map<String, Document> cacheMap = new HashMap<>();
XPath xpath = XPATH_FACTORY.newXPath();
xpath.setNamespaceContext(NAMESPACE_CONTEXT);
XPathExpression xpathExpression;
try {
xpathExpression = xpath.compile("//*[implementation/@class]");
} catch (XPathExpressionException ex) {
throw new RuntimeException("Compiling XPath expression failed.", ex);
}
Reflections reflections = new Reflections(METADATA_PATH, new ResourcesScanner());
Set<String> paths = reflections.getResources(Pattern.compile("^.*\\.xml$"));
for (String path : paths) {
parseMetadataDocuments(cacheMap, path, xpathExpression);
}
return cacheMap;
}
Aggregations