/** * Returns a distinct collection of URLs based on URLs derived from class loaders expanded with Manifest information. * <p> * The {@code MANIFEST.MF} file can contain a {@code Class-Path} entry that defines * additional jar files to be included on the classpath. This method finds the jar files * using the {@link #contextClassLoader()} and {@link #staticClassLoader()}, before * searching for any additional manifest classpaths. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest() { return forManifest(forClassLoader()); }
/** * Returns a distinct collection of URLs based on URLs derived from class loaders expanded with Manifest information. * <p> * The {@code MANIFEST.MF} file can contain a {@code Class-Path} entry that defines * additional jar files to be included on the classpath. This method finds the jar files * using the {@link #contextClassLoader()} and {@link #staticClassLoader()}, before * searching for any additional manifest classpaths. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest() { return forManifest(forClassLoader()); }
private static Collection<URL> effectiveClassPathUrls(ClassLoader... classLoaders) { return ClasspathHelper.forManifest(ClasspathHelper.forClassLoader(classLoaders)); }
/** * Returns a distinct collection of URLs by expanding the specified URLs with Manifest information. * <p> * The {@code MANIFEST.MF} file can contain a {@code Class-Path} entry that defines additional * jar files to be included on the classpath. This method takes each URL in turn, tries to * resolve it as a jar file, and if so, adds any additional manifest classpaths. * The returned collection of URLs will always contain all the input URLs. * <p> * The returned URLs retains the input order. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest(final Iterable<URL> urls) { Collection<URL> result = new ArrayList<URL>(); // determine if any of the URLs are JARs, and get any dependencies for (URL url : urls) { result.addAll(forManifest(url)); } return distinctUrls(result); }
/** * Returns a distinct collection of URLs by expanding the specified URLs with Manifest information. * <p> * The {@code MANIFEST.MF} file can contain a {@code Class-Path} entry that defines additional * jar files to be included on the classpath. This method takes each URL in turn, tries to * resolve it as a jar file, and if so, adds any additional manifest classpaths. * The returned collection of URLs will always contain all the input URLs. * <p> * The returned URLs retains the input order. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest(final Iterable<URL> urls) { Collection<URL> result = new ArrayList<URL>(); // determine if any of the URLs are JARs, and get any dependencies for (URL url : urls) { result.addAll(forManifest(url)); } return distinctUrls(result); }
/** * To handle the situation where classpath is specified in the manifest of the jar, we have to augment the URLs. * This happens as part of the surefire plugin as well as elsewhere in the wild (especially in maven when running tests. ;). * @param classLoaders * @return A collection of URLs representing the effective classpath URLs */ private static Collection<URL> effectiveClassPathUrls(ClassLoader... classLoaders) { return ClasspathHelper.forManifest(ClasspathHelper.forClassLoader(classLoaders)); }
/** * Returns the list of class path urls. * @return the list of class path urls. */ public static Set<URL> getClasspathURLs() { return ClasspathHelper.forManifest(); }
public static Collection<URL> forManifest(final Iterable<URL> urls) { Collection<URL> result = new ArrayList<>(); // determine if any of the URLs are JARs, and get any dependencies for (URL url : urls) { result.addAll(forManifest(url)); } return distinctUrls(result); }
public ReflectionPotentialBeanClassFinder(final BeanPropertyExtractor beanPropertyExtractor, final boolean ignoreClassesWithoutProperties, final boolean allowInterfaecs, final ClassLoader... classLoaders) { this.beanPropertyExtractor = beanPropertyExtractor; this.ignoreClassesWithoutProperties = ignoreClassesWithoutProperties; this.allowInterfaecs = allowInterfaecs; this.classLoaders = classLoaders; this.classLoaderURLs = ClasspathHelper.forManifest(ClasspathHelper.forClassLoader(classLoaders)); }
/** * Returns a distinct collection of URLs based on URLs derived from class loaders expanded with Manifest information. * <p> * The {@code MANIFEST.MF} file can contain a {@code Class-Path} entry that defines * additional jar files to be included on the classpath. This method finds the jar files * using the {@link #contextClassLoader()} and {@link #staticClassLoader()}, before * searching for any additional manifest classpaths. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest() { return forManifest(forClassLoader()); }
/** * Returns a distinct collection of URLs based on URLs derived from class loaders expanded with Manifest information. * <p> * The {@code MANIFEST.MF} file can contain a {@code Class-Path} entry that defines * additional jar files to be included on the classpath. This method finds the jar files * using the {@link #contextClassLoader()} and {@link #staticClassLoader()}, before * searching for any additional manifest classpaths. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest() { return forManifest(forClassLoader()); }
private static Collection<URL> effectiveClassPathUrls(ClassLoader... classLoaders) { return ClasspathHelper.forManifest(ClasspathHelper.forClassLoader(classLoaders)); }
private static Collection<URL> effectiveClassPathUrls(ClassLoader... classLoaders) { return ClasspathHelper.forManifest(ClasspathHelper.forClassLoader(classLoaders)); }
public static Collection<URL> forManifest() { return forManifest(forClassLoader()); }
/** * Returns a distinct collection of URLs by expanding the specified URLs with Manifest information. * <p> * The {@code MANIFEST.MF} file can contain a {@code Class-Path} entry that defines additional * jar files to be included on the classpath. This method takes each URL in turn, tries to * resolve it as a jar file, and if so, adds any additional manifest classpaths. * The returned collection of URLs will always contain all the input URLs. * <p> * The returned URLs retains the input order. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest(final Iterable<URL> urls) { Collection<URL> result = new ArrayList<URL>(); // determine if any of the URLs are JARs, and get any dependencies for (URL url : urls) { result.addAll(forManifest(url)); } return distinctUrls(result); }
/** * Returns a distinct collection of URLs by expanding the specified URLs with Manifest information. * <p> * The {@code MANIFEST.MF} file can contain a {@code Class-Path} entry that defines additional * jar files to be included on the classpath. This method takes each URL in turn, tries to * resolve it as a jar file, and if so, adds any additional manifest classpaths. * The returned collection of URLs will always contain all the input URLs. * <p> * The returned URLs retains the input order. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest(final Iterable<URL> urls) { Collection<URL> result = new ArrayList<URL>(); // determine if any of the URLs are JARs, and get any dependencies for (URL url : urls) { result.addAll(forManifest(url)); } return distinctUrls(result); }
/** * Compute urls to scan for annotations. * @return collection of urls */ public Collection<URL> getURLs() { if (this.urls == null) { // stores collections of urls to be scanned Collection<URL> result = new ArrayList<URL>(); Collection<String> strings = new HashSet<String>(); // get only urls of libraries that contains jsf types add(result, strings, ClasspathHelper.forResource("META-INF/faces-config.xml", this.getClass().getClassLoader())); // add jsf library with anotherFacesConfig String anotherFacesConfig = this.jsfAnnotatedClassFactoryConfiguration.getAnotherConfig(); if (anotherFacesConfig != null) { add(result, strings, ClasspathHelper.forResource(anotherFacesConfig, this.getClass().getClassLoader())); } // add project classes folder for (URL url : ClasspathHelper.forManifest()) { String file = url.getFile(); // check if adding classes folder if (isClassesFolder(file)) { add(result, strings, url); } } this.urls = result; } return this.urls; }
private void scanConceptsWithReflections() throws ObjectStoreConfigException { logger.debug("Search for concepts with reflections"); Set<URL> classpath = new HashSet<>(); classpath.addAll(ClasspathHelper.forClassLoader()); classpath.addAll(ClasspathHelper.forJavaClassPath()); classpath.addAll(ClasspathHelper.forManifest()); classpath.addAll(ClasspathHelper.forPackage("")); Reflections reflections = new Reflections(new ConfigurationBuilder() .setUrls(classpath) .useParallelExecutor() .filterInputsBy(FilterBuilder.parsePackages("-java, -javax, -sun, -com.sun")) .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner())); Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Iri.class, true); logger.debug("Search for concepts with reflections resulted in " + annotated.size() + " classes"); for (Class clazz : annotated) { logger.debug("Found concept class: " + clazz.getCanonicalName()); roleMapper.addConcept(clazz); } }
private static Reflections createReflections() { List<ClassLoader> classLoadersList = new LinkedList<>(); classLoadersList.add(ClasspathHelper.contextClassLoader()); classLoadersList.add(ClasspathHelper.staticClassLoader()); return new Reflections(new ConfigurationBuilder() .setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner()) .setUrls(ClasspathHelper.forManifest(ClasspathHelper.forClassLoader( classLoadersList.toArray(new ClassLoader[classLoadersList.size()])))) .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("com.kakao.hbase.manager.command")))); }
/** * Creates an Anno4j instance that can use the concepts contained in the given JAR file. * @param ontologyJar A JAR file containing concepts. * @param classLoader The class loader to use. * @param persistSchemaAnnotations Whether schema annotations should be scanned. * @return Returns an Anno4j instance. * @throws Exception Thrown on error. */ private static Anno4j getAnno4jWithClassLoader(File ontologyJar, ClassLoader classLoader, boolean persistSchemaAnnotations) throws Exception { Set<URL> clazzes = new HashSet<>(); clazzes.addAll(ClasspathHelper.forManifest(ontologyJar.toURI().toURL())); Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), new IDGeneratorAnno4jURN(), null, persistSchemaAnnotations, clazzes); // Register concepts found in JAR: RoleMapper mapper = anno4j.getObjectRepository().getConnection().getObjectFactory().getResolver().getRoleMapper(); for (final String className : getClassNamesInJar(ontologyJar)) { Class<?> clazz = classLoader.loadClass(className); if(clazz.getAnnotation(Iri.class) != null) { mapper.addConcept(clazz); } } return anno4j; }