diff --git a/packages/java/endpoint/src/main/java/com/vaadin/hilla/EndpointCodeGenerator.java b/packages/java/endpoint/src/main/java/com/vaadin/hilla/EndpointCodeGenerator.java index e27ad59b29..ed8bf7a401 100644 --- a/packages/java/endpoint/src/main/java/com/vaadin/hilla/EndpointCodeGenerator.java +++ b/packages/java/endpoint/src/main/java/com/vaadin/hilla/EndpointCodeGenerator.java @@ -87,12 +87,12 @@ public void update() { } ApplicationContextProvider.runOnContext(applicationContext -> { - List> endpoints = Stream - .of(BrowserCallable.class, Endpoint.class) + EngineConfiguration engineConfiguration = new EngineConfiguration(); + List> endpoints = engineConfiguration.getParser() + .getEndpointAnnotationClasses().stream() .map(applicationContext::getBeansWithAnnotation) .map(Map::values).flatMap(Collection::stream) .map(Object::getClass).distinct().toList(); - EngineConfiguration engineConfiguration = new EngineConfiguration(); ParserProcessor parser = new ParserProcessor(engineConfiguration, getClass().getClassLoader(), false); parser.process(endpoints); diff --git a/packages/java/engine-core/src/main/java/com/vaadin/hilla/engine/ParserConfiguration.java b/packages/java/engine-core/src/main/java/com/vaadin/hilla/engine/ParserConfiguration.java index 313525936e..bc95880b6f 100644 --- a/packages/java/engine-core/src/main/java/com/vaadin/hilla/engine/ParserConfiguration.java +++ b/packages/java/engine-core/src/main/java/com/vaadin/hilla/engine/ParserConfiguration.java @@ -1,10 +1,12 @@ package com.vaadin.hilla.engine; +import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.stream.Collectors; import jakarta.annotation.Nonnull; @@ -28,6 +30,16 @@ public List getEndpointAnnotations() { return endpointAnnotations; } + public List> getEndpointAnnotationClasses() { + return endpointAnnotations.stream().map(name -> { + try { + return (Class) Class.forName(name); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toList()); + } + public List getEndpointExposedAnnotations() { return endpointExposedAnnotations; } diff --git a/packages/java/engine-runtime/src/main/java/com/vaadin/hilla/internal/TaskGenerateOpenAPIImpl.java b/packages/java/engine-runtime/src/main/java/com/vaadin/hilla/internal/TaskGenerateOpenAPIImpl.java index 2a95b8530d..7a4b65f836 100644 --- a/packages/java/engine-runtime/src/main/java/com/vaadin/hilla/internal/TaskGenerateOpenAPIImpl.java +++ b/packages/java/engine-runtime/src/main/java/com/vaadin/hilla/internal/TaskGenerateOpenAPIImpl.java @@ -126,6 +126,8 @@ public void execute() throws ExecutionFailedException { var json = aotOutput.resolve(Path.of("resources", "META-INF", "native-image", EngineConfiguration.groupId, EngineConfiguration.artifactId, "reflect-config.json")); + var engineConfiguration = new EngineConfiguration(); + if (isProductionMode && Files.isRegularFile(json)) { try { String jsonContent = Files.readString(json); @@ -149,12 +151,10 @@ public void execute() throws ExecutionFailedException { return null; } }).filter(Objects::nonNull) - .filter(cls -> cls - .isAnnotationPresent(Endpoint.class) - || cls.isAnnotationPresent( - BrowserCallable.class)) + .filter(cls -> engineConfiguration.getParser() + .getEndpointAnnotationClasses().stream() + .anyMatch(cls::isAnnotationPresent)) .collect(Collectors.toList()); - var engineConfiguration = new EngineConfiguration(); var processor = new ParserProcessor(engineConfiguration, classLoader, isProductionMode); processor.process(endpoints); @@ -164,13 +164,12 @@ public void execute() throws ExecutionFailedException { } } else { ApplicationContextProvider.runOnContext(applicationContext -> { - List> endpoints = Stream - .of(BrowserCallable.class, Endpoint.class) + List> endpoints = engineConfiguration.getParser() + .getEndpointAnnotationClasses().stream() .map(applicationContext::getBeansWithAnnotation) .map(Map::values).flatMap(Collection::stream) .map(Object::getClass).distinct() .collect(Collectors.toList()); - var engineConfiguration = new EngineConfiguration(); var processor = new ParserProcessor(engineConfiguration, classLoader, isProductionMode); processor.process(endpoints);