use of com.google.common.reflect.ClassPath in project calcite-avatica by apache.
the class TestRunner method getAllTestClasses.
/**
* Finds all tests to run for the TCK.
*
* @return A list of test classes to run.
*/
List<Class<?>> getAllTestClasses() {
try {
ClassPath cp = ClassPath.from(getClass().getClassLoader());
ImmutableSet<ClassInfo> classes = cp.getTopLevelClasses("org.apache.calcite.avatica.tck.tests");
List<Class<?>> testClasses = new ArrayList<>(classes.size());
for (ClassInfo classInfo : classes) {
if (classInfo.getSimpleName().equals("package-info")) {
continue;
}
Class<?> clz = Class.forName(classInfo.getName());
if (Modifier.isAbstract(clz.getModifiers())) {
// Ignore abstract classes
continue;
}
testClasses.add(clz);
}
return testClasses;
} catch (Exception e) {
LOG.error("Failed to instantiate test classes", e);
Unsafe.systemExit(TestRunnerExitCodes.TEST_CASE_INSTANTIATION.ordinal());
// Unreachable..
return null;
}
}
use of com.google.common.reflect.ClassPath in project j2objc by google.
the class ASTClassInfoPrinter method main.
public static void main(String... args) {
// Clear saved state for new calls.
tree = TreeMultimap.create();
astLookup = Sets.newHashSet();
ClassPath cp = null;
try {
cp = ClassPath.from(ClassLoader.getSystemClassLoader());
} catch (IOException e) {
ErrorUtil.error(e.getMessage());
System.exit(1);
}
for (ClassInfo c : cp.getTopLevelClasses("org.eclipse.jdt.core.dom")) {
astLookup.add(c.getSimpleName());
}
for (ClassInfo ci : cp.getTopLevelClasses("com.google.devtools.j2objc.ast")) {
// Ignore package-info and JUnit tests.
if (ci.getSimpleName().equals("package-info") || TestCase.class.isAssignableFrom(ci.load())) {
continue;
}
walkSuperclassHierarchy(ci.load());
}
// Print hierarchy descending from Object.
printClassHierarchy("Object", "");
}
use of com.google.common.reflect.ClassPath in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ClassScanner method getClassesForPackage.
public List<Class<?>> getClassesForPackage(String packageName) throws ClassNotFoundException {
final List<Class<?>> classes = new ArrayList<>();
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
ClassPath classPath = ClassPath.from(classLoader);
// Some anonymous classes don't return true when calling isAnonymousClass(), but they
// always seem to be nested anonymous classes like com.android.settings.Foo$1$2. In
// general we don't want any anonymous classes so we just filter these out by searching
// for $[0-9] in the name.
Pattern anonymousClassPattern = Pattern.compile(".*\\$\\d+.*");
Matcher anonymousClassMatcher = anonymousClassPattern.matcher("");
for (ClassPath.ClassInfo info : classPath.getAllClasses()) {
if (info.getPackageName().startsWith(packageName)) {
try {
Class clazz = classLoader.loadClass(info.getName());
if (clazz.isAnonymousClass() || anonymousClassMatcher.reset(clazz.getName()).matches()) {
continue;
}
classes.add(clazz);
} catch (NoClassDefFoundError e) {
// do nothing. this class hasn't been found by the
// loader, and we don't care.
}
}
}
} catch (final IOException e) {
throw new ClassNotFoundException("Error when parsing " + packageName, e);
}
return classes;
}
use of com.google.common.reflect.ClassPath in project alluxio by Alluxio.
the class AllocatorContractTest method before.
/**
* Try to find all implementation classes of {@link Allocator} in the same package.
*/
@Before
@Override
public void before() throws Exception {
super.before();
mStrategies = new ArrayList<>();
try {
String packageName = Reflection.getPackageName(Allocator.class);
ClassPath path = ClassPath.from(Thread.currentThread().getContextClassLoader());
List<ClassPath.ClassInfo> clazzInPackage = new ArrayList<>(path.getTopLevelClassesRecursive(packageName));
for (ClassPath.ClassInfo clazz : clazzInPackage) {
Set<Class<?>> interfaces = new HashSet<>(Arrays.asList(clazz.load().getInterfaces()));
if (interfaces.size() > 0 && interfaces.contains(Allocator.class)) {
mStrategies.add(clazz.getName());
}
}
} catch (Exception e) {
fail("Failed to find implementation of allocate strategy");
}
}
use of com.google.common.reflect.ClassPath in project Openfire by igniterealtime.
the class XMPPServer method scanForSystemPropertyClasses.
private void scanForSystemPropertyClasses() {
try {
final Set<ClassPath.ClassInfo> classesInPackage = ClassPath.from(getClass().getClassLoader()).getTopLevelClassesRecursive("org.jivesoftware.openfire");
for (final ClassPath.ClassInfo classInfo : classesInPackage) {
final String className = classInfo.getName();
if (!CLASSES_TO_EXCLUDE.contains(className)) {
try {
final Class<?> clazz = classInfo.load();
final Field[] fields = clazz.getDeclaredFields();
for (final Field field : fields) {
if (field.getType().equals(SystemProperty.class)) {
try {
field.setAccessible(true);
logger.info("Accessing SystemProperty field {}#{}", className, field.getName());
field.get(null);
} catch (final Throwable t) {
logger.warn("Unable to access field {}#{}", className, field.getName(), t);
}
}
}
} catch (final Throwable t) {
logger.warn("Unable to load class {}", className, t);
}
}
}
} catch (final Throwable t) {
logger.warn("Unable to scan classpath for SystemProperty classes", t);
}
}
Aggregations