Skip to content

Commit

Permalink
feat: Make express mode default (#15745)
Browse files Browse the repository at this point in the history
* feat: Make express mode default

Set express mode as default mode
for development time.

Closes #15743

* Spring hotdeploy

* Fix deploymentconfiguration server method

* Set hotdeploy mode for failing tests

* Fix faulty expectation in test.

* set devmode for spring modules

* Clean up test.

Co-authored-by: Mikhail Shabarov <mikhail@vaadin.com>
  • Loading branch information
caalador and mshabarov committed Jan 26, 2023
1 parent b1fbe02 commit cdf0847
Show file tree
Hide file tree
Showing 31 changed files with 91 additions and 112 deletions.
2 changes: 1 addition & 1 deletion flow-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
<style>${gwt.module.style}</style>
<htmlunit>FF38</htmlunit>
<testTimeOut>300</testTimeOut>
<extraJvmArgs>-Xmx512m -Dvaadin.enableDevServer=false</extraJvmArgs>
<extraJvmArgs>-Xmx512m -Dvaadin.frontend.hotdeploy=false</extraJvmArgs>
<includes>${gwt.test.pattern}</includes>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import static com.vaadin.flow.server.Constants.TARGET;
import static com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES;
import static com.vaadin.flow.server.Constants.VAADIN_WEBAPP_RESOURCES;
import static com.vaadin.flow.server.InitParameters.FRONTEND_HOTDEPLOY;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE;
import static com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR;
Expand Down Expand Up @@ -507,7 +508,7 @@ public void existingTokenFile_parametersShouldBeRemoved()
JsonObject buildInfo = JsonUtil.parse(json);
Assert.assertNull(
"enable dev server token shouldn't be added " + "automatically",
buildInfo.get(SERVLET_PARAMETER_ENABLE_DEV_SERVER));
buildInfo.get(FRONTEND_HOTDEPLOY));
Assert.assertNotNull("productionMode token should be available",
buildInfo.get(SERVLET_PARAMETER_PRODUCTION_MODE));
Assert.assertNull("npmFolder should have been removed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static com.vaadin.flow.plugin.maven.BuildFrontendMojoTest.getPackageJson;
import static com.vaadin.flow.plugin.maven.BuildFrontendMojoTest.setProject;
import static com.vaadin.flow.server.Constants.PACKAGE_JSON;
import static com.vaadin.flow.server.InitParameters.FRONTEND_HOTDEPLOY;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE;
import static com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES;
Expand Down Expand Up @@ -154,7 +155,7 @@ public void tokenFileShouldExist_noDevModeTokenVisible()
.readFileToString(tokenFile, "UTF-8");
JsonObject buildInfo = JsonUtil.parse(json);
Assert.assertNull("No devMode token should be available",
buildInfo.get(SERVLET_PARAMETER_ENABLE_DEV_SERVER));
buildInfo.get(FRONTEND_HOTDEPLOY));
Assert.assertNotNull("productionMode token should be available",
buildInfo.get(SERVLET_PARAMETER_PRODUCTION_MODE));
}
Expand All @@ -165,7 +166,7 @@ public void existingTokenFile_enableDevServerShouldBeRemoved()

JsonObject initialBuildInfo = Json.createObject();
initialBuildInfo.put(SERVLET_PARAMETER_PRODUCTION_MODE, false);
initialBuildInfo.put(SERVLET_PARAMETER_ENABLE_DEV_SERVER, false);
initialBuildInfo.put(FRONTEND_HOTDEPLOY, false);
org.apache.commons.io.FileUtils.forceMkdir(tokenFile.getParentFile());
org.apache.commons.io.FileUtils.write(tokenFile,
JsonUtil.stringify(initialBuildInfo, 2) + "\n", "UTF-8");
Expand All @@ -176,7 +177,7 @@ public void existingTokenFile_enableDevServerShouldBeRemoved()
.readFileToString(tokenFile, "UTF-8");
JsonObject buildInfo = JsonUtil.parse(json);
Assert.assertNull("No devMode token should be available",
buildInfo.get(SERVLET_PARAMETER_ENABLE_DEV_SERVER));
buildInfo.get(FRONTEND_HOTDEPLOY));
Assert.assertNotNull("productionMode token should be available",
buildInfo.get(SERVLET_PARAMETER_PRODUCTION_MODE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public class FeatureFlags implements Serializable {
"Enforce client / constraint / binder validation",
"enforceFieldValidation",
"https://github.com/vaadin/platform/issues/3066", false, null);
public static final Feature EXPRESS_BUILD = new Feature(
"Express Build mode for Flow", "expressBuild",
"https://github.com/vaadin/platform/issues/3554", true, null);
private List<Feature> features = new ArrayList<>();

File propertiesFolder = null;
Expand All @@ -92,7 +89,6 @@ public FeatureFlags(Lookup lookup) {
features.add(new Feature(HILLA_ENGINE));
features.add(new Feature(COLLABORATION_ENGINE_BACKEND));
features.add(new Feature(ENFORCE_FIELD_VALIDATION));
features.add(new Feature(EXPRESS_BUILD));
loadProperties();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ public interface AbstractConfiguration extends Serializable {
boolean isProductionMode();

/**
* Get if the dev server should be enabled. True by default
* Get if the dev server should be enabled. false by default as express mode
* should be used.
*
* @return true if dev server should be used
*/
default boolean enableDevServer() {
if (isProductionMode()) {
return false;
}
return getBooleanProperty(
InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER, true);
return getBooleanProperty(InitParameters.FRONTEND_HOTDEPLOY, false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public class DefaultDeploymentConfiguration

public static final boolean DEFAULT_SEND_URLS_AS_PARAMETERS = true;

public static final boolean DEFAULT_FRONTEND_HOTDEPLOY = false;

private boolean productionMode;
private boolean xsrfProtectionEnabled;
private int heartbeatInterval;
Expand All @@ -91,6 +93,7 @@ public class DefaultDeploymentConfiguration
private boolean syncIdCheck;
private boolean sendUrlsAsParameters;
private boolean requestTiming;
private boolean enableDevServer;

private static AtomicBoolean logging = new AtomicBoolean(true);
private List<String> warnings = new ArrayList<>();
Expand Down Expand Up @@ -125,6 +128,7 @@ public DefaultDeploymentConfiguration(ApplicationConfiguration parentConfig,
checkPushMode();
checkSyncIdCheck();
checkSendUrlsAsParameters();
checkFrontendHotdeploy();

if (log) {
logMessages();
Expand Down Expand Up @@ -242,6 +246,11 @@ public PushMode getPushMode() {
return pushMode;
}

@Override
public boolean enableDevServer() {
return enableDevServer;
}

/**
* Log a warning if Vaadin is not running in production mode.
*/
Expand Down Expand Up @@ -373,4 +382,9 @@ private void checkSendUrlsAsParameters() {
DEFAULT_SEND_URLS_AS_PARAMETERS);
}

private void checkFrontendHotdeploy() {
enableDevServer = getBooleanProperty(InitParameters.FRONTEND_HOTDEPLOY,
DEFAULT_FRONTEND_HOTDEPLOY);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public class InitParameters implements Serializable {
public static final String SERVLET_PARAMETER_PRODUCTION_MODE = "productionMode";

public static final String SERVLET_PARAMETER_INITIAL_UIDL = "eagerServerLoad";
/**
* Enable dev server is deprecated. use {@link #FRONTEND_HOTDEPLOY}
*/
@Deprecated
public static final String SERVLET_PARAMETER_ENABLE_DEV_SERVER = "enableDevServer";
public static final String SERVLET_PARAMETER_REUSE_DEV_SERVER = "reuseDevServer";
public static final String SERVLET_PARAMETER_REQUEST_TIMING = "requestTiming";
Expand Down Expand Up @@ -194,4 +198,10 @@ public class InitParameters implements Serializable {
* @since
*/
public static final String ADDITIONAL_POSTINSTALL_PACKAGES = "npm.postinstallPackages";

/**
* Configuration name for enabling development using the frontend
* development server instead of using an application bundle.
*/
public static final String FRONTEND_HOTDEPLOY = "frontend.hotdeploy";
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.vaadin.flow.shared.communication.PushMode;

import static com.vaadin.flow.server.InitParameters.BUILD_FOLDER;
import static com.vaadin.flow.server.InitParameters.FRONTEND_HOTDEPLOY;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_CLOSE_IDLE_SESSIONS;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_DEVMODE_ENABLE_DEV_TOOLS;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_DEVMODE_ENABLE_LIVE_RELOAD;
Expand Down Expand Up @@ -148,6 +149,9 @@ public boolean isProductionMode() {

@Override
public boolean enableDevServer() {
if (isOwnProperty(FRONTEND_HOTDEPLOY)) {
return getBooleanProperty(FRONTEND_HOTDEPLOY, false);
}
return parentConfig.enableDevServer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static com.vaadin.flow.server.Constants.PROJECT_FRONTEND_GENERATED_DIR_TOKEN;
import static com.vaadin.flow.server.Constants.VAADIN_PREFIX;
import static com.vaadin.flow.server.InitParameters.BUILD_FOLDER;
import static com.vaadin.flow.server.InitParameters.FRONTEND_HOTDEPLOY;
import static com.vaadin.flow.server.InitParameters.NODE_DOWNLOAD_ROOT;
import static com.vaadin.flow.server.InitParameters.NODE_VERSION;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER;
Expand Down Expand Up @@ -125,8 +126,11 @@ protected Map<String, String> getConfigParametersUsingTokenData(
// These should be internal only so if there is a System
// property override then the user probably knows what
// they are doing.
if (buildInfo.hasKey(SERVLET_PARAMETER_ENABLE_DEV_SERVER)) {
params.put(SERVLET_PARAMETER_ENABLE_DEV_SERVER, String.valueOf(
if (buildInfo.hasKey(FRONTEND_HOTDEPLOY)) {
params.put(FRONTEND_HOTDEPLOY,
String.valueOf(buildInfo.getBoolean(FRONTEND_HOTDEPLOY)));
} else if (buildInfo.hasKey(SERVLET_PARAMETER_ENABLE_DEV_SERVER)) {
params.put(FRONTEND_HOTDEPLOY, String.valueOf(
buildInfo.getBoolean(SERVLET_PARAMETER_ENABLE_DEV_SERVER)));
}
if (buildInfo.hasKey(SERVLET_PARAMETER_REUSE_DEV_SERVER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vaadin.experimental.FeatureFlags;
import com.vaadin.flow.di.Lookup;
import com.vaadin.flow.di.ResourceProvider;
import com.vaadin.flow.server.AbstractPropertyConfiguration;
Expand Down Expand Up @@ -100,11 +99,6 @@ public boolean isDevModeSessionSerializationEnabled() {
false);
}

@Override
public boolean enableDevServer() {
return !FeatureFlags.get(getContext())
.isEnabled(FeatureFlags.EXPRESS_BUILD);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,16 @@ public void isXsrfProtectionEnabled_valueIsSetViaParentOnlyAndViaParent_valueIsT

@Test
public void enableDevServerParameter_expressBuildFeatureFlagIsON_resetsEnableDevServerToFalse() {
FeatureFlags featureFlags = Mockito.mock(FeatureFlags.class);
Mockito.when(featureFlags.isEnabled(FeatureFlags.EXPRESS_BUILD))
.thenReturn(true);

try (MockedStatic<FeatureFlags> featureFlagsStatic = Mockito
.mockStatic(FeatureFlags.class)) {
featureFlagsStatic.when(() -> FeatureFlags.get(context))
.thenReturn(featureFlags);
DefaultDeploymentConfiguration config = createDeploymentConfig(
new Properties());
Assert.assertFalse(
"Expected dev server to be disabled when the "
+ "Express Build feature flag is ON",
config.enableDevServer());
}
DefaultDeploymentConfiguration config = createDeploymentConfig(
new Properties());
Assert.assertFalse("Expected dev server to be disabled by default",
config.enableDevServer());

Properties init = new Properties();
init.put(InitParameters.FRONTEND_HOTDEPLOY, "true");
config = createDeploymentConfig(init);
Assert.assertTrue("Expected dev server to be enabled when set true",
config.enableDevServer());
}

private DefaultDeploymentConfiguration createDeploymentConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,26 +498,25 @@ private VaadinConfig mockTokenFileViaContextParam(String content)
}

@Test
public void externalStatsFileTrue_predefinedValuesAreNotOverridden()
public void externalStatsFileTrue_predefinedValuesAreNotOverridden_productionMode()
throws Exception {
// note that this situation shouldn't happen that the other
// settings
// would be against the external usage.
// settings would be against the external usage.
FileUtils.writeLines(tokenFile,
Arrays.asList("{", "\"enableDevServer\": true,",
Arrays.asList("{", "\"frontend.hotdeploy\": true,",
// production mode can be
// altered even when external
// stats
// are used
// stats are used
"\"productionMode\": true,",
"\"externalStatsFile\": true", "}"));

DeploymentConfiguration config = createConfig(Collections
.singletonMap(PARAM_TOKEN_FILE, tokenFile.getPath()));

assertEquals(true, config.isProductionMode());
assertEquals(true, config.enableDevServer());
assertEquals(true, config.isStatsExternal());
assertTrue(config.isProductionMode());
assertFalse("Dev server should be default false due to stats",
config.enableDevServer());
assertTrue(config.isStatsExternal());
assertEquals(Constants.DEFAULT_EXTERNAL_STATS_URL,
config.getExternalStatsUrl());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public void enableDevServer_valueIsProvidedViaPropertiesAndParent_valueIsAlwaysT
Mockito.when(appConfig.enableDevServer()).thenReturn(false);

Properties properties = new Properties();
properties.put(InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER,
properties.put(InitParameters.FRONTEND_HOTDEPLOY,
Boolean.TRUE.toString());
PropertyDeploymentConfiguration config = createConfiguration(appConfig,
properties);
Assert.assertFalse(config.enableDevServer());
Assert.assertTrue(config.enableDevServer());
Assert.assertEquals(properties, config.getInitParameters());
}

Expand Down Expand Up @@ -221,11 +221,11 @@ public void enableDevServer_valueIsProvidedViaParentOnly_propertyIsSetToAnotherV

// The property whose value is overridden above via API is different
Mockito.when(appConfig.getPropertyNames())
.thenReturn(Collections.enumeration(Collections.singleton(
InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER)));
.thenReturn(Collections.enumeration(Collections
.singleton(InitParameters.FRONTEND_HOTDEPLOY)));

Mockito.when(appConfig.getStringProperty(
InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER, null))
Mockito.when(appConfig
.getStringProperty(InitParameters.FRONTEND_HOTDEPLOY, null))
.thenReturn(Boolean.FALSE.toString());

PropertyDeploymentConfiguration config = createConfiguration(appConfig,
Expand All @@ -236,8 +236,8 @@ public void enableDevServer_valueIsProvidedViaParentOnly_propertyIsSetToAnotherV
// "getApplicationProperty" method checks the parent properties which
// should not be taken into account here
Assert.assertTrue(config.enableDevServer());
Assert.assertTrue(config.getInitParameters().containsKey(
InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER));
Assert.assertTrue(config.getInitParameters()
.containsKey(InitParameters.FRONTEND_HOTDEPLOY));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public void setup() {
properties = new HashMap<>();
properties.put(InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE,
"true");
properties.put(InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER,
"false");
properties.put(InitParameters.FRONTEND_HOTDEPLOY, "false");

Mockito.when(servletConfig.getInitParameterNames())
.thenReturn(Collections.enumeration(properties.keySet()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public void setup() {
properties = new HashMap<>();
properties.put(InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE,
"true");
properties.put(InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER,
"false");
properties.put(InitParameters.FRONTEND_HOTDEPLOY, "false");

Mockito.when(servletContext.getInitParameterNames())
.thenReturn(Collections.enumeration(properties.keySet()));
Expand Down

0 comments on commit cdf0847

Please sign in to comment.