本文整理汇总了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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}