Skip to content

Commit

Permalink
Remove direct references to the endpoint annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
cromoteca committed Jul 31, 2024
1 parent ed93bd9 commit 236efd5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public void update() {
}

ApplicationContextProvider.runOnContext(applicationContext -> {
List<Class<?>> endpoints = Stream
.of(BrowserCallable.class, Endpoint.class)
EngineConfiguration engineConfiguration = new EngineConfiguration();
List<Class<?>> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -28,6 +30,16 @@ public List<String> getEndpointAnnotations() {
return endpointAnnotations;
}

public List<Class<? extends Annotation>> getEndpointAnnotationClasses() {
return endpointAnnotations.stream().map(name -> {
try {
return (Class<? extends Annotation>) Class.forName(name);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
}

public List<String> getEndpointExposedAnnotations() {
return endpointExposedAnnotations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -164,13 +164,12 @@ public void execute() throws ExecutionFailedException {
}
} else {
ApplicationContextProvider.runOnContext(applicationContext -> {
List<Class<?>> endpoints = Stream
.of(BrowserCallable.class, Endpoint.class)
List<Class<?>> 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);
Expand Down

0 comments on commit 236efd5

Please sign in to comment.