This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch aot in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
commit afb4994e4836cc4db3a5f1f67f5f053699c4fef2 Author: Claus Ibsen <[email protected]> AuthorDate: Sun Mar 1 21:39:57 2026 +0100 CAMEL-23109: Remove aot experiment in camel-spring-boot --- components-starter/camel-xml-jaxb-starter/pom.xml | 6 - .../xml/jaxb/springboot/JAXBRuntimeHints.java | 294 --------------------- .../jaxb/springboot/graalvm/JAXBSubstitutions.java | 102 ------- .../main/resources/META-INF/spring/aot.factories | 18 -- .../camel/xml/jaxb/springboot/BeanScope.java | 27 -- .../org/apache/camel/xml/jaxb/springboot/Book.java | 47 ---- .../camel/xml/jaxb/springboot/IdentifiedType.java | 45 ---- .../xml/jaxb/springboot/JAXBRuntimeHintsTest.java | 57 ---- .../camel/xml/jaxb/springboot/USAddress.java | 177 ------------- .../apache/camel/xml/jaxb/springboot/jaxb.index | 1 - components-starter/pom.xml | 1 - .../camel/spring/boot/CamelAutoConfiguration.java | 2 - .../camel/spring/boot/aot/CamelRuntimeHints.java | 99 ------- .../camel/spring/boot/aot/ReflectionHelper.java | 257 ------------------ .../camel/spring/boot/aot/RuntimeHintsHelper.java | 76 ------ .../camel-spring-boot/native-image.properties | 17 -- .../spring/boot/aot/CamelRuntimeHintsTest.java | 56 ---- .../spring/boot/aot/ReflectionHelperTest.java | 145 ---------- .../src/main/docs/java-joor-dsl.json | 2 +- .../src/main/docs/xml-io-dsl.json | 2 +- dsl-starter/camel-xml-jaxb-dsl-starter/pom.xml | 10 - .../src/main/docs/xml-jaxb-dsl.json | 2 +- .../jaxb/springboot/aot/XMLDSLRuntimeHints.java | 30 --- .../main/resources/META-INF/spring/aot.factories | 18 -- .../src/main/docs/yaml-io-dsl.json | 15 ++ pom.xml | 1 - 26 files changed, 18 insertions(+), 1489 deletions(-) diff --git a/components-starter/camel-xml-jaxb-starter/pom.xml b/components-starter/camel-xml-jaxb-starter/pom.xml index 80a2f8fce04..4e55fbb9eb7 100644 --- a/components-starter/camel-xml-jaxb-starter/pom.xml +++ b/components-starter/camel-xml-jaxb-starter/pom.xml @@ -38,12 +38,6 @@ <artifactId>camel-xml-jaxb</artifactId> <version>${camel-version}</version> </dependency> - <dependency> - <groupId>org.graalvm.sdk</groupId> - <artifactId>graal-sdk</artifactId> - <version>${graal-sdk-version}</version> - <scope>provided</scope> - </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> diff --git a/components-starter/camel-xml-jaxb-starter/src/main/java/org/apache/camel/xml/jaxb/springboot/JAXBRuntimeHints.java b/components-starter/camel-xml-jaxb-starter/src/main/java/org/apache/camel/xml/jaxb/springboot/JAXBRuntimeHints.java deleted file mode 100644 index b04852d313c..00000000000 --- a/components-starter/camel-xml-jaxb-starter/src/main/java/org/apache/camel/xml/jaxb/springboot/JAXBRuntimeHints.java +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.xml.jaxb.springboot; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.lang.annotation.Annotation; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; - -import jakarta.xml.bind.annotation.XmlAccessOrder; -import jakarta.xml.bind.annotation.XmlAccessorType; -import jakarta.xml.bind.annotation.XmlAnyAttribute; -import jakarta.xml.bind.annotation.XmlAnyElement; -import jakarta.xml.bind.annotation.XmlAttachmentRef; -import jakarta.xml.bind.annotation.XmlAttribute; -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlElementDecl; -import jakarta.xml.bind.annotation.XmlElementRef; -import jakarta.xml.bind.annotation.XmlElementRefs; -import jakarta.xml.bind.annotation.XmlElementWrapper; -import jakarta.xml.bind.annotation.XmlElements; -import jakarta.xml.bind.annotation.XmlEnum; -import jakarta.xml.bind.annotation.XmlEnumValue; -import jakarta.xml.bind.annotation.XmlID; -import jakarta.xml.bind.annotation.XmlIDREF; -import jakarta.xml.bind.annotation.XmlInlineBinaryData; -import jakarta.xml.bind.annotation.XmlList; -import jakarta.xml.bind.annotation.XmlMimeType; -import jakarta.xml.bind.annotation.XmlMixed; -import jakarta.xml.bind.annotation.XmlNs; -import jakarta.xml.bind.annotation.XmlRegistry; -import jakarta.xml.bind.annotation.XmlRootElement; -import jakarta.xml.bind.annotation.XmlSchema; -import jakarta.xml.bind.annotation.XmlSchemaType; -import jakarta.xml.bind.annotation.XmlSchemaTypes; -import jakarta.xml.bind.annotation.XmlSeeAlso; -import jakarta.xml.bind.annotation.XmlTransient; -import jakarta.xml.bind.annotation.XmlType; -import jakarta.xml.bind.annotation.XmlValue; -import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapters; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.aot.hint.MemberCategory; -import org.springframework.aot.hint.RuntimeHints; -import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.aot.hint.TypeReference; -import org.springframework.asm.ClassReader; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.util.ReflectionUtils; - -import static org.apache.camel.spring.boot.aot.ReflectionHelper.applyIfMatch; -import static org.apache.camel.spring.boot.aot.ReflectionHelper.getClassesByAnnotations; -import static org.apache.camel.spring.boot.aot.RuntimeHintsHelper.registerClassHierarchy; - -final class JAXBRuntimeHints implements RuntimeHintsRegistrar { - - /** - * The logger. - */ - private static final Logger LOG = LoggerFactory.getLogger(JAXBRuntimeHints.class); - - private static final List<Class<? extends Annotation>> JAXB_ROOT_ANNOTATIONS = List.of(XmlRootElement.class, - XmlType.class, XmlRegistry.class, XmlJavaTypeAdapter.class, XmlSeeAlso.class); - - private static final List<Class<? extends Annotation>> JAXB_ANNOTATIONS = List.of(XmlAccessorType.class, - XmlAnyAttribute.class, XmlAnyElement.class, XmlAttachmentRef.class, XmlAttribute.class, XmlElement.class, - XmlElementDecl.class, XmlElementRef.class, XmlElementRefs.class, XmlElements.class, XmlElementWrapper.class, - XmlEnum.class, XmlEnumValue.class, XmlID.class, XmlIDREF.class, XmlInlineBinaryData.class, XmlList.class, - XmlMimeType.class, XmlMixed.class, XmlNs.class, XmlRegistry.class, XmlRootElement.class, XmlSchema.class, - XmlSchemaType.class, XmlSchemaTypes.class, XmlSeeAlso.class, XmlTransient.class, XmlType.class, - XmlValue.class, XmlJavaTypeAdapter.class, XmlJavaTypeAdapters.class); - - private static final List<String> NATIVE_PROXY_DEFINITIONS = List.of( - "org.glassfish.jaxb.core.marshaller.CharacterEscapeHandler", - "com.sun.xml.txw2.output.CharacterEscapeHandler", "org.glassfish.jaxb.core.v2.schemagen.episode.Bindings", - "org.glassfish.jaxb.core.v2.schemagen.episode.SchemaBindings", - "org.glassfish.jaxb.core.v2.schemagen.episode.Klass", - "org.glassfish.jaxb.core.v2.schemagen.episode.Package", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Annotated", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Annotation", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Any", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Appinfo", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.AttrDecls", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.AttributeType", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ComplexContent", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ComplexExtension", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ComplexRestriction", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ComplexType", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ComplexTypeHost", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ComplexTypeModel", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ContentModelContainer", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Documentation", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Element", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ExplicitGroup", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ExtensionType", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.FixedOrDefault", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Import", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.List", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.LocalAttribute", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.LocalElement", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.NestedParticle", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.NoFixedFacet", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Occurs", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Particle", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Redefinable", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Schema", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.SchemaTop", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.SimpleContent", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.SimpleDerivation", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.SimpleExtension", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.SimpleRestriction", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.SimpleRestrictionModel", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.SimpleType", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.SimpleTypeHost", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.TopLevelAttribute", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.TopLevelElement", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.TypeDefParticle", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.TypeHost", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Union", - "org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Wildcard", "com.sun.xml.txw2.TypedXmlWriter"); - private static final List<String> JAXB_RUNTIME_CLASSES = List.of("org.glassfish.jaxb.runtime.v2.ContextFactory", - "com.sun.xml.internal.stream.XMLInputFactoryImpl", "com.sun.xml.internal.stream.XMLOutputFactoryImpl", - "com.sun.org.apache.xpath.internal.functions.FuncNot", - "org.glassfish.jaxb.core.v2.model.nav.ReflectionNavigator", - "org.glassfish.jaxb.runtime.v2.runtime.property.SingleElementLeafProperty", - "org.glassfish.jaxb.runtime.v2.runtime.property.ArrayElementLeafProperty", - "org.glassfish.jaxb.runtime.v2.runtime.property.SingleElementNodeProperty", - "org.glassfish.jaxb.runtime.v2.runtime.property.SingleReferenceNodeProperty", - "org.glassfish.jaxb.runtime.v2.runtime.property.SingleMapNodeProperty", - "org.glassfish.jaxb.runtime.v2.runtime.property.ArrayElementNodeProperty", - "org.glassfish.jaxb.runtime.v2.runtime.property.ArrayReferenceNodeProperty", - "com.sun.org.apache.xerces.internal.impl.dv.xs.SchemaDVFactoryImpl", XmlAccessOrder.class.getName()); - - @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - List<Class<?>> classes = getClassesByAnnotations(classLoader, JAXB_ROOT_ANNOTATIONS); - for (Class<?> c : classes) { - if (c.isAnnotationPresent(XmlSeeAlso.class)) { - XmlSeeAlso annotation = c.getAnnotation(XmlSeeAlso.class); - for (Class<?> type : annotation.value()) { - hints.reflection().registerType(type, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS); - } - } - applyIfMatch(c, XmlJavaTypeAdapter.class, XmlJavaTypeAdapter::value, - type -> hints.reflection().registerType(type, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, - MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS, - MemberCategory.DECLARED_FIELDS)); - hints.reflection().registerType(c, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, - MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS, - MemberCategory.DECLARED_FIELDS); - } - boolean classDetected = false; - for (String className : getClassesFromIndexes(classLoader)) { - registerClassHierarchy(hints, classLoader, className, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, - MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS); - classDetected = true; - } - if (classes.isEmpty() && !classDetected) { - return; - } - // Register all JAXB indexes - hints.resources().registerPattern("**/jaxb.index"); - - hints.reflection().registerTypeIfPresent(classLoader, "jakarta.xml.bind.annotation.W3CDomHandler", - MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS); - for (Class<?> c : JAXB_ANNOTATIONS) { - hints.reflection().registerType(c, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, - MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS); - } - hints.proxies().registerJdkProxy(TypeReference.of(XmlSeeAlso.class), - TypeReference.of("org.glassfish.jaxb.core.v2.model.annotation.Locatable")); - for (String className : NATIVE_PROXY_DEFINITIONS) { - hints.proxies().registerJdkProxy(TypeReference.of(className)); - } - for (String className : JAXB_RUNTIME_CLASSES) { - hints.reflection().registerTypeIfPresent(classLoader, className, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, - MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS); - } - // Register the JAXB resource bundles - hints.reflection().registerTypeIfPresent(classLoader, "jakarta.xml.bind.Messages"); - hints.resources().registerPattern("jakarta/xml/bind/Messages.properties"); - hints.reflection().registerTypeIfPresent(classLoader, "jakarta.xml.bind.helpers.Messages"); - hints.resources().registerPattern("jakarta/xml/bind/helpers/Messages.properties"); - } - - private static List<String> getClassesFromIndexes(ClassLoader classLoader) { - List<String> classNames = new ArrayList<>(); - PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(classLoader); - try { - for (Resource resource : resolver.getResources("classpath*:**/jaxb.index")) { - String filename = resource.getFilename(); - if (filename == null || filename.isBlank()) { - continue; - } - String packageName = getPackageName(resource, "jaxb.index"); - if (packageName == null) { - LOG.debug("The package name could not be found for the resource {}", resource); - continue; - } - try (BufferedReader reader = new BufferedReader( - new StringReader(resource.getContentAsString(StandardCharsets.UTF_8)))) { - String line = reader.readLine(); - while (line != null) { - if (line.startsWith("#") || line.isBlank()) { - line = reader.readLine(); - continue; - } - String className = "%s%s".formatted(packageName, line.trim()); - LOG.debug("Found the class {} to register", className); - classNames.add(className); - line = reader.readLine(); - } - } - } - } catch (IOException e) { - LOG.debug("Could not load the JAXB indexes: {}", e.getMessage()); - } - return classNames; - } - - /** - * Give the package name of the given resource. - * - * @param resource - * the resource for which the package name is expected. - * @param fileName - * the name of file corresponding to the resource - * - * @return the package name if it could be found, {@code null} otherwise. - * - * @throws IOException - * an error occurs while trying to retrieve the package name. - */ - private static String getPackageName(Resource resource, String fileName) throws IOException { - URL url = resource.getURL(); - String protocol = url.getProtocol(); - String packageName = null; - if ("jar".equals(protocol)) { - String path = url.getPath(); - String suffix = ".jar!/"; - int index = path.indexOf(suffix); - if (index == -1) { - LOG.trace("The jar suffix could not be found in {}", path); - } else { - packageName = path.substring(index + suffix.length(), path.length() - fileName.length()); - } - } else if (resource.isFile()) { - File file = resource.getFile(); - File[] files = file.getParentFile().listFiles((dir, name) -> name.endsWith(".class")); - if (files != null && files.length > 0) { - try (InputStream is = new FileInputStream(files[0])) { - ClassReader reader = new ClassReader(is); - String className = reader.getClassName(); - int index = className.lastIndexOf('/'); - if (index == -1) { - packageName = ""; - } else { - packageName = className.substring(0, index + 1); - } - } - } else { - LOG.trace("No class file could be found in {}", file.getParentFile()); - } - } - if (packageName != null) { - packageName = packageName.replace('/', '.'); - } - return packageName; - } -} diff --git a/components-starter/camel-xml-jaxb-starter/src/main/java/org/apache/camel/xml/jaxb/springboot/graalvm/JAXBSubstitutions.java b/components-starter/camel-xml-jaxb-starter/src/main/java/org/apache/camel/xml/jaxb/springboot/graalvm/JAXBSubstitutions.java deleted file mode 100644 index 34664e794d6..00000000000 --- a/components-starter/camel-xml-jaxb-starter/src/main/java/org/apache/camel/xml/jaxb/springboot/graalvm/JAXBSubstitutions.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.xml.jaxb.springboot.graalvm; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - -import jakarta.xml.bind.annotation.XmlSeeAlso; - -import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import org.glassfish.jaxb.core.v2.model.annotation.Locatable; -import org.glassfish.jaxb.runtime.v2.model.annotation.LocatableAnnotation; -import org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeInlineAnnotationReader; - -public class JAXBSubstitutions { -} - -@TargetClass(RuntimeInlineAnnotationReader.class) -final class SubstituteRuntimeInlineAnnotationReader { - - @Alias - private Map<Class<? extends Annotation>, Map<Package, Annotation>> packageCache; - - @Substitute - public <A extends Annotation> A getFieldAnnotation(Class<A> annotation, Field field, Locatable srcPos) { - return field.getAnnotation(annotation); - } - - @Substitute - public Annotation[] getAllFieldAnnotations(Field field, Locatable srcPos) { - return field.getAnnotations(); - } - - @Substitute - public <A extends Annotation> A getClassAnnotation(Class<A> a, Class clazz, Locatable srcPos) { - A ann = ((Class<?>) clazz).getAnnotation(a); - return (ann != null && ann.annotationType() == XmlSeeAlso.class) ? LocatableAnnotation.create(ann, srcPos) - : ann; - } - - @Substitute - public <A extends Annotation> A getMethodAnnotation(Class<A> annotation, Method method, Locatable srcPos) { - return method.getAnnotation(annotation); - } - - @Substitute - public Annotation[] getAllMethodAnnotations(Method method, Locatable srcPos) { - return method.getAnnotations(); - } - - @Substitute - public <A extends Annotation> A getMethodParameterAnnotation(Class<A> annotation, Method method, int paramIndex, - Locatable srcPos) { - Annotation[] pa = method.getParameterAnnotations()[paramIndex]; - for (Annotation a : pa) { - if (a.annotationType() == annotation) - return (A) a; - } - return null; - } - - @SuppressWarnings("unchecked") - @Substitute - public <A extends Annotation> A getPackageAnnotation(Class<A> a, Class clazz, Locatable srcPos) { - Package p = clazz.getPackage(); - if (p == null) { - return null; - } - - Map<Package, Annotation> cache = packageCache.get(a); - if (cache == null) { - cache = new HashMap<>(); - packageCache.put(a, cache); - } - if (cache.containsKey(p)) { - return (A) cache.get(p); - } else { - A ann = p.getAnnotation(a); - cache.put(p, ann); - return ann; - } - } -} diff --git a/components-starter/camel-xml-jaxb-starter/src/main/resources/META-INF/spring/aot.factories b/components-starter/camel-xml-jaxb-starter/src/main/resources/META-INF/spring/aot.factories deleted file mode 100644 index a4d96c415be..00000000000 --- a/components-starter/camel-xml-jaxb-starter/src/main/resources/META-INF/spring/aot.factories +++ /dev/null @@ -1,18 +0,0 @@ -## --------------------------------------------------------------------------- -## Licensed to the Apache Software Foundation (ASF) under one or more -## contributor license agreements. See the NOTICE file distributed with -## this work for additional information regarding copyright ownership. -## The ASF licenses this file to You under the Apache License, Version 2.0 -## (the "License"); you may not use this file except in compliance with -## the License. You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## --------------------------------------------------------------------------- -org.springframework.aot.hint.RuntimeHintsRegistrar=\ -org.apache.camel.xml.jaxb.springboot.JAXBRuntimeHints diff --git a/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/BeanScope.java b/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/BeanScope.java deleted file mode 100644 index a81dcb4c4d8..00000000000 --- a/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/BeanScope.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.xml.jaxb.springboot; - -import jakarta.xml.bind.annotation.XmlEnum; - -@XmlEnum -public enum BeanScope { - Singleton, Request, Prototype; - - BeanScope() { - } -} diff --git a/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/Book.java b/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/Book.java deleted file mode 100644 index 280e5b1fef2..00000000000 --- a/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/Book.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.xml.jaxb.springboot; - -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlRootElement; -import jakarta.xml.bind.annotation.XmlTransient; -import jakarta.xml.bind.annotation.XmlType; - -@XmlRootElement(name = "book") -@XmlType(propOrder = { "id", "name", "date" }) -public class Book extends IdentifiedType { - private String name; - private String author; - - @XmlElement(name = "title") - public void setName(String name) { - this.name = name; - } - - @XmlTransient - public void setAuthor(String author) { - this.author = author; - } - - public String getName() { - return name; - } - - public String getAuthor() { - return author; - } -} diff --git a/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/IdentifiedType.java b/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/IdentifiedType.java deleted file mode 100644 index 1720ca2033b..00000000000 --- a/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/IdentifiedType.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.xml.jaxb.springboot; - -import jakarta.xml.bind.annotation.XmlAccessType; -import jakarta.xml.bind.annotation.XmlAccessorType; -import jakarta.xml.bind.annotation.XmlAttribute; -import jakarta.xml.bind.annotation.XmlID; -import jakarta.xml.bind.annotation.XmlType; - -import org.apache.camel.spi.Metadata; - -@XmlType(name = "identifiedType") -@XmlAccessorType(XmlAccessType.FIELD) -public abstract class IdentifiedType { - @XmlAttribute - @XmlID - @Metadata(description = "The id of this node") - private String id; - - public IdentifiedType() { - } - - public String getId() { - return this.id; - } - - public void setId(String value) { - this.id = value; - } -} diff --git a/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/JAXBRuntimeHintsTest.java b/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/JAXBRuntimeHintsTest.java deleted file mode 100644 index 309bd118358..00000000000 --- a/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/JAXBRuntimeHintsTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.xml.jaxb.springboot; - -import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.aot.hint.RuntimeHints; -import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Unit tests for {@link JAXBRuntimeHints}. - */ -class JAXBRuntimeHintsTest { - private final RuntimeHints hints = new RuntimeHints(); - - @BeforeEach - void init() { - new JAXBRuntimeHints().registerHints(hints, getClass().getClassLoader()); - } - - @Test - void shouldRegisterHintsForJAXB() throws Exception { - assertThat(RuntimeHintsPredicates.resource().forResource("jakarta/xml/bind/Messages.properties")) - .accepts(hints); - assertThat(RuntimeHintsPredicates.resource().forResource("org/apache/camel/spring/boot/aot/jaxb.index")) - .accepts(hints); - assertThat(RuntimeHintsPredicates.reflection().onType(Book.class)).accepts(hints); - assertThat(RuntimeHintsPredicates.reflection().onMethod(Book.class, "getName")).accepts(hints); - assertThat(RuntimeHintsPredicates.reflection().onType(IdentifiedType.class)).accepts(hints); - assertThat(RuntimeHintsPredicates.reflection().onMethod(IdentifiedType.class, "setId")).accepts(hints); - assertThat(RuntimeHintsPredicates.resource().forResource("org/apache/camel/core/xml/util/jsse/jaxb.index")) - .accepts(hints); - assertThat(RuntimeHintsPredicates.reflection().onType(BeanScope.class)).accepts(hints); - assertThat(RuntimeHintsPredicates.reflection() - .onMethod("org.glassfish.jaxb.core.v2.model.nav.ReflectionNavigator", "getInstance")).accepts(hints); - assertThat(RuntimeHintsPredicates.reflection().onType(USAddress.class)).accepts(hints); - assertThat(RuntimeHintsPredicates.reflection().onType(CollapsedStringAdapter.class)).accepts(hints); - } -} diff --git a/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/USAddress.java b/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/USAddress.java deleted file mode 100644 index 5b4cf5a9187..00000000000 --- a/components-starter/camel-xml-jaxb-starter/src/test/java/org/apache/camel/xml/jaxb/springboot/USAddress.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.xml.jaxb.springboot; - -import java.math.BigDecimal; - -import jakarta.xml.bind.annotation.XmlAccessType; -import jakarta.xml.bind.annotation.XmlAccessorType; -import jakarta.xml.bind.annotation.XmlAttribute; -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlType; -import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter; -import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "USAddress", propOrder = { "name", "street", "city", "state", "zip" }) -public class USAddress { - - @XmlElement(required = true) - protected String name; - @XmlElement(required = true) - protected String street; - @XmlElement(required = true) - protected String city; - @XmlElement(required = true) - protected String state; - @XmlElement(required = true) - protected BigDecimal zip; - @XmlAttribute - @XmlJavaTypeAdapter(CollapsedStringAdapter.class) - protected String country; - - /** - * Gets the value of the name property. - * - * @return possible object is {@link String } - * - */ - public String getName() { - return name; - } - - /** - * Sets the value of the name property. - * - * @param value - * allowed object is {@link String } - * - */ - public void setName(String value) { - this.name = value; - } - - /** - * Gets the value of the street property. - * - * @return possible object is {@link String } - * - */ - public String getStreet() { - return street; - } - - /** - * Sets the value of the street property. - * - * @param value - * allowed object is {@link String } - * - */ - public void setStreet(String value) { - this.street = value; - } - - /** - * Gets the value of the city property. - * - * @return possible object is {@link String } - * - */ - public String getCity() { - return city; - } - - /** - * Sets the value of the city property. - * - * @param value - * allowed object is {@link String } - * - */ - public void setCity(String value) { - this.city = value; - } - - /** - * Gets the value of the state property. - * - * @return possible object is {@link String } - * - */ - public String getState() { - return state; - } - - /** - * Sets the value of the state property. - * - * @param value - * allowed object is {@link String } - * - */ - public void setState(String value) { - this.state = value; - } - - /** - * Gets the value of the zip property. - * - * @return possible object is {@link java.math.BigDecimal } - * - */ - public BigDecimal getZip() { - return zip; - } - - /** - * Sets the value of the zip property. - * - * @param value - * allowed object is {@link java.math.BigDecimal } - * - */ - public void setZip(BigDecimal value) { - this.zip = value; - } - - /** - * Gets the value of the country property. - * - * @return possible object is {@link String } - * - */ - public String getCountry() { - if (country == null) { - return "US"; - } else { - return country; - } - } - - /** - * Sets the value of the country property. - * - * @param value - * allowed object is {@link String } - * - */ - public void setCountry(String value) { - this.country = value; - } - -} diff --git a/components-starter/camel-xml-jaxb-starter/src/test/resources/org/apache/camel/xml/jaxb/springboot/jaxb.index b/components-starter/camel-xml-jaxb-starter/src/test/resources/org/apache/camel/xml/jaxb/springboot/jaxb.index deleted file mode 100644 index 31d2b53009d..00000000000 --- a/components-starter/camel-xml-jaxb-starter/src/test/resources/org/apache/camel/xml/jaxb/springboot/jaxb.index +++ /dev/null @@ -1 +0,0 @@ -BeanScope diff --git a/components-starter/pom.xml b/components-starter/pom.xml index 362c9cb5616..a07aa34c154 100644 --- a/components-starter/pom.xml +++ b/components-starter/pom.xml @@ -497,7 +497,6 @@ <module>camel-workday-starter</module> <module>camel-xchange-starter</module> <module>camel-xj-starter</module> - <module>camel-xml-jaxb-starter</module> <module>camel-xml-jaxp-starter</module> <module>camel-xmlsecurity-starter</module> <module>camel-xmpp-starter</module> diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java index 03592509fad..d904ddf8809 100644 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java @@ -48,7 +48,6 @@ import org.apache.camel.spi.StartupConditionStrategy; import org.apache.camel.spi.StartupStepRecorder; import org.apache.camel.spi.VariableRepository; import org.apache.camel.spi.VariableRepositoryFactory; -import org.apache.camel.spring.boot.aot.CamelRuntimeHints; import org.apache.camel.spring.spi.ApplicationContextBeanRepository; import org.apache.camel.spring.spi.CamelBeanPostProcessor; import org.apache.camel.support.DefaultRegistry; @@ -82,7 +81,6 @@ import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.Environment; import org.springframework.core.env.MutablePropertySources; -@ImportRuntimeHints(CamelRuntimeHints.class) @Configuration(proxyBeanMethods = false) @EnableConfigurationProperties({CamelConfigurationProperties.class, CamelStartupConditionConfigurationProperties.class, PropertiesComponentConfiguration.class}) @Import(TypeConversionConfiguration.class) diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/aot/CamelRuntimeHints.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/aot/CamelRuntimeHints.java deleted file mode 100644 index 96bcd61ab33..00000000000 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/aot/CamelRuntimeHints.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.spring.boot.aot; - -import static org.apache.camel.spring.boot.aot.RuntimeHintsHelper.registerClassHierarchy; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.StringReader; -import java.nio.charset.StandardCharsets; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.aot.hint.MemberCategory; -import org.springframework.aot.hint.RuntimeHints; -import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; - -/** - * {@code CamelRuntimeHints} provide the basic hints for the native compilation of a Camel application. - */ -public final class CamelRuntimeHints implements RuntimeHintsRegistrar { - - /** - * The logger. - */ - private static final Logger LOG = LoggerFactory.getLogger(CamelRuntimeHints.class); - - @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - // Give access to the catalog - hints.resources().registerPattern("org/apache/camel/main/*.properties"); - // Register all the camel services - registerCamelServices(hints, classLoader); - // Register collections - hints.reflection().registerType(java.util.List.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, - MemberCategory.INVOKE_PUBLIC_METHODS); - hints.reflection().registerType(java.util.Collection.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, - MemberCategory.INVOKE_PUBLIC_METHODS); - } - - /** - * Register all the Camel services that could be found in the given classloader. - * - * @param hints - * the hints contributed so far for the deployment unit - * @param classLoader - * the ClassLoader to load classpath resources with, or {@code null} for using the thread context class - * loader at the time of actual resource access - */ - private static void registerCamelServices(RuntimeHints hints, ClassLoader classLoader) { - hints.resources().registerPattern("META-INF/services/org/apache/camel/**"); - PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(classLoader); - try { - for (Resource resource : resolver.getResources("classpath*:META-INF/services/org/apache/camel/**")) { - String filename = resource.getFilename(); - if (filename == null || filename.isBlank() || filename.endsWith(".properties")) { - continue; - } - try (BufferedReader reader = new BufferedReader( - new StringReader(resource.getContentAsString(StandardCharsets.UTF_8)))) { - String line = reader.readLine(); - String prefixClass = "class="; - while (line != null) { - if (line.startsWith("#") || line.isBlank()) { - line = reader.readLine(); - continue; - } - String className = line.trim(); - if (line.startsWith(prefixClass)) { - className = line.substring(prefixClass.length()); - } - LOG.debug("Found the class {} to register", className); - registerClassHierarchy(hints, classLoader, className, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, - MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS, - MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.INTROSPECT_PUBLIC_METHODS); - line = reader.readLine(); - } - } - } - } catch (IOException e) { - LOG.debug("Could not load the Camel services: {}", e.getMessage()); - } - } -} diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/aot/ReflectionHelper.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/aot/ReflectionHelper.java deleted file mode 100644 index bd673b75683..00000000000 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/aot/ReflectionHelper.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.spring.boot.aot; - -import java.lang.annotation.Annotation; -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import java.lang.reflect.Constructor; -import java.lang.reflect.Parameter; -import java.util.Arrays; -import java.util.Collections; -import java.util.EnumMap; -import java.util.List; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; -import org.springframework.core.io.ByteArrayResource; -import org.springframework.core.io.Resource; -import org.springframework.core.io.ResourceLoader; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.type.AnnotationMetadata; -import org.springframework.core.type.ClassMetadata; -import org.springframework.core.type.classreading.MetadataReader; -import org.springframework.core.type.classreading.MetadataReaderFactory; -import org.springframework.core.type.filter.AnnotationTypeFilter; -import org.springframework.core.type.filter.TypeFilter; -import org.springframework.util.ClassUtils; -import org.springframework.util.ReflectionUtils; - -/** - * {@code ReflectionHelper} utility class providing methods needed for the native mode. - */ -public final class ReflectionHelper { - - /** - * The logger. - */ - private static final Logger LOG = LoggerFactory.getLogger(ReflectionHelper.class); - - private ReflectionHelper() { - - } - - /** - * Apply a specific action anytime the annotation is found in the class according to the type of target supported by - * the annotation which can be either {@link ElementType#TYPE}, {@link ElementType#CONSTRUCTOR}, - * {@link ElementType#METHOD}, {@link ElementType#FIELD}, or {@link ElementType#PARAMETER}. - * - * @param c - * the target class - * @param a - * the target type of annotation - * @param getter - * the method allowing to extract the excepted values from the annotation - * @param onMatch - * the action to perform in case of a match - * @param <A> - * the type of the target annotation - * @param <T> - * the type of the content extracted from the annotation found - */ - public static <A extends Annotation, T> void applyIfMatch(Class<?> c, Class<A> a, Function<A, T> getter, - Consumer<T> onMatch) { - Set<ElementType> targets = null; - if (a.isAnnotationPresent(Target.class)) { - targets = Collections.newSetFromMap(new EnumMap<>(ElementType.class)); - targets.addAll(Arrays.asList(a.getAnnotation(Target.class).value())); - } - if ((targets == null || targets.contains(ElementType.TYPE)) && c.isAnnotationPresent(a)) { - onMatch.accept(getter.apply(c.getAnnotation(a))); - } - boolean checkConstructors = targets == null || targets.contains(ElementType.CONSTRUCTOR); - boolean checkParameters = targets == null || targets.contains(ElementType.PARAMETER); - if (checkConstructors || checkParameters) { - for (Constructor<?> constructor : c.getDeclaredConstructors()) { - if (checkConstructors && constructor.isAnnotationPresent(a)) { - onMatch.accept(getter.apply(constructor.getAnnotation(a))); - } - if (checkParameters) { - for (Parameter parameter : constructor.getParameters()) { - if (parameter.isAnnotationPresent(a)) { - onMatch.accept(getter.apply(parameter.getAnnotation(a))); - } - } - } - } - } - if (targets == null || targets.contains(ElementType.FIELD)) { - ReflectionUtils.doWithFields(c, field -> onMatch.accept(getter.apply(field.getAnnotation(a))), - field -> field.isAnnotationPresent(a)); - } - boolean checkMethods = targets == null || targets.contains(ElementType.METHOD); - if (checkMethods || checkParameters) { - ReflectionUtils.doWithMethods(c, method -> { - if (checkMethods && method.isAnnotationPresent(a)) { - onMatch.accept(getter.apply(method.getAnnotation(a))); - } - if (checkParameters) { - for (Parameter parameter : method.getParameters()) { - if (parameter.isAnnotationPresent(a)) { - onMatch.accept(getter.apply(parameter.getAnnotation(a))); - } - } - } - }); - } - } - - /** - * Give all the classes available in the given class loader that are annotated with at least one of the annotations. - * - * @param classLoader - * the class loader from which the classes to find are loaded - * @param annotations - * the target annotations - * - * @return the list of classes that are annotated with at least one of the annotations. - */ - public static List<Class<?>> getClassesByAnnotations(ClassLoader classLoader, - List<Class<? extends Annotation>> annotations) { - return getClassesByFilters(classLoader, - annotations.stream().map(AnnotationTypeFilter::new).collect(Collectors.toList())); - } - - /** - * Give all the classes available in the given class loader that match with at least one of the filters. - * - * @param classLoader - * the class loader from which the classes to find are loaded - * @param includeFilters - * the filters to apply the classes found - * - * @return a list of classes that match with at least one of the given filters - */ - public static List<Class<?>> getClassesByFilters(ClassLoader classLoader, List<TypeFilter> includeFilters) { - ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false) { - @Override - protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { - return true; - } - }; - provider.setResourceLoader(new PathMatchingResourcePatternResolver(classLoader)); - provider.setMetadataReaderFactory(new SafeMetadataReaderFactory(provider.getMetadataReaderFactory())); - provider.addExcludeFilter((metadata, factory) -> { - String className = metadata.getClassMetadata().getClassName(); - return className.startsWith("org.springframework.") || className.startsWith("java.") - || className.startsWith("jakarta."); - }); - for (TypeFilter filter : includeFilters) { - provider.addIncludeFilter(filter); - } - return provider.findCandidateComponents("").stream().map(b -> asClass(b, classLoader)) - .collect(Collectors.toList()); - } - - /** - * Convert the given bean definition into a class. - * - * @param bean - * the bean definition to convert. - * @param classLoader - * the classloader from which the class of the bean is loaded - * - * @return the class corresponding to the bean definition if it could be found, {@code null} otherwise. - */ - private static Class<?> asClass(BeanDefinition bean, ClassLoader classLoader) { - String beanClassName = bean.getBeanClassName(); - if (beanClassName == null) { - LOG.debug("The name of the class corresponding to the bean '{}' could not be found", bean); - } else { - try { - return ClassUtils.forName(beanClassName, classLoader); - } catch (ClassNotFoundException | NoClassDefFoundError e) { - LOG.debug("The class corresponding to the bean '{}' could not be found: {}", bean, e.getMessage()); - } - } - return null; - } - - /** - * {@code SafeMetadataReaderFactory} is a specific {@link MetadataReaderFactory} whose methods never throw any - * exceptions, if an error occurs while calling the underlying {@link MetadataReaderFactory} a debug message is - * logged and the default result is returned. - */ - private static class SafeMetadataReaderFactory implements MetadataReaderFactory { - - /** - * The instance of the default result in case of an error. - */ - private static final MetadataReader DEFAULT = new MetadataReader() { - @Override - public Resource getResource() { - return new ByteArrayResource(new byte[0]); - } - - @Override - public ClassMetadata getClassMetadata() { - return AnnotationMetadata.introspect(Object.class); - } - - @Override - public AnnotationMetadata getAnnotationMetadata() { - return AnnotationMetadata.introspect(Object.class); - } - }; - private final MetadataReaderFactory delegate; - - SafeMetadataReaderFactory(MetadataReaderFactory delegate) { - this.delegate = delegate; - } - - @Override - public MetadataReader getMetadataReader(String className) { - try { - return delegate.getMetadataReader(className); - } catch (Exception | NoClassDefFoundError e) { - LOG.debug("Could not get the metadata of the class {}", className); - } - return DEFAULT; - } - - @Override - public MetadataReader getMetadataReader(Resource resource) { - try { - return delegate.getMetadataReader(resource); - } catch (Exception | NoClassDefFoundError e) { - LOG.debug("Could not get the metadata of the resource {}", resource); - } - return DEFAULT; - } - - @Override - public ResourceLoader getResourceLoader() { - return delegate.getResourceLoader(); - } - } -} diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/aot/RuntimeHintsHelper.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/aot/RuntimeHintsHelper.java deleted file mode 100644 index 444eff3bcbf..00000000000 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/aot/RuntimeHintsHelper.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.spring.boot.aot; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.aot.hint.MemberCategory; -import org.springframework.aot.hint.RuntimeHints; -import org.springframework.util.ClassUtils; - -public final class RuntimeHintsHelper { - - /** - * The logger. - */ - private static final Logger LOG = LoggerFactory.getLogger(RuntimeHintsHelper.class); - - private RuntimeHintsHelper() { - } - - /** - * Register the given class and all its parent classes by applying the given member categories. - * - * @param hints - * the hints contributed so far for the deployment unit - * @param classLoader - * the ClassLoader to load classpath resources with, or {@code null} for using the thread context class - * loader at the time of actual resource access - * @param className - * the name of the class to register - * @param memberCategories - * the member categories to apply - */ - public static void registerClassHierarchy(RuntimeHints hints, ClassLoader classLoader, String className, - MemberCategory... memberCategories) { - try { - registerClassHierarchy(hints, ClassUtils.forName(className, classLoader), memberCategories); - } catch (ClassNotFoundException | NoClassDefFoundError e) { - LOG.debug("The class {} cannot be found", className); - } - } - - /** - * Register the given class and all its parent classes by applying the given member categories. - * - * @param hints - * the hints contributed so far for the deployment unit - * @param clazz - * the class to register - * @param memberCategories - * the member categories to apply - */ - public static void registerClassHierarchy(RuntimeHints hints, Class<?> clazz, MemberCategory... memberCategories) { - if (clazz.isInterface() || clazz.isArray()) { - return; - } - while (clazz != Object.class) { - hints.reflection().registerType(clazz, memberCategories); - clazz = clazz.getSuperclass(); - } - } -} diff --git a/core/camel-spring-boot/src/main/resources/META-INF/native-image/org.apache.camel.springboot/camel-spring-boot/native-image.properties b/core/camel-spring-boot/src/main/resources/META-INF/native-image/org.apache.camel.springboot/camel-spring-boot/native-image.properties deleted file mode 100644 index 88e8e90e1a3..00000000000 --- a/core/camel-spring-boot/src/main/resources/META-INF/native-image/org.apache.camel.springboot/camel-spring-boot/native-image.properties +++ /dev/null @@ -1,17 +0,0 @@ -## --------------------------------------------------------------------------- -## Licensed to the Apache Software Foundation (ASF) under one or more -## contributor license agreements. See the NOTICE file distributed with -## this work for additional information regarding copyright ownership. -## The ASF licenses this file to You under the Apache License, Version 2.0 -## (the "License"); you may not use this file except in compliance with -## the License. You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## --------------------------------------------------------------------------- -Args = -H:+AddAllCharsets diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/aot/CamelRuntimeHintsTest.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/aot/CamelRuntimeHintsTest.java deleted file mode 100644 index c74403ab5c6..00000000000 --- a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/aot/CamelRuntimeHintsTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.spring.boot.aot; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.camel.CamelContext; -import org.apache.camel.language.simple.SimpleLanguage; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.aot.hint.RuntimeHints; -import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; - -/** - * Unit tests for {@link CamelRuntimeHints}. - */ -class CamelRuntimeHintsTest { - - private final RuntimeHints hints = new RuntimeHints(); - - @BeforeEach - void init() { - new CamelRuntimeHints().registerHints(hints, getClass().getClassLoader()); - } - - @Test - void shouldRegisterHintsForCamelServices() throws Exception { - assertThat(RuntimeHintsPredicates.resource().forResource("META-INF/services/org/apache/camel/language/simple")) - .accepts(hints); - assertThat(RuntimeHintsPredicates.reflection().onConstructor(SimpleLanguage.class.getConstructor())) - .accepts(hints); - assertThat(RuntimeHintsPredicates.reflection().onMethod(SimpleLanguage.class.getMethod("init"))).accepts(hints); - assertThat(RuntimeHintsPredicates.reflection() - .onMethod(SimpleLanguage.class.getMethod("setCamelContext", CamelContext.class))).accepts(hints); - } - - @Test - void shouldRegisterHintsForCamelCatalog() { - assertThat(RuntimeHintsPredicates.resource().forResource("org/apache/camel/main/components.properties")) - .accepts(hints); - } -} diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/aot/ReflectionHelperTest.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/aot/ReflectionHelperTest.java deleted file mode 100644 index 21b69553577..00000000000 --- a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/aot/ReflectionHelperTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.spring.boot.aot; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.util.concurrent.atomic.AtomicInteger; -import org.junit.jupiter.api.Test; - -/** - * Unit tests for {@link ReflectionHelperTest}. - */ -class ReflectionHelperTest { - - private final AtomicInteger counter = new AtomicInteger(); - - @Test - void shouldAlwaysApply() { - ReflectionHelper.applyIfMatch(Foo.class, All.class, a -> null, x -> counter.incrementAndGet()); - assertThat(counter.get()).isEqualTo(11); - } - - @Test - void shouldNeverApply() { - ReflectionHelper.applyIfMatch(Foo.class, None.class, a -> null, x -> counter.incrementAndGet()); - assertThat(counter.get()).isZero(); - } - - @Test - void shouldApplyToClassOnly() { - ReflectionHelper.applyIfMatch(Foo.class, OnlyType.class, a -> null, x -> counter.incrementAndGet()); - assertThat(counter.get()).isEqualTo(1); - } - - @Test - void shouldApplyToOneSpecificConstructor() { - ReflectionHelper.applyIfMatch(Foo.class, OnlyConstructor.class, a -> null, x -> counter.incrementAndGet()); - assertThat(counter.get()).isEqualTo(1); - } - - @Test - void shouldApplyToOneSpecificField() { - ReflectionHelper.applyIfMatch(Foo.class, OnlyField.class, a -> null, x -> counter.incrementAndGet()); - assertThat(counter.get()).isEqualTo(1); - } - - @Test - void shouldApplyToOneSpecificMethod() { - ReflectionHelper.applyIfMatch(Foo.class, OnlyMethod.class, a -> null, x -> counter.incrementAndGet()); - assertThat(counter.get()).isEqualTo(1); - } - - @Test - void shouldApplyToSpecificParameters() { - ReflectionHelper.applyIfMatch(Foo.class, OnlyParameter.class, a -> null, x -> counter.incrementAndGet()); - assertThat(counter.get()).isEqualTo(2); - } - - @OnlyType - @All - public static class Foo { - - @All - private String someField1; - @OnlyField - @All - private String someField2; - - @All - private Foo() { - } - - @OnlyConstructor - @All - private Foo(@OnlyParameter @All String someParam1, @All String someParam2) { - } - - @All - private void someMethod1(@All String someParam1, @All @OnlyParameter String someParam2) { - } - - @OnlyMethod - @All - private void someMethod2() { - } - } - - @Retention(RetentionPolicy.RUNTIME) - public @interface All { - - } - - @Retention(RetentionPolicy.RUNTIME) - public @interface None { - - } - - @Target(ElementType.TYPE) - @Retention(RetentionPolicy.RUNTIME) - public @interface OnlyType { - - } - - @Target(ElementType.FIELD) - @Retention(RetentionPolicy.RUNTIME) - public @interface OnlyField { - - } - - @Target(ElementType.CONSTRUCTOR) - @Retention(RetentionPolicy.RUNTIME) - public @interface OnlyConstructor { - - } - - @Target(ElementType.METHOD) - @Retention(RetentionPolicy.RUNTIME) - public @interface OnlyMethod { - - } - - @Target(ElementType.PARAMETER) - @Retention(RetentionPolicy.RUNTIME) - public @interface OnlyParameter { - - } -} diff --git a/dsl-starter/camel-java-joor-dsl-starter/src/main/docs/java-joor-dsl.json b/dsl-starter/camel-java-joor-dsl-starter/src/main/docs/java-joor-dsl.json index 938fe319b6b..309073cd317 100644 --- a/dsl-starter/camel-java-joor-dsl-starter/src/main/docs/java-joor-dsl.json +++ b/dsl-starter/camel-java-joor-dsl-starter/src/main/docs/java-joor-dsl.json @@ -10,6 +10,6 @@ "supportLevel": "Stable", "groupId": "org.apache.camel", "artifactId": "camel-java-joor-dsl", - "version": "4.7.0-SNAPSHOT" + "version": "4.19.0-SNAPSHOT" } } diff --git a/dsl-starter/camel-xml-io-dsl-starter/src/main/docs/xml-io-dsl.json b/dsl-starter/camel-xml-io-dsl-starter/src/main/docs/xml-io-dsl.json index a37e41ceecf..a83b81de8d2 100644 --- a/dsl-starter/camel-xml-io-dsl-starter/src/main/docs/xml-io-dsl.json +++ b/dsl-starter/camel-xml-io-dsl-starter/src/main/docs/xml-io-dsl.json @@ -10,6 +10,6 @@ "supportLevel": "Stable", "groupId": "org.apache.camel", "artifactId": "camel-xml-io-dsl", - "version": "4.7.0-SNAPSHOT" + "version": "4.19.0-SNAPSHOT" } } diff --git a/dsl-starter/camel-xml-jaxb-dsl-starter/pom.xml b/dsl-starter/camel-xml-jaxb-dsl-starter/pom.xml index dd7eda4ac65..174b35525dd 100644 --- a/dsl-starter/camel-xml-jaxb-dsl-starter/pom.xml +++ b/dsl-starter/camel-xml-jaxb-dsl-starter/pom.xml @@ -39,20 +39,10 @@ <artifactId>spring-boot-starter</artifactId> <version>${spring-boot-version}</version> </dependency> - <dependency> - <groupId>org.apache.camel.springboot</groupId> - <artifactId>camel-spring-boot-xml-starter</artifactId> - <version>${project.version}</version> - </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-xml-jaxb-dsl</artifactId> <version>${camel-version}</version> </dependency> - <dependency> - <groupId>org.apache.camel.springboot</groupId> - <artifactId>camel-xml-jaxb-starter</artifactId> - <version>${project.version}</version> - </dependency> </dependencies> </project> \ No newline at end of file diff --git a/dsl-starter/camel-xml-jaxb-dsl-starter/src/main/docs/xml-jaxb-dsl.json b/dsl-starter/camel-xml-jaxb-dsl-starter/src/main/docs/xml-jaxb-dsl.json index 1d0a33b8006..ce6d20477e2 100644 --- a/dsl-starter/camel-xml-jaxb-dsl-starter/src/main/docs/xml-jaxb-dsl.json +++ b/dsl-starter/camel-xml-jaxb-dsl-starter/src/main/docs/xml-jaxb-dsl.json @@ -10,6 +10,6 @@ "supportLevel": "Stable", "groupId": "org.apache.camel", "artifactId": "camel-xml-jaxb-dsl", - "version": "4.7.0-SNAPSHOT" + "version": "4.19.0-SNAPSHOT" } } diff --git a/dsl-starter/camel-xml-jaxb-dsl-starter/src/main/java/org/apache/camel/dsl/xml/jaxb/springboot/aot/XMLDSLRuntimeHints.java b/dsl-starter/camel-xml-jaxb-dsl-starter/src/main/java/org/apache/camel/dsl/xml/jaxb/springboot/aot/XMLDSLRuntimeHints.java deleted file mode 100644 index 2cfac6ab430..00000000000 --- a/dsl-starter/camel-xml-jaxb-dsl-starter/src/main/java/org/apache/camel/dsl/xml/jaxb/springboot/aot/XMLDSLRuntimeHints.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.dsl.xml.jaxb.springboot.aot; - -import java.util.ArrayList; - -import org.springframework.aot.hint.MemberCategory; -import org.springframework.aot.hint.RuntimeHints; -import org.springframework.aot.hint.RuntimeHintsRegistrar; - -public final class XMLDSLRuntimeHints implements RuntimeHintsRegistrar { - @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - hints.reflection().registerType(ArrayList.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); - } -} diff --git a/dsl-starter/camel-xml-jaxb-dsl-starter/src/main/resources/META-INF/spring/aot.factories b/dsl-starter/camel-xml-jaxb-dsl-starter/src/main/resources/META-INF/spring/aot.factories deleted file mode 100644 index ec6037e214e..00000000000 --- a/dsl-starter/camel-xml-jaxb-dsl-starter/src/main/resources/META-INF/spring/aot.factories +++ /dev/null @@ -1,18 +0,0 @@ -## --------------------------------------------------------------------------- -## Licensed to the Apache Software Foundation (ASF) under one or more -## contributor license agreements. See the NOTICE file distributed with -## this work for additional information regarding copyright ownership. -## The ASF licenses this file to You under the Apache License, Version 2.0 -## (the "License"); you may not use this file except in compliance with -## the License. You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## --------------------------------------------------------------------------- -org.springframework.aot.hint.RuntimeHintsRegistrar=\ -org.apache.camel.dsl.xml.jaxb.springboot.aot.XMLDSLRuntimeHints diff --git a/dsl-starter/camel-yaml-dsl-starter/src/main/docs/yaml-io-dsl.json b/dsl-starter/camel-yaml-dsl-starter/src/main/docs/yaml-io-dsl.json new file mode 100644 index 00000000000..806cf26c0e2 --- /dev/null +++ b/dsl-starter/camel-yaml-dsl-starter/src/main/docs/yaml-io-dsl.json @@ -0,0 +1,15 @@ +{ + "other": { + "kind": "other", + "name": "yaml-io-dsl", + "title": "YAML DSL", + "description": "Camel YAML DSL with camel-yaml-io", + "deprecated": false, + "firstVersion": "4.0.0", + "label": "dsl", + "supportLevel": "Stable", + "groupId": "org.apache.camel", + "artifactId": "camel-yaml-io-dsl", + "version": "4.19.0-SNAPSHOT" + } +} diff --git a/pom.xml b/pom.xml index 2edb23ba72a..b3e88d2a43e 100644 --- a/pom.xml +++ b/pom.xml @@ -119,7 +119,6 @@ <!-- versions --> <avro-version>1.12.0</avro-version> - <graal-sdk-version>25.0.2</graal-sdk-version> <jakarta-jaxb-version>4.0.5</jakarta-jaxb-version> <jaxb-version>2.3.0</jaxb-version> <license-maven-plugin-version>5.0.0</license-maven-plugin-version>
