public boolean matches(URL url) { if (url.getProtocol().equals("file") && !hasJarFileInPath(url)) { java.io.File file = getFile(url); return file != null && file.isDirectory(); } else return false; }
public static void register(KieContainer kieContainer) { // TODO Support having multiple KieContainers on the classpath (maybe through ClassLoader to KieContainer mapping?) Vfs.addDefaultURLTypes(new ReflectionsKieVfsUrlType(kieContainer)); }
/** return an iterable of all {@link org.reflections.vfs.Vfs.File} in given urls, starting with given packagePrefix and matching nameFilter */ public static Iterable<File> findFiles(final Collection<URL> inUrls, final String packagePrefix, final Predicate<String> nameFilter) { Predicate<File> fileNamePredicate = new Predicate<File>() { public boolean apply(File file) { String path = file.getRelativePath(); if (path.startsWith(packagePrefix)) { String filename = path.substring(path.indexOf(packagePrefix) + packagePrefix.length()); return !Utils.isEmpty(filename) && nameFilter.apply(filename.substring(1)); } else { return false; } } }; return findFiles(inUrls, fileNamePredicate); }
/** tries to create a Dir from the given url, using the defaultUrlTypes */ public static Dir fromURL(final URL url) { return fromURL(url, defaultUrlTypes); }
public static void registerUrlTypes() { final List<UrlType> urlTypes = new LinkedList<>(); urlTypes.add(new EmptyUrlType(ENDINGS)); urlTypes.addAll(Arrays.asList(Vfs.DefaultUrlTypes.values())); Vfs.setDefaultURLTypes(urlTypes); }
if (!Vfs.getDefaultUrlTypes().contains(getInstance())) { Vfs.addDefaultURLTypes(getInstance());
private KernelManager() { // Load Nuun and Reflections classes to force initialization of Vfs url types try { Class.forName(Vfs.class.getCanonicalName()); Class.forName(AbstractClasspathScanner.class.getCanonicalName()); } catch (ClassNotFoundException e) { throw new RuntimeException("Cannot initialize the classpath scanning infrastructure", e); } // Save existing url types savedUrlTypes = Vfs.getDefaultUrlTypes(); // Find all classpath scan handlers and add their Vfs url types List<Vfs.UrlType> urlTypes = new ArrayList<>(); for (ClasspathScanHandler classpathScanHandler : ServiceLoader.load(ClasspathScanHandler.class)) { LOGGER.trace("Detected classpath handler {}", classpathScanHandler.getClass().getCanonicalName()); urlTypes.addAll(classpathScanHandler.urlTypes()); } LOGGER.debug("URL types for scanning: {}", urlTypes); detectedUrlTypes = urlTypes; }
/** tries to create a Dir from the given url, using the defaultUrlTypes */ public static Dir fromURL(final URL url) { return fromURL(url, defaultUrlTypes); }
/** * OSX contains file:// resources on the classpath including .mar and .jnilib files. * * Reflections use of Vfs doesn't recognize these URLs and logs warns when it sees them. By registering those file endings, we suppress the warns. */ public static void registerUrlTypes() { final List<Vfs.UrlType> urlTypes = Lists.newArrayList(); // include a list of file extensions / filenames to be recognized urlTypes.add(new EmptyIfFileEndingsUrlType(".mar", ".jnilib", ".so", ".dll")); urlTypes.addAll(Arrays.asList(Vfs.DefaultUrlTypes.values())); Vfs.setDefaultURLTypes(urlTypes); }
public boolean matches(URL url) { if (url.getProtocol().equals("file") && !hasJarFileInPath(url)) { java.io.File file = getFile(url); return file != null && file.isDirectory(); } else return false; }
/** tries to create a Dir from the given url, using the given urlTypes*/ public static Dir fromURL(final URL url, final UrlType... urlTypes) { return fromURL(url, Lists.<UrlType>newArrayList(urlTypes)); }
/** * OSX contains file:// resources on the classpath including .mar and .jnilib files. * <p> * Reflections use of Vfs doesn't recognize these URLs and logs warns when it sees them. By registering those file * endings, we supress the warns. */ public static void registerUrlTypes() { final List<Vfs.UrlType> urlTypes = Lists.newArrayList(); // include a list of file extensions / filenames to be recognized urlTypes.add(new EmptyIfFileEndingsUrlType(".mar", ".jnilib")); urlTypes.addAll(Arrays.asList(Vfs.DefaultUrlTypes.values())); Vfs.setDefaultURLTypes(urlTypes); }
/** return an iterable of all {@link org.reflections.vfs.Vfs.File} in given urls, starting with given packagePrefix and matching nameFilter */ public static Iterable<File> findFiles(final Collection<URL> inUrls, final String packagePrefix, final Predicate<String> nameFilter) { Predicate<File> fileNamePredicate = new Predicate<File>() { public boolean apply(File file) { String path = file.getRelativePath(); if (path.startsWith(packagePrefix)) { String filename = path.substring(path.indexOf(packagePrefix) + packagePrefix.length()); return !Utils.isEmpty(filename) && nameFilter.apply(filename.substring(1)); } else { return false; } } }; return findFiles(inUrls, fileNamePredicate); }
private static void addDefaultUrlTypes() { if (!added.getAndSet(true)) { Vfs.addDefaultURLTypes(new VfsUrlType()); } } }
public Dir createDir(final URL url) throws Exception { return new ZipDir(new JarFile(getFile(url))); } },
/** tries to create a Dir from the given url, using the given urlTypes*/ public static Dir fromURL(final URL url, final UrlType... urlTypes) { return fromURL(url, Lists.<UrlType>newArrayList(urlTypes)); }
@Programmatic @Override public <T> Set<Class<? extends T>> findSubTypesOfClasses(Class<T> type) { Vfs.setDefaultURLTypes(getUrlTypes()); final Reflections reflections = new Reflections( ClasspathHelper.forClassLoader(Thread.currentThread().getContextClassLoader()), ClasspathHelper.forClass(Object.class), new SubTypesScanner(false) ); return reflections.getSubTypesOf(type); }
long start = System.currentTimeMillis(); final Reflections reflections = new Reflections(); Iterable<Vfs.File> files = Vfs.findFiles(urls, packagePrefix, resourceNameFilter); for (final Vfs.File file : files) { InputStream inputStream = null;
public static void init() { Vfs.addDefaultURLTypes(new JnilibIgnoringUrlType()); } }
public Dir createDir(final URL url) throws Exception { return new SystemDir(getFile(url)); } },