From 0af3dca8d3f416c8ff1e1c54ca76360fb6352405 Mon Sep 17 00:00:00 2001 From: Jouni Koivuviita Date: Tue, 9 Jan 2024 09:20:39 +0200 Subject: [PATCH] fix: replace 'blocklist' and 'whitelist' with 'blocked' and 'allowed' (#1077) * fix: replace 'blocklist' and 'whitelist' with 'blocked' and 'allowed' * address review comments * remove `forRemoval` Co-authored-by: Marco Collovati * update deprecation log message Co-authored-by: Marco Collovati * fix typo --------- Co-authored-by: Marco Collovati --- .../src/main/resources/application.properties | 2 +- .../spring/VaadinConfigurationProperties.java | 85 ++++++++++++++----- .../VaadinServletContextInitializer.java | 53 ++++++++---- 3 files changed, 101 insertions(+), 39 deletions(-) diff --git a/vaadin-spring-tests/test-spring-boot-only-prepare/src/main/resources/application.properties b/vaadin-spring-tests/test-spring-boot-only-prepare/src/main/resources/application.properties index e426f2e20..f9bd28e05 100644 --- a/vaadin-spring-tests/test-spring-boot-only-prepare/src/main/resources/application.properties +++ b/vaadin-spring-tests/test-spring-boot-only-prepare/src/main/resources/application.properties @@ -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 diff --git a/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinConfigurationProperties.java b/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinConfigurationProperties.java index 91fc248bb..2a52e3e9c 100644 --- a/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinConfigurationProperties.java +++ b/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinConfigurationProperties.java @@ -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 blacklistedPackages = new ArrayList<>(); + private List blockedPackages = new ArrayList<>(); /** - * Custom package whitelist that should be scanned. + * List of allowed packages that should be scanned. */ - private List whitelistedPackages = new ArrayList<>(); + private List allowedPackages = new ArrayList<>(); /** * Gets the url mapping for the Vaadin servlet. @@ -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 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 blacklistedPackages) { - this.blacklistedPackages = new ArrayList<>(blacklistedPackages); + public List 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 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 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 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 getAllowedPackages() { + return Collections.unmodifiableList(allowedPackages); + } + + /** + * Set list of packages to be scanned. If allowedPackages + * is set then blockedPackages is ignored. + * + * @param allowedPackages list of packages to be scanned + * @deprecated use setAllowedPackages() + */ + @Deprecated + public void setWhitelistedPackages(List allowedPackages) { + this.allowedPackages = new ArrayList<>(allowedPackages); } /** - * Set list of packages to be scanned. If whitelistedPackages - * is set then blacklistedPackages is ignored. + * Set list of packages to be scanned. If allowedPackages + * is set then blockedPackages is ignored. * - * @param whitelistedPackages list of packages to be scanned + * @param allowedPackages list of packages to be scanned */ - public void setWhitelistedPackages(List whitelistedPackages) { - this.whitelistedPackages = new ArrayList<>(whitelistedPackages); + public void setAllowedPackages(List allowedPackages) { + this.allowedPackages = new ArrayList<>(allowedPackages); } } diff --git a/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinServletContextInitializer.java b/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinServletContextInitializer.java index fe188bb46..639056911 100644 --- a/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinServletContextInitializer.java +++ b/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinServletContextInitializer.java @@ -253,7 +253,7 @@ public void contextInitialized(ServletContextEvent event) { try { List> routeClasses = findByAnnotation( getRoutePackages(), Route.class, RouteAlias.class) - .collect(Collectors.toList()); + .collect(Collectors.toList()); getLogger().debug( "Found {} route classes. Here is the list: {}", @@ -334,8 +334,8 @@ public void contextInitialized(ServletContextEvent event) { Stream> hasErrorComponents = findBySuperType( getErrorParameterPackages(), HasErrorParameter.class) - .filter(Component.class::isAssignableFrom) - .map(clazz -> (Class) clazz); + .filter(Component.class::isAssignableFrom) + .map(clazz -> (Class) clazz); registry.setErrorNavigationTargets( hasErrorComponents.collect(Collectors.toSet())); } @@ -429,7 +429,7 @@ public void contextInitialized(ServletContextEvent event) { Set> classes = findByAnnotationOrSuperType(basePackages, customLoader, annotations, superTypes) - .collect(Collectors.toSet()); + .collect(Collectors.toSet()); final long classScanning = System.currentTimeMillis(); getLogger().info( @@ -437,10 +437,12 @@ public void contextInitialized(ServletContextEvent event) { (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 { @@ -490,7 +492,7 @@ public void contextInitialized(ServletContextEvent event) { Set> webComponentExporters = findBySuperType( getWebComponentPackages(), WebComponentExporter.class) - .collect(Collectors.toSet()); + .collect(Collectors.toSet()); try { initializer.process(webComponentExporters, @@ -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 neverScan; if (neverScanProperty == null) { neverScan = Collections.emptyList(); @@ -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); @@ -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."); } } @@ -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, @@ -868,13 +884,14 @@ public Enumeration 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(