-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(parser): add a fallback if AOT fails (#3314)
- Loading branch information
Showing
6 changed files
with
118 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...s/java/engine-core/src/main/java/com/vaadin/hilla/engine/LookupBrowserCallableFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.vaadin.hilla.engine; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import com.vaadin.flow.server.frontend.scanner.ClassFinder; | ||
|
||
class LookupBrowserCallableFinder { | ||
|
||
static List<Class<?>> findEndpointClasses(ClassFinder classFinder, | ||
EngineConfiguration engineConfiguration) { | ||
return engineConfiguration.getEndpointAnnotations().stream() | ||
.map(classFinder::getAnnotatedClasses).flatMap(Set::stream) | ||
.distinct().toList(); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
packages/java/engine-core/src/test/java/com/vaadin/hilla/engine/EngineConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.vaadin.hilla.engine; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import com.vaadin.flow.server.frontend.scanner.ClassFinder; | ||
|
||
public class EngineConfigurationTest { | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface BrowserCallableEndpoint { | ||
} | ||
|
||
private static class EndpointFromAot { | ||
} | ||
|
||
private static class EndpointFromClassFinder { | ||
} | ||
|
||
@Test | ||
public void shouldUseAot() throws Exception { | ||
var classFinder = mock(ClassFinder.class); | ||
when(classFinder | ||
.getAnnotatedClasses((Class<? extends Annotation>) any())) | ||
.thenThrow(RuntimeException.class); | ||
var conf = new EngineConfiguration.Builder().classFinder(classFinder) | ||
.build(); | ||
try (var aotMock = mockStatic(AotBrowserCallableFinder.class)) { | ||
when(AotBrowserCallableFinder.findEndpointClasses(conf)) | ||
.thenReturn(List.of(EndpointFromAot.class)); | ||
assertEquals(List.of(EndpointFromAot.class), | ||
conf.getBrowserCallableFinder().findBrowserCallables()); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldFallbackToClassFinder() throws Exception { | ||
var classFinder = mock(ClassFinder.class); | ||
when(classFinder | ||
.getAnnotatedClasses((Class<? extends Annotation>) any())) | ||
.thenReturn(Set.of(EndpointFromClassFinder.class)); | ||
var conf = new EngineConfiguration.Builder().classFinder(classFinder) | ||
.endpointAnnotations(BrowserCallableEndpoint.class).build(); | ||
try (var aotMock = mockStatic(AotBrowserCallableFinder.class)) { | ||
when(AotBrowserCallableFinder.findEndpointClasses(conf)) | ||
.thenThrow(ParserException.class); | ||
assertEquals(List.of(EndpointFromClassFinder.class), | ||
conf.getBrowserCallableFinder().findBrowserCallables()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters