Skip to content

Commit

Permalink
Revert "feat: improved endpoint detection (#21009)" (#21047)
Browse files Browse the repository at this point in the history
This reverts commit 530e757.
  • Loading branch information
mshabarov authored Feb 25, 2025
1 parent fe1db22 commit 0afeb5f
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -49,16 +47,6 @@ public TaskGenerateOpenAPI createTaskGenerateOpenAPI(Options options) {
return new TestTaskGenerateOpenAPI(options);
}

@Override
public Set<Class<? extends Annotation>> getBrowserCallableAnnotations() {
return Set.of();
}

@Override
public boolean hasBrowserCallables(Options options) {
return true;
}

/**
* An abstract parent for the test endpoints generator tasks.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ public void should_useHillaEngine_withNodeUpdater()
EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> EndpointRequestUtil.isHillaAvailable(Mockito.any()))
.thenReturn(true);
util.when(() -> EndpointRequestUtil
.areHillaEndpointsUsed(Mockito.any())).thenReturn(true);
BuildFrontendUtil.runNodeUpdater(adapter);
}

Expand All @@ -170,10 +168,10 @@ public void should_useHillaEngine_withNodeUpdater()
// Hilla Engine requires npm install, the order of execution is critical
final TaskRunNpmInstall taskRunNpmInstall = construction.constructed()
.get(0);
InOrder inOrder = Mockito.inOrder(taskGenerateOpenAPI,
taskRunNpmInstall, taskGenerateEndpoint);
inOrder.verify(taskGenerateOpenAPI).execute();
InOrder inOrder = Mockito.inOrder(taskRunNpmInstall,
taskGenerateOpenAPI, taskGenerateEndpoint);
inOrder.verify(taskRunNpmInstall).execute();
inOrder.verify(taskGenerateOpenAPI).execute();
inOrder.verify(taskGenerateEndpoint).execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import jakarta.servlet.http.HttpServletRequest;
import java.io.Serializable;

import com.vaadin.flow.server.frontend.EndpointGeneratorTaskFactory;
import com.vaadin.flow.server.frontend.Options;
import com.vaadin.flow.server.frontend.scanner.ClassFinder;

/**
Expand Down Expand Up @@ -88,22 +86,4 @@ static boolean isHillaAvailable(ClassFinder classFinder) {
return false;
}
}

/**
* Checks if Hilla is available and Hilla endpoints are used in the project.
*
* @return {@code true} if Hilla is available and Hilla endpoints are used,
* {@code false} otherwise
*/
static boolean areHillaEndpointsUsed(Options options) {
if (!EndpointRequestUtil.isHillaAvailable()) {
return false;
}
EndpointGeneratorTaskFactory endpointGeneratorTaskFactory = options
.getLookup().lookup(EndpointGeneratorTaskFactory.class);
if (endpointGeneratorTaskFactory != null) {
return endpointGeneratorTaskFactory.hasBrowserCallables(options);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.vaadin.flow.internal.JacksonUtils;
import com.vaadin.flow.internal.StringUtil;
import com.vaadin.flow.internal.UsageStatistics;
import com.vaadin.flow.internal.hilla.EndpointRequestUtil;
import com.vaadin.flow.server.Constants;
import com.vaadin.flow.server.LoadDependenciesOnStartup;
import com.vaadin.flow.server.Mode;
Expand Down Expand Up @@ -69,11 +68,9 @@ public static boolean needsBuild(Options options,
try {
boolean needsBuild;
if (mode.isProduction()) {
if (options.isForceProductionBuild()
|| FrontendUtils.isHillaUsed(
options.getFrontendDirectory(),
options.getClassFinder())
|| EndpointRequestUtil.areHillaEndpointsUsed(options)) {
if (options.isForceProductionBuild() || FrontendUtils
.isHillaUsed(options.getFrontendDirectory(),
options.getClassFinder())) {
if (options.isForceProductionBuild()) {
UsageStatistics.markAsUsed("flow/prod-build-requested",
null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package com.vaadin.flow.server.frontend;

import java.lang.annotation.Annotation;
import java.util.Set;

/**
* A factory for creating Vaadin Endpoint generator tasks.
* <p>
Expand Down Expand Up @@ -46,21 +43,4 @@ public interface EndpointGeneratorTaskFactory {
* @return an endpoint task that generates open api json file.
*/
TaskGenerateOpenAPI createTaskGenerateOpenAPI(Options options);

/**
* Fetches all endpoint-type annotations from Hilla configuration
*
* @return Set of endpoint-type annotations
*/
Set<Class<? extends Annotation>> getBrowserCallableAnnotations();

/**
* Determines the presence of annotations (e.g. BrowserCallable or Endpoint)
* which require Flow to add Hilla packages to the build.
*
* @param options
* the task options
* @return {@code true} if annotations are present, {@code false} otherwise
*/
boolean hasBrowserCallables(Options options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.stream.Stream;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import jakarta.servlet.ServletContext;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public class NodeTasks implements FallibleCommand {
TaskGenerateWebComponentBootstrap.class,
TaskGenerateFeatureFlags.class,
TaskInstallFrontendBuildPlugins.class,
TaskGenerateOpenAPI.class,
TaskUpdatePackages.class,
TaskRunNpmInstall.class,
TaskGenerateOpenAPI.class,
TaskGenerateEndpoint.class,
TaskCopyFrontendFiles.class,
TaskCopyLocalFrontendFiles.class,
Expand Down Expand Up @@ -319,22 +319,19 @@ private void addEndpointServicesTasks(Options options) {
if (!EndpointRequestUtil.isHillaAvailable(options.getClassFinder())) {
return;
}
if (EndpointRequestUtil.areHillaEndpointsUsed(options)
|| FrontendUtils.isHillaUsed(options.getFrontendDirectory())) {
Lookup lookup = options.getLookup();
EndpointGeneratorTaskFactory endpointGeneratorTaskFactory = lookup
.lookup(EndpointGeneratorTaskFactory.class);

if (endpointGeneratorTaskFactory != null) {
TaskGenerateOpenAPI taskGenerateOpenAPI = endpointGeneratorTaskFactory
.createTaskGenerateOpenAPI(options);
commands.add(taskGenerateOpenAPI);

if (options.getFrontendGeneratedFolder() != null) {
TaskGenerateEndpoint taskGenerateEndpoint = endpointGeneratorTaskFactory
.createTaskGenerateEndpoint(options);
commands.add(taskGenerateEndpoint);
}
Lookup lookup = options.getLookup();
EndpointGeneratorTaskFactory endpointGeneratorTaskFactory = lookup
.lookup(EndpointGeneratorTaskFactory.class);

if (endpointGeneratorTaskFactory != null) {
TaskGenerateOpenAPI taskGenerateOpenAPI = endpointGeneratorTaskFactory
.createTaskGenerateOpenAPI(options);
commands.add(taskGenerateOpenAPI);

if (options.getFrontendGeneratedFolder() != null) {
TaskGenerateEndpoint taskGenerateEndpoint = endpointGeneratorTaskFactory
.createTaskGenerateEndpoint(options);
commands.add(taskGenerateEndpoint);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import com.vaadin.experimental.FeatureFlags;
import com.vaadin.flow.internal.JacksonUtils;
import com.vaadin.flow.internal.JsonDecodingException;
import com.vaadin.flow.internal.hilla.EndpointRequestUtil;
import com.vaadin.flow.server.Constants;
import com.vaadin.flow.server.frontend.scanner.ClassFinder;
import com.vaadin.flow.server.frontend.scanner.FrontendDependencies;
Expand Down Expand Up @@ -621,8 +620,7 @@ private ObjectNode generateVersionsFromPackageJson(JsonNode packageJson) {
private void putHillaComponentsDependencies(
Map<String, String> dependencies, String packageJsonKey) {
if (FrontendUtils.isHillaUsed(options.getFrontendDirectory(),
options.getClassFinder())
|| EndpointRequestUtil.areHillaEndpointsUsed(options)) {
options.getClassFinder())) {
if (options.isReactEnabled()) {
dependencies.putAll(readDependenciesIfAvailable(
"hilla/components/react", packageJsonKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ public void should_useHillaEngine_whenEnabled()
EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> EndpointRequestUtil.isHillaAvailable(Mockito.any()))
.thenReturn(true);
util.when(() -> EndpointRequestUtil
.areHillaEndpointsUsed(Mockito.any())).thenReturn(true);

new NodeTasks(options).execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
import com.vaadin.flow.server.Mode;
import com.vaadin.flow.server.VaadinContext;
import com.vaadin.flow.server.VaadinServlet;
import com.vaadin.flow.server.frontend.EndpointGeneratorTaskFactory;
import com.vaadin.flow.server.frontend.FrontendUtils;
import com.vaadin.flow.server.frontend.NodeTasks;
import com.vaadin.flow.server.frontend.Options;
Expand Down Expand Up @@ -101,12 +100,9 @@ static class DevModeClassFinder extends DefaultClassFinder {

private static final Set<String> APPLICABLE_CLASS_NAMES = Collections
.unmodifiableSet(calculateApplicableClassNames());
private final Set<Class<? extends Annotation>> browserCallableAnnotations;

public DevModeClassFinder(Set<Class<?>> classes,
Set<Class<? extends Annotation>> browserCallableAnnotations) {
public DevModeClassFinder(Set<Class<?>> classes) {
super(classes);
this.browserCallableAnnotations = browserCallableAnnotations;
}

@Override
Expand All @@ -123,8 +119,7 @@ public <T> Set<Class<? extends T>> getSubTypesOf(Class<T> type) {
}

private void ensureImplementation(Class<?> clazz) {
if (!APPLICABLE_CLASS_NAMES.contains(clazz.getName())
&& !browserCallableAnnotations.contains(clazz)) {
if (!APPLICABLE_CLASS_NAMES.contains(clazz.getName())) {
throw new IllegalArgumentException("Unexpected class name "
+ clazz + ". Implementation error: the class finder "
+ "instance is not aware of this class. "
Expand All @@ -134,7 +129,6 @@ private void ensureImplementation(Class<?> clazz) {
}

private static Set<String> calculateApplicableClassNames() {

HandlesTypes handlesTypes = DevModeStartupListener.class
.getAnnotation(HandlesTypes.class);
return Stream.of(handlesTypes.value()).map(Class::getName)
Expand Down Expand Up @@ -249,18 +243,7 @@ public static DevModeHandler initDevModeHandler(Set<Class<?>> classes,
File frontendFolder = config.getFrontendFolder();

Lookup lookupFromContext = context.getAttribute(Lookup.class);

EndpointGeneratorTaskFactory endpointGeneratorTaskFactory = lookupFromContext
.lookup(EndpointGeneratorTaskFactory.class);

Set<Class<? extends Annotation>> browserCallableAnnotations = new HashSet<>();
if (endpointGeneratorTaskFactory != null) {
browserCallableAnnotations.addAll(endpointGeneratorTaskFactory
.getBrowserCallableAnnotations());
}

Lookup lookupForClassFinder = Lookup.of(
new DevModeClassFinder(classes, browserCallableAnnotations),
Lookup lookupForClassFinder = Lookup.of(new DevModeClassFinder(classes),
ClassFinder.class);
Lookup lookup = Lookup.compose(lookupForClassFinder, lookupFromContext);
Options options = new Options(lookup, baseDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ public void should_generateOpenApi() throws Exception {
EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> EndpointRequestUtil.isHillaAvailable(Mockito.any()))
.thenReturn(true);
util.when(() -> EndpointRequestUtil
.areHillaEndpointsUsed(Mockito.any())).thenReturn(true);
devModeStartupListener.onStartup(classes, servletContext);
handler = getDevModeHandler();
waitForDevServer();
Expand Down Expand Up @@ -146,8 +144,6 @@ public void should_generateTs_files() throws Exception {
EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> EndpointRequestUtil.isHillaAvailable(Mockito.any()))
.thenReturn(true);
util.when(() -> EndpointRequestUtil
.areHillaEndpointsUsed(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 @@ -17,11 +17,9 @@

import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -49,16 +47,6 @@ public TaskGenerateOpenAPI createTaskGenerateOpenAPI(Options options) {
return new TestTaskGenerateOpenAPI(options);
}

@Override
public Set<Class<? extends Annotation>> getBrowserCallableAnnotations() {
return Set.of();
}

@Override
public boolean hasBrowserCallables(Options options) {
return true;
}

/**
* An abstract parent for the test endpoints generator tasks.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -56,7 +55,7 @@
public class DevModeClassFinderTest {

private DevModeClassFinder classFinder = new DevModeClassFinder(
Collections.emptySet(), Collections.emptySet());
Collections.emptySet());

@Test
public void applicableClasses_knownClasses() {
Expand Down Expand Up @@ -128,7 +127,7 @@ public void callGetgetAnnotatedClassesByName_unexpectedType_throw()
@Test(expected = IllegalArgumentException.class)
public void callGetSubTypesOfByClass_unexpectedType_throw() {
DevModeClassFinder classFinder = new DevModeClassFinder(
Collections.emptySet(), Collections.emptySet());
Collections.emptySet());
classFinder.getSubTypesOf(Object.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,6 @@ public void should_generateOpenApi_when_EndpointPresents()
EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> EndpointRequestUtil
.isHillaAvailable(Mockito.any())).thenReturn(true);
util.when(() -> EndpointRequestUtil
.areHillaEndpointsUsed(Mockito.any())).thenReturn(true);
devModeStartupListener.onStartup(classes, servletContext);
handler = getDevModeHandler();
waitForDevServer();
Expand Down Expand Up @@ -427,8 +425,6 @@ public void should_generateTs_files() throws Exception {
EndpointRequestUtil.class, Mockito.CALLS_REAL_METHODS)) {
util.when(() -> EndpointRequestUtil
.isHillaAvailable(Mockito.any())).thenReturn(true);
util.when(() -> EndpointRequestUtil
.areHillaEndpointsUsed(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 @@ -47,7 +47,7 @@
* @author Vaadin Ltd
*
*/
@Configuration(proxyBeanMethods = false)
@Configuration
@AutoConfigureBefore(WebMvcAutoConfiguration.class)
@ConditionalOnClass(ServletContextInitializer.class)
@EnableConfigurationProperties(VaadinConfigurationProperties.class)
Expand Down
Loading

0 comments on commit 0afeb5f

Please sign in to comment.