|
5 | 5 | import java.lang.reflect.Modifier;
|
6 | 6 | import java.util.ArrayList;
|
7 | 7 | import java.util.Collection;
|
8 |
| -import java.util.Collections; |
9 | 8 | import java.util.List;
|
| 9 | +import java.util.OptionalInt; |
10 | 10 | import java.util.function.Predicate;
|
11 | 11 |
|
12 | 12 | import jakarta.enterprise.context.spi.Contextual;
|
@@ -113,58 +113,56 @@ public boolean test(BeanInfo bean) {
|
113 | 113 |
|
114 | 114 | @BuildStep
|
115 | 115 | void registerStartupObservers(ObserverRegistrationPhaseBuildItem observerRegistration,
|
| 116 | + List<SyntheticBeanBuildItem> syntheticBeans, |
116 | 117 | BuildProducer<ObserverConfiguratorBuildItem> configurators) {
|
117 | 118 |
|
118 | 119 | AnnotationStore annotationStore = observerRegistration.getContext().get(BuildExtension.Key.ANNOTATION_STORE);
|
119 | 120 |
|
120 |
| - for (BeanInfo bean : observerRegistration.getContext().beans().withTarget()) { |
121 |
| - // First check if the target is annotated with @Startup |
122 |
| - // Class for class-based bean, method for producer method, etc. |
123 |
| - AnnotationTarget target = bean.getTarget().get(); |
124 |
| - AnnotationInstance startupAnnotation = annotationStore.getAnnotation(target, STARTUP_NAME); |
125 |
| - if (startupAnnotation != null) { |
126 |
| - String id; |
127 |
| - if (target.kind() == Kind.METHOD) { |
128 |
| - id = target.asMethod().declaringClass().name() + "#" + target.asMethod().toString(); |
129 |
| - } else if (target.kind() == Kind.FIELD) { |
130 |
| - id = target.asField().declaringClass().name() + "#" + target.asField().toString(); |
131 |
| - } else { |
132 |
| - id = target.asClass().name().toString(); |
| 121 | + for (BeanInfo bean : observerRegistration.getContext().beans()) { |
| 122 | + if (bean.isSynthetic()) { |
| 123 | + OptionalInt startupPriority = bean.getStartupPriority(); |
| 124 | + if (startupPriority.isPresent()) { |
| 125 | + registerStartupObserver(observerRegistration, bean, bean.getIdentifier(), |
| 126 | + startupPriority.getAsInt(), null); |
133 | 127 | }
|
134 |
| - AnnotationValue priority = startupAnnotation.value(); |
135 |
| - registerStartupObserver(observerRegistration, bean, id, |
136 |
| - priority != null ? priority.asInt() : ObserverMethod.DEFAULT_PRIORITY, null); |
137 |
| - } |
138 |
| - |
139 |
| - List<MethodInfo> startupMethods = Collections.emptyList(); |
140 |
| - if (target.kind() == Kind.CLASS) { |
141 |
| - // If the target is a class then collect all non-static non-producer no-args methods annotated with @Startup |
142 |
| - startupMethods = new ArrayList<>(); |
143 |
| - for (MethodInfo method : target.asClass().methods()) { |
144 |
| - if (annotationStore.hasAnnotation(method, STARTUP_NAME)) { |
145 |
| - if (!method.isSynthetic() |
146 |
| - && !Modifier.isPrivate(method.flags()) |
147 |
| - && !Modifier.isStatic(method.flags()) |
148 |
| - && method.parametersCount() == 0 |
149 |
| - && !annotationStore.hasAnnotation(method, DotNames.PRODUCES)) { |
150 |
| - startupMethods.add(method); |
151 |
| - } else { |
152 |
| - if (!annotationStore.hasAnnotation(method, DotNames.PRODUCES)) { |
153 |
| - // Producer methods annotated with @Startup are valid and processed above |
154 |
| - LOG.warnf("Ignored an invalid @Startup method declared on %s: %s", |
155 |
| - method.declaringClass().name(), |
156 |
| - method); |
| 128 | + } else { |
| 129 | + // First check if the target is annotated with @Startup |
| 130 | + // Class for class-based bean, method for producer method, etc. |
| 131 | + AnnotationTarget target = bean.getTarget().get(); |
| 132 | + AnnotationInstance startupAnnotation = annotationStore.getAnnotation(target, STARTUP_NAME); |
| 133 | + if (startupAnnotation != null) { |
| 134 | + AnnotationValue priority = startupAnnotation.value(); |
| 135 | + registerStartupObserver(observerRegistration, bean, bean.getIdentifier(), |
| 136 | + priority != null ? priority.asInt() : ObserverMethod.DEFAULT_PRIORITY, null); |
| 137 | + } |
| 138 | + if (target.kind() == Kind.CLASS) { |
| 139 | + // If the target is a class then collect all non-static non-producer no-args methods annotated with @Startup |
| 140 | + List<MethodInfo> startupMethods = new ArrayList<>(); |
| 141 | + for (MethodInfo method : target.asClass().methods()) { |
| 142 | + if (annotationStore.hasAnnotation(method, STARTUP_NAME)) { |
| 143 | + if (!method.isSynthetic() |
| 144 | + && !Modifier.isPrivate(method.flags()) |
| 145 | + && !Modifier.isStatic(method.flags()) |
| 146 | + && method.parametersCount() == 0 |
| 147 | + && !annotationStore.hasAnnotation(method, DotNames.PRODUCES)) { |
| 148 | + startupMethods.add(method); |
| 149 | + } else { |
| 150 | + if (!annotationStore.hasAnnotation(method, DotNames.PRODUCES)) { |
| 151 | + // Producer methods annotated with @Startup are valid and processed above |
| 152 | + LOG.warnf("Ignored an invalid @Startup method declared on %s: %s", |
| 153 | + method.declaringClass().name(), |
| 154 | + method); |
| 155 | + } |
157 | 156 | }
|
158 | 157 | }
|
159 | 158 | }
|
160 |
| - } |
161 |
| - } |
162 |
| - if (!startupMethods.isEmpty()) { |
163 |
| - for (MethodInfo method : startupMethods) { |
164 |
| - AnnotationValue priority = annotationStore.getAnnotation(method, STARTUP_NAME).value(); |
165 |
| - registerStartupObserver(observerRegistration, bean, |
166 |
| - method.declaringClass().name() + "#" + method.toString(), |
167 |
| - priority != null ? priority.asInt() : ObserverMethod.DEFAULT_PRIORITY, method); |
| 159 | + if (!startupMethods.isEmpty()) { |
| 160 | + for (MethodInfo method : startupMethods) { |
| 161 | + AnnotationValue priority = annotationStore.getAnnotation(method, STARTUP_NAME).value(); |
| 162 | + registerStartupObserver(observerRegistration, bean, bean.getIdentifier() + method.toString(), |
| 163 | + priority != null ? priority.asInt() : ObserverMethod.DEFAULT_PRIORITY, method); |
| 164 | + } |
| 165 | + } |
168 | 166 | }
|
169 | 167 | }
|
170 | 168 | }
|
|
0 commit comments