Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: speedup startup time by excluding jars #19395

Merged
merged 8 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?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-allowed-ui</artifactId>
<description>Test UI with allowed-packages properties</description>
<packaging>jar</packaging>

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

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-dev-server</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-test-spring-filter-packages-lib-allowed</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-test-spring-filter-packages-lib-blocked</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-test-spring-filter-packages-lib-exclude</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>flow-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-frontend</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<maxAttempts>100</maxAttempts>
<wait>2500</wait>
<jmxPort>9009</jmxPort>
<jvmArguments>
-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=18888
</jvmArguments>
</configuration>
<executions>
<!-- start and stop application when running
integration tests -->
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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;

@Route("allowed")
public class AllowedView extends Div {
}
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;

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

@Route("blocked")
public class BlockedView extends Div {

public BlockedView() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.filtering;

import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;

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

@Route("")
public class ClassScannerView extends Div {

public static Set<Class<?>> classes = Collections.emptySet();
public static final String SCANNED_CLASSES = "scanned-classes";

public ClassScannerView() {
Span scannedClasses = new Span(classes.stream()
.map(Class::getSimpleName).collect(Collectors.joining(",")));
scannedClasses.setId(SCANNED_CLASSES);
add(scannedClasses);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.filtering;

import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Set;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.vaadin.flow.spring.VaadinServletContextInitializer;

/**
* The entry point of the Spring Boot application.
*/
@SpringBootApplication
@Configuration
public class TestServletInitializer {

public static void main(String[] args) {
SpringApplication.run(TestServletInitializer.class, args);
}

@Bean
public VaadinServletContextInitializer vaadinServletContextInitializer(
ApplicationContext context) {

return new VaadinServletContextInitializer(context) {
@Override
protected Set<Class<?>> findClassesForDevMode(
Set<String> basePackages,
List<Class<? extends Annotation>> annotations,
List<Class<?>> superTypes) {
ClassScannerView.classes = super.findClassesForDevMode(
basePackages, annotations, superTypes);
return ClassScannerView.classes;
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
server.port=8888

# By default, also following package is scanned in allowed-ui module:
# - com/vaadin/flow/spring/test/filtering
vaadin.allowed-packages=com/vaadin/flow/spring/test/allowed,com/vaadin/flow/spring/test/exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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.filtering;

import java.util.List;
import java.util.stream.Stream;

import com.vaadin.flow.spring.test.exclude.ExcludedRoute;
import com.vaadin.flow.spring.test.allowed.AllowedView;
import com.vaadin.flow.spring.test.allowed.startup.CustomVaadinServiceInitListener;
import com.vaadin.flow.spring.test.allowed.startup.vaadin.AllowedRoute;
import com.vaadin.flow.spring.test.allowed.BlockedRoute;
import com.vaadin.flow.spring.test.allowed.ScannedAllowedRoute;
import com.vaadin.flow.spring.test.blocked.startup.BlockedCustomVaadinServiceInitListener;
import com.vaadin.flow.spring.test.blocked.startup.vaadin.ScannedBlockedRoute;
import com.vaadin.flow.spring.test.blocked.BlockedView;
import com.vaadin.flow.testutil.ChromeBrowserTest;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;

/**
* Primary target of this IT is class scanning of DevModeServletContextListener
* in {@link com.vaadin.flow.spring.VaadinServletContextInitializer} and
* especially usage of {@code vaadin.blocked-packages} and
* {@code vaadin.allowed-packages} in a multi-module Maven project with jar
* packaged dependencies.
*/
public class ClassScannerIT extends ChromeBrowserTest {

@Test
public void allowedUiModule_withAllowedPackages() {
open();
assertClassAllowed(ClassScannerView.class.getSimpleName());
assertClassAllowed(AllowedView.class.getSimpleName());
assertClassBlocked(BlockedView.class.getSimpleName());
}

@Test
public void libAllowedModule_withAllowedPackagesJar() {
open();
assertClassAllowed(AllowedRoute.class.getSimpleName());
assertClassAllowed(
CustomVaadinServiceInitListener.class.getSimpleName());
assertClassBlocked(BlockedRoute.class.getSimpleName());
}

@Test
public void libBlockedModule_withBlockedPackagesJar() {
open();
assertClassBlocked(ScannedBlockedRoute.class.getSimpleName());
assertClassBlocked(
BlockedCustomVaadinServiceInitListener.class.getSimpleName());
assertClassAllowed(ScannedAllowedRoute.class.getSimpleName());
}

@Test
public void libExcludedModule_withExcludedJar() {
open();
assertClassBlocked(ExcludedRoute.class.getSimpleName());
}

private void assertClassAllowed(String className) {
Assert.assertTrue(className + " should be allowed.",
getScannedClasses().contains(className));
}

private void assertClassBlocked(String className) {
Assert.assertFalse(className + " should be blocked.",
getScannedClasses().contains(className));
}

private List<String> getScannedClasses() {
return Stream.of(findElement(By.id(ClassScannerView.SCANNED_CLASSES))
.getText().split(",")).map(String::trim).toList();
}

@Override
protected String getTestPath() {
return "/";
}
}
Loading
Loading