本文整理匯總了Java中org.reflections.scanners.ResourcesScanner類的典型用法代碼示例。如果您正苦於以下問題:Java ResourcesScanner類的具體用法?Java ResourcesScanner怎麽用?Java ResourcesScanner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ResourcesScanner類屬於org.reflections.scanners包,在下文中一共展示了ResourcesScanner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createCompositeMapping
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
public JSONObject createCompositeMapping(String compositeName) throws IOException {
ResourcesScanner resourceScanner = new ResourcesScanner();
Reflections reflections = new Reflections(resourceScanner);
Set<String> resources = reflections.getResources(Pattern.compile(".*\\.mapping\\.json"));
JSONObject properties = new JSONObject();
for(String resource : resources) {
InputStream is = getClass().getClassLoader().getResourceAsStream(resource);
if(is == null) {
throw new RuntimeException("Unable to read resource " + resource);
}
String json = IOUtils.toString(is, StandardCharsets.UTF_8);
JSONObject part = new JSONObject(json);
for(String key : part.keySet()) {
properties.put(key, part.get(key));
}
}
return new JSONObject().put("mappings", new JSONObject().put(compositeName, new JSONObject().put("properties", properties)));
}
示例2: doPackage
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
private void doPackage(FilterBuilder fb, List<RuleFactory> resultL) throws Exception {
List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))
.filterInputsBy(fb));
Set<Class<? extends RuleFactory>> subTypes = reflections.getSubTypesOf(RuleFactory.class);
for(Class<? extends RuleFactory> clazz : subTypes) {
RuleFactory factory = clazz.newInstance();
resultL.add(factory);
}
}
示例3: testReflections
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
@Test
public void testReflections() throws Exception {
List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
String packageName = "org.dnal.core.world";
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))
.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(packageName))));
Set<String> types = reflections.getAllTypes();
for(String s : types) {
System.out.println(s);
}
Set<Class<? extends RuleFactory>> subTypes = reflections.getSubTypesOf(RuleFactory.class);
for(Class<? extends RuleFactory> clazz : subTypes) {
System.out.println("sub: " + clazz.getName());
RuleFactory factory = clazz.newInstance();
RuleDeclaration decl = factory.getDeclaration();
System.out.println("d: " + decl.ruleName);
}
}
示例4: getResourceDirectoryContent
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
private ArrayList<String> getResourceDirectoryContent(String resourcePattern) {
ArrayList<String> tempFilesContentList = new ArrayList<>();
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage("io.logz"))
.setScanners(new ResourcesScanner())
.filterInputsBy(new FilterBuilder().include(resourcePattern)));
Set<String> properties = reflections.getResources(Pattern.compile(".*\\.json"));
properties.forEach((resourceName) -> {
URL resourceUrl = Resources.getResource(resourceName);
try {
tempFilesContentList.add(Resources.toString(resourceUrl, Charset.forName("utf-8")).replace("\n", ""));
} catch (IOException e) {
logger.info("Could not read file {}", resourceUrl.toString());
}
});
if (tempFilesContentList.isEmpty())
throw new RuntimeException("Did not find any files under "+ resourcePattern +"!");
return tempFilesContentList;
}
示例5: findAllPackagesStartingWith
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
/**
* Finds all package names starting with prefix
* @param prefix The package in which to start searching
* @param statik True to statically return components names
* @return a set of component name
*/
public List<String> findAllPackagesStartingWith(final String prefix, final boolean statik) {
final List<ClassLoader> classLoadersList = new ArrayList<>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false), new ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[classLoadersList.size()])))
.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(prefix))));
Set<Class<?>> classes = reflections.getSubTypesOf(Object.class);
final Set<String> packages = new HashSet<>();
for (final Class classInstance : classes) {
String packageName = classInstance.getPackage().getName();
packageName = packageName.split("\\.")[packageName.split("\\.").length-1].toLowerCase();
packages.add(packageName);
}
return new ArrayList<>(packages);
}
示例6: getPackageTypes
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
private static Collection<? extends Class<?>> getPackageTypes(String packageToPase, Collection<URL> urls) {
Set<Class<?>> classes = new HashSet<>();
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false /* exclude Object.class */), new ResourcesScanner(), new TypeElementsScanner())
.setUrls(urls)
.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(packageToPase)).exclude("java.*")));
Set<String> types;
types = reflections.getStore().get("TypeElementsScanner").keySet();
for (String type: types) {
Class<?> aClass = TypesHelper.loadClass(type, CLASS_LOADER);
boolean wantedElement = StringUtils.startsWith(type, packageToPase);
if (null != aClass && wantedElement) {
logger.log(Level.INFO, "looking up for type: " + type);
classes.add(aClass);
}
}
return classes;
}
示例7: scanForCommands
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
public static void scanForCommands() {
//Populate all the cmds
System.out.println("[EvenWurse] Reloading cmd list...");
ArrayList<ClassLoader> classLoadersList = new ArrayList<>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
Reflections reflections = new Reflections(
new ConfigurationBuilder().setScanners(new SubTypesScanner(), new ResourcesScanner()).setUrls(
ClasspathHelper
.forClassLoader(classLoadersList.toArray(new ClassLoader[classLoadersList.size()]))));
Set<Class<? extends Cmd>> classes = reflections.getSubTypesOf(Cmd.class);
KNOWN_CMDS = new Class[classes.size()];
for (int i = 0; i < classes.size(); i++) {
KNOWN_CMDS[i] = (Class<? extends Cmd>) classes.toArray()[i];
System.out.println("[EvenWurse] Found cmd: " + KNOWN_CMDS[i].getSimpleName() + "!");
}
System.out.println("[EvenWurse] Found " + KNOWN_CMDS.length + " cmds!");
}
示例8: scanForMods
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
public static void scanForMods() {
//Populate all the mods
System.out.println("[EvenWurse] Reloading mod list...");
ArrayList<ClassLoader> classLoadersList = new ArrayList<>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
Reflections reflections = new Reflections(
new ConfigurationBuilder().setScanners(new SubTypesScanner(), new ResourcesScanner()).setUrls(
ClasspathHelper
.forClassLoader(classLoadersList.toArray(new ClassLoader[classLoadersList.size()]))));
Set<Class<? extends Mod>> classes = reflections.getSubTypesOf(Mod.class);
KNOWN_MODS = new Class[classes.size()];
for (int i = 0; i < classes.size(); i++) {
KNOWN_MODS[i] = (Class<? extends Mod>) classes.toArray()[i];
System.out.println("[EvenWurse] Found mod: " + KNOWN_MODS[i].getSimpleName() + "!");
}
System.out.println("[EvenWurse] Found " + KNOWN_MODS.length + " mods!");
}
示例9: scan
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
public static Iterable<URL> scan(String pattern) {
// lookup from classpath
ConfigurationBuilder rcp = new ConfigurationBuilder()//
.setUrls(ClasspathHelper.forClassLoader())//
.setScanners(new ResourcesScanner());
{
String path = pathChar.replaceFrom(pattern, '.');
rcp.setInputsFilter(in -> (false == in.startsWith("java.")) && Wildcard.match(in, path));
}
Set<String> scans = new Reflections(rcp).getResources(Predicates.alwaysTrue());
// transforms strings to urls
return Iterables.transform(scans, res -> getURL(res));
}
示例10: registerScriptEngineFactories
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private void registerScriptEngineFactories() {
List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))
.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("com.jsen"))));
Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(ScriptEngineFactory.class);
for (Class<?> clazz : annotated) {
if (AbstractScriptEngineFactory.class.isAssignableFrom(clazz)) {
registerMimeContentFactory((Class<AbstractScriptEngineFactory>)clazz);
}
}
}
示例11: getAllDocStrings0
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
private Map<String, String> getAllDocStrings0(ClassLoader classLoader) {
final Configuration configuration = new ConfigurationBuilder()
.filterInputsBy(new FilterBuilder().includePackage(path))
.setUrls(ClasspathHelper.forPackage(path))
.addClassLoader(classLoader)
.setScanners(new ResourcesScanner());
if (configuration.getUrls() == null || configuration.getUrls().isEmpty()) {
return Collections.emptyMap();
}
Map<String, byte[]> files = new Reflections(configuration)
.getResources(this::acceptFile).stream()
.map(f -> {
try {
URL url = classLoader.getResource(f);
if (url == null) {
throw new IllegalStateException("not found: " + f);
}
return new SimpleImmutableEntry<>(f, Resources.toByteArray(url));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
})
.collect(toImmutableMap(Entry::getKey, Entry::getValue));
return getDocStringsFromFiles(files);
}
示例12: urls
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
public static List<URL> urls( String atPackage, String ext ) {
final ExecutorService executorService = Executors.newFixedThreadPool(
Runtime.getRuntime().availableProcessors(),
new ThreadFactoryBuilder().setNameFormat( "reflections-%d" ).build()
);
try {
final ConfigurationBuilder configuration = new ConfigurationBuilder()
.setUrls( ClasspathHelper.forPackage( atPackage ) )
.setScanners( new ResourcesScanner() )
.filterInputsBy( new FilterBuilder().includePackage( atPackage ) )
.setExecutorService( executorService );
final Reflections reflections = new Reflections( configuration );
final Set<String> resources = reflections.getResources( in -> in.endsWith( "." + ext ) );
return new ArrayList<>( Sets.map( resources, r -> Thread.currentThread().getContextClassLoader().getResource( r ) ) );
} finally {
executorService.shutdown();
}
}
示例13: Reflection
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
/**
* Creates reflection for package and base class.
* @param pack
* @param clazz
*/
public Reflection(String pack, Class clazz) {
if (clazz.equals(Object.class)) {
// @see http://stackoverflow.com/a/9571146
List<ClassLoader> classLoadersList = new LinkedList();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
this.reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false), new ResourcesScanner())
.addUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))
.addUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[1])))
.addUrls(ClasspathHelper.forJavaClassPath())
.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(pack))));
} else {
this.reflections = new Reflections(clazz);
}
}
示例14: initialize
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
public static void initialize() {
// Scan for json configuration files on the classpath
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setScanners(new ResourcesScanner());
builder.setUrls(ClasspathHelper.forClassLoader(
ClasspathHelper.contextClassLoader(),
ClasspathHelper.staticClassLoader()));
reflections = new Reflections(builder);
json = new Json();
for (String path : reflections.getResources(Pattern.compile(".*\\.json"))) {
if (!path.startsWith("items") && !path.startsWith("tiles") && !path.startsWith("walls"))
continue;
FileHandle file = Gdx.files.internal(path);
Type type = json.fromJson(null, file);
registerType(type);
}
airItem = getItem("airItem");
airTile = getTile("airTile");
airWall = getWall("airWall");
}
示例15: testAll
import org.reflections.scanners.ResourcesScanner; //導入依賴的package包/類
@Test
public void testAll() throws IOException {
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage("net.bramp.dissector.zip"))
.setScanners(new ResourcesScanner())
);
for (String path : reflections.getResources(Pattern.compile(".*\\.zip"))) {
System.out.print(path);
ExtendedRandomAccessFile in = open( path );
try {
new ZipDissector().read(in); // Read but don't do anything with it
System.out.println(" [OK]");
} catch (Exception e) {
System.out.println(" [BAD]");
}
}
}