/** get resources relative paths where simple name (key) matches given regular expression * <p>depends on ResourcesScanner configured * <pre>Set<String> xmls = reflections.getResources(".*\\.xml");</pre> */ public Set<String> getResources(final Pattern pattern) { return getResources(new Predicate<String>() { public boolean apply(String input) { return pattern.matcher(input).matches(); } }); }
/** get resources relative paths where simple name (key) matches given regular expression * <p>depends on ResourcesScanner configured * <pre>Set<String> xmls = reflections.getResources(".*\\.xml");</pre> */ public Set<String> getResources(final Pattern pattern) { return getResources(new Predicate<String>() { public boolean apply(String input) { return pattern.matcher(input).matches(); } }); }
/** * Scan the classpath for {@link #classpathRootName} and return all resources under it. * {@inheritDoc} * @see org.apache.gobblin.config.store.deploy.DeployableConfigSource#getDeployableConfigPaths() */ private Set<String> getDeployableConfigPaths() { ConfigurationBuilder cb = new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader()).setScanners(new ResourcesScanner()) .filterInputsBy(new FilterBuilder().include(String.format(".*%s.*", this.classpathRootName))); Reflections reflections = new Reflections(cb); Pattern pattern = Pattern.compile(".*"); return reflections.getResources(pattern); }
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); }
/** get resources relative paths where simple name (key) matches given regular expression * <p>depends on ResourcesScanner configured * <pre>Set<String> xmls = reflections.getResources(".*\\.xml");</pre> */ public Set<String> getResources(final Pattern pattern) { return getResources(new Predicate<String>() { public boolean apply(String input) { return pattern.matcher(input).matches(); } }); }
/** get resources relative paths where simple name (key) matches given regular expression * <p>depends on ResourcesScanner configured * <pre>Set<String> xmls = reflections.getResources(".*\\.xml");</pre> */ public Set<String> getResources(final Pattern pattern) { return getResources(new Predicate<String>() { public boolean apply(String input) { return pattern.matcher(input).matches(); } }); }
/** * Searches for all resources matching the given pattern. * * @param pattern * The pattern to match. * @return All available resources matching the given pattern. */ @SuppressWarnings("unchecked") public Set<String> lookupResources(final String pattern) { return reflections.getResources(Pattern.compile(pattern)); }
public static Set<String> searchResources(String regex) { return reflections.getResources(Pattern.compile(regex)); }
Reflections reflections = new Reflections("my.package"); Set<String> resourceStrings = reflections.getResources(s -> true /*match all resources*/); Set<URL> resources = resourceStrings.stream() .map(s -> getClass().getResource(s)) .collect(Collectors.toSet())
Reflections reflections = new Reflections("com.example.package", new ResourcesScanner()); Set<String> paths = reflections.getResources(Pattern.compile(".*\\.template$")); Map<String, String> templates = new LinkedHashMap<>(); for (String path : paths) { log.info("Found " + path); String templateName = Files.getNameWithoutExtension(path); URL resource = getClass().getClassLoader().getResource(path); String text = Resources.toString(resource, StandardCharsets.UTF_8); templates.put(templateName, text); }
Reflections reflections = new Reflections(null, new ResourcesScanner()); Set<String> resourceList = reflections.getResources(x -> true);
/** * @return A list of the property files containing the build/version info */ public static List<String> listGitPropertiesFiles() { Reflections reflections = new Reflections(new ResourcesScanner()); Set<String> resources = reflections.getResources(Pattern.compile(".*-git.properties")); List<String> out = new ArrayList<>(resources); Collections.sort(out); //Equivalent to sorting by groupID and artifactID return out; }
@Parameters(name = "{1}") public static List<Object[]> params() { List<Object[]> rval = new ArrayList<>(); Reflections refs = new Reflections("org.everit.json.schema.issues", new ResourcesScanner()); Set<String> paths = refs.getResources(Pattern.compile("schema.json")) .stream().map(path -> path.substring(0, path.lastIndexOf('/'))) .collect(Collectors.toSet()); for (String path : paths) { rval.add(new Object[] { path, path.substring(path.lastIndexOf('/') + 1) }); } return rval; }
public static void main(String[] args) { Reflections reflections = new Reflections(new ConfigurationBuilder() .setUrls(ClasspathHelper.forPackage("your.test.more")) .setScanners(new ResourcesScanner())); Set<String> textFiles = reflections.getResources(Pattern.compile(".*\\.txt")); for (String file : textFiles){ System.out.println(file); } }
public static Iterable<Object[]> allScripts() { Set<String> resources = new Reflections(ClasspathHelper.forPackage("pl.symentis.lua4j.tests"), new ResourcesScanner()).getResources(Pattern.compile("(.*)\\.lua")); return () -> resources.stream().map((String resource) -> new Object[] { resource }).iterator(); }
public Collection<Object[]> generateData(String testPackage, String pattern) { Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new ResourcesScanner()) .setUrls(ClasspathHelper.forPackage("")) .filterInputsBy(new FilterBuilder.Include(Pattern.quote(testPackage) + ".*"))); Collection<Object[]> data = new ArrayList<Object[]>(); for (String testResourceName : reflections.getResources(Pattern.compile(pattern))) { data.addAll(parseSingleResource(testResourceName)); } return data; }
/** * Scan the classpath for {@link #classpathRootName} and return all resources under it. * {@inheritDoc} * @see gobblin.config.store.deploy.DeployableConfigSource#getDeployableConfigPaths() */ private Set<String> getDeployableConfigPaths() { ConfigurationBuilder cb = new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader()).setScanners(new ResourcesScanner()) .filterInputsBy(new FilterBuilder().include(String.format(".*%s.*", this.classpathRootName))); Reflections reflections = new Reflections(cb); Pattern pattern = Pattern.compile(".*"); return reflections.getResources(pattern); }
public Collection<TestConfiguration> generateData(String testPackage, String pattern) { Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new ResourcesScanner()) .setUrls(ClasspathHelper.forPackage("")) .filterInputsBy(new FilterBuilder.Include(FilterBuilder.prefix(testPackage)))); Collection<TestConfiguration> data = new ArrayList<TestConfiguration>(); for (String testResourceName : reflections.getResources(Pattern.compile(pattern))) { data.addAll(parseSingleResource(testResourceName)); } return data; }
public Collection<TestConfiguration> generateData(String testPackage, String pattern) { Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new ResourcesScanner()) .setUrls(ClasspathHelper.forPackage("")) .filterInputsBy(new FilterBuilder.Include(FilterBuilder.prefix(testPackage)))); Collection<TestConfiguration> data = new ArrayList<TestConfiguration>(); for (String testResourceName : reflections.getResources(Pattern.compile(pattern))) { data.addAll(parseSingleResource(testResourceName)); } return data; }
public static List<RestxSpec> findSpecsIn(String location) throws IOException { RestxSpecLoader loader = new RestxSpecLoader(Factory.getInstance()); Set<String> specResources = new ConfigurationBuilder() .setUrls(ClasspathHelper.forPackage(location)) .setScanners(new ResourcesScanner()) .filterInputsBy(new FilterBuilder().includePackage(location.replace('/','.'))) .build() .getResources(Pattern.compile(".*\\.spec\\.yaml")); List<RestxSpec> loaded = Lists.newArrayList(); for (String specResource : specResources) { loaded.add(loader.load(specResource)); } return loaded; }