List of usage examples for com.google.common.reflect ClassPath.ClassInfo toString
public String toString()
From source file:dpfmanager.conformancechecker.tiff.TiffConformanceChecker.java
/** * Gets autofixes./*from ww w . j a va 2 s .c om*/ * * @return the autofixes */ public static ArrayList<String> getAutofixes() { ArrayList<String> classes = null; try { Logger.println("Loading autofixes from JAR"); String path = "DPF Manager-jfx.jar"; if (new File(path).exists()) { ZipInputStream zip = new ZipInputStream(new FileInputStream(path)); for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) { if (!entry.isDirectory() && entry.getName().endsWith(".class") && entry.getName().contains("autofixes") && !entry.getName().contains("autofix.class")) { if (classes == null) { classes = new ArrayList<String>(); } classes.add(entry.getName().substring(entry.getName().lastIndexOf("/") + 1) .replace(".class", "")); } } } else { Logger.println("Jar not found"); } } catch (Exception ex) { Logger.println("Error " + ex.toString()); } if (classes == null) { Logger.println("Loading autofixes through reflection"); try { //Reflections reflections = new Reflections(TiffConformanceChecker.getAutofixesClassPath(), new SubTypesScanner(false)); //Set<Class<? extends Object>> classesSet = reflections.getSubTypesOf(Object.class); Class cls = Class.forName("dpfmanager.conformancechecker.tiff.TiffConformanceChecker"); ClassLoader cll = cls.getClassLoader(); Set<ClassPath.ClassInfo> classesInPackage = ClassPath.from(cll) .getTopLevelClassesRecursive(TiffConformanceChecker.getAutofixesClassPath()); classes = new ArrayList<String>(); for (ClassPath.ClassInfo cl : classesInPackage) { if (!cl.toString().endsWith(".autofix")) { classes.add(cl.toString().substring(cl.toString().lastIndexOf(".") + 1)); } } } catch (Exception ex) { Logger.println("Exception getting classes"); } } if (classes == null) { Logger.println("Autofixes loaded manually"); classes = new ArrayList<String>(); classes.add(clearPrivateData.class.toString()); classes.add(makeBaselineCompliant.class.toString()); } Logger.println("Found " + classes.size() + " classes:"); for (String cl : classes) { Logger.println(cl); } return classes; }
From source file:org.apache.beam.sdk.util.ApiSurface.java
/** * Returns an {@link ApiSurface} like this one, but also including the named package and all of * its subpackages./*from ww w . j a v a2 s . c o m*/ */ public ApiSurface includingPackage(String packageName, ClassLoader classLoader) throws IOException { ClassPath classPath = ClassPath.from(classLoader); Set<Class<?>> newRootClasses = Sets.newHashSet(); for (ClassPath.ClassInfo classInfo : classPath.getTopLevelClassesRecursive(packageName)) { Class clazz = null; try { clazz = classInfo.load(); } catch (NoClassDefFoundError e) { // TODO: Ignore any NoClassDefFoundError errors as a workaround. (BEAM-2231) LOG.warn("Failed to load class: {}", classInfo.toString(), e); continue; } if (exposed(clazz.getModifiers())) { newRootClasses.add(clazz); } } LOG.debug("Including package {} and subpackages: {}", packageName, newRootClasses); newRootClasses.addAll(rootClasses); return new ApiSurface(newRootClasses, patternsToPrune); }