Skip to content

Commit

Permalink
Merge branch 'main' into feature/react19
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- authored Dec 18, 2024
2 parents 2a7b506 + fb02577 commit 6dd4520
Show file tree
Hide file tree
Showing 55 changed files with 1,317 additions and 137 deletions.
5 changes: 5 additions & 0 deletions flow-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<artifactId>flow-react</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>signals</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-push</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@ private void checkFlowCompatibility(PluginDescriptor pluginDescriptor) {
String pluginFlowVersion = pluginDescriptor.getArtifacts().stream()
.filter(isFlowServer).map(Artifact::getVersion).findFirst()
.orElse(null);
if (!Objects.equals(projectFlowVersion, pluginFlowVersion)) {
if (projectFlowVersion != null
&& !Objects.equals(projectFlowVersion, pluginFlowVersion)) {
getLog().warn(
"Vaadin Flow used in project does not match the version expected by the Vaadin plugin. "
+ "Flow version for project is "
Expand Down
2 changes: 1 addition & 1 deletion flow-plugins/flow-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.8.1</version>
<version>3.9.0</version>
<configuration>
<skipInstallation>${skipTests}</skipInstallation>
<skipInvocation>${skipTests}</skipInvocation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.vaadin.flow.plugin.maven;

import javax.inject.Inject;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -53,7 +52,6 @@
import com.vaadin.flow.plugin.base.BuildFrontendUtil;
import com.vaadin.flow.plugin.base.PluginAdapterBase;
import com.vaadin.flow.server.Constants;
import com.vaadin.flow.server.ExecutionFailedException;
import com.vaadin.flow.server.InitParameters;
import com.vaadin.flow.server.frontend.FrontendTools;
import com.vaadin.flow.server.frontend.FrontendUtils;
Expand Down Expand Up @@ -271,7 +269,6 @@ public abstract class FlowModeAbstractMojo extends AbstractMojo
* <configuration>
* <frontendExtraFileExtensions>svg,ico</frontendExtraFileExtensions>
* </configuration>
*
*/
@Parameter(property = InitParameters.FRONTEND_EXTRA_EXTENSIONS, defaultValue = "${null}")
private List<String> frontendExtraFileExtensions;
Expand Down Expand Up @@ -720,7 +717,8 @@ private void checkFlowCompatibility(PluginDescriptor pluginDescriptor) {
String pluginFlowVersion = pluginDescriptor.getArtifacts().stream()
.filter(isFlowServer).map(Artifact::getBaseVersion).findFirst()
.orElse(null);
if (!Objects.equals(projectFlowVersion, pluginFlowVersion)) {
if (projectFlowVersion != null
&& !Objects.equals(projectFlowVersion, pluginFlowVersion)) {
getLog().warn(
"Vaadin Flow used in project does not match the version expected by the Vaadin plugin. "
+ "Flow version for project is "
Expand Down
9 changes: 9 additions & 0 deletions flow-plugins/flow-plugin-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,17 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</exclusion>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist.version}</version>
</dependency>
<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-exec</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions flow-polymer2lit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<packaging>jar</packaging>

<properties>
<version.roaster>2.30.0.Final</version.roaster>
<version.roaster>2.30.1.Final</version.roaster>
</properties>

<dependencies>
Expand All @@ -31,7 +31,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.12.0</version>
<version>1.13.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.Router;
import com.vaadin.flow.server.Attributes;
import com.vaadin.flow.server.ErrorEvent;
import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.VaadinSession;
import com.vaadin.flow.shared.Registration;
Expand Down Expand Up @@ -338,7 +339,12 @@ public static void onComponentDetach(Component component) {
}

DetachEvent detachEvent = new DetachEvent(component);
component.onDetach(detachEvent);
try {
component.onDetach(detachEvent);
} catch (RuntimeException e) {
VaadinSession.getCurrent().getErrorHandler()
.error(new ErrorEvent(e));
}
fireEvent(component, detachEvent);

// inform component about onEnabledState if parent and child states
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.io.Serializable;

import com.vaadin.flow.server.ErrorEvent;
import com.vaadin.flow.server.VaadinSession;
import com.vaadin.flow.shared.Registration;

/**
Expand All @@ -38,7 +40,14 @@ default Registration addDetachListener(
ComponentEventListener<DetachEvent> listener) {
if (this instanceof Component) {
return ComponentUtil.addListener((Component) this,
DetachEvent.class, listener);
DetachEvent.class, event -> {
try {
listener.onComponentEvent(event);
} catch (RuntimeException e) {
VaadinSession.getCurrent().getErrorHandler()
.error(new ErrorEvent(e));
}
});
} else {
throw new IllegalStateException(String.format(
"The class '%s' doesn't extend '%s'. "
Expand Down
36 changes: 23 additions & 13 deletions flow-server/src/main/java/com/vaadin/flow/server/VaadinService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1565,22 +1565,32 @@ public void requestStart(VaadinRequest request, VaadinResponse response) {
*/
public void requestEnd(VaadinRequest request, VaadinResponse response,
VaadinSession session) {
vaadinRequestInterceptors
.forEach(requestInterceptor -> requestInterceptor
.requestEnd(request, response, session));
if (session != null) {
assert VaadinSession.getCurrent() == session;
session.lock();
vaadinRequestInterceptors.forEach(requestInterceptor -> {
try {
cleanupSession(session);
final long duration = (System.nanoTime() - (Long) request
.getAttribute(REQUEST_START_TIME_ATTRIBUTE)) / 1000000;
session.setLastRequestDuration(duration);
} finally {
session.unlock();
requestInterceptor.requestEnd(request, response, session);
} catch (Exception ex) {
getLogger().error(
"Error occurred while processing Vaadin request interceptor {}",
requestInterceptor.getClass().getName(), ex);
}
});
try {
if (session != null) {
assert VaadinSession.getCurrent() == session;
session.lock();
try {
cleanupSession(session);
final long duration = (System.nanoTime() - (Long) request
.getAttribute(REQUEST_START_TIME_ATTRIBUTE))
/ 1000000;
session.setLastRequestDuration(duration);
} finally {
session.unlock();
}
}
} finally {
CurrentInstance.clearAll();
}
CurrentInstance.clearAll();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.io.Serializable;
import java.util.Locale;

import org.slf4j.LoggerFactory;

import com.vaadin.flow.shared.BrowserDetails;

/**
Expand Down Expand Up @@ -65,7 +67,13 @@ public class WebBrowser implements Serializable {

if (agent != null) {
browserApplication = agent;
browserDetails = new BrowserDetails(agent);
browserDetails = new BrowserDetails(agent) {
@Override
protected void log(String error, Exception e) {
LoggerFactory.getLogger(BrowserDetails.class).error(error,
e);
}
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.vaadin.flow.router.NotFoundException;
import com.vaadin.flow.router.RouteParameters;
import com.vaadin.flow.router.internal.PathUtil;
import com.vaadin.flow.server.Constants;
import com.vaadin.flow.server.HandlerHelper;
import com.vaadin.flow.server.VaadinRequest;
import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.VaadinServletRequest;
Expand Down Expand Up @@ -369,7 +371,13 @@ protected Predicate<String> getRolesChecker(VaadinRequest request) {
*/
protected String getRequestURL(VaadinRequest vaadinRequest) {
if (vaadinRequest instanceof VaadinServletRequest httpRequest) {
return httpRequest.getRequestURL().toString();
String url = httpRequest.getRequestURL().toString();
if (HandlerHelper.isRequestType(vaadinRequest,
HandlerHelper.RequestType.PUSH)
&& url.endsWith(Constants.PUSH_MAPPING)) {
url = url.substring(0, url.indexOf(Constants.PUSH_MAPPING));
}
return url;
}
return "";
}
Expand Down Expand Up @@ -446,7 +454,7 @@ public NavigationContext createNavigationContext(Class<?> navigationTarget,
Objects.requireNonNull(vaadinService);
return new NavigationContext(vaadinService.getRouter(),
navigationTarget, new Location(path), RouteParameters.empty(),
vaadinRequest.getUserPrincipal(),
getRolesChecker(vaadinRequest), false);
getPrincipal(vaadinRequest), getRolesChecker(vaadinRequest),
false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
*/
public final class BundleValidationUtil {

private static final String FRONTEND_HASHES_STATS_KEY = "frontendHashes";

/**
* Checks if an application needs a new frontend bundle.
*
Expand Down Expand Up @@ -217,6 +219,20 @@ private static boolean needsBuildInternal(Options options,
// are found missing in bundle.
return true;
}

// In dev mode index html is served from frontend folder, not from
// dev-bundle, so rebuild is not required for custom content.
if (options.isProductionMode() && BundleValidationUtil
.hasCustomIndexHtml(options, statsJson)) {
UsageStatistics.markAsUsed("flow/rebundle-reason-custom-index-html",
null);
return true;
}
// index.html hash has already been checked, if needed.
// removing it from hashes map to prevent other unnecessary checks
statsJson.getObject(FRONTEND_HASHES_STATS_KEY)
.remove(FrontendUtils.INDEX_HTML);

if (!BundleValidationUtil.frontendImportsFound(statsJson, options,
frontendDependencies)) {
UsageStatistics.markAsUsed(
Expand Down Expand Up @@ -648,7 +664,8 @@ public static boolean frontendImportsFound(JsonObject statsJson,
FrontendUtils.FRONTEND_FOLDER_ALIAS.length()))
.collect(Collectors.toList());

final JsonObject frontendHashes = statsJson.getObject("frontendHashes");
final JsonObject frontendHashes = statsJson
.getObject(FRONTEND_HASHES_STATS_KEY);
List<String> faultyContent = new ArrayList<>();

for (String jarImport : jarImports) {
Expand Down Expand Up @@ -696,6 +713,27 @@ public static boolean frontendImportsFound(JsonObject statsJson,
return true;
}

private static boolean hasCustomIndexHtml(Options options,
JsonObject statsJson) throws IOException {
File indexHtml = new File(options.getFrontendDirectory(),
FrontendUtils.INDEX_HTML);
if (indexHtml.exists()) {
final JsonObject frontendHashes = statsJson
.getObject(FRONTEND_HASHES_STATS_KEY);
String frontendFileContent = FileUtils.readFileToString(indexHtml,
StandardCharsets.UTF_8);
List<String> faultyContent = new ArrayList<>();
compareFrontendHashes(frontendHashes, faultyContent,
FrontendUtils.INDEX_HTML, frontendFileContent);
if (!faultyContent.isEmpty()) {
logChangedFiles(faultyContent,
"Detected changed content for frontend files:");
return true;
}
}
return false;
}

private static boolean indexFileAddedOrDeleted(Options options,
JsonObject frontendHashes) {
Collection<String> indexFiles = Arrays.asList(FrontendUtils.INDEX_TS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public class FrontendTools {
private static final FrontendVersion WHITESPACE_ACCEPTING_NPM_VERSION = new FrontendVersion(
7, 0);

private static final int SUPPORTED_NODE_MAJOR_VERSION = 18;
private static final int SUPPORTED_NODE_MINOR_VERSION = 12;
private static final int SUPPORTED_NPM_MAJOR_VERSION = 8;
private static final int SUPPORTED_NODE_MAJOR_VERSION = 20;
private static final int SUPPORTED_NODE_MINOR_VERSION = 0;
private static final int SUPPORTED_NPM_MAJOR_VERSION = 9;
private static final int SUPPORTED_NPM_MINOR_VERSION = 6;

static final FrontendVersion SUPPORTED_NODE_VERSION = new FrontendVersion(
Expand Down
Loading

0 comments on commit 6dd4520

Please sign in to comment.