Skip to content

Commit e03a912

Browse files
committed
feat: default to actual production mode from Vaadin
Close #79
1 parent 164ec43 commit e03a912

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.flowingcode.vaadin.addons</groupId>
55
<artifactId>error-window-vaadin</artifactId>
6-
<version>4.0.2-SNAPSHOT</version>
6+
<version>4.1.0-SNAPSHOT</version>
77
<name>Error Window Add-on</name>
88
<description>Error handler that displays a dialog with exception information</description>
99
<url>https://www.flowingcode.com/en/open-source/</url>

src/main/java/com/flowingcode/vaadin/addons/errorwindow/ErrorWindowFactory.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Error Window Add-on
44
* %%
5-
* Copyright (C) 2017 - 2023 Flowing Code
5+
* Copyright (C) 2017 - 2024 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -37,6 +37,17 @@ public interface ErrorWindowFactory {
3737
* @return true if the application is in production mode, false otherwise
3838
*/
3939
default boolean isProductionMode() {
40-
return ("true".equals(System.getProperty("productionMode")));
40+
String errorWindowProductionMode = System.getProperty("errorWindowProductionMode");
41+
if (errorWindowProductionMode != null) {
42+
return Boolean.valueOf(errorWindowProductionMode);
43+
}
44+
45+
String productionMode = System.getProperty("productionMode");
46+
if (productionMode != null) {
47+
return Boolean.valueOf(productionMode);
48+
}
49+
50+
return VaadinServiceInitListenerImpl.getProductionMode();
4151
}
52+
4253
}

src/main/java/com/flowingcode/vaadin/addons/errorwindow/VaadinServiceInitListenerImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Error Window Add-on
44
* %%
5-
* Copyright (C) 2017 - 2023 Flowing Code
5+
* Copyright (C) 2017 - 2024 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -39,6 +39,8 @@ public class VaadinServiceInitListenerImpl implements VaadinServiceInitListener
3939

4040
private static final long serialVersionUID = 1L;
4141

42+
private static boolean productionMode;
43+
4244
/**
4345
* Implements the {@code serviceInit} method from {@code VaadinServiceInitListener} interface.
4446
* This method sets {@code ErrorManager} as the error handler and registers {@link ErrorView} as
@@ -48,6 +50,8 @@ public class VaadinServiceInitListenerImpl implements VaadinServiceInitListener
4850
*/
4951
@Override
5052
public void serviceInit(ServiceInitEvent event) {
53+
productionMode = event.getSource().getDeploymentConfiguration().isProductionMode();
54+
5155
event
5256
.getSource()
5357
.addSessionInitListener(ev -> ev.getSession().setErrorHandler(this::handleError));
@@ -76,4 +80,9 @@ private void handleError(ErrorEvent event) {
7680
event.getThrowable().printStackTrace();
7781
}
7882
}
83+
84+
static boolean getProductionMode() {
85+
return productionMode;
86+
}
87+
7988
}

src/test/java/com/flowingcode/vaadin/addons/errorwindow/ErrorwindowDemo.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Error Window Add-on
44
* %%
5-
* Copyright (C) 2017 - 2023 Flowing Code
5+
* Copyright (C) 2017 - 2024 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@
3030
import com.vaadin.flow.component.upload.Upload;
3131
import com.vaadin.flow.router.PageTitle;
3232
import com.vaadin.flow.router.Route;
33+
import java.util.Optional;
3334

3435
@DemoSource
3536
@PageTitle("Error Window Demo")
@@ -102,9 +103,10 @@ public ErrorwindowDemo() {
102103
});
103104

104105
Checkbox productionModeCb = new Checkbox("Production Mode");
106+
productionModeCb.setValue(getProductionMode());
105107
productionModeCb.addValueChangeListener(
106108
e -> {
107-
System.setProperty("productionMode", "" + productionModeCb.getValue().toString());
109+
setProductionMode(e.getValue());
108110
Notification.show(
109111
"Currently production mode is: " + System.getProperty("productionMode"));
110112
});
@@ -135,4 +137,16 @@ public ErrorwindowDemo() {
135137
add(upload);
136138

137139
}
140+
141+
private boolean getProductionMode() {
142+
return Optional.ofNullable(System.getProperty("errorWindowProductionMode"))
143+
.map(Boolean::valueOf).orElseGet(() -> {
144+
setProductionMode(true);
145+
return Boolean.TRUE;
146+
});
147+
}
148+
149+
private void setProductionMode(boolean mode) {
150+
System.setProperty("errorWindowProductionMode", Boolean.toString(mode));
151+
}
138152
}

0 commit comments

Comments
 (0)