serviceTypes.forEach(it -> spec.add(it.getPackage().getName())); ClassGraph scanner = new ClassGraph().enableAllInfo() .whitelistPackages(spec.toArray(new String[spec.size()])); }; ScanResult result = scanner.scan();
public ClasspathScanLoadHelper(Collection<String> packagesToScan) { scanResult = new ClassGraph().whitelistPackages(packagesToScan.toArray(new String[] {})) .enableClassInfo() .enableAnnotationInfo().scan(); }
public Collection<String> findFunctionsInJar(File jarFile) throws IOException { ClassGraph fastClasspathScanner = new ClassGraph().disableDirScanning() .removeTemporaryFilesAfterScan().overrideClasspath(jarFile.getAbsolutePath()); ScanResult scanResult = fastClasspathScanner.enableClassInfo().scan(); Set<String> functionClasses = new HashSet<>(); functionClasses.addAll(scanResult.getClassesImplementing(Function.class.getName()).getNames()); functionClasses.addAll(scanResult.getSubclasses(FunctionAdapter.class.getName()).getNames()); return functionClasses; } }
public ClasspathScanningPrimitiveTypeRegistry(ClassLoader classLoader) { Map<String, PrimitiveType> types = CACHE.computeIfAbsent(classLoader, cl -> { final Map<String, PrimitiveType> result = new ConcurrentHashMap<>(); final String[] whitelistPackages = StringUtils.split(System.getProperty("io.atomix.whitelistPackages"), ","); final ClassGraph classGraph = whitelistPackages != null ? new ClassGraph().enableClassInfo().whitelistPackages(whitelistPackages).addClassLoader(classLoader) : new ClassGraph().enableClassInfo().addClassLoader(classLoader); try (final ScanResult scanResult = classGraph.scan()) { scanResult.getClassesImplementing(PrimitiveType.class.getName()).forEach(classInfo -> { if (classInfo.isInterface() || classInfo.isAbstract() || Modifier.isPrivate(classInfo.getModifiers())) { return; } final PrimitiveType primitiveType = newInstance(classInfo.loadClass()); final PrimitiveType oldPrimitiveType = result.put(primitiveType.name(), primitiveType); if (oldPrimitiveType != null) { LOGGER.warn("Found multiple primitives types name={}, classes=[{}, {}]", primitiveType.name(), oldPrimitiveType.getClass().getName(), primitiveType.getClass().getName()); } }); } return Collections.unmodifiableMap(result); }); primitiveTypes.putAll(types); }
@Override public List<String> getClassNamesForPackage(String packageName, URL url) { try (ScanResult scan = new ClassGraph() .disableNestedJarScanning() .enableClassInfo() .ignoreClassVisibility() .overrideClasspath(url) .whitelistPackagesNonRecursive(packageName) .scan()) { return scan.getAllClasses().getNames(); } } }
public static void checkInitByAnnotatedClass() { if (!annotatedClassInitialized) { // look for classes annotated with @Properties try (ScanResult scanResult = new ClassGraph().enableAllInfo().scan()) { ClassInfoList classInfoList = scanResult.getClassesWithAnnotation(io.github.thingersoft.pm.api.annotations.Properties.class.getName()); for (ClassInfo mappedClassInfo : classInfoList) { Class<?> mappedClass = mappedClassInfo.loadClass(); initByAnnotatedClass(mappedClass); } } catch (IllegalArgumentException e) { throw new RuntimeException("Properties injection mapping failed", e); } } }
ClassGraph cg = new ClassGraph() // Create a new ClassGraph instance .overrideClasspath( java_classpaths ) //get custom classpath .whitelistPackages( selected_packages ); // Scan com.xyz and subpackages cg = cg.enableAllInfo(); cg = cg.enableClassInfo(); cg = cg.enableFieldInfo(); cg = cg.enableMethodInfo(); cg = cg.ignoreFieldVisibility(); cg = cg.ignoreMethodVisibility(); cg = cg.verbose(); Arrays.stream( java_classpaths ) .forEach( System.out::println ); cg = cg.enableAnnotationInfo(); cg = cg.ignoreClassVisibility(); cg = cg.enableInterClassDependencies(); cg = cg.enableExternalClasses();
scanner = new ClassGraph(); if (GuiceContext.config.isWhiteList()) scanner.whitelistPackages(packages); scanner.whitelistPaths(paths); scanner.blacklistPaths(blacklistList); scanner.blacklistPaths("META-INF/MANIFEST.MF"); scanner.blacklistJars(jarBlacklist); scanner.blacklistModules(modulesBlacklist); scanner.enableFieldInfo(); scanner.enableAnnotationInfo(); scanner.enableMethodInfo(); scanner.ignoreFieldVisibility(); scanner.ignoreMethodVisibility(); scanner.verbose(); scanResult = scanner.scan(GuiceContext.getThreadCount()); Map<String, ResourceList.ByteArrayConsumer> fileScans = quickScanFiles(); fileScans.forEach((key, value) ->
public ScanResult getScanResult() { if (scanResult == null) { TypeScriptGenerator.getLogger().info("Scanning classpath"); final Date scanStart = new Date(); ClassGraph classGraph = new ClassGraph().enableAllInfo(); if (classLoader != null) { classGraph = classGraph.overrideClasspath((Object[])classLoader.getURLs()); } if (verbose) { classGraph = classGraph.verbose(); } final ScanResult result = classGraph.scan(); final int count = result.getAllClasses().size(); final Date scanEnd = new Date(); final double timeInSeconds = (scanEnd.getTime() - scanStart.getTime()) / 1000.0; TypeScriptGenerator.getLogger().info(String.format("Scanning finished in %.2f seconds. Total number of classes: %d.", timeInSeconds, count)); scanResult = result; } return scanResult; }
graph.whitelistPathsNonRecursive(paths); graph.blacklistPaths(blacklistList); graph.blacklistJars(jarBlacklist); graph.whitelistModules(modulesBlacklist); graph.blacklistJars(jarBlacklist); graph.blacklistModules(modulesBlacklist); graph.ignoreParentModuleLayers(); graph.whitelistPackages(packages); graph.blacklistPackages(packages); graph.ignoreParentModuleLayers(); graph.enableFieldInfo(); graph.enableAnnotationInfo(); graph.enableMethodInfo(); graph.ignoreFieldVisibility(); graph.ignoreMethodVisibility();
stopWatch.start("prepare"); ClassGraph classGraph = new ClassGraph() .enableClassInfo(); classGraph = classGraph.enableAnnotationInfo(); classGraph = classGraph.enableExternalClasses() .enableSystemPackages() // Find classes in javax.faces .blacklistPackages("java", "jdk", "sun", "javafx", "oracle") .blacklistPackages("javax.xml", "javax.el", "javax.persistence") .blacklistModules("java.*", "jdk.*") .filterClasspathElements(path -> { log.debug("Path {}", path); return true; stopWatch.start("classpath scan"); try (ScanResult scanResult = classGraph.scan()) {
@Override public List<URL> getClasspathURLs() { try (ScanResult scan = new ClassGraph() .disableNestedJarScanning() .scan()) { return scan.getClasspathURLs(); } }
/** * Starts up Guice and the scanner */ private void loadScanner() { Stopwatch stopwatch = Stopwatch.createStarted(); GuiceContext.log.info("Loading Classpath Scanner - [" + GuiceContext.getThreadCount() + "] threads"); if (GuiceContext.config == null) { loadConfiguration(); } scanner = new ClassGraph(); configureScanner(scanner); try { scanResult = scanner.scan(GuiceContext.getThreadCount()); Map<String, ResourceList.ByteArrayConsumer> fileScans = quickScanFiles(); fileScans.forEach((key, value) -> scanResult.getResourcesWithLeafName(key) .forEachByteArray(value)); } catch (Exception mpe) { GuiceContext.log.log(Level.SEVERE, "Unable to run scanner", mpe); } stopwatch.stop(); GuiceContext.log.fine("Loaded Classpath Scanner - Took [" + stopwatch.elapsed(TimeUnit.MILLISECONDS) + "] millis."); }
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", justification = "https://github.com/spotbugs/spotbugs/issues/756") public void scanClasses() throws IOException { ClassGraph classGraph = new ClassGraph() .enableAllInfo() .enableExternalClasses() .enableSystemJarsAndModules(); classGraph = getClassGraphConfigurer().apply(classGraph); try (ScanResult scanResult = classGraph.scan()) { for (ScanResultHandler scanResultHandler : this.scanResultHandlers) { scanResultHandler.handle(scanResult, getBaseDir()); } } } }
/** * Enables the determination of inter-class dependencies, which may be read by calling * {@link ClassInfo#getClassDependencies()}, {@link ScanResult#getClassDependencyMap()} or * {@link ScanResult#getReverseClassDependencyMap()}. (Automatically calls {@link #enableClassInfo()}, * {@link #enableFieldInfo()}, {@link #enableMethodInfo()}, {@link #enableAnnotationInfo()}, * {@link #ignoreClassVisibility()}, {@link #ignoreFieldVisibility()} and {@link #ignoreMethodVisibility()}.) * */ public ClassGraph enableInterClassDependencies() { enableClassInfo(); enableFieldInfo(); enableMethodInfo(); enableAnnotationInfo(); ignoreClassVisibility(); ignoreFieldVisibility(); ignoreMethodVisibility(); scanSpec.enableInterClassDependencies = true; return this; }
new ClassGraph() .enableAnnotationInfo() .scan()) { ClassInfoList entities = scanResult.getClassesWithAnnotation(Entity.class.getName());
/** * Scans the classpath, blocking until the scan is complete. * * @throws RuntimeException * if any of the worker threads throws an uncaught exception, or the scan was interrupted. * @return a {@link ScanResult} object representing the result of the scan. */ public ScanResult scan() { return scan(DEFAULT_NUM_WORKER_THREADS); }
final List<URL> urls = new ClassGraph().overrideClasspath(deserialized.classpath).getClasspathURLs();
List<String> classpathUnpackedTmp = new ArrayList<String>(); try { List<File> classpathElements = new ClassGraph().getClasspathFiles(); final File classpathDir = Files.createTempDirectory("jbd_classpath_").toFile(); Runtime.getRuntime().addShutdownHook(new FileRemover(classpathDir));
/** * Enables the saving of method info during the scan. This information can be obtained using * {@link ClassInfo#getMethodInfo()} etc. By default, method info is not scanned. (Automatically calls * {@link #enableClassInfo()}.) * * @return this (for method chaining). */ public ClassGraph enableMethodInfo() { enableClassInfo(); scanSpec.enableMethodInfo = true; return this; }