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


Java FastClasspathScanner类代码示例

本文整理汇总了Java中io.github.lukehutch.fastclasspathscanner.FastClasspathScanner的典型用法代码示例。如果您正苦于以下问题:Java FastClasspathScanner类的具体用法?Java FastClasspathScanner怎么用?Java FastClasspathScanner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: findConstructors

import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入依赖的package包/类
private void findConstructors(Consumer<Class<?>> actionPerClass, String packagePrefix, Class<? extends Annotation> annotationClass) {
    LOGGER.info("Finding all classes in {} with {} constructors",
            packagePrefix, annotationClass.getCanonicalName());

    List<Class> injectableClass = new ArrayList<>();
    new FastClasspathScanner(packagePrefix)
            .matchClassesWithMethodAnnotation(
                    annotationClass,
                    (matchingClass, matchingMethod) -> {
                        injectableClass.add(matchingClass);
                    })
            .scan();

    injectableClass.forEach(clazz -> {
        actionPerClass.accept(clazz);
        LOGGER.info(clazz.getCanonicalName());
    });
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:19,代码来源:GuiceTest.java

示例2: deployToResteasy

import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入依赖的package包/类
@Override
public Single<Void> deployToResteasy(VertxResteasyDeployment deployment) {
	JsonArray packages = AppGlobals.get().getConfig().getJsonArray("scan");
	if(packages == null) {
		System.err.println("Not scanning any packages, please specify the 'scan' array of packages in configuration");
	}else {
		String[] packagesToScan = (String[]) packages.getList().toArray(new String[packages.size()+1]);
		packagesToScan[packagesToScan.length-1] = "net.redpipe.engine";
		new FastClasspathScanner(packagesToScan)
			.matchClassesWithAnnotation(Path.class, klass -> {
				if(!Modifier.isAbstract(klass.getModifiers()))
					deployment.getActualResourceClasses().add(klass);
			})
			.matchClassesWithAnnotation(Provider.class, klass -> {
				if(!Modifier.isAbstract(klass.getModifiers()))
					deployment.getActualProviderClasses().add(klass);
			})
			.scan();
	}
	return Single.just(null);
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:22,代码来源:FCSPlugin.java

示例3: populateParsersFromClasspath

import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入依赖的package包/类
public Map<MessageType, Parser<com.google.protobuf.Message>> populateParsersFromClasspath() {
    Map<MessageType, Parser<com.google.protobuf.Message>> parsers = new HashMap<>();
    List<Class<? extends com.google.protobuf.GeneratedMessageV3>> foundProtoMessages = new ArrayList<>();

    new FastClasspathScanner()
            .matchSubclassesOf(com.google.protobuf.GeneratedMessageV3.class, matchingClass ->
                    foundProtoMessages.add(matchingClass)).scan();

    // This algorithm adds parsers for all protobuf messages in the classpath including base types such as com.google.protobuf.DoubleValue.
    for (Class<? extends com.google.protobuf.GeneratedMessageV3> clazz : foundProtoMessages) {
        try {
            java.lang.reflect.Method method = clazz.getMethod("parser"); // static method, no arguments
            @SuppressWarnings("unchecked")
            Parser<com.google.protobuf.Message> parser = (Parser<com.google.protobuf.Message>) method.invoke(null, (Object[]) null); // static method, no arguments
            parsers.put(MessageType.of(clazz), parser);

            // too noisy: logger.debug("Added parser for protobuf type {}", clazz.getTypeName());

        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {
            // too noisy: logger.debug("Ignoring protobuf type {} as we cannot invoke static method parse().", clazz.getTypeName());
        }
    }

    return parsers;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:26,代码来源:ReflectionTypeDictionaryFactory.java

示例4: 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));
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:19,代码来源:AbstractServiceAutomaticHandlerRegistrationTest.java

示例5: scanClasspathForMappings

import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入依赖的package包/类
protected void scanClasspathForMappings(String basePackage) {
    FastClasspathScanner scanner = new FastClasspathScanner(basePackage);
    scanner.matchClassesWithAnnotation(ContentItemMapping.class, classWithAnnotation -> {
        ContentItemMapping contentItemMapping = classWithAnnotation.getAnnotation(ContentItemMapping.class);
        registerType(contentItemMapping.value(), classWithAnnotation);
    }).matchSubclassesOf(InlineContentItemsResolver.class, subclass -> {
        try {
            registerInlineContentItemsResolver(ConstructorUtils.invokeConstructor(subclass, null));
        } catch (NoSuchMethodException |
                IllegalAccessException |
                InvocationTargetException |
                InstantiationException e) {
            // No default constructor, no InlineContentItemsResolver.
        }
    }).scan();
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:17,代码来源:StronglyTypedContentItemConverter.java

示例6: HashClassfileContents

import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入依赖的package包/类
public HashClassfileContents(String... packagePrefixesToScan) {
    this.classNameToClassfileHash = new HashMap<String, String>();
    this.scanner = new FastClasspathScanner(packagePrefixesToScan)
    // MD5-hash all files ending in ".class"
            .matchFilenameExtension("class", new FileMatchProcessor() {
                @Override
                public void processMatch(String relativePath, InputStream inputStream, int length)
                        throws IOException {
                    final MessageDigest digest;
                    try {
                        digest = MessageDigest.getInstance("MD5");
                    } catch (NoSuchAlgorithmException e) {
                        throw new RuntimeException(e);
                    }
                    final byte[] buffer = new byte[8192];
                    for (int read; (read = inputStream.read(buffer)) > 0;) {
                        digest.update(buffer, 0, read);
                    }
                    String hash = "0000000000000000000000000000000"
                            + new BigInteger(1, digest.digest()).toString(16);
                    String className = relativePath.substring(0, relativePath.length() - 6).replace('/', '.');
                    classNameToClassfileHash.put(className, hash.substring(hash.length() - 32));
                }
            });
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:26,代码来源:HashClassfileContents.java

示例7: createCommandHandler

import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入依赖的package包/类
private CommandHandler createCommandHandler(String command,
        ServerParameters serverParameters, CommandConfiguration configuration) {
    final List<Class<?>> handlers = new ArrayList<>();
    new FastClasspathScanner(HANDLER_PACKAGE)
            .matchClassesWithAnnotation(Command.class, handlers::add).scan();
    Class<?> handler = null;
    Command annotation = null;
    for (Class<?> handlerClass : handlers) {
        annotation = handlerClass.getAnnotation(Command.class);
        if (Arrays.stream(annotation.command()).anyMatch(command::equals)) {
            handler = handlerClass;
            break;
        }
    }
    if (handler == null) {
        throw new ApplicationException(
                MessageConstants.getMessage(ERROR_COMMAND_HANDLER_NOT_FOUND, command));
    }
    try {
        return instatiateCommandHandler(serverParameters, configuration, handler, annotation);
    } catch (InstantiationException | IllegalAccessException e) {
        throw new ApplicationException(MessageConstants.getMessage(ERROR_LOAD_HANDLER_CLASS,
                handler.getName()), e);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:26,代码来源:CommandManager.java

示例8: getSubtypes

import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入依赖的package包/类
public static Class<?>[] getSubtypes(Class clazz) {
  Set<Class<? extends AbstractConfig>> classSet = new HashSet();
  FastClasspathScanner s = new FastClasspathScanner();
  s.scan().getNamesOfSubclassesOf(clazz).forEach(c -> {
    try {
      classSet.add((Class<? extends AbstractConfig>) Class.forName(c));
    } catch (ClassNotFoundException e) {
    }
  });

  /*
   * Remove abstract classes as they are not allowed in the mapper
   */
  classSet.removeIf(p -> Modifier.isAbstract(p.getModifiers()) == true);

  return classSet.toArray(new Class<?>[classSet.size()]);
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:18,代码来源:AbstractConfig.java

示例9: 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;
}
 
开发者ID:JavaEden,项目名称:Orchid,代码行数:22,代码来源:OrchidFlags.java

示例10: create

import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入依赖的package包/类
/**
 * Create new instance of a ApplicationContext.
 * <ul>
 * <li>Create ApplicationContext with default configurations</li>
 * <li>Load default Injectors from classpath</li>
 * </ul>
 *
 * @return Returns an instance of {@link ApplicationContext}.
 */
public static ApplicationContext create() {
  ApplicationContext ctx = create(ApplicationContext.create());

  String ignoreInjectors = System.getProperty(Keys.IGNORE_AUTO_INJECTORS, Boolean.FALSE.toString());
  if (!Boolean.TRUE.toString().equals(ignoreInjectors)) {
    new FastClasspathScanner(StringUtils.EMPTY).matchClassesImplementing(InjectorAdapter.class, c -> {

      try {
        InjectorAdapter injector = c.newInstance();
        ctx.addInjector(injector);
      } catch (Exception e) {
        // ignore invalid injector
      }
    }).scan();
  }
  return ctx;
}
 
开发者ID:jspare-projects,项目名称:jspare-container,代码行数:27,代码来源:Environment.java

示例11: 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;
}
 
开发者ID:czyzby,项目名称:uedi,代码行数:19,代码来源:DefaultClassScanner.java

示例12: 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);
}
 
开发者ID:yeagy,项目名称:tmc,代码行数:24,代码来源:Compositor.java

示例13: 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);
}
 
开发者ID:io-informatics,项目名称:jackson-jsonld,代码行数:17,代码来源:JsonldContextFactory.java

示例14: 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);
}
 
开发者ID:czyzby,项目名称:gdx-lml,代码行数:18,代码来源:DesktopClassScanner.java

示例15: scanClasspath

import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; //导入依赖的package包/类
public ScanResult scanClasspath() {
    if (scanResult == null) {
        System.out.println("Scanning classpath");
        final Date scanStart = new Date();
        final ScanResult result = new FastClasspathScanner()
                .overrideClasspath((Object[])classLoader.getURLs())
                .verbose(verbose)
                .scan();
        final int count = result.getNamesOfAllClasses().size();
        final Date scanEnd = new Date();
        final double timeInSeconds = (scanEnd.getTime() - scanStart.getTime()) / 1000.0;
        System.out.println(String.format("Scanning finished in %.2f seconds. Total number of classes: %d.", timeInSeconds, count));
        scanResult = result;
    }
    return scanResult;
}
 
开发者ID:vojtechhabarta,项目名称:typescript-generator,代码行数:17,代码来源:Input.java


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