|
53 | 53 | * @since 2.0 |
54 | 54 | */ |
55 | 55 | public class ReflectionsClassFinder implements ClassFinder { |
| 56 | + /** |
| 57 | + * System property name to be used to disable default package filtering |
| 58 | + * during class scan. See {@link #applyScannerPackageFilters(ClassGraph)} |
| 59 | + * and {@link #DEFAULT_REJECTED_PACKAGES} |
| 60 | + */ |
| 61 | + public static final String DISABLE_DEFAULT_PACKAGE_FILTER = "vaadin.classfinder.disableDefaultPackageFilter"; |
| 62 | + |
| 63 | + private static final String[] DEFAULT_REJECTED_PACKAGES = new String[] { |
| 64 | + "antlr", "cglib", "ch.quos.logback", "commons-codec", |
| 65 | + "commons-fileupload", "commons-io", "commons-logging", |
| 66 | + "com.fasterxml", "tools.jackson", "com.google", "com.h2database", |
| 67 | + "com.helger", "com.vaadin.external.atmosphere", "com.vaadin.webjar", |
| 68 | + "junit", "net.bytebuddy", "org.apache", "org.aspectj", |
| 69 | + "org.bouncycastle", "org.dom4j", "org.easymock", |
| 70 | + "org.eclipse.persistence", "org.hamcrest", "org.hibernate", |
| 71 | + "org.javassist", "org.jboss", "org.jsoup", "org.seleniumhq", |
| 72 | + "org.slf4j", "org.atmosphere", "org.springframework", |
| 73 | + "org.webjars.bowergithub", "org.yaml", |
| 74 | + |
| 75 | + "java.*", "javax.*", "javafx.*", "com.sun.*", "oracle.deploy", |
| 76 | + "oracle.javafx", "oracle.jrockit", "oracle.jvm", "oracle.net", |
| 77 | + "oracle.nio", "oracle.tools", "oracle.util", "oracle.webservices", |
| 78 | + "oracle.xmlns", |
| 79 | + |
| 80 | + "com.intellij.*", "org.jetbrains", |
| 81 | + |
| 82 | + "com.vaadin.external.gwt", "javassist.*", "io.methvin", |
| 83 | + "com.github.javaparser", "oshi.*", "io.micrometer", "jakarta.*", |
| 84 | + "com.nimbusds", "elemental.util", "org.reflections", |
| 85 | + "org.aopalliance", "org.objectweb", |
| 86 | + |
| 87 | + "com.vaadin.hilla", "com.vaadin.copilot" }; |
| 88 | + |
56 | 89 | private static final Logger LOGGER = LoggerFactory |
57 | 90 | .getLogger(ReflectionsClassFinder.class); |
| 91 | + |
58 | 92 | private final transient ClassLoader classLoader; |
59 | 93 |
|
60 | 94 | // Cache all discovered classes by annotation |
@@ -108,7 +142,7 @@ public ReflectionsClassFinder(ClassLoader classLoader, URL... urls) { |
108 | 142 | .ignoreClassVisibility() // Scan non-public classes |
109 | 143 | .filterClasspathElements( |
110 | 144 | path -> !path.endsWith("module-info.class")); |
111 | | - |
| 145 | + applyScannerPackageFilters(classGraph); |
112 | 146 | if (VersionFinder.JAVA_MAJOR_VERSION < 24) { |
113 | 147 | // Not available on Java 24+ currently, because of the deprecation |
114 | 148 | // of the Unsafe API |
@@ -296,4 +330,10 @@ private Map<String, Set<String>> buildSubtypeCache( |
296 | 330 |
|
297 | 331 | return cache; |
298 | 332 | } |
| 333 | + |
| 334 | + private void applyScannerPackageFilters(ClassGraph classGraph) { |
| 335 | + if (!Boolean.getBoolean(DISABLE_DEFAULT_PACKAGE_FILTER)) { |
| 336 | + classGraph.rejectPackages(DEFAULT_REJECTED_PACKAGES); |
| 337 | + } |
| 338 | + } |
299 | 339 | } |
0 commit comments