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

refactor: extract common config functionality and introduce add config #9635

Merged
merged 6 commits into from
Dec 16, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import com.vaadin.flow.server.AbstractConfiguration;
import com.vaadin.flow.server.Constants;
import com.vaadin.flow.server.InitParameters;
import com.vaadin.flow.server.WrappedSession;
import com.vaadin.flow.shared.communication.PushMode;

import static com.vaadin.flow.server.Constants.POLYFILLS_DEFAULT_VALUE;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_POLYFILLS;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_USE_V14_BOOTSTRAP;

/**
* A collection of properties configured at deploy time as well as a way of
Expand All @@ -39,23 +39,8 @@
* @author Vaadin Ltd
* @since 1.0
*/
public interface DeploymentConfiguration extends Serializable {

/**
* Returns whether Vaadin is in production mode.
*
* @return true if in production mode, false otherwise.
*/
boolean isProductionMode();

/**
* Returns whether Vaadin is running in useDeprecatedV14Bootstrapping.
*
* @return true if in useDeprecatedV14Bootstrapping, false otherwise.
*/
default boolean useV14Bootstrap() {
return getBooleanProperty(SERVLET_PARAMETER_USE_V14_BOOTSTRAP, false);
}
public interface DeploymentConfiguration
extends AbstractConfiguration, Serializable {
caalador marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns whether the server provides timing info to the client.
Expand Down Expand Up @@ -195,6 +180,7 @@ <T> T getApplicationOrSystemProperty(String propertyName, T defaultValue,
* @return the property value, or the passed default value if no property
* value is found
*/
@Override
default String getStringProperty(String propertyName, String defaultValue) {
return getApplicationOrSystemProperty(propertyName, defaultValue,
Function.identity());
Expand Down Expand Up @@ -224,6 +210,7 @@ default String getStringProperty(String propertyName, String defaultValue) {
* @throws IllegalArgumentException
* if property value string is not a boolean value
*/
@Override
default boolean getBooleanProperty(String propertyName,
boolean defaultValue) throws IllegalArgumentException {
String booleanString = getStringProperty(propertyName, null);
Expand Down Expand Up @@ -283,7 +270,8 @@ default boolean disableAutomaticServletRegistration() {
* <code>false</code> to not serve Brotli files.
*/
default boolean isBrotli() {
return getBooleanProperty(InitParameters.SERVLET_PARAMETER_BROTLI, false);
return getBooleanProperty(InitParameters.SERVLET_PARAMETER_BROTLI,
false);
}

default String getCompiledWebComponentsPath() {
Expand All @@ -295,8 +283,8 @@ default String getCompiledWebComponentsPath() {
* Returns an array with polyfills to be loaded when the app is loaded.
*
* The default value is empty, but it can be changed by setting the
* {@link InitParameters#SERVLET_PARAMETER_POLYFILLS} as a comma separated list
* of JS files to load.
* {@link InitParameters#SERVLET_PARAMETER_POLYFILLS} as a comma separated
* list of JS files to load.
*
* @return polyfills to load
*/
Expand All @@ -308,16 +296,6 @@ default List<String> getPolyfills() {
.collect(Collectors.toList());
}

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

/**
* Get if the dev server should be reused on each reload. True by default,
* set it to false in tests so as dev server is not kept as a daemon after
Expand All @@ -326,8 +304,8 @@ default boolean enableDevServer() {
* @return true if dev server should be reused
*/
default boolean reuseDevServer() {
return getBooleanProperty(InitParameters.SERVLET_PARAMETER_REUSE_DEV_SERVER,
true);
return getBooleanProperty(
InitParameters.SERVLET_PARAMETER_REUSE_DEV_SERVER, true);
}

/**
Expand Down Expand Up @@ -377,18 +355,9 @@ default boolean isEagerServerLoad() {
/**
* Checks if dev mode live reload is enabled or not.
*
* @return {@code true} if dev mode live reload is enabled, {@code false} otherwise
* @return {@code true} if dev mode live reload is enabled, {@code false}
* otherwise
*/
boolean isDevModeLiveReloadEnabled();

/**
* Returns whether pnpm is enabled or not.
*
* @return {@code true} if enabled, {@code false} if not
* @since 2.2
*/
default boolean isPnpmEnabled() {
return getBooleanProperty(InitParameters.SERVLET_PARAMETER_ENABLE_PNPM,
Boolean.valueOf(Constants.ENABLE_PNPM_DEFAULT_STRING));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2000-2020 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.server;

import java.io.Serializable;

import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_USE_V14_BOOTSTRAP;

/**
* Defines a base contract for configuration (e.g. on an application level,
* servlet level,...).
*
* @author Vaadin Ltd
* @since
*
*/
public interface AbstractConfiguration extends Serializable {
/**
* Returns whether Vaadin is in production mode.
*
* @return true if in production mode, false otherwise.
*/
boolean isProductionMode();

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

/**
* Returns whether Vaadin is running in useDeprecatedV14Bootstrapping.
*
* @return true if in useDeprecatedV14Bootstrapping, false otherwise.
*/
default boolean useV14Bootstrap() {
return getBooleanProperty(SERVLET_PARAMETER_USE_V14_BOOTSTRAP, false);
}

/**
* Gets a configured property as a string.
*
* @param name
* The simple of the property, in some contexts, lookup might be
* performed using variations of the provided name.
* @param defaultValue
* the default value that should be used if no value has been
* defined
* @return the property value, or the passed default value if no property
* value is found
*/
String getStringProperty(String name, String defaultValue);

/**
* Gets a configured property as a boolean.
*
*
* @param name
* The simple of the property, in some contexts, lookup might be
* performed using variations of the provided name.
* @param defaultValue
* the default value that should be used if no value has been
* defined
* @return the property value, or the passed default value if no property
* value is found
*
*/
boolean getBooleanProperty(String name, boolean defaultValue);

/**
* Returns whether pnpm is enabled or not.
*
* @return {@code true} if enabled, {@code false} if not
*/
default boolean isPnpmEnabled() {
return getBooleanProperty(InitParameters.SERVLET_PARAMETER_ENABLE_PNPM,
Boolean.valueOf(Constants.ENABLE_PNPM_DEFAULT_STRING));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.server;

import java.util.Map;

import com.vaadin.flow.component.UI;
import com.vaadin.flow.function.DeploymentConfiguration;

Expand All @@ -26,8 +28,18 @@
* @author Vaadin Ltd
* @since 1.0
*/
public abstract class AbstractDeploymentConfiguration
implements DeploymentConfiguration {
public abstract class AbstractDeploymentConfiguration extends
AbstractPropertyConfiguration implements DeploymentConfiguration {

/**
* Creates a new configuration based on {@code properties}.
*
* @param properties
* configuration properties
*/
protected AbstractDeploymentConfiguration(Map<String, String> properties) {
super(properties);
}

@Override
public String getUIClassName() {
Expand Down
Loading