當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。