Skip to content

Commit 96bb948

Browse files
authored
fix: pre-compile visitable classes regex pattern (#17280)
Pre compiles the regex pattern to improve build frontend performance during the bytecode scan and collection of reachable classes. Also adds some package exclusions for well knonw libraries that should not be visited. Part of #17234
1 parent 86a01c6 commit 96bb948

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

‎flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/FrontendDependencies.java‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Map;
3333
import java.util.Map.Entry;
3434
import java.util.Set;
35+
import java.util.regex.Pattern;
3536
import java.util.stream.Collectors;
3637
import java.util.stream.Stream;
3738

@@ -73,6 +74,19 @@
7374
*/
7475
public class FrontendDependencies extends AbstractDependenciesScanner {
7576

77+
//@formatter:off
78+
private static final Pattern VISITABLE_CLASS_PATTERN = Pattern.compile("(^$|"
79+
+ ".*(slf4j).*|"
80+
// #5803
81+
+ "^(java|sun|oracle|elemental|javax|jakarta|oshi|"
82+
+ "org\\.(apache|atmosphere|jsoup|jboss|w3c|spring|joda|hibernate|glassfish|hsqldb|osgi|jooq)|"
83+
+ "com\\.(helger|spring|gwt|lowagie|fasterxml|sun|nimbusds|googlecode)|"
84+
+ "net\\.(sf|bytebuddy)"
85+
+ ").*|"
86+
+ ".*(Exception)$"
87+
+ ")");
88+
//@formatter:on
89+
7690
private final HashMap<String, EntryPointData> entryPoints = new LinkedHashMap<>();
7791
private ThemeDefinition themeDefinition;
7892
private AbstractTheme themeInstance;
@@ -798,15 +812,8 @@ private boolean shouldVisit(String className) {
798812
// factories. This is the reason of having just a blacklist of some
799813
// common name-spaces that would not have components.
800814
// We also exclude Feature-Flag classes
801-
return className != null && // @formatter:off
802-
!isExperimental(className) &&
803-
!className.matches(
804-
"(^$|"
805-
+ ".*(slf4j).*|"
806-
// #5803
807-
+ "^(java|sun|elemental|javax|jakarta|oshi|org.(apache|atmosphere|jsoup|jboss|w3c|spring|joda|hibernate|glassfish|hsqldb)|com.(helger|spring|gwt|lowagie|fasterxml|sun|nimbusds)|net.(sf|bytebuddy)).*|"
808-
+ ".*(Exception)$"
809-
+ ")"); // @formatter:on
815+
return className != null && !isExperimental(className)
816+
&& !VISITABLE_CLASS_PATTERN.matcher(className).matches();
810817
}
811818

812819
private URL getUrl(String className) {

0 commit comments

Comments
 (0)