|
| 1 | +/* |
| 2 | + * Copyright 2023 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.data.elasticsearch.aot; |
| 17 | + |
| 18 | +import static org.springframework.data.elasticsearch.aot.ElasticsearchAotPredicates.*; |
| 19 | + |
| 20 | +import java.util.Arrays; |
| 21 | + |
| 22 | +import org.springframework.aot.hint.MemberCategory; |
| 23 | +import org.springframework.aot.hint.RuntimeHints; |
| 24 | +import org.springframework.aot.hint.RuntimeHintsRegistrar; |
| 25 | +import org.springframework.aot.hint.TypeReference; |
| 26 | +import org.springframework.data.elasticsearch.client.elc.EntityAsMap; |
| 27 | +import org.springframework.data.elasticsearch.core.event.AfterConvertCallback; |
| 28 | +import org.springframework.data.elasticsearch.core.event.AfterLoadCallback; |
| 29 | +import org.springframework.data.elasticsearch.core.event.AfterSaveCallback; |
| 30 | +import org.springframework.data.elasticsearch.core.event.AuditingEntityCallback; |
| 31 | +import org.springframework.data.elasticsearch.core.event.BeforeConvertCallback; |
| 32 | +import org.springframework.data.elasticsearch.core.event.ReactiveAfterConvertCallback; |
| 33 | +import org.springframework.data.elasticsearch.core.event.ReactiveAfterLoadCallback; |
| 34 | +import org.springframework.data.elasticsearch.core.event.ReactiveAfterSaveCallback; |
| 35 | +import org.springframework.data.elasticsearch.core.event.ReactiveAuditingEntityCallback; |
| 36 | +import org.springframework.data.elasticsearch.core.event.ReactiveBeforeConvertCallback; |
| 37 | +import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext; |
| 38 | +import org.springframework.lang.Nullable; |
| 39 | + |
| 40 | +/** |
| 41 | + * @author Peter-Josef Meisch |
| 42 | + * @since 5.1 |
| 43 | + */ |
| 44 | +public class ElasticsearchRuntimeHints implements RuntimeHintsRegistrar { |
| 45 | + |
| 46 | + @Override |
| 47 | + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { |
| 48 | + hints.reflection().registerTypes( // |
| 49 | + Arrays.asList( // |
| 50 | + TypeReference.of(AfterConvertCallback.class), // |
| 51 | + TypeReference.of(AfterLoadCallback.class), // |
| 52 | + TypeReference.of(AfterSaveCallback.class), // |
| 53 | + TypeReference.of(BeforeConvertCallback.class), // |
| 54 | + TypeReference.of(EntityAsMap.class) // |
| 55 | + ), // |
| 56 | + builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, |
| 57 | + MemberCategory.INVOKE_PUBLIC_METHODS)); |
| 58 | + |
| 59 | + if (isReactorPresent()) { |
| 60 | + hints.reflection().registerTypes( // |
| 61 | + Arrays.asList( // |
| 62 | + TypeReference.of(ReactiveAfterConvertCallback.class), // |
| 63 | + TypeReference.of(ReactiveAfterLoadCallback.class), // |
| 64 | + TypeReference.of(ReactiveAfterSaveCallback.class), // |
| 65 | + TypeReference.of(ReactiveBeforeConvertCallback.class) // |
| 66 | + ), // |
| 67 | + builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, |
| 68 | + MemberCategory.INVOKE_PUBLIC_METHODS)); |
| 69 | + } |
| 70 | + |
| 71 | + // properties needed to log the different versions |
| 72 | + hints.resources().registerPattern("versions.properties"); |
| 73 | + hints.resources().registerPattern("co/elastic/clients/version.properties"); |
| 74 | + } |
| 75 | +} |
0 commit comments