Search in sources :

Example 26 with ClassPath

use of com.google.common.reflect.ClassPath in project zuul by Netflix.

the class ZuulFiltersModule method findClassNames.

// Get compiled filter classes to be found on classpath.
@VisibleForTesting
String[] findClassNames(AbstractConfiguration config) {
    // Find individually-specified filter classes.
    String[] filterClassNamesStrArray = config.getStringArray("zuul.filters.classes");
    Stream<String> classNameStream = Arrays.stream(filterClassNamesStrArray).map(String::trim).filter(blank.negate());
    // Find filter classes in specified packages.
    String[] packageNamesStrArray = config.getStringArray("zuul.filters.packages");
    ClassPath cp;
    try {
        cp = ClassPath.from(this.getClass().getClassLoader());
    } catch (IOException e) {
        throw new RuntimeException("Error attempting to read classpath to find filters!", e);
    }
    Stream<String> packageStream = Arrays.stream(packageNamesStrArray).map(String::trim).filter(blank.negate()).flatMap(packageName -> cp.getTopLevelClasses(packageName).stream()).map(ClassPath.ClassInfo::load).filter(ZuulFilter.class::isAssignableFrom).map(Class::getCanonicalName);
    String[] filterClassNames = Stream.concat(classNameStream, packageStream).toArray(String[]::new);
    if (filterClassNames.length != 0) {
        LOG.info("Using filter classnames: ");
        for (String location : filterClassNames) {
            LOG.info("  " + location);
        }
    }
    return filterClassNames;
}
Also used : FilterFactory(com.netflix.zuul.FilterFactory) GuiceFilterFactory(com.netflix.zuul.guice.GuiceFilterFactory) FilenameFilter(java.io.FilenameFilter) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) FilterFileManagerConfig(com.netflix.zuul.FilterFileManager.FilterFileManagerConfig) Predicate(java.util.function.Predicate) FilterUsageNotifier(com.netflix.zuul.FilterUsageNotifier) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) ZuulFilter(com.netflix.zuul.filters.ZuulFilter) Provides(com.google.inject.Provides) BasicFilterUsageNotifier(com.netflix.zuul.BasicFilterUsageNotifier) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Stream(java.util.stream.Stream) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ClassPath(com.google.common.reflect.ClassPath) AbstractModule(com.google.inject.AbstractModule) ClassPath(com.google.common.reflect.ClassPath) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ClassPath (com.google.common.reflect.ClassPath)26 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)8 ClassInfo (com.google.common.reflect.ClassPath.ClassInfo)5 URL (java.net.URL)3 List (java.util.List)3 ReflectionException (io.openems.api.exception.ReflectionException)2 URLClassLoader (java.net.URLClassLoader)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 Predicate (java.util.function.Predicate)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 BuckEventListener (com.facebook.buck.event.BuckEventListener)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Function (com.google.common.base.Function)1 Collections2 (com.google.common.collect.Collections2)1