use of io.github.lukehutch.fastclasspathscanner.FastClasspathScanner in project scheduler by btrplace.
the class TestScanner method testGroups.
public List<TestCampaign> testGroups(String... groups) throws IllegalAccessException, InvocationTargetException, InstantiationException {
List<Executable> ms = new ArrayList<>();
Set<String> ok = Stream.of(groups).collect(Collectors.toSet());
FastClasspathScanner scanner = new FastClasspathScanner();
scanner.matchClassesWithMethodAnnotation(CstrTest.class, (cl, m) -> {
CstrTest a = m.getAnnotation(CstrTest.class);
for (String g : a.groups()) {
if (ok.contains(g)) {
ms.add(m);
}
}
}).scan(Runtime.getRuntime().availableProcessors() - 1);
return test(ms.toArray(new Method[ms.size()]));
}
use of io.github.lukehutch.fastclasspathscanner.FastClasspathScanner in project uavstack by uavorg.
the class MSCPProfileHandler method doProfiling.
@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);
}
use of io.github.lukehutch.fastclasspathscanner.FastClasspathScanner in project uavstack by uavorg.
the class ComponentProfileHandler method doProfiling.
@Override
public void doProfiling(ProfileElement elem, ProfileContext context) {
UAVServer.ServerVendor sv = (UAVServer.ServerVendor) UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
// only support JEE Application, not 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;
}
/**
* 1.5 for other none JEE or Spring tech profiling
*/
dubboProfileHandler.doProfiling(elem, context);
/**
* 2.load available annotation classes
*/
Map<String, Class<?>> annoAvailableClasses = new HashMap<String, Class<?>>();
for (String annoClsName : componentClassNames) {
try {
Class<?> c = webappclsLoader.loadClass(annoClsName);
annoAvailableClasses.put(annoClsName, c);
} catch (ClassNotFoundException e) {
// ignore
if (this.logger.isDebugable()) {
this.logger.warn("Annotation Class [" + annoClsName + "] is not found in web application [" + elem.getRepository().getProfile().getId() + "]", e);
}
}
}
/**
* 2.1 load available interface classes
*/
Map<String, Class<?>> interfaceAvailableClasses = new HashMap<String, Class<?>>();
for (String interfaceClsName : componentInterfaceNames) {
try {
Class<?> c = webappclsLoader.loadClass(interfaceClsName);
interfaceAvailableClasses.put(interfaceClsName, c);
} catch (ClassNotFoundException e) {
// ignore
if (this.logger.isDebugable()) {
this.logger.warn("Interface Class [" + interfaceClsName + "] is not found in web application [" + elem.getRepository().getProfile().getId() + "]", e);
}
}
}
/**
* 3. see what kind of components we could get via annotations
*/
UAVServer.ServerVendor vendor = (ServerVendor) UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
/**
* NOTE: currently for spring boot, we use its base classloader as the webappclassloader, and should scan all
* packages
*/
ClassLoader[] classLoaders = null;
if (vendor != UAVServer.ServerVendor.SPRINGBOOT) {
classLoaders = new ClassLoader[] { webappclsLoader };
String scanPackages = System.getProperty("com.creditease.uav.uavmof.profile.package.header");
if (StringHelper.isEmpty(scanPackages)) {
scanPackage[0] = "com";
} else {
scanPackage = scanPackages.split(",");
}
} else {
scanPackage[0] = "";
}
FastClasspathScanner fcs = new FastClasspathScanner(classLoaders, scanPackage);
fcs.scan();
// store FastClasspathScanner instance into ProfileContext
context.put(FastClasspathScanner.class, fcs);
/**
* 4.tide components we get from annotations & deployment descriptors
*/
// store the DescriptorProcessor instance for better performance
Map<String, DescriptorProcessor> dpInstances = new LinkedHashMap<String, DescriptorProcessor>();
// get web application root
InterceptContext itContext = context.get(InterceptContext.class);
String webAppRoot = (String) itContext.get(InterceptConstants.BASEPATH);
for (String componentClassName : componentClassNames) {
// set the instance id = simple name of the annotation class
ProfileElementInstance inst = elem.getInstance(componentClassName);
// load componentsByAnno first
loadComponentsByAnno(context, webappclsLoader, fcs, annoAvailableClasses, componentClassName, inst);
}
for (String componentClassName : componentInterfaceNames) {
// set the instance id = simple name of the annotation class
ProfileElementInstance inst = elem.getInstance(componentClassName);
// load componentsByInterface
loadComponentsByInterface(context, webappclsLoader, fcs, interfaceAvailableClasses, componentClassName, inst);
}
String[] allComponentNames = new String[componentClassNames.length + componentInterfaceNames.length];
System.arraycopy(componentClassNames, 0, allComponentNames, 0, componentClassNames.length);
System.arraycopy(componentInterfaceNames, 0, allComponentNames, componentClassNames.length, componentInterfaceNames.length);
for (String componentClassName : allComponentNames) {
ProfileElementInstance inst = elem.getInstance(componentClassName);
// try to load componentsByDescriptor
loadComponentsByDescriptor(dpInstances, webAppRoot, context, componentClassName, inst);
// try to load componentsByDynamic Creation, currently is for servlet 3.x and webservice
loadComponentsByDynamic(itContext, componentClassName, inst, context, annoAvailableClasses, fcs);
/**
* NOTE: in order to control the monitor data url, we need collect ther servlet url to help to identify if
* an url is a service url
*/
if (componentClassName.equalsIgnoreCase("javax.servlet.annotation.WebServlet")) {
collectServletInfoForMonitor(inst);
}
/**
* collectProfileServiceMap
*/
collectProfileServiceMap(componentClassName, inst);
}
/**
* 4.1 add common info instance from descriptor to profile element
*/
// web.xml related common info
loadCommonInfoFromWebXML(elem, dpInstances, webAppRoot, context);
/**
* 5.confirm there is update
*/
elem.getRepository().setUpdate(true);
// release resources quickly
dpInstances.clear();
}
use of io.github.lukehutch.fastclasspathscanner.FastClasspathScanner in project uavstack by uavorg.
the class FastScanServlet method doGet.
@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);
}
use of io.github.lukehutch.fastclasspathscanner.FastClasspathScanner in project VoxelGamesLibv2 by VoxelGamesLib.
the class VoxelGamesLibModule method getScannerWithAddons.
@Provides
@Named("IncludeAddons")
public FastClasspathScanner getScannerWithAddons(ModuleHandler moduleHandler) {
FastClasspathScanner scanner = getScanner();
moduleHandler.getModuleClassLoaders().forEach(scanner::addClassLoader);
return scanner;
}
Aggregations