Class ConfigurationBuilder
- java.lang.Object
-
- org.reflections.util.ConfigurationBuilder
-
- All Implemented Interfaces:
Configuration
public class ConfigurationBuilder extends java.lang.Object implements Configuration
a fluent builder forConfiguration, to be used for constructing aReflectionsinstanceusage:
new Reflections( new ConfigurationBuilder() .filterInputsBy(new FilterBuilder().include("your project's common package prefix here...")) .setUrls(ClasspathHelper.forClassLoader()) .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner().filterResultsBy(myClassAnnotationsFilter)));executorServiceis used optionally used for parallel scanning. if value is null then scanning is done in a simple for loopdefaults: accept all for
inputsFilter,executorServiceis null,serializerisXmlSerializer
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ClassLoader[]classLoadersprivate java.util.concurrent.ExecutorServiceexecutorServiceprivate booleanexpandSuperTypesprivate java.util.function.Predicate<java.lang.String>inputsFilterprotected MetadataAdaptermetadataAdapterprivate java.util.Set<Scanner>scannersprivate Serializerserializerprivate java.util.Set<java.net.URL>urls
-
Constructor Summary
Constructors Constructor Description ConfigurationBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ConfigurationBuilderaddClassLoader(java.lang.ClassLoader classLoader)add class loader, might be used for resolving methods/fieldsConfigurationBuilderaddClassLoaders(java.lang.ClassLoader... classLoaders)add class loader, might be used for resolving methods/fieldsConfigurationBuilderaddClassLoaders(java.util.Collection<java.lang.ClassLoader> classLoaders)add class loader, might be used for resolving methods/fieldsConfigurationBuilderaddScanners(Scanner... scanners)set the scanners instances for scanning different metadataConfigurationBuilderaddUrls(java.net.URL... urls)add urls to be scannedConfigurationBuilderaddUrls(java.util.Collection<java.net.URL> urls)add urls to be scannedstatic ConfigurationBuilderbuild(java.lang.Object... params)constructs aConfigurationBuilderusing the given parameters, in a non statically typed way.ConfigurationBuilderfilterInputsBy(java.util.function.Predicate<java.lang.String> inputsFilter)sets the input filter for all resources to be scanned.ConfigurationBuilderforPackages(java.lang.String... packages)java.lang.ClassLoader[]getClassLoaders()get class loader, might be used for scanning or resolving methods/fieldsjava.util.concurrent.ExecutorServicegetExecutorService()executor service used to scan files.java.util.function.Predicate<java.lang.String>getInputsFilter()get the fully qualified name filter used to filter types to be scannedMetadataAdaptergetMetadataAdapter()returns the metadata adapter.java.util.Set<Scanner>getScanners()the scanner instances used for scanning different metadataSerializergetSerializer()the default serializer to use when saving Reflectionjava.util.Set<java.net.URL>getUrls()the urls to be scannedvoidsetClassLoaders(java.lang.ClassLoader[] classLoaders)set class loader, might be used for resolving methods/fieldsConfigurationBuildersetExecutorService(java.util.concurrent.ExecutorService executorService)sets the executor service used for scanning.ConfigurationBuildersetExpandSuperTypes(boolean expandSuperTypes)if set to true, Reflections will expand super types after scanning.voidsetInputsFilter(java.util.function.Predicate<java.lang.String> inputsFilter)sets the input filter for all resources to be scanned.ConfigurationBuildersetMetadataAdapter(MetadataAdapter metadataAdapter)sets the metadata adapter used to fetch metadata from classesConfigurationBuildersetScanners(Scanner... scanners)set the scanners instances for scanning different metadataConfigurationBuildersetSerializer(Serializer serializer)sets the serializer used when issuingReflections.save(java.lang.String)ConfigurationBuildersetUrls(java.net.URL... urls)set the urls to be scannedConfigurationBuildersetUrls(java.util.Collection<java.net.URL> urls)set the urls to be scannedbooleanshouldExpandSuperTypes()if true (default), expand super types after scanning, for super types that were not scanned.ConfigurationBuilderuseParallelExecutor()sets the executor service used for scanning to ThreadPoolExecutor with core size asRuntime.availableProcessors()ConfigurationBuilderuseParallelExecutor(int availableProcessors)sets the executor service used for scanning to ThreadPoolExecutor with core size as the given availableProcessors parameter.
-
-
-
Field Detail
-
scanners
private java.util.Set<Scanner> scanners
-
urls
private java.util.Set<java.net.URL> urls
-
metadataAdapter
protected MetadataAdapter metadataAdapter
-
inputsFilter
private java.util.function.Predicate<java.lang.String> inputsFilter
-
serializer
private Serializer serializer
-
executorService
private java.util.concurrent.ExecutorService executorService
-
classLoaders
private java.lang.ClassLoader[] classLoaders
-
expandSuperTypes
private boolean expandSuperTypes
-
-
Method Detail
-
build
public static ConfigurationBuilder build(java.lang.Object... params)
constructs aConfigurationBuilderusing the given parameters, in a non statically typed way. that is, each element inparamsis guessed by it's type and populated into the configuration.String- add urls usingClasspathHelper.forPackage(String, ClassLoader...)()}Class- add urls usingClasspathHelper.forClass(Class, ClassLoader...)ClassLoader- use these classloaders in order to find urls in ClasspathHelper.forPackage(), ClasspathHelper.forClass() and for resolving typesScanner- use given scanner, overriding the default scannersURL- add the given url for scanningObject[]- flatten and use each element as above
FilterBuilderwill be set according to given packages.use any parameter type in any order. this constructor uses instanceof on each param and instantiate a
ConfigurationBuilderappropriately.
-
forPackages
public ConfigurationBuilder forPackages(java.lang.String... packages)
-
getScanners
public java.util.Set<Scanner> getScanners()
Description copied from interface:Configurationthe scanner instances used for scanning different metadata- Specified by:
getScannersin interfaceConfiguration
-
setScanners
public ConfigurationBuilder setScanners(Scanner... scanners)
set the scanners instances for scanning different metadata
-
addScanners
public ConfigurationBuilder addScanners(Scanner... scanners)
set the scanners instances for scanning different metadata
-
getUrls
public java.util.Set<java.net.URL> getUrls()
Description copied from interface:Configurationthe urls to be scanned- Specified by:
getUrlsin interfaceConfiguration
-
setUrls
public ConfigurationBuilder setUrls(java.util.Collection<java.net.URL> urls)
set the urls to be scanneduse
ClasspathHelperconvenient methods to get the relevant urls
-
setUrls
public ConfigurationBuilder setUrls(java.net.URL... urls)
set the urls to be scanneduse
ClasspathHelperconvenient methods to get the relevant urls
-
addUrls
public ConfigurationBuilder addUrls(java.util.Collection<java.net.URL> urls)
add urls to be scanneduse
ClasspathHelperconvenient methods to get the relevant urls
-
addUrls
public ConfigurationBuilder addUrls(java.net.URL... urls)
add urls to be scanneduse
ClasspathHelperconvenient methods to get the relevant urls
-
getMetadataAdapter
public MetadataAdapter getMetadataAdapter()
returns the metadata adapter. if javassist library exists in the classpath, this method returnsJavassistAdapterotherwise defaults toJavaReflectionAdapter.the
JavassistAdapteris preferred in terms of performance and class loading.- Specified by:
getMetadataAdapterin interfaceConfiguration
-
setMetadataAdapter
public ConfigurationBuilder setMetadataAdapter(MetadataAdapter metadataAdapter)
sets the metadata adapter used to fetch metadata from classes
-
getInputsFilter
public java.util.function.Predicate<java.lang.String> getInputsFilter()
Description copied from interface:Configurationget the fully qualified name filter used to filter types to be scanned- Specified by:
getInputsFilterin interfaceConfiguration
-
setInputsFilter
public void setInputsFilter(java.util.function.Predicate<java.lang.String> inputsFilter)
sets the input filter for all resources to be scanned.supply a
Predicateor use theFilterBuilder
-
filterInputsBy
public ConfigurationBuilder filterInputsBy(java.util.function.Predicate<java.lang.String> inputsFilter)
sets the input filter for all resources to be scanned.supply a
Predicateor use theFilterBuilder
-
getExecutorService
public java.util.concurrent.ExecutorService getExecutorService()
Description copied from interface:Configurationexecutor service used to scan files. if null, scanning is done in a simple for loop- Specified by:
getExecutorServicein interfaceConfiguration
-
setExecutorService
public ConfigurationBuilder setExecutorService(java.util.concurrent.ExecutorService executorService)
sets the executor service used for scanning.
-
useParallelExecutor
public ConfigurationBuilder useParallelExecutor()
sets the executor service used for scanning to ThreadPoolExecutor with core size asRuntime.availableProcessors()default is ThreadPoolExecutor with a single core
-
useParallelExecutor
public ConfigurationBuilder useParallelExecutor(int availableProcessors)
sets the executor service used for scanning to ThreadPoolExecutor with core size as the given availableProcessors parameter. the executor service spawns daemon threads by default.default is ThreadPoolExecutor with a single core
-
getSerializer
public Serializer getSerializer()
Description copied from interface:Configurationthe default serializer to use when saving Reflection- Specified by:
getSerializerin interfaceConfiguration
-
setSerializer
public ConfigurationBuilder setSerializer(Serializer serializer)
sets the serializer used when issuingReflections.save(java.lang.String)
-
getClassLoaders
public java.lang.ClassLoader[] getClassLoaders()
get class loader, might be used for scanning or resolving methods/fields- Specified by:
getClassLoadersin interfaceConfiguration
-
shouldExpandSuperTypes
public boolean shouldExpandSuperTypes()
Description copied from interface:Configurationif true (default), expand super types after scanning, for super types that were not scanned.- Specified by:
shouldExpandSuperTypesin interfaceConfiguration
-
setExpandSuperTypes
public ConfigurationBuilder setExpandSuperTypes(boolean expandSuperTypes)
if set to true, Reflections will expand super types after scanning.
-
setClassLoaders
public void setClassLoaders(java.lang.ClassLoader[] classLoaders)
set class loader, might be used for resolving methods/fields
-
addClassLoader
public ConfigurationBuilder addClassLoader(java.lang.ClassLoader classLoader)
add class loader, might be used for resolving methods/fields
-
addClassLoaders
public ConfigurationBuilder addClassLoaders(java.lang.ClassLoader... classLoaders)
add class loader, might be used for resolving methods/fields
-
addClassLoaders
public ConfigurationBuilder addClassLoaders(java.util.Collection<java.lang.ClassLoader> classLoaders)
add class loader, might be used for resolving methods/fields
-
-