Exemplo n.º 1
0
  /**
   * 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();
    }
  }
Exemplo n.º 2
0
  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();
    }
  }