Skip to content

Commit

Permalink
feat: Watch for theme changes in other Maven modules (#16740)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- committed May 11, 2023
1 parent 9903a46 commit 8f15c54
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 12 deletions.
1 change: 1 addition & 0 deletions flow-tests/pom.xml
Expand Up @@ -289,6 +289,7 @@
<module>test-router-custom-context</module>
<module>test-live-reload</module>
<module>test-live-reload-multimodule</module>
<module>test-live-reload-multimodule/pom-devbundle.xml</module>
<module>test-redeployment</module>

<module>test-scalability</module>
Expand Down
20 changes: 20 additions & 0 deletions flow-tests/test-live-reload-multimodule/library/pom-devbundle.xml
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>flow-test-live-reload-multimodule-devbundle</artifactId>
<groupId>com.vaadin</groupId>
<version>24.1-SNAPSHOT</version>
<relativePath>../pom-devbundle.xml</relativePath>
</parent>
<artifactId>flow-test-live-reload-multimodule-library-devbundle</artifactId>
<name>The frontend library module for a live reload multi module project (dev bundle)</name>

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

</project>
8 changes: 0 additions & 8 deletions flow-tests/test-live-reload-multimodule/library/pom.xml
Expand Up @@ -16,12 +16,4 @@
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

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

</project>
50 changes: 50 additions & 0 deletions flow-tests/test-live-reload-multimodule/pom-devbundle.xml
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>flow-tests</artifactId>
<groupId>com.vaadin</groupId>
<version>24.1-SNAPSHOT</version>
</parent>
<artifactId>flow-test-live-reload-multimodule-devbundle</artifactId>
<name>The main module for a live reload multi module project (dev bundle)</name>

<packaging>pom</packaging>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<vaadin.devmode.liveReload.enabled>true</vaadin.devmode.liveReload.enabled>
<vaadin.frontend.hotdeploy>false</vaadin.frontend.hotdeploy>
</properties>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-test-resources</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-test-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-dev-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-test-lumo</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<modules>
<module>library/pom-devbundle.xml</module>
<module>ui/pom-devbundle.xml</module>
<module>theme/pom-devbundle.xml</module>
</modules>

</project>
1 change: 1 addition & 0 deletions flow-tests/test-live-reload-multimodule/pom.xml
Expand Up @@ -44,6 +44,7 @@
<modules>
<module>library</module>
<module>ui</module>
<module>theme</module>
</modules>

</project>
20 changes: 20 additions & 0 deletions flow-tests/test-live-reload-multimodule/theme/pom-devbundle.xml
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>flow-test-live-reload-multimodule-devbundle</artifactId>
<groupId>com.vaadin</groupId>
<version>24.1-SNAPSHOT</version>
<relativePath>../pom-devbundle.xml</relativePath>
</parent>
<artifactId>flow-test-live-reload-multimodule-theme-devbundle</artifactId>
<name>The theme module for a live reload multi module project (dev bundle)</name>

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

</project>
19 changes: 19 additions & 0 deletions flow-tests/test-live-reload-multimodule/theme/pom.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>flow-test-live-reload-multimodule-hotdeploy</artifactId>
<groupId>com.vaadin</groupId>
<version>24.1-SNAPSHOT</version>
</parent>
<artifactId>flow-test-live-reload-multimodule-theme-hotdeploy</artifactId>
<name>The theme module for a live reload multi module project (hotdeploy)</name>

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

</project>
@@ -0,0 +1,3 @@
body {
background: lightblue;
}
54 changes: 54 additions & 0 deletions flow-tests/test-live-reload-multimodule/ui/pom-devbundle.xml
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>flow-test-live-reload-multimodule-devbundle</artifactId>
<groupId>com.vaadin</groupId>
<version>24.1-SNAPSHOT</version>
<relativePath>../pom-devbundle.xml</relativePath>
</parent>
<artifactId>flow-test-live-reload-multimodule-ui-devbundle</artifactId>
<name>The UI module for a live reload multi module project (dev bundle)</name>

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

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-test-live-reload-multimodule-library-devbundle</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-test-live-reload-multimodule-theme-devbundle</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>flow-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>prepare-frontend</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Run jetty before integration tests, and stop after -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
5 changes: 5 additions & 0 deletions flow-tests/test-live-reload-multimodule/ui/pom.xml
Expand Up @@ -22,6 +22,11 @@
<artifactId>flow-test-live-reload-multimodule-library-hotdeploy</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-test-live-reload-multimodule-theme-hotdeploy</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
@@ -0,0 +1,9 @@
package com.vaadin.flow.uitest.multimodule.ui;

import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.theme.Theme;

@Theme("mytheme")
public class AppShell implements AppShellConfigurator {

}
Expand Up @@ -19,13 +19,11 @@
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.uitest.servlet.ViewTestLayout;

@Route(value = "com.vaadin.flow.uitest.multimodule.ui.FrontendLiveReloadView", layout = ViewTestLayout.class)
public class FrontendLiveReloadView extends Div
implements AppShellConfigurator {
public class FrontendLiveReloadView extends Div {

@Tag("in-frontend")
@JsModule("./in-frontend.js")
Expand All @@ -41,6 +39,7 @@ public static class InResourcesFrontend extends Component {

public FrontendLiveReloadView() {
add(new ProjectFolderInfo());
add(new ProjectHotdeployInfo());
add(new InFrontend());
add(new InResourcesFrontend());
}
Expand Down
@@ -0,0 +1,21 @@
package com.vaadin.flow.uitest.multimodule.ui;

import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.server.Mode;
import com.vaadin.flow.server.VaadinContext;
import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.startup.ApplicationConfiguration;

@Tag("project-hotdeploy-info")
public class ProjectHotdeployInfo extends Div {

public ProjectHotdeployInfo() {
VaadinContext context = VaadinService.getCurrent().getContext();
Span hotdeploy = new Span(ApplicationConfiguration.get(context)
.getMode() == Mode.DEVELOPMENT_FRONTEND_LIVERELOAD ? "true"
: "false");
add(hotdeploy);
}
}
Expand Up @@ -29,6 +29,7 @@
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import org.openqa.selenium.StaleElementReferenceException;
import org.slf4j.LoggerFactory;
Expand All @@ -55,6 +56,10 @@ public void cleanup() {
@Test
public void modifyMetaInfFrontendFile() throws IOException {
open();
boolean hotdeploy = $("project-hotdeploy-info").first().getText()
.equalsIgnoreCase("true");
// Live reload of frontend files only works when using hotdeploy
Assume.assumeTrue(hotdeploy);

String uiModuleFolder = $("project-folder-info").first().getText();
File libraryFolder = new File(new File(uiModuleFolder).getParentFile(),
Expand All @@ -80,6 +85,10 @@ public void modifyMetaInfFrontendFile() throws IOException {
@Test
public void modifyMetaInfResourcesFrontendFile() throws IOException {
open();
boolean hotdeploy = $("project-hotdeploy-info").first().getText()
.equalsIgnoreCase("true");
// Live reload of frontend files only works when using hotdeploy
Assume.assumeTrue(hotdeploy);

String uiModuleFolder = $("project-folder-info").first().getText();
File libraryFolder = new File(new File(uiModuleFolder).getParentFile(),
Expand All @@ -105,6 +114,29 @@ public void modifyMetaInfResourcesFrontendFile() throws IOException {
() -> $("in-resources-frontend").first().getText());
}

@Test
public void modifyThemeFile() throws IOException {
open();
String uiModuleFolder = $("project-folder-info").first().getText();
File themeFolder = new File(new File(uiModuleFolder).getParentFile(),
"theme");
Path stylesCssPath = Path.of("src", "main", "resources", "META-INF",
"resources", "themes", "mytheme", "styles.css");
Path stylesCss = themeFolder.toPath().resolve(stylesCssPath);

revertThemeIfNeeded(stylesCss);
this.cleanup.add(() -> revertThemeIfNeeded(stylesCss));
Assert.assertEquals("rgba(173, 216, 230, 1)", getBackgroundColor());

modifyTheme(stylesCss.toFile());

waitUntilEquals("rgba(144, 238, 144, 1)", this::getBackgroundColor);
}

private String getBackgroundColor() {
return $("body").first().getCssValue("background-color");
}

private void waitUntilEquals(String expected, Supplier<String> supplier) {
waitUntil(driver -> {
try {
Expand All @@ -123,6 +155,15 @@ private void revertJsFileIfNeeded(Path path) throws UncheckedIOException {
modify(path.toFile(), ". It was modified</span>", "</span>", false);
}

private void modifyTheme(File file) throws UncheckedIOException {
modify(file, "lightblue", "lightgreen", true);
}

private void revertThemeIfNeeded(Path stylesCss)
throws UncheckedIOException {
modify(stylesCss.toFile(), "lightgreen", "lightblue", false);
}

private void modify(File file, String from, String to,
boolean failIfNotModified) throws UncheckedIOException {
try {
Expand Down
4 changes: 4 additions & 0 deletions scripts/computeMatrix.js
Expand Up @@ -91,6 +91,10 @@ const moduleWeights = {
'flow-tests/vaadin-spring-tests/test-mvc-without-endpoints': { pos: 5, weight: 2 },
'flow-tests/test-live-reload-multimodule/ui': {pos:6},
'flow-tests/test-live-reload-multimodule/library': {pos:6},
'flow-tests/test-live-reload-multimodule/theme': {pos:6},
'flow-tests/test-live-reload-multimodule/ui/pom-devbundle.xml': {pos:6},
'flow-tests/test-live-reload-multimodule/library/pom-devbundle.xml': {pos:6},
'flow-tests/test-live-reload-multimodule/theme/pom-devbundle.xml': {pos:6},
'flow-tests/test-redeployment': { weight: 13 },
'flow-tests/test-pwa': { weight: 10 },
'flow-tests/test-frontend/vite-pwa-disabled-offline': { weight: 7 },
Expand Down
Expand Up @@ -109,13 +109,17 @@ private boolean watchDependencyFolder(File metaInfFolder,
File metaInfFrontend = new File(metaInfFolder, "frontend");
File metaInfResourcesFrontend = new File(
new File(metaInfFolder, "resources"), "frontend");
File metaInfResourcesThemes = new File(
new File(metaInfFolder, "resources"), "themes");

boolean watching1 = watchAndCopy(metaInfFrontend,
jarFrontendResourcesFolder);
boolean watching2 = watchAndCopy(metaInfResourcesFrontend,
jarFrontendResourcesFolder);
boolean watching3 = watchAndCopy(metaInfResourcesThemes,
new File(jarFrontendResourcesFolder, "themes"));

return watching1 || watching2;
return watching1 || watching2 || watching3;
}

private boolean watchAndCopy(File watchFolder, File targetFolder) {
Expand Down

0 comments on commit 8f15c54

Please sign in to comment.