xapi.dev.scanner.X_Scanner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xapi-gwt Show documentation
Show all versions of xapi-gwt Show documentation
This module exists solely to package all other gwt modules into a single
uber jar. This makes deploying to non-mavenized targets much easier.
Of course, you would be wise to inherit your dependencies individually;
the uber jar is intended for projects like collide,
which have complex configuration, and adding many jars would be a pain.
The newest version!
package xapi.dev.scanner;
import java.lang.annotation.Annotation;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import xapi.bytecode.ClassFile;
import xapi.dev.X_Dev;
import xapi.dev.resource.impl.StringDataResource;
import xapi.dev.scanner.api.ClasspathScanner;
import xapi.dev.scanner.impl.ClasspathResourceMap;
import xapi.inject.X_Inject;
import xapi.util.X_String;
public class X_Scanner {
private X_Scanner() {}
public static ClasspathResourceMap scanClassloader(ClassLoader cl) {
return scanAll()
.scan(cl);
}
public static Callable scanClassloaderAsync(ClassLoader cl) {
return X_Inject.instance(ClasspathScanner.class)
.matchClassFile(".*")
.matchResource(".*")
.matchSourceFile(".*")
.scanPackage("")
.scan(cl, Executors.newCachedThreadPool());
}
private static ClasspathScanner scanAll() {
return X_Inject.instance(ClasspathScanner.class)
.matchClassFile(".*")
.matchResource(".*")
.matchSourceFile(".*")
.scanPackage("");
}
public static ClasspathResourceMap scanClassloader(ClassLoader cl,
boolean scanClasses, boolean scanSources, boolean scanResources, String pkg) {
ClasspathScanner scanner = X_Inject.instance(ClasspathScanner.class);
if (scanClasses)
scanner.matchClassFile(".*");
if (scanResources)
scanner.matchResource(".*");
if (scanSources)
scanner.matchSourceFile(".*");
scanner.scanPackage(X_String.notNull(pkg));
return scanner.scan(cl);
}
public static Iterable findPoms(ClassLoader cl) {
return X_Inject.instance(ClasspathScanner.class)
.matchResource(".*pom.*xml")
.scanPackage("")
.scan(cl)
.findResources("");
}
public static Iterable findGwtXml(ClassLoader cl) {
return X_Inject.instance(ClasspathScanner.class)
.matchResource(".*gwt.*xml")// also match .gwtxml files
.scanPackage("")
.scan(cl)
.findResources("");
}
public static Iterable findEnums(ClassLoader cl) {
return X_Inject.instance(ClasspathScanner.class)
.matchClassFile(".*")
.scanPackage("")
.scan(cl)
.findDirectSubclasses(Enum.class);
}
@SafeVarargs
public static Iterable findMethodsWithAnnotations(ClassLoader cl, Class extends Annotation> ... annoClass) {
return X_Inject.instance(ClasspathScanner.class)
.matchClassFile(".*")
.scanPackage("")
.scan(cl)
.findClassWithAnnotatedMethods(annoClass);
}
public static ClasspathResourceMap scanFolder(String url) {
return scanClassloader(new URLClassLoader(new URL[]{X_Dev.toUrl(url)}));
}
public static ClasspathResourceMap scanFolder(String url,
boolean scanClasses, boolean scanSources, boolean scanResources, String pkg) {
return scanClassloader(
new URLClassLoader(new URL[]{X_Dev.toUrl(url)})
, scanClasses, scanSources, scanResources, pkg);
}
public static Iterable findDirectSubclasses(ClassLoader classLoader, Class> ... cls) {
return
X_Inject.instance(ClasspathScanner.class)
.matchClassFile(".*")
.scanPackage("")
.scan(classLoader)
.findDirectSubclasses(cls);
}
public static Iterable findImplementationsOf(ClassLoader classLoader, Class> ... cls) {
return
X_Inject.instance(ClasspathScanner.class)
.matchClassFile(".*")
.scanPackage("")
.scan(classLoader)
.findImplementationOf(cls);
}
public static Iterable findClassesInPackage(ClassLoader classLoader, String pkgName) {
return
X_Inject.instance(ClasspathScanner.class)
.matchClassFile(".*")
.scanPackage("")
.scan(classLoader)
.findClassesInPackage(pkgName);
}
}