From d00357ab63e28823381303f0d9103e4b714fe9ad Mon Sep 17 00:00:00 2001 From: Vaadin Bot Date: Mon, 22 Jul 2024 09:03:54 +0200 Subject: [PATCH] fix: ignore abstract AppShellConfigurators (#19706) (#19708) * fix: ignore abstract AppShellConfigurators * Also test that interface is ignored * Make annotations Inherited; fix test * Revert @PageTitle change * Remove import as well Co-authored-by: Teppo Kurki --- .../vaadin/flow/component/page/Inline.java | 3 +++ .../main/java/com/vaadin/flow/server/PWA.java | 2 ++ .../startup/VaadinAppShellInitializer.java | 2 ++ .../VaadinAppShellInitializerTest.java | 19 ++++++++++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/flow-server/src/main/java/com/vaadin/flow/component/page/Inline.java b/flow-server/src/main/java/com/vaadin/flow/component/page/Inline.java index acf4df8666a..0db1223d038 100644 --- a/flow-server/src/main/java/com/vaadin/flow/component/page/Inline.java +++ b/flow-server/src/main/java/com/vaadin/flow/component/page/Inline.java @@ -17,6 +17,7 @@ import java.lang.annotation.Documented; import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -32,6 +33,7 @@ @Target(ElementType.TYPE) @Documented @Repeatable(Inline.Container.class) +@Inherited public @interface Inline { /** * File content wrapping enum. @@ -82,6 +84,7 @@ enum Position { @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Documented + @Inherited @interface Container { /** diff --git a/flow-server/src/main/java/com/vaadin/flow/server/PWA.java b/flow-server/src/main/java/com/vaadin/flow/server/PWA.java index 54075ea127d..eccddf27678 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/PWA.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/PWA.java @@ -16,6 +16,7 @@ package com.vaadin.flow.server; import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @@ -55,6 +56,7 @@ */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) +@Inherited public @interface PWA { /** diff --git a/flow-server/src/main/java/com/vaadin/flow/server/startup/VaadinAppShellInitializer.java b/flow-server/src/main/java/com/vaadin/flow/server/startup/VaadinAppShellInitializer.java index 9dcd00b1183..17892ad7452 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/startup/VaadinAppShellInitializer.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/startup/VaadinAppShellInitializer.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.lang.annotation.Annotation; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -104,6 +105,7 @@ public static void init(Set> classes, VaadinContext context) { .lookup(AppShellPredicate.class); classes.stream() + .filter(clazz -> !Modifier.isAbstract(clazz.getModifiers())) // sort classes by putting the app shell in first position .sorted((a, b) -> predicate.isShell(a) ? -1 : predicate.isShell(b) ? 1 : 0) diff --git a/flow-server/src/test/java/com/vaadin/flow/server/startup/VaadinAppShellInitializerTest.java b/flow-server/src/test/java/com/vaadin/flow/server/startup/VaadinAppShellInitializerTest.java index fc8c1eb80f0..75ab7d2f3e1 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/startup/VaadinAppShellInitializerTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/startup/VaadinAppShellInitializerTest.java @@ -66,8 +66,16 @@ @NotThreadSafe public class VaadinAppShellInitializerTest { + public interface InterfaceAppShellWithoutAnnotations + extends AppShellConfigurator { + } + + public static abstract class AbstractAppShellWithoutAnnotations + implements InterfaceAppShellWithoutAnnotations { + } + public static class MyAppShellWithoutAnnotations - implements AppShellConfigurator { + extends AbstractAppShellWithoutAnnotations { } @Meta(name = "foo", content = "bar") @@ -399,6 +407,15 @@ public void should_throw_when_multipleAppShell() throws Exception { initializer.process(classes, servletContext); } + @Test + public void should_not_throw_when_interface_and_abstract_and_concrete_AppShell() + throws Exception { + classes.add(InterfaceAppShellWithoutAnnotations.class); + classes.add(AbstractAppShellWithoutAnnotations.class); + classes.add(MyAppShellWithoutAnnotations.class); + initializer.process(classes, servletContext); + } + @Test public void should_not_throw_when_appShellAnnotationsAreAllowed_and_offendingClass() throws Exception {