diff --git a/pom.xml b/pom.xml index 477658a..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/ @@ -54,7 +54,7 @@ - 14.9.8 + 14.11.11 1.8 1.8 UTF-8 @@ -136,7 +136,7 @@ com.flowingcode.vaadin.addons.demo commons-demo - 3.8.0 + 3.10.0 test 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..cd83fff 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") @@ -100,14 +101,17 @@ 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( e -> { - System.setProperty("productionMode", "" + productionModeCb.getValue().toString()); + setProductionMode(e.getValue()); Notification.show( "Currently production mode is: " + System.getProperty("productionMode")); }); + // #endif Upload upload = new Upload(new NullMemoryBuffer()); upload.addSucceededListener(ev -> { @@ -135,4 +139,18 @@ public ErrorwindowDemo() { add(upload); } + + // #if vaadin eq 0 + 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)); + } + // #endif }