本文整理汇总了Java中org.reflections.util.ConfigurationBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationBuilder类的具体用法?Java ConfigurationBuilder怎么用?Java ConfigurationBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationBuilder类属于org.reflections.util包,在下文中一共展示了ConfigurationBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GuiceApplication
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
protected GuiceApplication(String... basePackages) {
final ConfigurationBuilder confBuilder = new ConfigurationBuilder();
final FilterBuilder filterBuilder = new FilterBuilder();
if (basePackages.length == 0) {
basePackages = new String[] {};
}
logger.info("op=create, auto_scan_packages={}", (Object[]) basePackages);
for (String pkg : basePackages) {
confBuilder.addUrls(ClasspathHelper.forPackage(pkg));
filterBuilder.include(FilterBuilder.prefix(pkg));
}
confBuilder.filterInputsBy(filterBuilder)
.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
this.reflections = new Reflections(confBuilder);
}
示例2: fromConfigWithPackage
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
/**
* Scans the specified packages for annotated classes, and applies Config values to them.
*
* @param config the Config to derive values from
* @param packageNamePrefix the prefix to limit scanning to - e.g. "com.github"
* @return The constructed TypesafeConfigModule.
*/
public static TypesafeConfigModule fromConfigWithPackage(Config config, String packageNamePrefix) {
ConfigurationBuilder configBuilder =
new ConfigurationBuilder()
.filterInputsBy(new FilterBuilder().includePackage(packageNamePrefix))
.setUrls(ClasspathHelper.forPackage(packageNamePrefix))
.setScanners(
new TypeAnnotationsScanner(),
new MethodParameterScanner(),
new MethodAnnotationsScanner(),
new FieldAnnotationsScanner()
);
Reflections reflections = new Reflections(configBuilder);
return new TypesafeConfigModule(config, reflections);
}
示例3: prepareAndgetContextListener
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
/**
* Prepares the logger context. Locates the context and
* sets the configuration file.
* @return the logger context
*/
private ServletContextListener prepareAndgetContextListener() {
try {
if (StringUtils.isNotBlank(this.loggerContextPackageName)) {
final Collection<URL> set = ClasspathHelper.forPackage(this.loggerContextPackageName);
final Reflections reflections = new Reflections(new ConfigurationBuilder().addUrls(set).setScanners(new SubTypesScanner()));
final Set<Class<? extends ServletContextListener>> subTypesOf = reflections.getSubTypesOf(ServletContextListener.class);
final ServletContextListener loggingContext = subTypesOf.iterator().next().newInstance();
this.context.setInitParameter(this.logConfigurationField, this.logConfigurationFile.getURI().toString());
return loggingContext;
}
return null;
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
示例4: getCasBannerInstance
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
/**
* Gets cas banner instance.
*
* @return the cas banner instance
*/
public static Banner getCasBannerInstance() {
final String packageName = CasEmbeddedContainerUtils.class.getPackage().getName();
final Reflections reflections =
new Reflections(new ConfigurationBuilder()
.filterInputsBy(new FilterBuilder().includePackage(packageName))
.setUrls(ClasspathHelper.forPackage(packageName))
.setScanners(new SubTypesScanner(true)));
final Set<Class<? extends AbstractCasBanner>> subTypes = reflections.getSubTypesOf(AbstractCasBanner.class);
subTypes.remove(DefaultCasBanner.class);
if (subTypes.isEmpty()) {
return new DefaultCasBanner();
}
try {
final Class<? extends AbstractCasBanner> clz = subTypes.iterator().next();
LOGGER.debug("Created banner [{}]", clz);
return clz.newInstance();
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return new DefaultCasBanner();
}
示例5: generateReport
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
public void generateReport(String packageName,List<String> flagList) throws IOException
{
URL testClassesURL = Paths.get("target/test-classes").toUri().toURL();
URLClassLoader classLoader = URLClassLoader.newInstance(new URL[]{testClassesURL},
ClasspathHelper.staticClassLoader());
reflections = new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage(packageName,classLoader))
.addClassLoader(classLoader)
.filterInputsBy(new FilterBuilder().includePackage(packageName))
.setScanners(new MethodAnnotationsScanner(), new TypeAnnotationsScanner(), new SubTypesScanner())
);
List<Map<String, TestClass>> list = new ArrayList<>();
for (String flag : flagList)
{
list.add(printMethods(flag));
}
Gson gson = new Gson();
String overviewTemplate = IOUtils.toString(getClass().getResourceAsStream("/index.tpl.html"));
String editedTemplate = overviewTemplate.replace("##TEST_DATA##", gson.toJson(list));
FileUtils.writeStringToFile(new File("target/test-list-html-report/index.html"), editedTemplate);
logger.info("report file generated");
}
示例6: ReflectionsServiceDiscovery
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
public ReflectionsServiceDiscovery(String resourceSearchPackages, JsonServiceLocator locator) {
this.locator = locator;
ConfigurationBuilder builder = new ConfigurationBuilder();
PreconditionUtil.assertNotNull("no resourceSearchPackage configured", resourceSearchPackages);
FilterBuilder filter = new FilterBuilder();
for (String resourceSearchPackage : resourceSearchPackages.split(",")) {
builder = builder.addUrls(ClasspathHelper.forPackage(resourceSearchPackage));
filter.includePackage(resourceSearchPackage);
}
filter.includePackage(Repository.class.getPackage().getName());
filter.includePackage(ResourceRepository.class.getPackage().getName());
builder = builder.filterInputsBy(filter);
builder = builder.addUrls(ClasspathHelper.forClass(Repository.class));
builder = builder.addUrls(ClasspathHelper.forClass(ResourceRepository.class));
builder = builder.addUrls(ClasspathHelper.forClass(ResourceRepositoryV2.class));
builder = builder.setScanners(new SubTypesScanner(false), new TypeAnnotationsScanner());
reflections = new Reflections(builder);
}
示例7: CommandHandler
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
public CommandHandler() {
try {
Set<URL> classPathList = new HashSet<>();
classPathList.addAll(ClasspathHelper.forJavaClassPath());
Set<Class<? extends Command>> result = new Reflections(
new ConfigurationBuilder().setScanners(new SubTypesScanner()).setUrls(classPathList))
.getSubTypesOf(Command.class);
for (Class<? extends Command> c : result) {
String[] categoryString = c.getPackage().toString().split("\\.");
String category = categoryString[categoryString.length - 1];
if (category.equalsIgnoreCase("commands")) {
category = "default";
}
Command command = c.newInstance();
command.getSettings().setCategory(category);
commands.add(command);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: concreteSubTypesOf
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
private static <T> List<Class<? extends T>> concreteSubTypesOf(final Class<? extends T> clazz) {
final ConfigurationBuilder conf = new ConfigurationBuilder()
.setUrls(ClasspathHelper.forClass(clazz))
.setScanners(new SubTypesScanner(true));
final Reflections reflections = new Reflections(conf);
final List<Class<? extends T>> result = new ArrayList<>();
for (final Class<? extends T> type : reflections.getSubTypesOf(clazz)) {
if (type.isInterface()) {
continue;
}
if (Modifier.isAbstract(type.getModifiers())) {
continue;
}
result.add(type);
}
return result;
}
示例9: tweetEntities
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
@Test
public void tweetEntities() {
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forJavaClassPath())
.forPackages(TweetEntity.class.getPackage().getName())
);
List<Class<?>> allClasses = new ArrayList<>();
List<Class<? extends TweetEntity>> classes = list(reflections, TweetEntity.class);
allClasses.add(MediaEntity.Variant.class);
allClasses.add(MediaEntity.Size.class);
allClasses.addAll(classes);
for (Class<?> cls : allClasses) {
StringBuilder builder = new StringBuilder();
processClass(cls, builder);
System.out.println(builder);
}
}
示例10: before
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
@BeforeEach
public void before() throws MalformedURLException {
log.info("before() - Configuring reflections to use package '{}'", packages());
if (null == this.reflections) {
this.reflections = new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forJavaClassPath())
.forPackages(packages())
);
}
List<Class<? extends Transformation>> transformClasses = list(Transformation.class);
List<Class<? extends SourceConnector>> sourceConnectorClasses = list(SourceConnector.class);
List<Class<? extends SinkConnector>> sinkConnectorClasses = list(SinkConnector.class);
this.pluginTemplate = PluginTemplate.from(sourceConnectorClasses, sinkConnectorClasses, transformClasses);
}
示例11: computeClasses
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
private void computeClasses() {
this.annotatedClassMap = new HashMap<>();
this.otherClassMap = new HashMap<>();
TypesHandled handlesTypes = handlesTypes();
// check if any type is handled
if (!handlesTypes.isEmpty()) {
// create reflections
Reflections reflections = new Reflections(new ConfigurationBuilder().setExpandSuperTypes(false).setUrls(getURLs()));
// add types annotated for each type to be handled
for (Class<? extends Annotation> annotationType : handlesTypes.getAnnotationTypes()) {
this.annotatedClassMap.put(annotationType, reflections.getTypesAnnotatedWith(annotationType));
}
// add subtype of other types to be handled
for (Class<?> otherType : handlesTypes.getOtherTypes()) {
this.otherClassMap.put(otherType, (Set<Class<?>>) reflections.getSubTypesOf(otherType));
}
}
}
示例12: doPackage
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
private void doPackage(FilterBuilder fb, List<RuleFactory> resultL) throws Exception {
List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))
.filterInputsBy(fb));
Set<Class<? extends RuleFactory>> subTypes = reflections.getSubTypesOf(RuleFactory.class);
for(Class<? extends RuleFactory> clazz : subTypes) {
RuleFactory factory = clazz.newInstance();
resultL.add(factory);
}
}
示例13: testReflections
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
@Test
public void testReflections() throws Exception {
List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
String packageName = "org.dnal.core.world";
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))
.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(packageName))));
Set<String> types = reflections.getAllTypes();
for(String s : types) {
System.out.println(s);
}
Set<Class<? extends RuleFactory>> subTypes = reflections.getSubTypesOf(RuleFactory.class);
for(Class<? extends RuleFactory> clazz : subTypes) {
System.out.println("sub: " + clazz.getName());
RuleFactory factory = clazz.newInstance();
RuleDeclaration decl = factory.getDeclaration();
System.out.println("d: " + decl.ruleName);
}
}
示例14: getResourceDirectoryContent
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
private ArrayList<String> getResourceDirectoryContent(String resourcePattern) {
ArrayList<String> tempFilesContentList = new ArrayList<>();
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage("io.logz"))
.setScanners(new ResourcesScanner())
.filterInputsBy(new FilterBuilder().include(resourcePattern)));
Set<String> properties = reflections.getResources(Pattern.compile(".*\\.json"));
properties.forEach((resourceName) -> {
URL resourceUrl = Resources.getResource(resourceName);
try {
tempFilesContentList.add(Resources.toString(resourceUrl, Charset.forName("utf-8")).replace("\n", ""));
} catch (IOException e) {
logger.info("Could not read file {}", resourceUrl.toString());
}
});
if (tempFilesContentList.isEmpty())
throw new RuntimeException("Did not find any files under "+ resourcePattern +"!");
return tempFilesContentList;
}
示例15: scan
import org.reflections.util.ConfigurationBuilder; //导入依赖的package包/类
Set<Class<? extends T>> scan(Class<? extends T> aClass) {
Configuration configuration = ConfigurationBuilder.build((Object[]) packages).addClassLoaders(classLoaders)
.addScanners(new AssignableScanner(aClass));
Reflections reflections = new Reflections(configuration);
Predicate<Class<? extends T>> classPredicate = klass ->
Modifier.isPublic(klass.getModifiers()) &&
(!klass.isMemberClass() || (klass.isMemberClass() && Modifier
.isStatic(klass.getModifiers()))) &&
!Modifier.isInterface(klass.getModifiers()) &&
!Modifier.isAbstract(klass.getModifiers());
HashSet<Class<? extends T>> subtypes = Sets.newHashSet(
ReflectionUtils.forNames(
reflections.getStore()
.getAll(AssignableScanner.class.getSimpleName(),
Collections.singletonList(aClass.getName())), classLoaders));
return subtypes.stream().filter(classPredicate).collect(Collectors.toSet());
}