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: default to actual production mode from Vaadin #80

Merged
merged 4 commits into from
Jun 4, 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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.flowingcode.vaadin.addons</groupId>
<artifactId>error-window-vaadin</artifactId>
<version>4.0.2-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
<name>Error Window Add-on</name>
<description>Error handler that displays a dialog with exception information</description>
<url>https://www.flowingcode.com/en/open-source/</url>
Expand Down Expand Up @@ -54,7 +54,7 @@
</licenses>

<properties>
<vaadin.version>14.9.8</vaadin.version>
<vaadin.version>14.11.11</vaadin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -136,7 +136,7 @@
<dependency>
<groupId>com.flowingcode.vaadin.addons.demo</groupId>
<artifactId>commons-demo</artifactId>
<version>3.8.0</version>
<version>3.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
paodb marked this conversation as resolved.
Show resolved Hide resolved
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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));
Expand Down Expand Up @@ -76,4 +80,9 @@ private void handleError(ErrorEvent event) {
event.getThrowable().printStackTrace();
}
}

static boolean getProductionMode() {
return productionMode;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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));
}
paodb marked this conversation as resolved.
Show resolved Hide resolved
// #endif
}
Loading