private ClassLoader[] loaders() { return configuration.getClassLoaders(); } }
protected void scan() { if (configuration.getUrls() == null || configuration.getUrls().isEmpty()) { if (log != null) log.warn("given scan urls are empty. set urls in the configuration"); return; log.debug("going to scan these urls:\n{}", Joiner.on("\n").join(configuration.getUrls())); ExecutorService executorService = configuration.getExecutorService(); List<Future<?>> futures = Lists.newArrayList(); for (final URL url : configuration.getUrls()) { try { if (executorService != null) {
protected MetadataAdapter getMetadataAdapter() { return configuration.getMetadataAdapter(); }
/** * constructs a Reflections instance and scan according to given {@link org.reflections.Configuration} * <p>it is preferred to use {@link org.reflections.util.ConfigurationBuilder} */ public Reflections(final Configuration configuration) { this.configuration = configuration; store = new Store(configuration); if (configuration.getScanners() != null && !configuration.getScanners().isEmpty()) { //inject to scanners for (Scanner scanner : configuration.getScanners()) { scanner.setConfiguration(configuration); scanner.setStore(store.getOrCreate(scanner.getClass().getSimpleName())); } scan(); if (configuration.shouldExpandSuperTypes()) { expandSuperTypes(); } } }
protected void scan(URL url) { Vfs.Dir dir = Vfs.fromURL(url); try { for (final Vfs.File file : dir.getFiles()) { // scan if inputs filter accepts file relative path or fqn Predicate<String> inputsFilter = configuration.getInputsFilter(); String path = file.getRelativePath(); String fqn = path.replace('/', '.'); if (inputsFilter == null || inputsFilter.apply(path) || inputsFilter.apply(fqn)) { Object classObject = null; for (Scanner scanner : configuration.getScanners()) { try { if (scanner.acceptsInput(path) || scanner.acceptResult(fqn)) { classObject = scanner.scan(file, classObject); } } catch (Exception e) { if (log != null && log.isDebugEnabled()) log.debug("could not scan file " + file.getRelativePath() + " in url " + url.toExternalForm() + " with scanner " + scanner.getClass().getSimpleName(), e); } } } } } finally { dir.close(); } }
/** * serialize to a given directory and filename * <p>* it is preferred to specify a designated directory (for example META-INF/reflections), * so that it could be found later much faster using the load method * <p>see the documentation for the save method on the configured {@link org.reflections.serializers.Serializer} */ public File save(final String filename) { return save(filename, configuration.getSerializer()); }
public Store(Configuration configuration) { storeMap = new HashMap<String, Multimap<String, String>>(); concurrent = configuration.getExecutorService() != null; }
private Map<String, String> getAllDocStrings0(ClassLoader classLoader) { final Configuration configuration = new ConfigurationBuilder() .filterInputsBy(new FilterBuilder().includePackage(path)) .setUrls(ClasspathHelper.forPackage(path, classLoader)) .addClassLoader(classLoader) .setScanners(new ResourcesScanner()); if (configuration.getUrls() == null || configuration.getUrls().isEmpty()) { return Collections.emptyMap(); } final 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); }
/** * constructs a Reflections instance and scan according to given {@link org.reflections.Configuration} * <p>it is preferred to use {@link org.reflections.util.ConfigurationBuilder} */ public Reflections(final Configuration configuration) { this.configuration = configuration; store = new Store(configuration); if (configuration.getScanners() != null && !configuration.getScanners().isEmpty()) { //inject to scanners for (Scanner scanner : configuration.getScanners()) { scanner.setConfiguration(configuration); scanner.setStore(store.getOrCreate(scanner.getClass().getSimpleName())); } scan(); } }
protected void scan(URL url) { Vfs.Dir dir = Vfs.fromURL(url); try { for (final Vfs.File file : dir.getFiles()) { // scan if inputs filter accepts file relative path or fqn Predicate<String> inputsFilter = configuration.getInputsFilter(); String path = file.getRelativePath(); String fqn = path.replace('/', '.'); if (inputsFilter == null || inputsFilter.apply(path) || inputsFilter.apply(fqn)) { Object classObject = null; for (Scanner scanner : configuration.getScanners()) { try { if (scanner.acceptsInput(path) || scanner.acceptsInput(fqn)) { classObject = scanner.scan(file, classObject); } } catch (Exception e) { if (log != null) { // SLF4J will filter out Throwables from the format string arguments. log.debug("could not scan file {} in url {} with scanner {}", file.getRelativePath(), url.toExternalForm(), scanner.getClass().getSimpleName(), e); } } } } } } finally { dir.close(); } }
/** * constructs a Reflections instance and scan according to given {@link org.reflections.Configuration} * <p>it is preferred to use {@link org.reflections.util.ConfigurationBuilder} */ public Reflections(final Configuration configuration) { this.configuration = configuration; store = new Store(configuration); if (configuration.getScanners() != null && !configuration.getScanners().isEmpty()) { //inject to scanners for (Scanner scanner : configuration.getScanners()) { scanner.setConfiguration(configuration); scanner.setStore(store.getOrCreate(index(scanner.getClass()))); } scan(); if (configuration.shouldExpandSuperTypes()) { expandSuperTypes(); } } }
/** * serialize to a given directory and filename * <p>* it is preferred to specify a designated directory (for example META-INF/reflections), * so that it could be found later much faster using the load method * <p>see the documentation for the save method on the configured {@link org.reflections.serializers.Serializer} */ public File save(final String filename) { return save(filename, configuration.getSerializer()); }
public Store(Configuration configuration) { storeMap = new HashMap<String, Multimap<String, String>>(); concurrent = configuration.getExecutorService() != null; }
/** * Builds a {@link Reflections} instance that will scan for classes in, and * load them from, the given class loader. * * @param classLoader The class loader to scan and load from. * @return A new {@link Reflections} instance. */ static Reflections createReflections(ClassLoader classLoader, String packagePrefix) { // We set up reflections to use the classLoader for loading classes // and also to use the classLoader to determine the list of URLs: ConfigurationBuilder configurationBuilder = new ConfigurationBuilder().addClassLoader(classLoader); if (StringUtils.isNotBlank(packagePrefix)) { configurationBuilder.addUrls(ClasspathHelper.forPackage(packagePrefix, classLoader)); } else { configurationBuilder.addUrls(ClasspathHelper.forClassLoader(classLoader)); } Reflections reflections = new Reflections(configurationBuilder); log.info("Reflections URLs: {}", reflections.getConfiguration().getUrls()); if (Main.configuration.classesReloadable && reflections.getConfiguration().getUrls().size() == 0 && StringUtils.isNotEmpty(Main.configuration.packagePrefix)) { log.info("It looks like no reloadable classes were found. Is '{}' the correct package prefix for your app?", Main.configuration.packagePrefix); } return reflections; } }
protected void scan() { if (configuration.getUrls() == null || configuration.getUrls().isEmpty()) { if (log != null) log.warn("given scan urls are empty. set urls in the configuration"); return; log.debug("going to scan these urls:\n" + Joiner.on("\n").join(configuration.getUrls())); ExecutorService executorService = configuration.getExecutorService(); List<Future<?>> futures = Lists.newArrayList(); for (final URL url : configuration.getUrls()) { try { if (executorService != null) {
private ClassLoader[] loaders() { return configuration.getClassLoaders(); } }
protected MetadataAdapter getMetadataAdapter() { return configuration.getMetadataAdapter(); }
protected void scan(URL url) { Vfs.Dir dir = Vfs.fromURL(url); try { for (final Vfs.File file : dir.getFiles()) { // scan if inputs filter accepts file relative path or fqn Predicate<String> inputsFilter = configuration.getInputsFilter(); String path = file.getRelativePath(); String fqn = path.replace('/', '.'); if (inputsFilter == null || inputsFilter.apply(path) || inputsFilter.apply(fqn)) { Object classObject = null; for (Scanner scanner : configuration.getScanners()) { try { if (scanner.acceptsInput(path) || scanner.acceptResult(fqn)) { classObject = scanner.scan(file, classObject); } } catch (Exception e) { if (log != null && log.isDebugEnabled()) log.debug("could not scan file " + file.getRelativePath() + " in url " + url.toExternalForm() + " with scanner " + scanner.getClass().getSimpleName(), e); } } } } } finally { dir.close(); } }
public Reflections(final Configuration configuration) { this.configuration = configuration; store = new Store(configuration); if (configuration.getScanners() != null && ! configuration.getScanners().isEmpty()) { //inject to scanners for (Scanner scanner : configuration.getScanners()) { scanner.setConfiguration(configuration); scanner.setStore(store.getOrCreate(scanner.getClass().getSimpleName())); } scan(); if (configuration.shouldExpandSuperTypes()) { expandSuperTypes(); } } }
/** merges saved Reflections resources from the given input stream, using the serializer configured in this instance's Configuration * <br> useful if you know the serialized resource location and prefer not to look it up the classpath * */ public Reflections collect(final InputStream inputStream) { try { merge(configuration.getSerializer().read(inputStream)); if (log != null) log.info("Reflections collected metadata from input stream using serializer " + configuration.getSerializer().getClass().getName()); } catch (Exception ex) { throw new ReflectionsException("could not merge input stream", ex); } return this; }