本文整理汇总了Java中io.github.lukehutch.fastclasspathscanner.FastClasspathScanner.scan方法的典型用法代码示例。如果您正苦于以下问题:Java FastClasspathScanner.scan方法的具体用法?Java FastClasspathScanner.scan怎么用?Java FastClasspathScanner.scan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.github.lukehutch.fastclasspathscanner.FastClasspathScanner
的用法示例。
在下文中一共展示了FastClasspathScanner.scan方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: it_should_find_handlers
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
@Test
public void it_should_find_handlers() throws Exception {
TestService service = new TestService();
service.initializeGuice();
FastClasspathScanner scanner = new FastClasspathScanner();
ScanResult scanResult = scanner.scan();
List<String> rpcHandlers = scanResult.getNamesOfClassesWithAnnotation(RpcHandler.class);
service.registerMethodHandlers(rpcHandlers);
Map<String, ServiceMethodHandler<? extends Message, ? extends Message>> s = service.getMethodHandlers();
assertThat(s.size() == 2);
assertThat(s.containsKey("Test.handler1"));
assertThat(s.containsKey("Test.handler2"));
assertThat(s.get("Test.handler1").getClass().equals(TestHandler.class));
assertThat(s.get("Test.handler2").getClass().equals(TestHandler2.class));
}
示例2: getInstance
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
public static OrchidFlags getInstance() {
if (instance == null) {
List<OrchidFlag> orchidFlags = new ArrayList<>();
FastClasspathScanner scanner = new FastClasspathScanner();
scanner.matchClassesImplementing(OrchidFlag.class, (matchingClass) -> {
try {
OrchidFlag option = matchingClass.newInstance();
if (option != null) {
orchidFlags.add(option);
}
}
catch (Exception e) {
e.printStackTrace();
}
});
scanner.scan();
instance = new OrchidFlags(orchidFlags);
}
return instance;
}
示例3: getClassesImplementing
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "rawtypes" }) // Raw types usage due to awkward generics API.
public Iterable<Class<?>> getClassesImplementing(final Class<?> root, final Class<?>... interfaces) {
final Set<Class<?>> classes = new HashSet<>();
final FastClasspathScanner scanner = new FastClasspathScanner(root.getPackage().getName());
for (final Class<?> implemented : interfaces) {
scanner.matchClassesImplementing(implemented, new InterfaceMatchProcessor() {
@Override
public void processMatch(final Class implementingClass) {
if (!Modifier.isAbstract(implementingClass.getModifiers()) && !implementingClass.isInterface()) {
classes.add(implementingClass);
}
}
});
}
scanner.scan();
return classes;
}
示例4: loadModule
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
private ObjectNode loadModule(final String moduleName) throws TmcException {
final List<ObjectNode> modules = new ArrayList<>();
FileMatchProcessor fileMatchProcessor = new FileMatchProcessor() {
@Override
public void processMatch(String relativePath, InputStream inputStream, long lengthBytes) throws IOException {
modules.add((ObjectNode) MAPPER.readTree(inputStream));
}
};
FastClasspathScanner scanner = new FastClasspathScanner();
for (String suffix : VALID_FILE_SUFFIXES) {
scanner.matchFilenamePathLeaf(moduleName + suffix, fileMatchProcessor);
}
scanner.scan();
if (modules.isEmpty()) {
throw new TmcException("cannot find tmc module: " + moduleName);
}
if (modules.size() > 1) {
throw new TmcException("classpath contains more than one module " + moduleName);
}
return modules.get(0);
}
示例5: fromPackage
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
public static ObjectNode fromPackage(String packageName) {
ObjectNode generatedContext = JsonNodeFactory.withExactBigDecimals(true).objectNode();
FastClasspathScanner scanner = new FastClasspathScanner(packageName);
scanner.matchAllStandardClasses((clazz) -> {
if(!Modifier.isAbstract(clazz.getModifiers()) && AnnotationsUtils.isAnnotationPresent(clazz, JsonldTypeFromJavaClass.class)) {
Optional<String> type = JsonldResourceUtils.dynamicTypeLookup(clazz);
type.ifPresent(t ->generatedContext.set(clazz.getSimpleName(), TextNode.valueOf(t)));
}
if(AnnotationsUtils.isAnnotationPresent(clazz, ioinformarics.oss.jackson.module.jsonld.annotation.JsonldResource.class)) {
Optional<ObjectNode> resourceContext = fromAnnotations(clazz);
resourceContext.ifPresent((context) -> JsonUtils.merge(generatedContext, context));
}
});
scanner.scan();
return (ObjectNode) JsonNodeFactory.withExactBigDecimals(true).objectNode().set("@context", generatedContext);
}
示例6: findClassesAnnotatedWith
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
@Override
public Array<Class<?>> findClassesAnnotatedWith(final Class<?> root,
final Iterable<Class<? extends Annotation>> annotations) {
final ObjectSet<Class<?>> result = GdxSets.newSet(); // Using set to remove duplicates.
final FastClasspathScanner scanner = new FastClasspathScanner(root.getPackage().getName(),
AutumnRoot.class.getPackage().getName());
for (final Class<? extends Annotation> annotation : annotations) {
scanner.matchClassesWithAnnotation(annotation, new ClassAnnotationMatchProcessor() {
@Override
public void processMatch(final Class<?> matchingClass) {
result.add(matchingClass);
}
});
}
scanner.scan();
return GdxArrays.newArray(result);
}
示例7: getGeneratedProtoClasses
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
public List<String> getGeneratedProtoClasses(String serviceName) {
FastClasspathScanner cpScanner = new FastClasspathScanner();
ScanResult scanResult = cpScanner.scan();
List<String> oldProtobuf = scanResult.getNamesOfSubclassesOf(GeneratedMessage.class);
List<String> newProtobuf = scanResult.getNamesOfSubclassesOf(GeneratedMessageV3.class);
List<String> retval = Stream.concat(oldProtobuf.stream(),
newProtobuf.stream()).collect(Collectors.toList());
String[] packageTokens = serviceName.split("\\.");
return retval.stream().filter(s -> protoFilePackageMatches(s, packageTokens)).collect(Collectors.toList());
}
示例8: doInstallDProxy
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
public void doInstallDProxy(ClassLoader webapploader, final String appid, String contextPath) {
// like SMS, which uses the sun jax-ws RI/Metro-jax-ws RI bind webservices when the servlet starts should
// profile in ComponentProfileHandler
FastClasspathScanner fcs = new FastClasspathScanner(new ClassLoader[] { webapploader });
fcs.scan();
List<String> endPoints = fcs.getNamesOfDirectSubclassesOf("javax.xml.ws.Endpoint");
if (!endPoints.isEmpty()) {
dpInstall.setTargetClassLoader(webapploader);
for (int i = 0; i < endPoints.size(); i++) {
dpInstall.installProxy(endPoints.get(i),
new String[] { "com.creditease.uav.monitorframework.webservice.interceptors" },
new DynamicProxyProcessor() {
@Override
public void process(DPMethod m) throws Exception {
if ("publish".equals(m.getName()) && m.getParameterTypes().length > 0
&& m.getParameterTypes()[0].getSimpleName().equals("String")) {
dpInstall.defineLocalVal(m, "mObj", WebServiceListenerIT.class);
m.insertBefore("{mObj=new WebServiceListenerIT(\"" + appid
+ "\");mObj.obtainWsInfo($1,getImplementor());}");
}
}
}, false);
}
// release loader
dpInstall.releaseTargetClassLoader();
}
}
示例9: doGet
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
FastClasspathScanner scanner = new FastClasspathScanner("com.creditease");
long st = System.nanoTime();
FastClasspathScanner scannerm1 = scanner.scan();
long end = System.nanoTime() - st;
System.out.println(end);
List<String> lista = scannerm1.getNamesOfClassesWithAnnotation(WebService.class);
for (String str : lista) {
System.out.println("webservice m1 -" + str);
}
st = System.nanoTime();
FastClasspathScanner scanner2 = new FastClasspathScanner("com.creditease");
scanner2.matchClassesWithAnnotation(WebService.class, new ClassAnnotationMatchProcessor() {
@SuppressWarnings("rawtypes")
@Override
public void processMatch(Class arg0) {
System.out.println("webservice m1 -" + arg0.getName());
}
}).scan();
end = System.nanoTime() - st;
System.out.println(end);
resp.getWriter().write("FastClasspathScanner cost:" + end);
}
示例10: configure
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
@Override
protected void configure() {
final StringBuilder moduleLog = new StringBuilder();
moduleLog.append("Auto-loading modules: ");
moduleLog.append("\n--------------------");
FastClasspathScanner scanner = new FastClasspathScanner();
scanner.matchClassesImplementing(Module.class, (matchingClass) -> {
if (isInstantiable(matchingClass)) {
try {
Module provider = matchingClass.newInstance();
if (provider != null) {
install(provider);
if (!provider.getClass().getName().startsWith("com.eden.orchid.OrchidModule")) {
moduleLog.append("\n * " + provider.getClass().getName());
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
});
scanner.scan();
moduleLog.append("\n--------------------");
Clog.i(moduleLog.toString());
}
示例11: getClassesImplementing
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
@Override
public Iterable<Class<?>> getClassesImplementing(final Class<?> root, final Class<?>... interfaces) {
final Set<Class<?>> classes = new HashSet<>();
final FastClasspathScanner scanner = new FastClasspathScanner(root.getPackage().getName());
Stream.of(interfaces).forEach(implemented -> scanner.matchClassesImplementing(implemented,
implementingClass -> process(implementingClass, classes)));
scanner.scan();
return classes;
}
示例12: findClasses
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
/**
* @return mapping from annotation class to list of classes with that annotation (on the classpath)
*/
public static Map<Class<?>, List<Class<?>>> findClasses(String packageName, Class<? extends java.lang.annotation.Annotation>... annotations) {
Map<Class<?>, List<Class<?>>> map = new HashMap<>();
FastClasspathScanner scanner = new FastClasspathScanner(packageName);
for (Class<? extends Annotation> annotationClass : annotations) {
map.put(annotationClass, new ArrayList<>());
scanner.matchClassesWithAnnotation(annotationClass, map.get(annotationClass)::add);
}
scanner.scan();
return map;
}
示例13: doProfiling
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入方法依赖的package包/类
@Override
public void doProfiling(ProfileElement elem, ProfileContext context) {
UAVServer.ServerVendor sv = (UAVServer.ServerVendor) UAVServer.instance()
.getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
// only support MSCP Application
if (sv != UAVServer.ServerVendor.MSCP) {
return;
}
if (!ProfileConstants.PROELEM_COMPONENT.equals(elem.getElemId())) {
return;
}
InterceptContext ic = context.get(InterceptContext.class);
if (ic == null) {
this.logger.warn("Profile:Annotation FAILs as No InterceptContext available", null);
return;
}
/**
* 1. get webappclassloader
*/
ClassLoader webappclsLoader = (ClassLoader) ic.get(InterceptConstants.WEBAPPLOADER);
if (null == webappclsLoader) {
this.logger.warn("Profile:JARS FAILs as No webappclsLoader available", null);
return;
}
Collection<ClassLoader> clList = ConfigurationManager.getInstance().getFeatureClassLoader();
clList.add(webappclsLoader);
ClassLoader[] allcl = new ClassLoader[clList.size()];
allcl = clList.toArray(allcl);
/**
* 2. see what kind of components we could get via annotations or interface or parentClass
*/
FastClasspathScanner fcs = new FastClasspathScanner(allcl, "com.creditease.uav", "com.creditease.agent",
"org.uavstack");
fcs.scan();
/**
* 3. get MSCPServlets profile info
*/
InterceptContext itContext = context.get(InterceptContext.class);
String appRootPath = (String) itContext.get(InterceptConstants.BASEPATH);
String appName = (String) itContext.get(InterceptConstants.APPNAME);
for (String componentClassName : componentClassMap.keySet()) {
// set the instance id = simple name of the annotation class
ProfileElementInstance inst = elem.getInstance(componentClassName);
ComponentProcessor cp = componentClassMap.get(componentClassName);
cp.handle(componentClassName, appName, inst, fcs);
}
/**
* 4. load application info
*/
loadAppInfo(elem, appRootPath, appName);
}