本文整理汇总了Java中org.reflections.util.ConfigurationBuilder.setUrls方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationBuilder.setUrls方法的具体用法?Java ConfigurationBuilder.setUrls怎么用?Java ConfigurationBuilder.setUrls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.reflections.util.ConfigurationBuilder
的用法示例。
在下文中一共展示了ConfigurationBuilder.setUrls方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BeanScanner
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
public BeanScanner(final BeanManagerImpl beanManager, final ClassLoader classLoader, final String packageToScan)
{
this.beanManager = beanManager;
final ConfigurationBuilder config = new ConfigurationBuilder();
config.setClassLoaders(new ClassLoader[] {classLoader});
config.setUrls(ClasspathHelper.forPackage(packageToScan, classLoader));
if (StringUtils.isNotEmpty(packageToScan))
{
config.filterInputsBy(new FilterBuilder().includePackage(packageToScan));
}
config.useParallelExecutor();
config.setScanners(new SubTypesScanner(false));
this.reflections = new Reflections(config);
}
示例2: init
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
/**
* Init stuff is responsible to grab all DTOs found in classpath (classloader) and setup model for
* String Template
*/
protected void init() {
ConfigurationBuilder configurationBuilder =
new ConfigurationBuilder().setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
if (useClassPath) {
configurationBuilder.setUrls(forJavaClassPath());
} else {
configurationBuilder.setUrls(forClassLoader());
}
// keep only DTO interfaces
Reflections reflections = new Reflections(configurationBuilder);
List<Class<?>> annotatedWithDtos =
new ArrayList<>(reflections.getTypesAnnotatedWith(DTO.class));
List<Class<?>> interfacesDtos =
annotatedWithDtos
.stream()
.filter(clazz -> clazz.isInterface())
.collect(Collectors.toList());
interfacesDtos.stream().forEach(this::analyze);
}
示例3: initialize
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
public static void initialize() {
// Scan for json configuration files on the classpath
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setScanners(new ResourcesScanner());
builder.setUrls(ClasspathHelper.forClassLoader(
ClasspathHelper.contextClassLoader(),
ClasspathHelper.staticClassLoader()));
reflections = new Reflections(builder);
json = new Json();
for (String path : reflections.getResources(Pattern.compile(".*\\.json"))) {
if (!path.startsWith("items") && !path.startsWith("tiles") && !path.startsWith("walls"))
continue;
FileHandle file = Gdx.files.internal(path);
Type type = json.fromJson(null, file);
registerType(type);
}
airItem = getItem("airItem");
airTile = getTile("airTile");
airWall = getWall("airWall");
}
示例4: CommandManager
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
public CommandManager() {
ConfigurationBuilder builder = new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false), new ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(Arrays.asList(ClasspathHelper.contextClassLoader(), ClasspathHelper.staticClassLoader()).toArray(new ClassLoader[0])))
.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("github.scarsz.discordsrv.commands")));
builder = builder.setUrls(builder.getUrls().stream().filter(url -> !Pattern.compile(".*[.](so|dll)", Pattern.CASE_INSENSITIVE).matcher(url.getFile()).matches()).collect(Collectors.toList()));
Reflections reflections = new Reflections(builder);
for (String className : reflections.getAllTypes()) {
Class clazz; try { clazz = Class.forName(className); } catch (ClassNotFoundException ignored) { continue; }
if (clazz.isAnnotation()) continue;
for (Method method : clazz.getMethods()) {
if (!method.isAnnotationPresent(Command.class)) continue; // make sure method is marked as an annotation
if (method.getParameters().length != 2) {
DiscordSRV.debug("Method " + method.toGenericString().replace("public static void ", "") + " annotated as command but parameters count != 2");
continue;
}
if (method.getParameters()[0].getType() != CommandSender.class && method.getParameters()[0].getType() != Player.class) {
DiscordSRV.debug("Method " + method.toGenericString().replace("public static void ", "") + " annotated as command but parameter 1's type != CommandSender || Player");
continue;
}
if (method.getParameters()[1].getType() != String[].class) {
DiscordSRV.debug("Method " + method.toGenericString().replace("public static void ", "") + " annotated as command but parameter 2's type != String[]");
continue;
}
Command annotation = method.getAnnotation(Command.class);
for (String commandName : annotation.commandNames()) commands.put(commandName.toLowerCase(), method);
}
}
}
示例5: getDataMapperNames
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
@Override
public List<String> getDataMapperNames() {
List<ClassLoader> classLoadersList = new LinkedList<>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner());
cb.setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])));
FilterBuilder fb = new FilterBuilder();
for (Package aPackage : getSearchPackages()) {
fb.include(FilterBuilder.prefix(aPackage.getName()));
}
cb.filterInputsBy(fb);
Reflections reflections = new Reflections(cb);
Set<Class<?>> subTypesOf =
reflections.getSubTypesOf(Object.class);
ArrayList<String> collected = subTypesOf.stream()
.map(Class::getSimpleName)
.collect(Collectors.toCollection(ArrayList::new));
return collected;
}
示例6: findDynaObjects
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
private void findDynaObjects() throws IOException {
ConfigurationBuilder configuration = new ConfigurationBuilder();
List<URL> urls = new ArrayList<>();
for (String element : classpath) {
urls.add(new File(element).toURI().toURL());
}
ClassLoader contextClassLoader =
URLClassLoader.newInstance(
urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader());
Thread.currentThread().setContextClassLoader(contextClassLoader);
configuration.setUrls(ClasspathHelper.forClassLoader(contextClassLoader));
configuration.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
Reflections reflection = new Reflections(configuration);
Set<Class<?>> classes = reflection.getTypesAnnotatedWith(DynaObject.class);
for (Class clazz : classes) {
// accept only classes
if (clazz.isEnum() || clazz.isInterface() || clazz.isAnnotation()) {
continue;
}
dynaClasses.add(new ClassModel(clazz));
System.out.println(String.format("New Dyna Object Found: %s", clazz.getCanonicalName()));
}
System.out.println(String.format("Found: %d Dyna Objects", dynaClasses.size()));
}
示例7: init
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
/**
* Scans the classpath for resources.
*
* @param packages
* @throws Siren4JException
*/
@SuppressWarnings("deprecation")
private void init(String... packages) throws Siren4JException {
LOG.info("Siren4J scanning classpath for resource entries...");
Reflections reflections = null;
ConfigurationBuilder builder = new ConfigurationBuilder();
Collection<URL> urls = new HashSet<URL>();
if (packages != null && packages.length > 0) {
//limit scan to packages
for (String pkg : packages) {
urls.addAll(ClasspathHelper.forPackage(pkg));
}
} else {
urls.addAll(ClasspathHelper.forPackage("com."));
urls.addAll(ClasspathHelper.forPackage("org."));
urls.addAll(ClasspathHelper.forPackage("net."));
}
//Always add Siren4J Resources by default, this will add the collection resource
//and what ever other resource gets added to this package and has the entity annotation.
urls.addAll(ClasspathHelper.forPackage("com.google.code.siren4j.resource"));
builder.setUrls(urls);
reflections = new Reflections(builder);
Set<Class<?>> types = reflections.getTypesAnnotatedWith(Siren4JEntity.class);
for (Class<?> c : types) {
Siren4JEntity anno = c.getAnnotation(Siren4JEntity.class);
String name = StringUtils
.defaultIfBlank(anno.name(), anno.entityClass().length > 0 ? anno.entityClass()[0] : c.getName());
putEntry(StringUtils.defaultIfEmpty(name, c.getName()), c, false);
// Always add the class name as an entry in the index if it does not already exist.
if (!containsEntityEntry(c.getName())) {
putEntry(StringUtils.defaultIfEmpty(c.getName(), c.getName()), c, false);
}
}
}
示例8: searchClasses
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
/**
* This is not entirely reliable method.
* Maybe it would be better to rely on Spring ClassPathScanningCandidateComponentProvider
*/
public static void searchClasses(String packageName, Consumer<Class> consumer) {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setScanners(new SubTypesScanner(false));
builder.setUrls(ClasspathHelper.forPackage(packageName, LOGGER.getClass().getClassLoader()));
builder.setInputsFilter(new FilterBuilder().includePackage(packageName));
Reflections reflections = new Reflections(builder);
Multimap<String, String> map = reflections.getStore().get(SubTypesScanner.class.getSimpleName());
Set<String> types = new HashSet<>();
for (String key : map.keySet()) {
Collection<String> col = map.get(key);
if (col == null) {
continue;
}
for (String c : col) {
String simpleName = c.replaceFirst(packageName + "\\.", "");
if (simpleName.contains(".")) {
continue;
}
types.add(c);
}
}
for (String type : types) {
try {
Class clazz = Class.forName(type);
consumer.accept(clazz);
} catch (ClassNotFoundException e) {
LOGGER.error("Error during loading class {}. ", type);
}
}
}
示例9: getConfigurationBuilder
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
private static Configuration getConfigurationBuilder() {
ConfigurationBuilder configurationBuilder= ConfigurationBuilder.build("org.apache.gobblin.metastore.database",
effectiveClassPathUrls(DatabaseJobHistoryStore.class.getClassLoader()));
List<URL> filteredUrls = Lists.newArrayList(Iterables.filter(configurationBuilder.getUrls(), new Predicate<URL>() {
@Override
public boolean apply(@Nullable URL input) {
return input != null && (!input.getProtocol().equals("file") || new File(input.getFile()).exists());
}
}));
configurationBuilder.setUrls(filteredUrls);
return configurationBuilder;
}
示例10: findEntities
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
private List<String> findEntities() {
final ConfigurationBuilder c = new ConfigurationBuilder();
c.setUrls(ClasspathHelper.forPackage(PACKAGE));
c.setScanners(new TypeAnnotationsScanner());
final Reflections reflections = new Reflections(c);
final Set<Class<?>> entities = reflections.getTypesAnnotatedWith(Entity.class);
final List<String> entityClassNameList = new ArrayList<String>(entities.size());
for (final Class<?> entity : entities) {
entityClassNameList.add(entity.getName());
}
return entityClassNameList;
}
示例11: addPackage
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
public void addPackage(String packageName) {
ConfigurationBuilder config = new ConfigurationBuilder();
FilterBuilder fb = new FilterBuilder();
fb.include(FilterBuilder.prefix(packageName));
config.filterInputsBy(fb);
Set<URL> urls = ClasspathHelper.forPackage(packageName);
urls = GoogleReflectionsUtil.fixURLs(urls); //jboss compatibility hack
config.setUrls(urls);
Reflections packageReflections = new Reflections(config);
//packageReflections = new Reflections(packageName);
reflections.merge(packageReflections);
refresh();
}
示例12: testSubtypes3
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testSubtypes3() {
ConfigurationBuilder config = new ConfigurationBuilder();
config.setUrls(ClasspathHelper.forClass(this.getClass()));
//SubTypesScanner scanner = new SubTypesScanner(false);
//config.setScanners(scanner);
Reflections reflections = new Reflections(config);
Set<Class<? extends Object>> classes = reflections.getTypesAnnotatedWith(LObject.class);
System.out.println(classes);
}
示例13: EntityScanner
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
/**
* Creates an EntityScanner using the given Morphia instance with the given predicate.
*
* @param m the Morphia instance
* @param predicate the Predicate to use when determining which classes to map.
*/
public EntityScanner(final Morphia m, final Predicate<String> predicate) {
Predicate<String> localPredicate = predicate;
if (localPredicate == null) {
localPredicate = Predicates.alwaysTrue();
}
Assert.parametersNotNull("m, predicate", m, localPredicate);
final ConfigurationBuilder conf = new ConfigurationBuilder();
conf.setScanners(new TypeElementsScanner(), new TypeAnnotationsScanner());
final Set<URL> s = new HashSet<URL>();
s.addAll(ClasspathHelper.forClassLoader());
s.addAll(ClasspathHelper.forJavaClassPath());
final Iterator<URL> iterator = s.iterator();
while (iterator.hasNext()) {
final URL url = iterator.next();
if (url.getPath().endsWith("jnilib")) {
iterator.remove();
}
}
conf.setUrls(new ArrayList<URL>(s));
conf.filterInputsBy(localPredicate);
conf.addScanners(new SubTypesScanner());
final Reflections r = new Reflections(conf);
final Set<Class<?>> entities = r.getTypesAnnotatedWith(Entity.class);
for (final Class<?> c : entities) {
m.map(c);
}
}
示例14: createReflectionsForGwtTestCase
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
private static Reflections createReflectionsForGwtTestCase() {
ConfigurationBuilder inputFilterByName = new ConfigurationBuilder();
inputFilterByName.setUrls(ClasspathHelper.forPackage("eu.ydp.empiria"));
inputFilterByName.setScanners(new GwtTestCaseScanner(), new SubTypesScanner());
return new Reflections(inputFilterByName);
}
示例15: execute
import org.reflections.util.ConfigurationBuilder; //导入方法依赖的package包/类
public void execute() throws MojoExecutionException, MojoFailureException {
//
if (StringUtils.isEmpty(destinations)) {
destinations = resolveOutputDirectory() + "/META-INF/reflections/" + getProject().getArtifactId() + "-reflections.xml";
}
String outputDirectory = resolveOutputDirectory();
if (!new File(outputDirectory).exists()) {
getLog().warn(String.format("Reflections plugin is skipping because %s was not found", outputDirectory));
return;
}
//
ConfigurationBuilder config = new ConfigurationBuilder();
config.setUrls(parseUrls());
if (!isEmpty(includeExclude)) {
config.filterInputsBy(FilterBuilder.parse(includeExclude));
}
config.setScanners(!isEmpty(scanners) ? parseScanners() : new Scanner[]{new SubTypesScanner(), new TypeAnnotationsScanner()});
if (!isEmpty(serializer)) {
try {
Serializer serializerInstance = (Serializer) forName(serializer, "org.reflections.serializers").newInstance();
config.setSerializer(serializerInstance);
if (serializerInstance instanceof JavaCodeSerializer) {
int size = config.getScanners().size();
config.addScanners(new TypeElementsScanner());
if (size != config.getScanners().size()) {
getLog().info("added type scanners for JavaCodeSerializer");
}
}
} catch (Exception ex) {
throw new ReflectionsException("could not create serializer instance", ex);
}
}
if (parallel != null && parallel.equals(Boolean.TRUE)) {
config.useParallelExecutor();
}
//
if (Reflections.log == null) {
try {
Reflections.log = new MavenLogAdapter(getLog());
} catch (Error e) {
//ignore
}
}
Reflections reflections = new Reflections(config);
reflections.save(destinations.trim());
}