From 326394143b621e40a5475b590eeb24ca46ba0d00 Mon Sep 17 00:00:00 2001 From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:49:33 -0300 Subject: [PATCH 1/4] build: upgrade commons-demo to 3.10.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 477658a..55310bc 100644 --- a/pom.xml +++ b/pom.xml @@ -136,7 +136,7 @@ com.flowingcode.vaadin.addons.demo commons-demo - 3.8.0 + 3.10.0 test From 164ec43b7c83908479cd2e055c21150d425e6503 Mon Sep 17 00:00:00 2001 From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:50:13 -0300 Subject: [PATCH 2/4] build: upgrade vaadin dependency to 14.11.11 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 55310bc..acc00b5 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,7 @@ - 14.9.8 + 14.11.11 1.8 1.8 UTF-8 From e03a912b74c7a3bfdfaf77474c1a0914abf88271 Mon Sep 17 00:00:00 2001 From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:54:05 -0300 Subject: [PATCH 3/4] feat: default to actual production mode from Vaadin Close #79 --- pom.xml | 2 +- .../addons/errorwindow/ErrorWindowFactory.java | 15 +++++++++++++-- .../VaadinServiceInitListenerImpl.java | 11 ++++++++++- .../addons/errorwindow/ErrorwindowDemo.java | 18 ++++++++++++++++-- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index acc00b5..f16dcc9 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.flowingcode.vaadin.addons error-window-vaadin - 4.0.2-SNAPSHOT + 4.1.0-SNAPSHOT Error Window Add-on Error handler that displays a dialog with exception information https://www.flowingcode.com/en/open-source/ diff --git a/src/main/java/com/flowingcode/vaadin/addons/errorwindow/ErrorWindowFactory.java b/src/main/java/com/flowingcode/vaadin/addons/errorwindow/ErrorWindowFactory.java index dd7a256..25eec28 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/errorwindow/ErrorWindowFactory.java +++ b/src/main/java/com/flowingcode/vaadin/addons/errorwindow/ErrorWindowFactory.java @@ -2,7 +2,7 @@ * #%L * Error Window Add-on * %% - * Copyright (C) 2017 - 2023 Flowing Code + * Copyright (C) 2017 - 2024 Flowing Code * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,17 @@ public interface ErrorWindowFactory { * @return true if the application is in production mode, false otherwise */ default boolean isProductionMode() { - return ("true".equals(System.getProperty("productionMode"))); + String errorWindowProductionMode = System.getProperty("errorWindowProductionMode"); + if (errorWindowProductionMode != null) { + return Boolean.valueOf(errorWindowProductionMode); + } + + String productionMode = System.getProperty("productionMode"); + if (productionMode != null) { + return Boolean.valueOf(productionMode); + } + + return VaadinServiceInitListenerImpl.getProductionMode(); } + } diff --git a/src/main/java/com/flowingcode/vaadin/addons/errorwindow/VaadinServiceInitListenerImpl.java b/src/main/java/com/flowingcode/vaadin/addons/errorwindow/VaadinServiceInitListenerImpl.java index 07a97a1..d04399b 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/errorwindow/VaadinServiceInitListenerImpl.java +++ b/src/main/java/com/flowingcode/vaadin/addons/errorwindow/VaadinServiceInitListenerImpl.java @@ -2,7 +2,7 @@ * #%L * Error Window Add-on * %% - * Copyright (C) 2017 - 2023 Flowing Code + * Copyright (C) 2017 - 2024 Flowing Code * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,8 @@ public class VaadinServiceInitListenerImpl implements VaadinServiceInitListener private static final long serialVersionUID = 1L; + private static boolean productionMode; + /** * Implements the {@code serviceInit} method from {@code VaadinServiceInitListener} interface. * This method sets {@code ErrorManager} as the error handler and registers {@link ErrorView} as @@ -48,6 +50,8 @@ public class VaadinServiceInitListenerImpl implements VaadinServiceInitListener */ @Override public void serviceInit(ServiceInitEvent event) { + productionMode = event.getSource().getDeploymentConfiguration().isProductionMode(); + event .getSource() .addSessionInitListener(ev -> ev.getSession().setErrorHandler(this::handleError)); @@ -76,4 +80,9 @@ private void handleError(ErrorEvent event) { event.getThrowable().printStackTrace(); } } + + static boolean getProductionMode() { + return productionMode; + } + } diff --git a/src/test/java/com/flowingcode/vaadin/addons/errorwindow/ErrorwindowDemo.java b/src/test/java/com/flowingcode/vaadin/addons/errorwindow/ErrorwindowDemo.java index ab0b0f0..adc219b 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/errorwindow/ErrorwindowDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/errorwindow/ErrorwindowDemo.java @@ -2,7 +2,7 @@ * #%L * Error Window Add-on * %% - * Copyright (C) 2017 - 2023 Flowing Code + * Copyright (C) 2017 - 2024 Flowing Code * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ import com.vaadin.flow.component.upload.Upload; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; +import java.util.Optional; @DemoSource @PageTitle("Error Window Demo") @@ -102,9 +103,10 @@ public ErrorwindowDemo() { }); Checkbox productionModeCb = new Checkbox("Production Mode"); + productionModeCb.setValue(getProductionMode()); productionModeCb.addValueChangeListener( e -> { - System.setProperty("productionMode", "" + productionModeCb.getValue().toString()); + setProductionMode(e.getValue()); Notification.show( "Currently production mode is: " + System.getProperty("productionMode")); }); @@ -135,4 +137,16 @@ public ErrorwindowDemo() { add(upload); } + + private boolean getProductionMode() { + return Optional.ofNullable(System.getProperty("errorWindowProductionMode")) + .map(Boolean::valueOf).orElseGet(() -> { + setProductionMode(true); + return Boolean.TRUE; + }); + } + + private void setProductionMode(boolean mode) { + System.setProperty("errorWindowProductionMode", Boolean.toString(mode)); + } } From c317540a4c7099994159f23881e4bae1e0d13946 Mon Sep 17 00:00:00 2001 From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:58:26 -0300 Subject: [PATCH 4/4] chore(demo): hide code that changes production mode --- .../vaadin/addons/errorwindow/ErrorwindowDemo.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/flowingcode/vaadin/addons/errorwindow/ErrorwindowDemo.java b/src/test/java/com/flowingcode/vaadin/addons/errorwindow/ErrorwindowDemo.java index adc219b..cd83fff 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/errorwindow/ErrorwindowDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/errorwindow/ErrorwindowDemo.java @@ -101,7 +101,8 @@ public ErrorwindowDemo() { new ErrorWindow(e, "CUSTOM ERROR MESSAGE", errorWindowI18n).open(); } }); - + + // #if vaadin eq 0 Checkbox productionModeCb = new Checkbox("Production Mode"); productionModeCb.setValue(getProductionMode()); productionModeCb.addValueChangeListener( @@ -110,6 +111,7 @@ public ErrorwindowDemo() { Notification.show( "Currently production mode is: " + System.getProperty("productionMode")); }); + // #endif Upload upload = new Upload(new NullMemoryBuffer()); upload.addSucceededListener(ev -> { @@ -138,6 +140,7 @@ public ErrorwindowDemo() { } + // #if vaadin eq 0 private boolean getProductionMode() { return Optional.ofNullable(System.getProperty("errorWindowProductionMode")) .map(Boolean::valueOf).orElseGet(() -> { @@ -149,4 +152,5 @@ private boolean getProductionMode() { private void setProductionMode(boolean mode) { System.setProperty("errorWindowProductionMode", Boolean.toString(mode)); } + // #endif }