Skip to content

Commit

Permalink
fix: pre-compile visitable classes regex pattern (#17280)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mcollovati authored and vaadin-bot committed Jul 25, 2023
1 parent 199b5e1 commit ab5e283
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -73,6 +74,19 @@
*/
public class FrontendDependencies extends AbstractDependenciesScanner {

//@formatter:off
private static final Pattern VISITABLE_CLASS_PATTERN = Pattern.compile("(^$|"
+ ".*(slf4j).*|"
// #5803
+ "^(java|sun|oracle|elemental|javax|jakarta|oshi|"
+ "org\\.(apache|atmosphere|jsoup|jboss|w3c|spring|joda|hibernate|glassfish|hsqldb|osgi|jooq)|"
+ "com\\.(helger|spring|gwt|lowagie|fasterxml|sun|nimbusds|googlecode)|"
+ "net\\.(sf|bytebuddy)"
+ ").*|"
+ ".*(Exception)$"
+ ")");
//@formatter:on

private final HashMap<String, EntryPointData> entryPoints = new LinkedHashMap<>();
private ThemeDefinition themeDefinition;
private AbstractTheme themeInstance;
Expand Down Expand Up @@ -764,15 +778,8 @@ private boolean shouldVisit(String className) {
// factories. This is the reason of having just a blacklist of some
// common name-spaces that would not have components.
// We also exclude Feature-Flag classes
return className != null && // @formatter:off
!isExperimental(className) &&
!className.matches(
"(^$|"
+ ".*(slf4j).*|"
// #5803
+ "^(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)).*|"
+ ".*(Exception)$"
+ ")"); // @formatter:on
return className != null && !isExperimental(className)
&& !VISITABLE_CLASS_PATTERN.matcher(className).matches();
}

private URL getUrl(String className) {
Expand Down

0 comments on commit ab5e283

Please sign in to comment.