Skip to content

Commit

Permalink
fix: replace 'blocklist' and 'whitelist' with 'blocked' and 'allowed' (
Browse files Browse the repository at this point in the history
…#1077)

* fix: replace 'blocklist' and 'whitelist' with 'blocked' and 'allowed'

* address review comments

* remove `forRemoval`

Co-authored-by: Marco Collovati <marco@vaadin.com>

* update deprecation log message

Co-authored-by: Marco Collovati <marco@vaadin.com>

* fix typo

---------

Co-authored-by: Marco Collovati <marco@vaadin.com>
  • Loading branch information
jouni and mcollovati committed Jan 9, 2024
1 parent 57deaeb commit 0af3dca
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
server.port=8888
vaadin.blacklisted-packages=vaadin-spring/target/test-classes
vaadin.blocked-packages=vaadin-spring/target/test-classes
vaadin.pnpm.enable=true
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ public class VaadinConfigurationProperties {
private boolean asyncSupported = true;

/**
* Whetcher pnpm support is enabled
* Whether pnpm support is enabled.
**/
private boolean pnpmEnabled = false;

/**
* Custom package blacklist that should be skipped in scanning.
* List of blocked packages that shouldn't be scanned.
*/
private List<String> blacklistedPackages = new ArrayList<>();
private List<String> blockedPackages = new ArrayList<>();

/**
* Custom package whitelist that should be scanned.
* List of allowed packages that should be scanned.
*/
private List<String> whitelistedPackages = new ArrayList<>();
private List<String> allowedPackages = new ArrayList<>();

/**
* Gets the url mapping for the Vaadin servlet.
Expand Down Expand Up @@ -112,39 +112,84 @@ public void setPnpmEnabled(boolean pnpmEnabled) {
}

/**
* Get a list of packages that are blacklisted for class scanning.
* Get a list of packages that are blocked for class scanning.
*
* @return package blacklist
* @return blocked packages
* @deprecated use getBlockedPackages()
*/
@Deprecated
public List<String> getBlacklistedPackages() {
return Collections.unmodifiableList(blacklistedPackages);
return Collections.unmodifiableList(blockedPackages);
}

/**
* Set list of packages to ignore for class scanning.
* Get a list of packages that are blocked for class scanning.
*
* @param blacklistedPackages list of packages to ignore
* @return blocked packages
*/
public void setBlacklistedPackages(List<String> blacklistedPackages) {
this.blacklistedPackages = new ArrayList<>(blacklistedPackages);
public List<String> getBlockedPackages() {
return Collections.unmodifiableList(blockedPackages);
}

/**
* Get a list of packages that are white-listed for class scanning.
* Set a list of packages to ignore for class scanning.
*
* @return package white-list
* @param blockedPackages list of packages to ignore
* @deprecated use setBlockedPackages()
*/
@Deprecated
public void setBlacklistedPackages(List<String> blockedPackages) {
this.blockedPackages = new ArrayList<>(blockedPackages);
}

/**
* Set a list of packages to ignore for class scanning.
*
* @param blockedPackages list of packages to ignore
*/
public void setBlockedPackages(List<String> blockedPackages) {
this.blockedPackages = new ArrayList<>(blockedPackages);
}

/**
* Get a list of packages that are allowed for class scanning.
*
* @return allowed packages
* @deprecated use getAllowedPackages()
*/
@Deprecated
public List<String> getWhitelistedPackages() {
return Collections.unmodifiableList(whitelistedPackages);
return Collections.unmodifiableList(allowedPackages);
}

/**
* Get a list of packages that are allowed for class scanning.
*
* @return allowed packages
*/
public List<String> getAllowedPackages() {
return Collections.unmodifiableList(allowedPackages);
}

/**
* Set list of packages to be scanned. If <code>allowedPackages</code>
* is set then <code>blockedPackages</code> is ignored.
*
* @param allowedPackages list of packages to be scanned
* @deprecated use setAllowedPackages()
*/
@Deprecated
public void setWhitelistedPackages(List<String> allowedPackages) {
this.allowedPackages = new ArrayList<>(allowedPackages);
}

/**
* Set list of packages to be scanned. If <code>whitelistedPackages</code>
* is set then <code>blacklistedPackages</code> is ignored.
* Set list of packages to be scanned. If <code>allowedPackages</code>
* is set then <code>blockedPackages</code> is ignored.
*
* @param whitelistedPackages list of packages to be scanned
* @param allowedPackages list of packages to be scanned
*/
public void setWhitelistedPackages(List<String> whitelistedPackages) {
this.whitelistedPackages = new ArrayList<>(whitelistedPackages);
public void setAllowedPackages(List<String> allowedPackages) {
this.allowedPackages = new ArrayList<>(allowedPackages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void contextInitialized(ServletContextEvent event) {
try {
List<Class<?>> routeClasses = findByAnnotation(
getRoutePackages(), Route.class, RouteAlias.class)
.collect(Collectors.toList());
.collect(Collectors.toList());

getLogger().debug(
"Found {} route classes. Here is the list: {}",
Expand Down Expand Up @@ -334,8 +334,8 @@ public void contextInitialized(ServletContextEvent event) {

Stream<Class<? extends Component>> hasErrorComponents = findBySuperType(
getErrorParameterPackages(), HasErrorParameter.class)
.filter(Component.class::isAssignableFrom)
.map(clazz -> (Class<? extends Component>) clazz);
.filter(Component.class::isAssignableFrom)
.map(clazz -> (Class<? extends Component>) clazz);
registry.setErrorNavigationTargets(
hasErrorComponents.collect(Collectors.toSet()));
}
Expand Down Expand Up @@ -429,18 +429,20 @@ public void contextInitialized(ServletContextEvent event) {

Set<Class<?>> classes = findByAnnotationOrSuperType(basePackages,
customLoader, annotations, superTypes)
.collect(Collectors.toSet());
.collect(Collectors.toSet());

final long classScanning = System.currentTimeMillis();
getLogger().info(
"Search for subclasses and classes with annotations took {} seconds",
(classScanning - start) / 1000);

if (classScanning > 10000 && appContext.getEnvironment()
.getProperty("vaadin.whitelisted-packages") == null) {
.getProperty("vaadin.allowed-packages") == null
&& appContext.getEnvironment()
.getProperty("vaadin.whitelisted-packages") == null) {
getLogger().info(
"Due to slow search it is recommended to use the whitelisted-packages feature to make scanning faster.\n\n"
+ "See the whitelisted-packages section in the docs at https://vaadin.com/docs/latest/flow/integrations/spring/configuration#special-configuration-parameters");
"Class scanning is taking a long time. You can use the allowed-packages property to make it faster.\n\n"
+ "See documentation for details: https://vaadin.com/docs/integrations/spring/configuration");
}

try {
Expand Down Expand Up @@ -490,7 +492,7 @@ public void contextInitialized(ServletContextEvent event) {

Set<Class<?>> webComponentExporters = findBySuperType(
getWebComponentPackages(), WebComponentExporter.class)
.collect(Collectors.toSet());
.collect(Collectors.toSet());

try {
initializer.process(webComponentExporters,
Expand Down Expand Up @@ -520,12 +522,19 @@ public void contextDestroyed(ServletContextEvent sce) {
* {@code context} provided.
*
* @param context
* the application context
* the application context
*/
public VaadinServletContextInitializer(ApplicationContext context) {
appContext = context;
String neverScanProperty = appContext.getEnvironment()
.getProperty("vaadin.blacklisted-packages");
.getProperty("vaadin.blocked-packages");
if (neverScanProperty == null) {
neverScanProperty = appContext.getEnvironment()
.getProperty("vaadin.blacklisted-packages");
if (neverScanProperty != null) {
getLogger().warn("vaadin.blacklisted-packages is deprecated and may not be supported in the future. Use vaadin.blocked-packages instead.");
}
}
List<String> neverScan;
if (neverScanProperty == null) {
neverScan = Collections.emptyList();
Expand All @@ -535,7 +544,14 @@ public VaadinServletContextInitializer(ApplicationContext context) {
}

String onlyScanProperty = appContext.getEnvironment()
.getProperty("vaadin.whitelisted-packages");
.getProperty("vaadin.allowed-packages");
if (onlyScanProperty == null) {
onlyScanProperty = appContext.getEnvironment()
.getProperty("vaadin.whitelisted-packages");
if (onlyScanProperty != null) {
getLogger().warn("vaadin.whitelisted-packages is deprecated and may not be supported in the future. Use vaadin.allowed-packages instead.");
}
}
if (onlyScanProperty == null) {
customScanOnly = Collections.emptyList();
customLoader = new CustomResourceLoader(appContext, neverScan);
Expand All @@ -549,7 +565,7 @@ public VaadinServletContextInitializer(ApplicationContext context) {

if (!customScanOnly.isEmpty() && !neverScan.isEmpty()) {
getLogger().warn(
"vaadin.blacklisted-packages is ignored because both vaadin.whitelisted-packages and vaadin.blacklisted-packages have been set.");
"vaadin.blocked-packages is ignored because both vaadin.allowed-packages and vaadin.blocked-packages have been set.");
}
}

Expand Down Expand Up @@ -817,9 +833,9 @@ protected static class SpringStubServletConfig implements ServletConfig {
* Constructor.
*
* @param context
* the ServletContext
* the ServletContext
* @param registration
* the ServletRegistration for this ServletConfig instance
* the ServletRegistration for this ServletConfig instance
*/
private SpringStubServletConfig(ServletContext context,
ServletRegistrationBean registration,
Expand Down Expand Up @@ -868,13 +884,14 @@ public Enumeration<String> getInitParameterNames() {
* Creates a DeploymentConfiguration.
*
* @param context
* the ServletContext
* the ServletContext
* @param registration
* the ServletRegistrationBean to get servlet parameters from
* the ServletRegistrationBean to get servlet parameters
* from
* @param servletClass
* the class to look for properties defined with annotations
* the class to look for properties defined with annotations
* @param appContext
* the ApplicationContext
* the ApplicationContext
* @return a DeploymentConfiguration instance
*/
public static DeploymentConfiguration createDeploymentConfiguration(
Expand Down

0 comments on commit 0af3dca

Please sign in to comment.