use of io.github.classgraph.ClassGraph in project querydsl by querydsl.
the class SerializationTest method expressions.
@Test
public void expressions() throws Exception {
Map<Class<?>, Object> args = new HashMap<>();
args.put(Object.class, "obj");
args.put(BeanPath.class, new EntityPathBase<Object>(Object.class, "obj"));
args.put(Class.class, Integer.class);
args.put(Class[].class, new Class<?>[] { Object.class, Object.class });
args.put(java.util.Date.class, new java.util.Date(0));
args.put(java.sql.Date.class, new java.sql.Date(0));
args.put(java.sql.Time.class, new java.sql.Time(0));
args.put(java.sql.Timestamp.class, new java.sql.Timestamp(0));
args.put(Expression.class, Expressions.enumPath(Gender.class, "e"));
args.put(Expression[].class, new Expression<?>[] { Expressions.enumPath(Gender.class, "e"), Expressions.stringPath("s") });
args.put(FactoryExpression.class, Projections.tuple(Expressions.stringPath("str")));
args.put(GroupExpression.class, GroupBy.avg(Expressions.numberPath(Integer.class, "num")));
args.put(Number.class, 1);
args.put(Operator.class, Ops.AND);
args.put(Path.class, Expressions.stringPath("str"));
args.put(PathBuilderValidator.class, PathBuilderValidator.DEFAULT);
args.put(PathMetadata.class, PathMetadataFactory.forVariable("obj"));
args.put(PathInits.class, PathInits.DEFAULT);
args.put(Predicate.class, Expressions.path(Object.class, "obj").isNull());
args.put(QueryMetadata.class, new DefaultQueryMetadata());
args.put(String.class, "obj");
ClassGraph reflections = new ClassGraph().enableClassInfo();
List<Class<?>> types = reflections.scan().getSubclasses(Expression.class.getName()).loadClasses();
for (Class<?> type : types) {
if (!type.isInterface() && !type.isMemberClass() && !Modifier.isAbstract(type.getModifiers())) {
for (Constructor<?> c : type.getConstructors()) {
Object[] parameters = new Object[c.getParameterTypes().length];
for (int i = 0; i < c.getParameterTypes().length; i++) {
parameters[i] = Objects.requireNonNull(args.get(c.getParameterTypes()[i]), c.getParameterTypes()[i].getName());
}
c.setAccessible(true);
Object o = c.newInstance(parameters);
assertEquals(o, Serialization.serialize(o));
}
}
}
}
use of io.github.classgraph.ClassGraph in project querydsl by querydsl.
the class CycleClassInitDependencyTest method overrideClassLoader.
@BeforeClass
public static void overrideClassLoader() {
loader = Thread.currentThread().getContextClassLoader();
Collection<URL> urls = new ClassGraph().getClasspathURLs();
ClassLoader cl = URLClassLoader.newInstance(urls.toArray(new URL[0]), null);
Thread.currentThread().setContextClassLoader(cl);
}
use of io.github.classgraph.ClassGraph in project morphia by mongodb.
the class Mapper method getClasses.
private List<Class> getClasses(ClassLoader loader, String packageName, boolean mapSubPackages) throws ClassNotFoundException {
final Set<Class> classes = new HashSet<>();
ClassGraph classGraph = new ClassGraph().addClassLoader(loader).enableAllInfo();
if (mapSubPackages) {
classGraph.acceptPackages(packageName);
classGraph.acceptPackages(packageName + ".*");
} else {
classGraph.acceptPackagesNonRecursive(packageName);
}
try (ScanResult scanResult = classGraph.scan()) {
for (ClassInfo classInfo : scanResult.getAllClasses()) {
classes.add(Class.forName(classInfo.getName(), true, loader));
}
}
return new ArrayList<>(classes);
}
use of io.github.classgraph.ClassGraph in project beam by apache.
the class ClasspathScanningResourcesDetectorTest method shouldDetectResourcesInOrderTheyAppearInURLClassLoader.
@Test
public void shouldDetectResourcesInOrderTheyAppearInURLClassLoader() throws Exception {
File file1 = createTestTmpJarFile("test1");
File file2 = createTestTmpJarFile("test2");
ClassLoader classLoader = new URLClassLoader(new URL[] { file1.toURI().toURL(), file2.toURI().toURL() });
ClasspathScanningResourcesDetector detector = new ClasspathScanningResourcesDetector(new ClassGraph());
List<String> result = detector.detect(classLoader);
assertThat(result, containsInRelativeOrder(containsString(file1.getAbsolutePath()), containsString(file2.getAbsolutePath())));
}
use of io.github.classgraph.ClassGraph in project beam by apache.
the class ClasspathScanningResourcesDetectorTest method shouldNotDetectOrdinaryFiles.
@Test
public void shouldNotDetectOrdinaryFiles() throws Exception {
File textFile = tmpFolder.newFile("ordinaryTextFile.txt");
ClassLoader classLoader = new URLClassLoader(new URL[] { textFile.toURI().toURL() });
ClasspathScanningResourcesDetector detector = new ClasspathScanningResourcesDetector(new ClassGraph());
List<String> result = detector.detect(classLoader);
assertThat(result, not(hasItem(containsString(textFile.getAbsolutePath()))));
}
Aggregations