Skip to content

Commit

Permalink
feat: filterable class scanning of JAR (#19299)
Browse files Browse the repository at this point in the history
* feat: filterable class scanning of JAR

This change improves optimization of class scanning of `VaadinServletContextInitializer` by reading optional configuration file within a JAR dependency. Configuration file is a regular properties file that can contain `vaadin.allowed-packages` or `vaadin.blocked-packages` to exclude/include packages being scanned by `VaadinServletContextInitializer`. Package exclusion/inclusion effects only classes in the JAR/module where `META-INF/VAADIN/package.properties` is located at.

Notice that this is only affecting the performance of the class scanning of Vaadin specific annotations and types and this feature is not meant to be used for excluding packages from the whole application. E.g. excluding `VaadinServiceInitListener` in a Spring application is not stopping Spring and Vaadin initializing it anyway, although some time-consuming actions like `DevModeServletContextListener` would still exclude it for optimization.

Fixes: #19117

* chore: refactoring and Javadoc

* chore: cleaned up IT

* chore: updated version to 24.5-SNAPSHOT

* chore: updated computeMatrix.js

* chore: formatting

* chore: added sub-modules

* chore: serialized FilterableResourceResolver

* chore: refactored code review findings

* chore: serialized PackageInfo
  • Loading branch information
tltv authored May 6, 2024
1 parent be17780 commit 2bdf3e0
Show file tree
Hide file tree
Showing 22 changed files with 1,153 additions and 11 deletions.
1 change: 1 addition & 0 deletions flow-tests/vaadin-spring-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@

<module>test-spring-boot-only-prepare</module>
<module>test-spring-white-list</module>
<module>test-spring-filter-packages</module>

</modules>
</profile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2000-2024 Vaadin Ltd.
~
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not
~ use this file except in compliance with the License. You may obtain a copy of
~ the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
~ License for the specific language governing permissions and limitations under
~ the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vaadin-test-spring-filter-packages</artifactId>
<groupId>com.vaadin</groupId>
<version>24.5-SNAPSHOT</version>
</parent>
<artifactId>vaadin-test-spring-filter-packages-lib-allowed</artifactId>
<name>Library with vaadin.allowed-packages property
</name>

<packaging>jar</packaging>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2000-2024 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.spring.test.allowed;

import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.Route;

/**
* Blocked route in a jar package.
*/
@Route("blocked-route-in-jar")
public class BlockedRoute extends Div {

public BlockedRoute() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2000-2024 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.spring.test.allowed.startup;

import com.vaadin.flow.server.ServiceInitEvent;
import com.vaadin.flow.server.VaadinServiceInitListener;

public class CustomVaadinServiceInitListener
implements VaadinServiceInitListener {

@Override
public void serviceInit(ServiceInitEvent event) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2000-2024 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.spring.test.allowed.startup.vaadin;

import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.Route;

@Route(value = "allowed-route-in-jar")
public class AllowedRoute extends Div {

public AllowedRoute() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vaadin.allowed-packages=com/vaadin/flow/spring/test/allowed/startup
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2000-2024 Vaadin Ltd.
~
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not
~ use this file except in compliance with the License. You may obtain a copy of
~ the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
~ License for the specific language governing permissions and limitations under
~ the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vaadin-test-spring-filter-packages</artifactId>
<groupId>com.vaadin</groupId>
<version>24.5-SNAPSHOT</version>
</parent>
<artifactId>vaadin-test-spring-filter-packages-lib-blocked</artifactId>
<name>Library with vaadin.blocked-packages property
</name>

<packaging>jar</packaging>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2000-2024 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.spring.test.blocked;

import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.Route;

@Route("allowed-route-in-another-jar")
public class ScannedAllowedRoute extends Div {

public ScannedAllowedRoute() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2000-2024 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.spring.test.blocked.startup;

import com.vaadin.flow.server.ServiceInitEvent;
import com.vaadin.flow.server.VaadinServiceInitListener;

public class BlockedCustomVaadinServiceInitListener
implements VaadinServiceInitListener {

@Override
public void serviceInit(ServiceInitEvent event) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2000-2024 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.spring.test.blocked.startup.vaadin;

import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.Route;

@Route(value = "blocked-route-in-scanned-jar")
public class ScannedBlockedRoute extends Div {

public ScannedBlockedRoute() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vaadin.blocked-packages=com/vaadin/flow/spring/test/blocked/startup
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2000-2024 Vaadin Ltd.
~
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not
~ use this file except in compliance with the License. You may obtain a copy of
~ the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
~ License for the specific language governing permissions and limitations under
~ the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vaadin-test-spring-filter-packages</artifactId>
<groupId>com.vaadin</groupId>
<version>24.5-SNAPSHOT</version>
</parent>
<artifactId>vaadin-test-spring-filter-packages-lib-exclude</artifactId>
<name>Library with vaadin.blocked-jar property
</name>

<packaging>jar</packaging>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
42 changes: 42 additions & 0 deletions flow-tests/vaadin-spring-tests/test-spring-filter-packages/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2000-2024 Vaadin Ltd.
~
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not
~ use this file except in compliance with the License. You may obtain a copy of
~ the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
~ License for the specific language governing permissions and limitations under
~ the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vaadin-spring-tests</artifactId>
<groupId>com.vaadin</groupId>
<version>24.5-SNAPSHOT</version>
</parent>
<artifactId>vaadin-test-spring-filter-packages</artifactId>
<name>The main module for a Spring boot package filter tests
</name>

<packaging>pom</packaging>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<modules>
<module>lib-allowed</module>
<module>lib-blocked</module>
<module>lib-exclude</module>
<module>ui</module>
</modules>

</project>
Loading

0 comments on commit 2bdf3e0

Please sign in to comment.