Search in sources :

Example 36 with ApplicationConfiguration

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();
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) VaadinContext(com.vaadin.flow.server.VaadinContext) VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) ServletContext(javax.servlet.ServletContext) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 37 with ApplicationConfiguration

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;
}
Also used : IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) FrontendTools(com.vaadin.flow.server.frontend.FrontendTools)

Example 38 with ApplicationConfiguration

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();
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 39 with ApplicationConfiguration

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));
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 40 with ApplicationConfiguration

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());
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Aggregations

ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)61 Properties (java.util.Properties)39 Test (org.junit.Test)39 VaadinContext (com.vaadin.flow.server.VaadinContext)14 Lookup (com.vaadin.flow.di.Lookup)9 VaadinService (com.vaadin.flow.server.VaadinService)7 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)6 ServletContext (javax.servlet.ServletContext)5 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)4 VaadinServletService (com.vaadin.flow.server.VaadinServletService)4 VaadinSession (com.vaadin.flow.server.VaadinSession)4 File (java.io.File)4 Before (org.junit.Before)4 UI (com.vaadin.flow.component.UI)3 ResourceProvider (com.vaadin.flow.di.ResourceProvider)3 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)3 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2