From 0d19eb136519c9d224b5cd93b96a707704dcc66d Mon Sep 17 00:00:00 2001 From: Teppo Kurki Date: Fri, 17 Jan 2025 15:54:00 +0200 Subject: [PATCH 1/2] feat: exec Hilla tasks whenever Hilla is available. Hilla will decide what to do. --- .../java/com/vaadin/flow/server/frontend/NodeTasks.java | 4 ++-- .../vaadin/flow/server/frontend/NodeTasksHillaTest.java | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeTasks.java b/flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeTasks.java index 64c48c72163..67a051c84cd 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeTasks.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeTasks.java @@ -37,6 +37,7 @@ import com.vaadin.flow.di.Lookup; import com.vaadin.flow.internal.UsageStatistics; +import com.vaadin.flow.internal.hilla.EndpointRequestUtil; import com.vaadin.flow.server.Constants; import com.vaadin.flow.server.ExecutionFailedException; import com.vaadin.flow.server.Mode; @@ -315,8 +316,7 @@ private void addGenerateServiceWorkerTask(Options options, } private void addEndpointServicesTasks(Options options) { - if (!FrontendUtils.isHillaUsed(options.getFrontendDirectory(), - options.getClassFinder())) { + if (!EndpointRequestUtil.isHillaAvailable(options.getClassFinder())) { return; } Lookup lookup = options.getLookup(); diff --git a/flow-server/src/test/java/com/vaadin/flow/server/frontend/NodeTasksHillaTest.java b/flow-server/src/test/java/com/vaadin/flow/server/frontend/NodeTasksHillaTest.java index 49ffe3d0766..65dfbd75839 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/frontend/NodeTasksHillaTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/frontend/NodeTasksHillaTest.java @@ -31,6 +31,7 @@ import org.mockito.junit.MockitoRule; import com.vaadin.flow.di.Lookup; +import com.vaadin.flow.internal.hilla.EndpointRequestUtil; import com.vaadin.flow.server.ExecutionFailedException; import com.vaadin.flow.server.frontend.scanner.ClassFinder; import com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder; @@ -117,10 +118,10 @@ public void should_useHillaEngine_whenEnabled() Mockito.doReturn(endpointGeneratorTaskFactory).when(options.getLookup()) .lookup(EndpointGeneratorTaskFactory.class); - try (MockedStatic util = Mockito - .mockStatic(FrontendUtils.class, Mockito.CALLS_REAL_METHODS)) { - util.when(() -> FrontendUtils.isHillaUsed(Mockito.any(), - Mockito.any())).thenReturn(true); + try (MockedStatic util = Mockito.mockStatic( + EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) { + util.when(() -> EndpointRequestUtil.isHillaAvailable(Mockito.any())) + .thenReturn(true); new NodeTasks(options).execute(); } From ce90444cf8e62509474b56df41d343849b78629c Mon Sep 17 00:00:00 2001 From: Teppo Kurki Date: Fri, 17 Jan 2025 17:03:48 +0200 Subject: [PATCH 2/2] fix tests --- .../flow/plugin/base/BuildFrontendUtilTest.java | 9 +++++---- .../base/devserver/DevModeEndpointTest.java | 17 +++++++++-------- .../startup/DevModeInitializerTest.java | 17 +++++++++-------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/flow-plugins/flow-plugin-base/src/test/java/com/vaadin/flow/plugin/base/BuildFrontendUtilTest.java b/flow-plugins/flow-plugin-base/src/test/java/com/vaadin/flow/plugin/base/BuildFrontendUtilTest.java index 8e1e2166d56..2f0858165ac 100644 --- a/flow-plugins/flow-plugin-base/src/test/java/com/vaadin/flow/plugin/base/BuildFrontendUtilTest.java +++ b/flow-plugins/flow-plugin-base/src/test/java/com/vaadin/flow/plugin/base/BuildFrontendUtilTest.java @@ -35,6 +35,7 @@ import com.vaadin.experimental.FeatureFlags; import com.vaadin.flow.di.Lookup; +import com.vaadin.flow.internal.hilla.EndpointRequestUtil; import com.vaadin.flow.server.Constants; import com.vaadin.flow.server.ExecutionFailedException; import com.vaadin.flow.server.InitParameters; @@ -151,10 +152,10 @@ public void should_useHillaEngine_withNodeUpdater() .when(endpointGeneratorTaskFactory) .createTaskGenerateEndpoint(Mockito.any()); - try (MockedStatic util = Mockito - .mockStatic(FrontendUtils.class, Mockito.CALLS_REAL_METHODS)) { - util.when(() -> FrontendUtils.isHillaUsed(Mockito.any(), - Mockito.any())).thenReturn(true); + try (MockedStatic util = Mockito.mockStatic( + EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) { + util.when(() -> EndpointRequestUtil.isHillaAvailable(Mockito.any())) + .thenReturn(true); BuildFrontendUtil.runNodeUpdater(adapter); } diff --git a/vaadin-dev-server/src/test/java/com/vaadin/base/devserver/DevModeEndpointTest.java b/vaadin-dev-server/src/test/java/com/vaadin/base/devserver/DevModeEndpointTest.java index 8f5ba6fa5b9..0ec719b9931 100644 --- a/vaadin-dev-server/src/test/java/com/vaadin/base/devserver/DevModeEndpointTest.java +++ b/vaadin-dev-server/src/test/java/com/vaadin/base/devserver/DevModeEndpointTest.java @@ -22,6 +22,7 @@ import com.vaadin.base.devserver.startup.DevModeStartupListener; import com.vaadin.flow.di.ResourceProvider; import com.vaadin.flow.internal.DevModeHandlerManager; +import com.vaadin.flow.internal.hilla.EndpointRequestUtil; import com.vaadin.flow.server.VaadinServlet; import com.vaadin.flow.server.VaadinServletContext; import com.vaadin.flow.server.frontend.EndpointGeneratorTaskFactory; @@ -107,10 +108,10 @@ public void should_generateOpenApi() throws Exception { .toFile(); Assert.assertFalse(generatedOpenApiJson.exists()); - try (MockedStatic util = Mockito - .mockStatic(FrontendUtils.class, Mockito.CALLS_REAL_METHODS)) { - util.when(() -> FrontendUtils.isHillaUsed(Mockito.any(), - Mockito.any())).thenReturn(true); + try (MockedStatic util = Mockito.mockStatic( + EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) { + util.when(() -> EndpointRequestUtil.isHillaAvailable(Mockito.any())) + .thenReturn(true); devModeStartupListener.onStartup(classes, servletContext); handler = getDevModeHandler(); waitForDevServer(); @@ -139,10 +140,10 @@ public void should_generateTs_files() throws Exception { assertFalse(ts1.exists()); assertFalse(ts2.exists()); - try (MockedStatic util = Mockito - .mockStatic(FrontendUtils.class, Mockito.CALLS_REAL_METHODS)) { - util.when(() -> FrontendUtils.isHillaUsed(Mockito.any(), - Mockito.any())).thenReturn(true); + try (MockedStatic util = Mockito.mockStatic( + EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) { + util.when(() -> EndpointRequestUtil.isHillaAvailable(Mockito.any())) + .thenReturn(true); devModeStartupListener.onStartup(classes, servletContext); handler = getDevModeHandler(); waitForDevServer(); diff --git a/vaadin-dev-server/src/test/java/com/vaadin/base/devserver/startup/DevModeInitializerTest.java b/vaadin-dev-server/src/test/java/com/vaadin/base/devserver/startup/DevModeInitializerTest.java index b142e5d8a77..ea8a2cbbbf0 100644 --- a/vaadin-dev-server/src/test/java/com/vaadin/base/devserver/startup/DevModeInitializerTest.java +++ b/vaadin-dev-server/src/test/java/com/vaadin/base/devserver/startup/DevModeInitializerTest.java @@ -36,6 +36,7 @@ import com.vaadin.flow.component.dependency.JsModule; import com.vaadin.flow.component.page.AppShellConfigurator; import com.vaadin.flow.di.Lookup; +import com.vaadin.flow.internal.hilla.EndpointRequestUtil; import com.vaadin.flow.router.Route; import com.vaadin.flow.server.InitParameters; import com.vaadin.flow.server.LoadDependenciesOnStartup; @@ -352,10 +353,10 @@ public void should_generateOpenApi_when_EndpointPresents() javaSourceFolder.getRoot().getAbsolutePath()); Assert.assertFalse(generatedOpenApiJson.exists()); - try (MockedStatic util = Mockito.mockStatic( - FrontendUtils.class, Mockito.CALLS_REAL_METHODS)) { - util.when(() -> FrontendUtils.isHillaUsed(Mockito.any(), - Mockito.any())).thenReturn(true); + try (MockedStatic util = Mockito.mockStatic( + EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) { + util.when(() -> EndpointRequestUtil + .isHillaAvailable(Mockito.any())).thenReturn(true); devModeStartupListener.onStartup(classes, servletContext); handler = getDevModeHandler(); waitForDevServer(); @@ -420,10 +421,10 @@ public void should_generateTs_files() throws Exception { System.setProperty("vaadin." + CONNECT_JAVA_SOURCE_FOLDER_TOKEN, javaSourceFolder.getRoot().getAbsolutePath()); - try (MockedStatic util = Mockito.mockStatic( - FrontendUtils.class, Mockito.CALLS_REAL_METHODS)) { - util.when(() -> FrontendUtils.isHillaUsed(Mockito.any(), - Mockito.any())).thenReturn(true); + try (MockedStatic util = Mockito.mockStatic( + EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) { + util.when(() -> EndpointRequestUtil + .isHillaAvailable(Mockito.any())).thenReturn(true); devModeStartupListener.onStartup(classes, servletContext); handler = getDevModeHandler(); waitForDevServer();