本文整理匯總了Java中com.google.common.reflect.ClassPath.getTopLevelClassesRecursive方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassPath.getTopLevelClassesRecursive方法的具體用法?Java ClassPath.getTopLevelClassesRecursive怎麽用?Java ClassPath.getTopLevelClassesRecursive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.reflect.ClassPath
的用法示例。
在下文中一共展示了ClassPath.getTopLevelClassesRecursive方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findMessageClasses
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private Iterable<Class<? extends AbstractMessage>> findMessageClasses() {
try {
List<Class<? extends AbstractMessage>> result = new ArrayList<>();
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
ClassPath classpath = ClassPath.from(classloader);
ImmutableSet<ClassInfo> xx =
classpath.getTopLevelClassesRecursive("net.wizardsoflua.testenv.net");
Iterable<ClassInfo> yy = Iterables.filter(xx, input -> {
Class<?> cls = input.load();
return AbstractMessage.class.isAssignableFrom(cls)
&& !Modifier.isAbstract(cls.getModifiers());
});
for (ClassInfo classInfo : yy) {
result.add((Class<? extends AbstractMessage>) classInfo.load());
}
return result;
} catch (IOException e) {
throw new UndeclaredThrowableException(e);
}
}
示例2: getClasses
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
@API public static List<Class<?>> getClasses(String path)
{
try
{
ClassPath classPath = ClassPath.from(ClassUtil.class.getClassLoader());
Set<ClassInfo> classInfo = classPath.getTopLevelClassesRecursive(path);
Iterator<ClassInfo> iterator = classInfo.iterator();
List<Class<?>> classes = new ArrayList<>();
while(iterator.hasNext())
{
ClassInfo ci = iterator.next();
Optional<Class<?>> classOptional = getClass(ci.getName());
classOptional.ifPresent(classes::add);
}
return classes;
}
catch(IOException e)
{
throw new UncheckedIOException(e);
}
}
示例3: getCheckstyleModulesRecursive
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
/**
* Gets checkstyle's modules in the given package recursively.
* @param packageName the package name to use
* @param loader the class loader used to load Checkstyle package name
* @return the set of checkstyle's module classes
* @throws IOException if the attempt to read class path resources failed
* @see ModuleReflectionUtils#isCheckstyleModule(Class)
*/
private static Set<Class<?>> getCheckstyleModulesRecursive(
String packageName, ClassLoader loader) throws IOException {
final ClassPath classPath = ClassPath.from(loader);
final Set<Class<?>> result = new HashSet<Class<?>>();
for (ClassInfo clsInfo : classPath.getTopLevelClassesRecursive(packageName)) {
final Class<?> cls = clsInfo.load();
if (ModuleReflectionUtils.isCheckstyleModule(cls)
&& !cls.getName().endsWith("Stub")
&& !cls.getCanonicalName()
.startsWith("com.puppycrawl.tools.checkstyle.internal.testmodules")
&& !cls.getCanonicalName()
.startsWith("com.puppycrawl.tools.checkstyle.packageobjectfactory")) {
result.add(cls);
}
}
return result;
}
示例4: collectSteps
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private static Map<CukesComponent, Multimap<StepType, StepDefinition>> collectSteps() throws IOException, ClassNotFoundException {
Map<CukesComponent, Multimap<StepType, StepDefinition>> steps = createStepsStubs();
ClassPath classPath = ClassPath.from(DocumentationGenerator.class.getClassLoader());
ImmutableSet<ClassPath.ClassInfo> classes = classPath.getTopLevelClassesRecursive("lv.ctco.cukes");
for (ClassPath.ClassInfo classInfo : classes) {
String className = classInfo.getName();
Class<?> aClass = Class.forName(className);
Method[] methods = aClass.getMethods();
for (Method method : methods) {
StepType type = StepType.getTypeForMethod(method);
if (type != null) {
CukesComponent component = CukesComponent.findByClassName(className);
steps.get(component).put(type, new StepDefinition(type.getPattern(method), type.getDescription(method)));
}
}
}
return steps;
}
示例5: scan
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
public void scan(Listener<Class<?>> listener) {
try {
ClassPath path = ClassPath.from(classLoader);
for (String packageName : packages) {
for (ClassInfo classInfo : path.getTopLevelClassesRecursive(packageName)) {
Class<?> clazz = classLoader.loadClass(classInfo.getName());
if (match(clazz)) {
listener.handle(clazz);
}
}
}
} catch (Exception e) {
e.printStackTrace();
// TODO Handle exception
}
}
示例6: getConvertersClasses
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private Set<Class<?>> getConvertersClasses(String converterPackage, ClassLoader classLoader) {
Set<Class<?>> classes = Collections.emptySet();
try {
ClassPath classPath = ClassPath.from(classLoader);
Set<com.google.common.reflect.ClassPath.ClassInfo> classInfos =
classPath.getTopLevelClassesRecursive(converterPackage);
if (CollectionUtils.isNotEmpty(classInfos)) {
classes = Sets.newHashSet();
for (com.google.common.reflect.ClassPath.ClassInfo classInfo : classInfos) {
Class<?> converterClass = Class.forName(classInfo.getName());
if (Converter.class.isAssignableFrom(converterClass) &&
classInfo.getName().contains(converterPackage)) {
classes.add(converterClass);
}
}
}
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException(format(CONVERTER_LOAD_ERROR, converterPackage), e);
}
return classes;
}
示例7: loadByScanPath
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
protected Collection<Class<T>> loadByScanPath() throws IOException
{
ClassPath classPath;
Set<Class<T>> classes = Sets.newHashSet();
classPath = ClassPath.from(pluginType.getClassLoader());
ImmutableSet<ClassPath.ClassInfo> infos;
infos = classPath.getTopLevelClassesRecursive(packageName);
for (ClassPath.ClassInfo info : infos)
{
Class<?> clazz = info.load();
if (pluginType.isAssignableFrom(clazz))
classes.add((Class<T>) clazz);
}
return classes;
}
示例8: initProviders
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private void initProviders() {
ClassPath classPath;
try {
classPath = ClassPath.from(ProviderContext.class.getClassLoader());
} catch (IOException e) {
throw new RuntimeException(e);
}
Set<ClassInfo> classInfos = classPath.getTopLevelClassesRecursive(basePackage);
for (ClassInfo classInfo : classInfos) {
Class<?> clazz = classInfo.load();
if (clazz.getAnnotation(Provider.class) == null) {
continue;
}
Class<?>[] interfaces = clazz.getInterfaces();
if (interfaces == null || interfaces.length == 0) {
throw new RuntimeException("Must implement interface");
}
Object providerInstance = objenesis.newInstance(clazz);
providerContainer.register(interfaces[0], providerInstance);
registry.register(new Registration(NetUtils.getLocalAddress(), port, interfaces[0].getName()));
}
}
示例9: generate
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
public String generate() throws MojoExecutionException {
final ClassPath classPath = initClassPath();
final Set<ClassInfo> allClasses = classPath.getTopLevelClassesRecursive(prefix);
String diagram = classDiagramBuilder
.addClasse(allClasses.stream()
// apply filters
.filter(defaultFilter())
.filter(additionalClassPredicate)
.map(ClassInfo::load).collect(Collectors.toList()))
.excludes(excludes)
.setHeader(readHeader())
.setFooter(readFooter())
.withNamesMapper(namesMapper)
.withLinkMaker(this)
.withDependencies(diagramWithDependencies)
.build();
return diagram;
}
示例10: getPluginClassInfo
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private static Collection<ClassPath.ClassInfo> getPluginClassInfo(File jar) {
try {
URLClassLoader loader = new URLClassLoader(new URL[] {jar.toURI().toURL()}, PluginLoader.class.getClassLoader());
ClassPath path = ClassPath.from(loader);
return path.getTopLevelClassesRecursive("com.forgehax");
} catch (Throwable t) {
return Collections.emptySet();
}
}
示例11: execute
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
/**
*
* @throws MojoExecutionException
*/
public void execute() throws MojoExecutionException {
getLog().info("start main");
propertyfile = "/home/sap/workspace/Jerkoff/exemple-project/src/main/resources/META-INF/generator.properties";
try {
getLog().info("load " + propertyfile);
Properties prop = PropertiesUtils.loadPropertiesFromAbs(propertyfile);
String packageToScan = PropertiesUtils.getRequiredProperty(prop,
PropertiesUtils.PACKAGE_TO_SCAN);
getLog().info("Scan package: " + packageToScan);
ClassPath classpath = ClassPath.from(getClassLoader());
File sourcePath = new File(
PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.TARGET_FOLDER));
MongoDBDao mongo = new MongoDBDaoImpl(prop);
PojoCreator creator = new PojoCreatorImpl(prop, mongo);
for (ClassPath.ClassInfo classInfo : classpath
.getTopLevelClassesRecursive(packageToScan)) {
Class<?> clazz = classInfo.load();
getLog().info("Creating tests for class " + clazz.getSimpleName());
TypeSpec classTest = creator.getTypeSpec(clazz);
creator.writeJavaFile(sourcePath, clazz, classTest);
}
} catch (Exception e) {
getLog().error(e);
throw new MojoExecutionException(e.getMessage());
}
getLog().info("end main");
}
示例12: findClasses
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private Iterable<Class<?>> findClasses() {
try {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
ClassPath classpath = ClassPath.from(classloader);
ImmutableSet<ClassInfo> xx = classpath.getTopLevelClassesRecursive(CLASSES_PACKAGE);
Iterable<ClassInfo> yy = Iterables.filter(xx, input -> isLuaClass(input));
return Iterables.transform(yy, ClassInfo::load);
} catch (IOException e) {
throw new UndeclaredThrowableException(e);
}
}
示例13: findTestClasses
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private Iterable<Class<?>> findTestClasses() {
try {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
ClassPath classpath = ClassPath.from(classloader);
ImmutableSet<ClassInfo> xx = classpath.getTopLevelClassesRecursive("net.wizardsoflua.tests");
Iterable<ClassInfo> yy = Iterables.filter(xx, input -> hasTestMethod(input));
return Iterables.transform(yy, ClassInfo::load);
} catch (IOException e) {
throw new UndeclaredThrowableException(e);
}
}
示例14: discoverAddons
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private void discoverAddons() throws IOException, InstantiationException, IllegalAccessException
{
final ClassPath classPath = ClassPath.from(Container.class.getClassLoader());
final Set<ClassPath.ClassInfo> classInfos = classPath.getTopLevelClassesRecursive("cloud.orbit.container.addons");
classInfos.stream()
.map(ClassPath.ClassInfo::load)
.filter(c -> !c.isInterface() && Addon.class.isAssignableFrom(c))
.forEach(addonClass ->
{
Addon addon = null;
try
{
addon = (Addon) addonClass.newInstance();
}
catch(Exception e)
{
throw new UncheckedException(e);
}
packagesToScan.addAll(addon.getPackagesToScan());
classesToScan.addAll(addon.getClassesToScan());
discoveredAddons.add(addon);
});
logger.info("Container discovered {} addons.", discoveredAddons.size());
}
示例15: crawlPackages
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void crawlPackages() throws Exception
{
getDiscoveredClasses().clear();
getDiscoveredServices().clear();
final ClassPath classPath = ClassPath.from(Container.class.getClassLoader());
// Scan Packages
final List<String> packages = new ArrayList<>();
final List<String> configPackages = config.getAsList("orbit.container.packages", String.class);
if(configPackages != null) packages.addAll(configPackages);
if(packagesToScan != null) packages.addAll(packagesToScan);
for (final String currentPackage : packages)
{
final Set<ClassPath.ClassInfo> classInfos = classPath.getTopLevelClassesRecursive(currentPackage);
for (final ClassPath.ClassInfo classInfo : classInfos)
{
final Class<?> loadedClass = classInfo.load();
processClass(loadedClass);
}
}
// Scan classes
final List<String> classes = new ArrayList<>();
final List<String> configClasses = config.getAsList("orbit.container.classes", String.class);
if(configClasses != null) classes.addAll(configClasses);
if(classesToScan != null) classes.addAll(classesToScan);
for (final String currentClass : classes)
{
processClass(Class.forName(currentClass));
}
logger.info("Container considered {} classes and discovered {} services.", discoveredClasses.size(), discoveredServices.size());
}