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

Extract app config from deployment config #9642

Merged
merged 32 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ea29c37
refactor: extract common config functionality and introduce add config
Dec 11, 2020
9c41873
refactor: use application level configuration instead of deployment conf
Dec 11, 2020
e13980f
chore: implement deployment configs being based on parent app config
Dec 14, 2020
d9fcad8
fix: fix javadoc params
Dec 14, 2020
7c8be83
fix: correct javadocs references
Dec 14, 2020
b1e65f4
test: use App config and adapt unit tests
Dec 15, 2020
37d1030
fix: correct variable name
Dec 16, 2020
b42bd48
test: make unit tests for DefaultApplicationConfigurationFactory
Dec 16, 2020
85ce4fd
test: add unit tests for properties in DefaultDeploymentConfiguration
Dec 16, 2020
282fc3c
test: add precedence tests for PropertyDeploymentConfiguration
Dec 16, 2020
e119e09
test: add unit test for app config factory in lookup
Dec 16, 2020
352b98d
test: extend unit tests for PropertyDeploymentConfiguration
Dec 17, 2020
e91f0be
test: use App config in DevModeHandlerTest instead deployment config
Dec 17, 2020
81ea8f3
test: use app config instead of deployment config in unit tests
Dec 17, 2020
5e4a45d
test: fixes unit tests after introducing merging properties
Dec 17, 2020
8cce983
test: fix DevModeInitializerClassLoaderTest
Dec 17, 2020
1b773f5
fix: yet another fix of unit tests
Dec 17, 2020
92f993d
test: run ITs without app shell validation check
Dec 17, 2020
dda1b6e
fix: yet another unit test fix
Dec 17, 2020
a1ef765
fix: javadocs fix
Dec 17, 2020
865935a
fix: fix IT servets
Dec 17, 2020
2044221
fix: fix fusion code
Dec 17, 2020
497b282
it's never ending story
Dec 17, 2020
777e9a8
chore: adapt fusion code to use app config and make factory OSGi capable
Dec 18, 2020
5b4d5df
fix: correct "createDeploymentConfiguration" code impl
Dec 18, 2020
aba867a
fix: yet another fix for createDeploymentConfiguration impl
Dec 18, 2020
a221f98
fix: rewrite UI IT to avoid removed annotation
Dec 18, 2020
8385059
fix: SQ fixes
Dec 19, 2020
638e0c8
fix: get rid of exception which is never thrown anymore
Dec 19, 2020
1b4e4bb
fix: review comments
Dec 19, 2020
c72c972
test: extend unit test with checking token file reading
Dec 21, 2020
0d98d6d
test: add a test to check that every method has its own impl
Dec 21, 2020
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 @@ -17,9 +17,15 @@
package com.vaadin.flow.component.dnd;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.dnd.internal.DnDUtilHelper;
import com.vaadin.flow.component.internal.DependencyList;
Expand All @@ -30,11 +36,8 @@
import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.VaadinServlet;
import com.vaadin.flow.server.VaadinSession;
import com.vaadin.flow.server.startup.ApplicationConfiguration;
import com.vaadin.flow.shared.ui.Dependency;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

public abstract class AbstractDnDUnitTest {

Expand All @@ -43,8 +46,12 @@ public abstract class AbstractDnDUnitTest {

@Before
public void setup() {
ApplicationConfiguration appConfig = Mockito
.mock(ApplicationConfiguration.class);
Mockito.when(appConfig.getPropertyNames())
.thenReturn(Collections.emptyEnumeration());
DefaultDeploymentConfiguration configuration = new DefaultDeploymentConfiguration(
VaadinServlet.class, new Properties());
appConfig, VaadinServlet.class, new Properties());

VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(service.resolveResource(Mockito.anyString()))
Expand Down
9 changes: 9 additions & 0 deletions flow-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<!-- DefaultApplicationConfigurationFactory is declared as an OSGi service -->

<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
<version>${osgi.compendium.version}</version>
<scope>provided</scope>
</dependency>


<!-- API DEPENDENCIES -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ public interface DeploymentConfiguration
*/
boolean isRequestTiming();

/**
* Returns whether cross-site request forgery protection is enabled.
*
* @return true if XSRF protection is enabled, false otherwise.
*/
boolean isXsrfProtectionEnabled();

/**
* Returns whether sync id checking is enabled. The sync id is used to
* gracefully handle situations when the client sends a message to a
Expand Down Expand Up @@ -166,26 +159,6 @@ public interface DeploymentConfiguration
<T> T getApplicationOrSystemProperty(String propertyName, T defaultValue,
Function<String, T> converter);

/**
* A shorthand of
* {@link DeploymentConfiguration#getApplicationOrSystemProperty(String, Object, Function)}
* for {@link String} type.
*
* @param propertyName
* 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
*/
@Override
default String getStringProperty(String propertyName, String defaultValue) {
return getApplicationOrSystemProperty(propertyName, defaultValue,
Function.identity());
}

/**
* A shorthand of
* {@link DeploymentConfiguration#getApplicationOrSystemProperty(String, Object, Function)}
Expand Down Expand Up @@ -296,18 +269,6 @@ default List<String> getPolyfills() {
.collect(Collectors.toList());
}

/**
* 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
* the test.
*
* @return true if dev server should be reused
*/
default boolean reuseDevServer() {
return getBooleanProperty(
InitParameters.SERVLET_PARAMETER_REUSE_DEV_SERVER, true);
}

/**
* Get if the stats.json file should be retrieved from an external service
* or through the classpath.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.Serializable;

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

/**
Expand Down Expand Up @@ -45,6 +46,18 @@ default boolean enableDevServer() {
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
* the test.
*
* @return true if dev server should be reused
*/
default boolean reuseDevServer() {
return getBooleanProperty(
InitParameters.SERVLET_PARAMETER_REUSE_DEV_SERVER, true);
}

/**
* Returns whether Vaadin is running in useDeprecatedV14Bootstrapping.
*
Expand Down Expand Up @@ -94,4 +107,14 @@ default boolean isPnpmEnabled() {
Boolean.valueOf(Constants.ENABLE_PNPM_DEFAULT_STRING));
}

/**
* Returns whether cross-site request forgery protection is enabled.
*
* @return true if XSRF protection is enabled, false otherwise.
*/
default boolean isXsrfProtectionEnabled() {
return !getBooleanProperty(SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION,
false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.vaadin.flow.server;

import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import java.util.function.Function;

Expand Down Expand Up @@ -82,17 +83,7 @@ public boolean getBooleanProperty(String name, boolean defaultValue) {
* @return String value or null if not found
*/
public String getApplicationProperty(String parameterName) {

String val = properties.get(parameterName);
if (val != null) {
return val;
}

// Try lower case application properties for backward compatibility
// with 3.0.2 and earlier
val = properties.get(parameterName.toLowerCase());

return val;
return getApplicationProperty(getProperties()::get, parameterName);
}

/**
Expand Down Expand Up @@ -150,4 +141,27 @@ protected String getSystemProperty(String parameterName) {
return System.getProperty(VAADIN_PREFIX + parameterName);
}

/**
* Gets application property value using the {@code valueProvider}.
*
* @param valueProvider
* a value provider for the property
* @param propertyName
* the name or the parameter.
* @return String value or null if not found
*/
protected String getApplicationProperty(
Function<String, String> valueProvider, String propertyName) {
String val = valueProvider.apply(propertyName);
if (val != null) {
return val;
}

// Try lower case application properties for backward compatibility with
// 3.0.2 and earlier
val = valueProvider.apply(propertyName.toLowerCase(Locale.ENGLISH));

return val;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.slf4j.LoggerFactory;

import com.vaadin.flow.function.DeploymentConfiguration;
import com.vaadin.flow.server.startup.ApplicationConfiguration;
import com.vaadin.flow.shared.communication.PushMode;

import static com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR;
Expand Down Expand Up @@ -56,7 +57,8 @@ public class DefaultDeploymentConfiguration
+ "Client-side views written in TypeScript are not supported. Vaadin 15+ enables client-side and server-side views.\n"
+ "See https://vaadin.com/docs/v15/flow/typescript/starting-the-app.html for more information.";

// not a warning anymore, but keeping variable name to avoid breaking anything
// not a warning anymore, but keeping variable name to avoid breaking
// anything
public static final String WARNING_V15_BOOTSTRAP = "Using Vaadin 15+ bootstrap mode.%n %s%n %s";

private static final String DEPLOYMENT_WARNINGS = "Following issues were discovered with deployment configuration:";
Expand Down Expand Up @@ -128,9 +130,9 @@ public class DefaultDeploymentConfiguration
* the init parameters that should make up the foundation for
* this configuration
*/
public DefaultDeploymentConfiguration(Class<?> systemPropertyBaseClass,
Properties initParameters) {
super(systemPropertyBaseClass, initParameters);
public DefaultDeploymentConfiguration(ApplicationConfiguration parentConfig,
Class<?> systemPropertyBaseClass, Properties initParameters) {
super(parentConfig, systemPropertyBaseClass, initParameters);

boolean log = logging.getAndSet(false);

Expand Down Expand Up @@ -287,8 +289,12 @@ public String getPushURL() {
* Log a warning if Vaadin is not running in production mode.
*/
private void checkProductionMode(boolean log) {
productionMode = getBooleanProperty(
InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE, false);
if (isOwnProperty(InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE)) {
productionMode = getBooleanProperty(
InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE, false);
} else {
productionMode = getParentConfiguration().isProductionMode();
}
if (log) {
if (productionMode) {
info.add("Vaadin is running in production mode.");
Expand All @@ -306,8 +312,13 @@ private void checkProductionMode(boolean log) {
* Log a message about the bootstrapping being used.
*/
private void checkV14Bootsrapping(boolean log) {
useDeprecatedV14Bootstrapping = getBooleanProperty(
InitParameters.SERVLET_PARAMETER_USE_V14_BOOTSTRAP, false);
if (isOwnProperty(InitParameters.SERVLET_PARAMETER_USE_V14_BOOTSTRAP)) {
useDeprecatedV14Bootstrapping = getBooleanProperty(
InitParameters.SERVLET_PARAMETER_USE_V14_BOOTSTRAP, false);
} else {
useDeprecatedV14Bootstrapping = getParentConfiguration()
.useV14Bootstrap();
}
if (log) {
if (useDeprecatedV14Bootstrapping) {
warnings.add(WARNING_V14_BOOTSTRAP);
Expand Down Expand Up @@ -362,15 +373,23 @@ private String getIndexHTMLMessage(String frontendDir) {
*/
private void checkRequestTiming() {
requestTiming = getBooleanProperty(
InitParameters.SERVLET_PARAMETER_REQUEST_TIMING, !productionMode);
InitParameters.SERVLET_PARAMETER_REQUEST_TIMING,
!productionMode);
}

/**
* Log a warning if cross-site request forgery protection is disabled.
*/
private void checkXsrfProtection(boolean loggWarning) {
xsrfProtectionEnabled = !getBooleanProperty(
InitParameters.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, false);
if (isOwnProperty(
InitParameters.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION)) {
xsrfProtectionEnabled = !getBooleanProperty(
InitParameters.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION,
false);
} else {
xsrfProtectionEnabled = getParentConfiguration()
.isXsrfProtectionEnabled();
}
if (!xsrfProtectionEnabled && loggWarning) {
warnings.add(WARNING_XSRF_PROTECTION_DISABLED);
}
Expand Down Expand Up @@ -422,17 +441,18 @@ private void checkCloseIdleSessions() {
private void checkPushMode() {
try {
pushMode = getApplicationOrSystemProperty(
InitParameters.SERVLET_PARAMETER_PUSH_MODE, PushMode.DISABLED,
stringMode -> Enum.valueOf(PushMode.class,
stringMode.toUpperCase()));
InitParameters.SERVLET_PARAMETER_PUSH_MODE,
PushMode.DISABLED, stringMode -> Enum
.valueOf(PushMode.class, stringMode.toUpperCase()));
} catch (IllegalArgumentException e) {
warnings.add(WARNING_PUSH_MODE_NOT_RECOGNIZED);
pushMode = PushMode.DISABLED;
}
}

private void checkPushURL() {
pushURL = getStringProperty(InitParameters.SERVLET_PARAMETER_PUSH_URL, "");
pushURL = getStringProperty(InitParameters.SERVLET_PARAMETER_PUSH_URL,
"");
}

private void checkSyncIdCheck() {
Expand All @@ -446,4 +466,5 @@ private void checkSendUrlsAsParameters() {
InitParameters.SERVLET_PARAMETER_SEND_URLS_AS_PARAMETERS,
DEFAULT_SEND_URLS_AS_PARAMETERS);
}

}
Loading