当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationDetector.detect方法代码示例

本文整理汇总了Java中eu.infomas.annotation.AnnotationDetector.detect方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationDetector.detect方法的具体用法?Java AnnotationDetector.detect怎么用?Java AnnotationDetector.detect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eu.infomas.annotation.AnnotationDetector的用法示例。


在下文中一共展示了AnnotationDetector.detect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: detect

import eu.infomas.annotation.AnnotationDetector; //导入方法依赖的package包/类
public static void detect(AnnotationDetector ANNOTATION_DETECTOR, String... packageNames) {
    try {
        String libLocation = "lib" + File.separator;
        File[] externalCommands = new File(libLocation + "commands").listFiles();
        if (externalCommands != null) {
            ANNOTATION_DETECTOR.detect(externalCommands);
        }
        if (SystemDefaults.getClassesFromJar.get()) {
            ANNOTATION_DETECTOR.detect(new File(FilePath.getEngineJarPath()));
        } else {
            ANNOTATION_DETECTOR.detect(packageNames);
        }
        ANNOTATION_DETECTOR.detect(new File(FilePath.getAppRoot(), "userdefined"));
    } catch (IOException ex) {
        Logger.getLogger(AnnontationUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:18,代码来源:AnnontationUtil.java

示例2: process

import eu.infomas.annotation.AnnotationDetector; //导入方法依赖的package包/类
public void process(Collection<String> ... pkgs) {

		List<String> packages = Lists.newArrayList();

		for (Collection<String> p : pkgs) {
			packages.addAll(p);
		}

		final AnnotationDetector cf = new AnnotationDetector(new TaskAnnotationReporter());
		try {

			// Full classpath
			if (packages == null || packages.size() == 0) {
				logger.debug("Processing Sorcerer annotations in full classpath");
				cf.detect();
				return;
			}

			for (String pkg : packages) {
				logger.debug("Processing Sorcerer annotations in package " + pkg);
				cf.detect(pkg);
			}

		} catch (IOException e) {
			logger.error("Could not successfully process Annotations", e);
		}
	}
 
开发者ID:turn,项目名称:sorcerer,代码行数:28,代码来源:InfomasAnnotationProcessor.java

示例3: startScan

import eu.infomas.annotation.AnnotationDetector; //导入方法依赖的package包/类
private static Set<Class<?>> startScan(final Set<Class<?>> classes,
                                       final Reporter reporter, String... packageNames) {
    final AnnotationDetector cf = new AnnotationDetector(reporter);
    try {
        if (packageNames.length == 0) {
            // 解决在web容器下扫描不到类的问题.
            URL url = Thread.currentThread().getContextClassLoader()
                    .getResource("");
            File file = new File(url.getPath());
            File[] files = file.listFiles(new FileFilter() {

                @Override
                public boolean accept(File pathname) {
                    return pathname.isDirectory() && !pathname.isHidden();
                }
            });
            List<String> fileNames = new LinkedList<>();
            for (File one : files) {
                fileNames.add(one.getName());
            }
            LOG.debug("san path:{}", fileNames);
            cf.detect(ArrayUtils.toStringArray(fileNames));
            // FIXME 这里扫描全部可能会有性能问题
            // XXX 在java项目中可以扫描到jar文件中的类,在web项目中不行.
            cf.detect();
        } else {
            cf.detect(packageNames);
        }
    } catch (IOException e) {
        LOG.error("scan package error packages:{}",
                Arrays.toString(packageNames));
    }
    return classes;
}
 
开发者ID:fivesmallq,项目名称:web-data-extractor,代码行数:35,代码来源:AnnotationClassScanner.java

示例4: init

import eu.infomas.annotation.AnnotationDetector; //导入方法依赖的package包/类
/**
 * Scan the requested packages on the classpath for HK2 'Service' and 'Contract' annotated classes.
 * Load the metadata for those classes into the HK2 Service Locator.
 * 
 * This implementation should support all Annotations that are supported by HK2 - however - if you are using 
 * HK2 older than 2.3.0 - note that it is impacted by this bug:  https://java.net/jira/browse/HK2-187
 * 
 * For an implementation that is not impacted by that bug, see {@link HK2RuntimeInitializerCustom}
 * 
 * @see org.glassfish.hk2.api.ServiceLocatorFactory#create(String)
 * @see ServiceLocatorUtilities#createAndPopulateServiceLocator(String)
 * 
 * @param serviceLocatorName - The name of the ServiceLocator to find (or create if it doesn't yet exist)  
 * @param readInhabitantFiles - Read and process inhabitant files before doing the classpath scan.  Annotated items
 * found during the scan will override items found in the inhabitant files, if they collide.  
 * @param packageNames -- The set of package names to scan recursively - for example - new String[]{"org.foo", "com.bar"}
 * If not provided, the entire classpath is scanned 
 * @return - The created ServiceLocator (but in practice, you can lookup this ServiceLocator by doing:
 * <pre>
 * {@code
 * ServiceLocatorFactory.getInstance().create("SomeName");
 * }
 * </pre>
 * @throws IOException
 * @throws ClassNotFoundException
 */
public static ServiceLocator init(String serviceLocatorName, boolean readInhabitantFiles, String ... packageNames) throws IOException, ClassNotFoundException 
{
	AnnotatedClasses ac = new AnnotatedClasses();
	
	@SuppressWarnings("unchecked")
	AnnotationDetector cf = new AnnotationDetector(new AnnotationReporter(ac, new Class[]{Service.class}));
	if (packageNames == null || packageNames.length == 0)
	{
		cf.detect();
	}
	else
	{
		cf.detect(packageNames);
	}
	
	ServiceLocator locator = null;
	
	if (readInhabitantFiles)
	{
		locator = ServiceLocatorUtilities.createAndPopulateServiceLocator(serviceLocatorName);
	}
	else
	{
		ServiceLocatorFactory factory = ServiceLocatorFactory.getInstance();
		locator = factory.create(serviceLocatorName);
	}

	for (ActiveDescriptor<?> ad : ServiceLocatorUtilities.addClasses(locator, ac.getAnnotatedClasses()))
	{
		log.debug("Added " + ad.toString());
	}
	
	return locator;
}
 
开发者ID:darmbrust,项目名称:HK2Utilities,代码行数:61,代码来源:HK2RuntimeInitializer.java

示例5: run

import eu.infomas.annotation.AnnotationDetector; //导入方法依赖的package包/类
@Override
protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception {

    final CouchbaseClientFactory factory = strategy.getCouchbaseClientFactory(configuration);
    factory.start();

    log.info("Let's see if we can find any Resource classes ...");
    final AnnotationDetector.FieldReporter reporter = new AnnotationDetector.FieldReporter() {

        @Override
        public void reportFieldAnnotation(Class<? extends Annotation> annotation, String className, String fieldName) {
            log.info("Annotation: " + annotation.getSimpleName() + " ClassName: " + className + " FieldName: " + fieldName);
            Field field = null;
            try {
                field = Class.forName(className).getDeclaredField(fieldName);
                log.info("Field type is: " + field.getType().getSimpleName());
                AccessorFactory.getFactory().getAccessor(field.getType(), factory);
            } catch (Exception e) {
                log.error("Unable to retrieve annotated field.", e);
            }
        }

        @Override
        public Class<? extends Annotation>[] annotations() {
            return new Class[] {Accessor.class};
        }
    };

    final AnnotationDetector cf = new AnnotationDetector(reporter);
    cf.detect();

    factory.stop();

}
 
开发者ID:smartmachine,项目名称:dropwizard-couchbase,代码行数:35,代码来源:CouchbaseInitCommand.java

示例6: startScan

import eu.infomas.annotation.AnnotationDetector; //导入方法依赖的package包/类
private static Set<Class<?>> startScan(final Set<Class<?>> classes,
		final Reporter reporter, String... packageNames) {
	final AnnotationDetector cf = new AnnotationDetector(reporter);
	try {
		if (packageNames.length == 0) {
			// 解决在web容器下扫描不到类的问题.
			URL url = Thread.currentThread().getContextClassLoader()
					.getResource("");
			File file = new File(url.getPath());
			File[] files = file.listFiles(new FileFilter() {

				@Override
				public boolean accept(File pathname) {
					return pathname.isDirectory() && !pathname.isHidden();
				}
			});
			List<String> fileNames = new ArrayList<String>();
			for (File one : files) {
				fileNames.add(one.getName());
			}
			LOG.debug("san path:{}", fileNames);
			cf.detect(toStringArray(fileNames));
			// FIXME 这里扫描全部可能会有性能问题
			// XXX 在java项目中可以扫描到jar文件中的类,在web项目中不行.
			cf.detect();
		} else {
			cf.detect(packageNames);
		}
	} catch (IOException e) {
		LOG.error("scan package error packages:{}",
				Arrays.toString(packageNames));
	}
	return classes;
}
 
开发者ID:fivesmallq,项目名称:guice-ext,代码行数:35,代码来源:AnnotationClassScanner.java


注:本文中的eu.infomas.annotation.AnnotationDetector.detect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。