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 committed Jul 25, 2023
1 parent 2463b85 commit 8fee0cc
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.slf4j.Logger;
Expand Down Expand Up @@ -67,6 +68,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, EndPointData> endPoints = new HashMap<>();
private ThemeDefinition themeDefinition;
private AbstractTheme themeInstance;
Expand Down Expand Up @@ -631,15 +645,8 @@ private boolean isVisitable(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 8fee0cc

Please sign in to comment.