Skip to content

Commit

Permalink
feat: execute Hilla tasks whenever Hilla is available (#20567)
Browse files Browse the repository at this point in the history
Execute Hilla tasks (TaskGenerateOpenAPI and TaskGenerateEndpoint) whenever Hilla is available on the classpath. These tasks should determine the required actions themselves, instead of Flow trying to do it.

Fixes #20289
Fixes #18800
  • Loading branch information
tepi authored Feb 3, 2025
1 parent f5c972a commit 21a4145
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,10 +152,10 @@ public void should_useHillaEngine_withNodeUpdater()
.when(endpointGeneratorTaskFactory)
.createTaskGenerateEndpoint(Mockito.any());

try (MockedStatic<FrontendUtils> util = Mockito
.mockStatic(FrontendUtils.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> FrontendUtils.isHillaUsed(Mockito.any(),
Mockito.any())).thenReturn(true);
try (MockedStatic<EndpointRequestUtil> util = Mockito.mockStatic(
EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> EndpointRequestUtil.isHillaAvailable(Mockito.any()))
.thenReturn(true);
BuildFrontendUtil.runNodeUpdater(adapter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,10 +118,10 @@ public void should_useHillaEngine_whenEnabled()
Mockito.doReturn(endpointGeneratorTaskFactory).when(options.getLookup())
.lookup(EndpointGeneratorTaskFactory.class);

try (MockedStatic<FrontendUtils> util = Mockito
.mockStatic(FrontendUtils.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> FrontendUtils.isHillaUsed(Mockito.any(),
Mockito.any())).thenReturn(true);
try (MockedStatic<EndpointRequestUtil> util = Mockito.mockStatic(
EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> EndpointRequestUtil.isHillaAvailable(Mockito.any()))
.thenReturn(true);

new NodeTasks(options).execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,10 +108,10 @@ public void should_generateOpenApi() throws Exception {
.toFile();

Assert.assertFalse(generatedOpenApiJson.exists());
try (MockedStatic<FrontendUtils> util = Mockito
.mockStatic(FrontendUtils.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> FrontendUtils.isHillaUsed(Mockito.any(),
Mockito.any())).thenReturn(true);
try (MockedStatic<EndpointRequestUtil> util = Mockito.mockStatic(
EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> EndpointRequestUtil.isHillaAvailable(Mockito.any()))
.thenReturn(true);
devModeStartupListener.onStartup(classes, servletContext);
handler = getDevModeHandler();
waitForDevServer();
Expand Down Expand Up @@ -139,10 +140,10 @@ public void should_generateTs_files() throws Exception {

assertFalse(ts1.exists());
assertFalse(ts2.exists());
try (MockedStatic<FrontendUtils> util = Mockito
.mockStatic(FrontendUtils.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> FrontendUtils.isHillaUsed(Mockito.any(),
Mockito.any())).thenReturn(true);
try (MockedStatic<EndpointRequestUtil> util = Mockito.mockStatic(
EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> EndpointRequestUtil.isHillaAvailable(Mockito.any()))
.thenReturn(true);
devModeStartupListener.onStartup(classes, servletContext);
handler = getDevModeHandler();
waitForDevServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -352,10 +353,10 @@ public void should_generateOpenApi_when_EndpointPresents()
javaSourceFolder.getRoot().getAbsolutePath());

Assert.assertFalse(generatedOpenApiJson.exists());
try (MockedStatic<FrontendUtils> util = Mockito.mockStatic(
FrontendUtils.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> FrontendUtils.isHillaUsed(Mockito.any(),
Mockito.any())).thenReturn(true);
try (MockedStatic<EndpointRequestUtil> util = Mockito.mockStatic(
EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> EndpointRequestUtil
.isHillaAvailable(Mockito.any())).thenReturn(true);
devModeStartupListener.onStartup(classes, servletContext);
handler = getDevModeHandler();
waitForDevServer();
Expand Down Expand Up @@ -420,10 +421,10 @@ public void should_generateTs_files() throws Exception {
System.setProperty("vaadin." + CONNECT_JAVA_SOURCE_FOLDER_TOKEN,
javaSourceFolder.getRoot().getAbsolutePath());

try (MockedStatic<FrontendUtils> util = Mockito.mockStatic(
FrontendUtils.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> FrontendUtils.isHillaUsed(Mockito.any(),
Mockito.any())).thenReturn(true);
try (MockedStatic<EndpointRequestUtil> util = Mockito.mockStatic(
EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> EndpointRequestUtil
.isHillaAvailable(Mockito.any())).thenReturn(true);
devModeStartupListener.onStartup(classes, servletContext);
handler = getDevModeHandler();
waitForDevServer();
Expand Down

0 comments on commit 21a4145

Please sign in to comment.