use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class DevModeBrowserLauncher method isProductionMode.
private static boolean isProductionMode(GenericWebApplicationContext app) {
ServletContext servletContext = app.getServletContext();
VaadinContext context = new VaadinServletContext(servletContext);
ApplicationConfiguration applicationConfiguration = ApplicationConfiguration.get(context);
return applicationConfiguration.isProductionMode();
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class AbstractDevServerRunner method doStartDevServer.
/**
* Starts the dev server and returns the started process.
*
* @return the started process or {@code null} if no process was started
*/
protected Process doStartDevServer() {
ApplicationConfiguration config = getApplicationConfiguration();
ProcessBuilder processBuilder = new ProcessBuilder().directory(getProjectRoot());
FrontendTools tools = new FrontendTools(config, getProjectRoot());
tools.validateNodeAndNpmVersion();
List<String> command = getServerStartupCommand(tools);
FrontendUtils.console(FrontendUtils.GREEN, START);
if (getLogger().isDebugEnabled()) {
getLogger().debug(FrontendUtils.commandToString(getProjectRoot().getAbsolutePath(), command));
}
processBuilder.command(command);
Map<String, String> environment = processBuilder.environment();
updateServerStartupEnvironment(tools, environment);
try {
Process process = processBuilder.redirectErrorStream(true).start();
/*
* We only can save the dev server process reference the first time
* that the DevModeHandler is created. There is no way to store it
* in the servlet container, and we do not want to save it in the
* global JVM.
*
* We instruct the JVM to stop the server daemon when the JVM stops,
* to avoid leaving daemons running in the system.
*
* NOTE: that in the corner case that the JVM crashes or it is
* killed the daemon will be kept running. But anyways it will also
* happens if the system was configured to be stop the daemon when
* the servlet context is destroyed.
*/
Runtime.getRuntime().addShutdownHook(new Thread(this::stop));
DevServerOutputTracker outputTracker = new DevServerOutputTracker(process.getInputStream(), getServerSuccessPattern(), getServerFailurePattern(), this::onDevServerCompilation);
outputTracker.find();
getLogger().info(LOG_START, getServerName());
int timeout = Integer.parseInt(config.getStringProperty(InitParameters.SERVLET_PARAMETER_DEVMODE_WEBPACK_TIMEOUT, DEFAULT_TIMEOUT_FOR_PATTERN));
outputTracker.awaitFirstMatch(timeout);
return process;
} catch (IOException e) {
getLogger().error("Failed to start the " + getServerName() + " process", e);
} catch (InterruptedException e) {
getLogger().debug(getServerName() + " process start has been interrupted", e);
}
return null;
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class PushHandler method isProductionMode.
private boolean isProductionMode() {
VaadinContext context = service.getContext();
ApplicationConfiguration conf = ApplicationConfiguration.get(context);
return conf.isProductionMode();
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class DefaultDeploymentConfigurationTest method testGetSystemPropertyForDefaultPackage.
@Test
public void testGetSystemPropertyForDefaultPackage() throws ClassNotFoundException {
Class<?> clazz = Class.forName("ClassInDefaultPackage");
String value = "value";
String prop = "prop";
System.setProperty(prop, value);
Properties initParameters = new Properties();
ApplicationConfiguration appConfig = setupAppConfig();
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
DefaultDeploymentConfiguration config = new DefaultDeploymentConfiguration(appConfig, clazz, initParameters);
assertEquals(value, config.getSystemProperty(prop));
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class DefaultDeploymentConfigurationTest method isProductionMode_productionModeIsSetViaPropertiesAndViaParent_productionModeIsTakenFromProperties.
@Test
public void isProductionMode_productionModeIsSetViaPropertiesAndViaParent_productionModeIsTakenFromProperties() {
ApplicationConfiguration appConfig = setupAppConfig();
Mockito.when(appConfig.isProductionMode()).thenReturn(false);
Properties initParameters = new Properties();
initParameters.setProperty(InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE, Boolean.TRUE.toString());
DefaultDeploymentConfiguration config = createDeploymentConfig(appConfig, initParameters);
// the deployment configuration parameter takes precedence over parent
// config
Assert.assertTrue(config.isProductionMode());
}
Aggregations