本文整理汇总了Java中org.reflections.scanners.AbstractScanner类的典型用法代码示例。如果您正苦于以下问题:Java AbstractScanner类的具体用法?Java AbstractScanner怎么用?Java AbstractScanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractScanner类属于org.reflections.scanners包,在下文中一共展示了AbstractScanner类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateSchemas
import org.reflections.scanners.AbstractScanner; //导入依赖的package包/类
private void generateSchemas() throws Exception {
File[] jars = collectJars();
if (jars == null) {
throw new MojoExecutionException("No classpath file found in the target directory");
}
List<URL> jarURLs = new ArrayList<URL>();
jarURLs.add(classesDirectory.toURI().toURL());
for (File jar : jars) {
jarURLs.add(jar.toURI().toURL());
}
final List<String> injectableClassNames = new ArrayList<String>();
// Scan classes only
new Reflections(new ConfigurationBuilder().
addUrls(classesDirectory.toURI().toURL()).setScanners(new AbstractScanner() {
@Override
public void scan(Object cls) {
if ((cls instanceof ClassFile) && isInjectable((ClassFile) cls, getLog())) {
injectableClassNames.add(((ClassFile) cls).getName());
}
}
}));
URLClassLoader classLoader = new URLClassLoader(jarURLs.toArray(new URL[jarURLs.size()]), ConfigProperty.class.getClassLoader());
ClassLoader[] loaders = new ClassLoader[]{classLoader};
List<Class> injectableClasses = (List<Class>) (Object) ReflectionUtils.forNames(injectableClassNames, loaders);
processClasses(injectableClasses);
}
示例2: createConfigFile
import org.reflections.scanners.AbstractScanner; //导入依赖的package包/类
private void createConfigFile() throws Exception {
File classesDir = new File(outputDirectory, "classes/");
File libDir = new File(outputDirectory, "lib");
File[] jars = libDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
});
if (jars == null) {
throw new MojoExecutionException("No jar files found in " + libDir.getAbsolutePath());
}
List<URL> jarURLs = new ArrayList<URL>();
jarURLs.add(classesDir.toURI().toURL());
for (File jar : jars) {
jarURLs.add(jar.toURI().toURL());
}
// Scan classes and all jars
final List<String> candidates = new ArrayList<String>();
new Reflections(new ConfigurationBuilder().
addUrls(jarURLs).setScanners(new AbstractScanner() {
@Override
public void scan(Object cls) {
if ((cls instanceof ClassFile)) {
ClassFile classFile = (ClassFile) cls;
if (XmlSchemaGeneratingMojo.isInjectable(classFile, getLog()) &&
(classFile.getName().equals(configClassName) || classFile.getName().endsWith(configClassName))) {
candidates.add(classFile.getName());
}
}
}
}));
if (candidates.isEmpty()) {
throw new MojoFailureException("No class found for " + configClassName);
}
if (candidates.size() > 1) {
throw new MojoFailureException("More classes found for " + configClassName + ":" + candidates);
}
String fullClassName = candidates.get(0);
URLClassLoader classLoader = new URLClassLoader(jarURLs.toArray(new URL[jarURLs.size()]),
ConfigProperty.class.getClassLoader());
Class configClass = ReflectionUtils.forName(fullClassName, classLoader);
generateToFile(configClass);
}