@@ -105,18 +105,38 @@ public class VaadinServletContextInitializer
105
105
private ResourceLoader customLoader ;
106
106
107
107
/**
108
- * packages that are white-listed (should be scanned) by default and can't
109
- * be overriden by <code>addedWhiteListed</code>.
108
+ * Packages that should be excluded when scanning all packages.
110
109
*/
111
- private static final List <String > DEFAULT_WHITE_LISTED = Stream
110
+ private static final List <String > DEFAULT_SCAN_NEVER = Stream .of ("antlr" ,
111
+ "cglib" , "ch/quos/logback" , "commons-codec" , "commons-fileupload" ,
112
+ "commons-io" , "commons-logging" , "com/fasterxml" , "com/google" ,
113
+ "com/h2database" , "com/helger" , "com/vaadin/external/atmosphere" ,
114
+ "com/vaadin/webjar" , "junit" , "net/bytebuddy" , "org/apache" ,
115
+ "org/aspectj" , "org/bouncycastle" , "org/dom4j" , "org/easymock" ,
116
+ "org/hamcrest" , "org/hibernate" , "org/javassist" , "org/jboss" ,
117
+ "org/jsoup" , "org/seleniumhq" , "org/slf4j" , "org/atmosphere" ,
118
+ "org/springframework" , "org/webjars/bowergithub" , "org/yaml" ,
119
+
120
+ "java/" , "javax/" , "javafx/" , "com/sun/" , "oracle/deploy" ,
121
+ "oracle/javafx" , "oracle/jrockit" , "oracle/jvm" , "oracle/net" ,
122
+ "oracle/nio" , "oracle/tools" , "oracle/util" , "oracle/webservices" ,
123
+ "oracle/xmlns" ,
124
+
125
+ "com/intellij/" , "org/jetbrains" ).collect (Collectors .toList ());
126
+
127
+ /**
128
+ * Packages that should be scanned by default and can't be overriden by
129
+ * a custom list.
130
+ */
131
+ private static final List <String > DEFAULT_SCAN_ONLY = Stream
112
132
.of (Component .class .getPackage ().getName (),
113
133
Theme .class .getPackage ().getName (), "com.vaadin.shrinkwrap" )
114
134
.collect (Collectors .toList ());
115
135
116
136
/**
117
- * Packages whitelisted by the user
137
+ * Packages marked by the user to be scanned exclusively.
118
138
*/
119
- private List <String > customWhitelist ;
139
+ private final List <String > customScanOnly ;
120
140
121
141
/**
122
142
* Class path scanner that reuses infrastructure from Spring while also
@@ -324,8 +344,8 @@ public void contextInitialized(ServletContextEvent event) {
324
344
}
325
345
326
346
Set <String > basePackages ;
327
- if (isWhitelistSet ()) {
328
- basePackages = new HashSet <>(getWhiteListPackages ());
347
+ if (isScanOnlySet ()) {
348
+ basePackages = new HashSet <>(getScanOnlyPackages ());
329
349
} else {
330
350
basePackages = Collections .singleton ("" );
331
351
}
@@ -361,11 +381,11 @@ public void contextDestroyed(ServletContextEvent event) {
361
381
// NO-OP
362
382
}
363
383
364
- private Collection <String > getWhiteListPackages () {
384
+ private Collection <String > getScanOnlyPackages () {
365
385
HashSet <String > npmPackages = new HashSet <>(getDefaultPackages ());
366
- npmPackages .addAll (DEFAULT_WHITE_LISTED );
367
- if (customWhitelist != null ) {
368
- npmPackages .addAll (customWhitelist );
386
+ npmPackages .addAll (DEFAULT_SCAN_ONLY );
387
+ if (customScanOnly != null ) {
388
+ npmPackages .addAll (customScanOnly );
369
389
}
370
390
return npmPackages ;
371
391
}
@@ -386,8 +406,9 @@ private void collectDevModeTypes(
386
406
}
387
407
}
388
408
389
- private boolean isWhitelistSet () {
390
- return customWhitelist != null && !customWhitelist .isEmpty ();
409
+ private boolean isScanOnlySet () {
410
+ return customScanOnly != null
411
+ && !customScanOnly .isEmpty ();
391
412
}
392
413
}
393
414
@@ -440,31 +461,30 @@ public void contextDestroyed(ServletContextEvent sce) {
440
461
*/
441
462
public VaadinServletContextInitializer (ApplicationContext context ) {
442
463
appContext = context ;
443
- String blacklistProperty = appContext .getEnvironment ()
464
+ String neverScanProperty = appContext .getEnvironment ()
444
465
.getProperty ("vaadin.blacklisted-packages" );
445
- List <String > blacklist ;
446
- if (blacklistProperty == null ) {
447
- blacklist = Collections .emptyList ();
466
+ List <String > neverScan ;
467
+ if (neverScanProperty == null ) {
468
+ neverScan = Collections .emptyList ();
448
469
} else {
449
- blacklist = Arrays .stream (blacklistProperty .split ("," ))
470
+ neverScan = Arrays .stream (neverScanProperty .split ("," ))
450
471
.map (String ::trim ).collect (Collectors .toList ());
451
472
}
452
473
453
- String whitelistProperty = appContext .getEnvironment ()
474
+ String onlyScanProperty = appContext .getEnvironment ()
454
475
.getProperty ("vaadin.whitelisted-packages" );
455
- if (whitelistProperty == null ) {
456
- customWhitelist = Collections .emptyList ();
457
- customLoader = new CustomResourceLoader (appContext , blacklist );
476
+ if (onlyScanProperty == null ) {
477
+ customScanOnly = Collections .emptyList ();
478
+ customLoader = new CustomResourceLoader (appContext , neverScan );
458
479
459
480
} else {
460
- customWhitelist = Arrays .stream (whitelistProperty .split ("," ))
461
- .map (whitelistedPackage -> whitelistedPackage
462
- .replace ('/' , '.' ).trim ())
481
+ customScanOnly = Arrays .stream (onlyScanProperty .split ("," ))
482
+ .map (onlyPackage -> onlyPackage .replace ('/' , '.' ).trim ())
463
483
.collect (Collectors .toList ());
464
484
customLoader = appContext ;
465
485
}
466
486
467
- if (!customWhitelist .isEmpty () && !blacklist .isEmpty ()) {
487
+ if (!customScanOnly .isEmpty () && !neverScan .isEmpty ()) {
468
488
getLogger ().warn (
469
489
"vaadin.blacklisted-packages is ignored because both vaadin.whitelisted-packages and vaadin.blacklisted-packages have been set." );
470
490
}
@@ -604,34 +624,22 @@ private List<String> getDefaultPackages() {
604
624
*/
605
625
private static class CustomResourceLoader
606
626
extends PathMatchingResourcePatternResolver {
607
- /**
608
- * Blacklisted packages that shouldn't be scanned for when scanning all
609
- * packages.
610
- */
611
- private List <String > blackListed = Stream .of ("antlr" , "cglib" ,
612
- "ch/quos/logback" , "commons-codec" , "commons-fileupload" ,
613
- "commons-io" , "commons-logging" , "com/fasterxml" , "com/google" ,
614
- "com/h2database" , "com/helger" ,
615
- "com/vaadin/external/atmosphere" , "com/vaadin/webjar" , "javax/" ,
616
- "junit" , "net/bytebuddy" , "org/apache" , "org/aspectj" ,
617
- "org/bouncycastle" , "org/dom4j" , "org/easymock" , "org/hamcrest" ,
618
- "org/hibernate" , "org/javassist" , "org/jboss" , "org/jsoup" ,
619
- "org/seleniumhq" , "org/slf4j" , "org/atmosphere" ,
620
- "org/springframework" , "org/webjars/bowergithub" , "org/yaml" )
621
- .collect (Collectors .toList ());
622
-
623
- private static List <String > defaultWhiteList = DEFAULT_WHITE_LISTED
624
- .stream ().map (packageName -> packageName .replace ('.' , '/' ))
625
- .collect (Collectors .toList ());
627
+
628
+ private final PrefixTree scanNever = new PrefixTree (DEFAULT_SCAN_NEVER );
629
+
630
+ private final PrefixTree scanAlways = new PrefixTree (
631
+ DEFAULT_SCAN_ONLY .stream ()
632
+ .map (packageName -> packageName .replace ('.' , '/' ))
633
+ .collect (Collectors .toList ()));
626
634
627
635
public CustomResourceLoader (ResourceLoader resourceLoader ,
628
- List <String > addedBlacklist ) {
636
+ List <String > addedScanNever ) {
629
637
super (resourceLoader );
630
638
631
- Objects .requireNonNull (addedBlacklist ,
632
- "addedBlacklist shouldn't be null!" );
639
+ Objects .requireNonNull (addedScanNever ,
640
+ "addedScanNever shouldn't be null!" );
633
641
634
- blackListed . addAll ( addedBlacklist );
642
+ addedScanNever . forEach ( scanNever :: addPrefix );
635
643
}
636
644
637
645
/**
@@ -699,11 +707,8 @@ private Resource[] collectResources(String locationPattern)
699
707
}
700
708
701
709
private boolean shouldPathBeScanned (String path ) {
702
- if (defaultWhiteList .stream ().anyMatch (path ::startsWith )) {
703
- return true ;
704
- }
705
-
706
- return !blackListed .stream ().anyMatch (path ::startsWith );
710
+ return scanAlways .hasPrefix (path )
711
+ || !scanNever .hasPrefix (path );
707
712
}
708
713
}
709
714
0 commit comments