Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add endpoint detection #2938

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat: add endpoint detection #2938

wants to merge 5 commits into from

Conversation

tepi
Copy link
Contributor

@tepi tepi commented Nov 28, 2024

Add check for if endpoint generator needs to run

Fixes vaadin/flow#20289
Fixes vaadin/flow#18800

@tepi
Copy link
Contributor Author

tepi commented Nov 29, 2024

Needs to be tested along with vaadin/flow#20567 in order to compile

Comment on lines 18 to 20
return !classFinder.getAnnotatedClasses(Endpoint.class).isEmpty()
|| !classFinder.getAnnotatedClasses(BrowserCallable.class)
.isEmpty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should probably exclude Hilla internal annotated classes, like SignalsHandler

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point, indeed, without this Flow would always try to generate the endpoints unless one completely excludes Hilla.
Something similar is needed:

        ClassFinder classFinder = options.getClassFinder();
        return Stream.concat(
            classFinder.getAnnotatedClasses(Endpoint.class).stream(),
                classFinder.getAnnotatedClasses(BrowserCallable.class).stream())
            .anyMatch(annotatedClass -> !annotatedClass.getPackage().getName()
                .startsWith("com.vaadin.hilla"));

Comment on lines 49 to 50
Assertions.fail("Class " + clazz.getName()
+ " is annotated with @BrowserCallable or @Endpoint, but missing @InternalBrowserCallable.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the assertion message is not correct here: in this case, all annotatedClasses will have @InternalBrowserCallable annotation, but they might miss @BrowserCallable or @Endpoint

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the messages in the two tests are inverted

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they are inverted indeed, thanks for noticing it 👍

@mshabarov mshabarov force-pushed the feat/endpoint-detection branch from ed89b41 to 5e2e68c Compare December 19, 2024 13:28
@mshabarov mshabarov requested a review from platosha December 20, 2024 08:38
@mshabarov
Copy link
Contributor

This should be ready for review now, trying locally and it seems to pass on existing tests and new ones.
Requires review and a suitable time to merge flow and hilla parts simultaneously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants