-
Notifications
You must be signed in to change notification settings - Fork 2k
add support for Spring Framework 6 AOT engine #2402
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ | |
<maven-plugin-version>1.0.0</maven-plugin-version> | ||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
||
<reflections.version>0.10.2</reflections.version> | ||
<javax.annotation.version>1.3.2</javax.annotation.version> | ||
<snakeyaml.version>1.33</snakeyaml.version> | ||
<slf4j.version>2.0.3</slf4j.version> | ||
|
@@ -89,6 +89,11 @@ | |
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.reflections</groupId> | ||
<artifactId>reflections</artifactId> | ||
<version>${reflections.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
|
@@ -482,49 +487,49 @@ | |
<include>src/test/groovy/**/*.groovy</include> | ||
</includes> | ||
|
||
<importOrder> <!-- or a custom ordering --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove these whitespace changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i believe this has now been addressed. |
||
<order>java,javax,org,com,com.diffplug, | ||
</order> <!-- or use <file>${basedir}/eclipse.importorder</file> --> | ||
</importOrder> | ||
<greclipse /> <!-- has its own section below --> | ||
<licenseHeader> | ||
<content> | ||
/* | ||
Copyright $YEAR The Kubernetes Authors. | ||
Licensed 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. | ||
*/ | ||
</content> | ||
</licenseHeader> | ||
</groovy> | ||
<licenseHeader> | ||
<content> | ||
/* | ||
Copyright $YEAR The Kubernetes Authors. | ||
Licensed 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. | ||
*/ | ||
</content> | ||
<delimiter>package </delimiter> | ||
</licenseHeader> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<importOrder> <!-- or a custom ordering --> | ||
<order>java,javax,org,com,com.diffplug, | ||
</order> <!-- or use <file>${basedir}/eclipse.importorder</file> --> | ||
</importOrder> | ||
<greclipse/> <!-- has its own section below --> | ||
<licenseHeader> | ||
<content> | ||
/* | ||
Copyright $YEAR The Kubernetes Authors. | ||
Licensed 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. | ||
*/ | ||
</content> | ||
</licenseHeader> | ||
</groovy> | ||
<licenseHeader> | ||
<content> | ||
/* | ||
Copyright $YEAR The Kubernetes Authors. | ||
Licensed 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. | ||
*/ | ||
</content> | ||
<delimiter>package</delimiter> | ||
</licenseHeader> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package io.kubernetes.client.spring.extended.controller.config.aot; | ||
|
||
|
||
import com.google.gson.annotations.JsonAdapter; | ||
import io.swagger.annotations.ApiModel; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.reflections.Reflections; | ||
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.TypeReference; | ||
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution; | ||
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor; | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
import org.springframework.boot.autoconfigure.AutoConfigurationPackages; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Registers hints to support Spring Framework 6 and Spring Boot 3 AOT | ||
*/ | ||
public class KubernetesBeanFactoryInitializationAotProcessor implements BeanFactoryInitializationAotProcessor { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(KubernetesBeanFactoryInitializationAotProcessor.class); | ||
|
||
private final MemberCategory[] allMemberCategories = MemberCategory.values(); | ||
|
||
@Override | ||
public BeanFactoryInitializationAotContribution processAheadOfTime( | ||
@NotNull ConfigurableListableBeanFactory beanFactory) { | ||
return (generationContext, beanFactoryInitializationCode) -> { | ||
RuntimeHints hints = generationContext.getRuntimeHints(); | ||
String[] classNames = new String[]{ | ||
"com.google.gson.JsonElement",// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why there are empty comments after each of these lines? |
||
"io.kubernetes.client.informer.cache.ProcessorListener", // | ||
"io.kubernetes.client.extended.controller.Controller", // | ||
"io.kubernetes.client.util.generic.GenericKubernetesApi$StatusPatch", // | ||
"io.kubernetes.client.util.Watch$Response" // | ||
}; | ||
for (String className : classNames) { | ||
LOGGER.info("registering " + className + " for reflection"); | ||
hints.reflection().registerType(TypeReference.of(className), allMemberCategories); | ||
} | ||
registerForPackage("io.kubernetes", hints); | ||
Collection<String> packages = AutoConfigurationPackages.get(beanFactory); | ||
for (String packageName : packages) { | ||
registerForPackage(packageName, hints); | ||
} | ||
}; | ||
} | ||
|
||
private void registerForPackage(String packageName, RuntimeHints hints) { | ||
Reflections reflections = new Reflections(packageName); | ||
Set<Class<?>> apiModels = reflections.getTypesAnnotatedWith(ApiModel.class); | ||
Set<Class<?>> jsonAdapters = findJsonAdapters(reflections); | ||
Set<Class<?>> all = new HashSet<>(); | ||
all.addAll(jsonAdapters); | ||
all.addAll(apiModels); | ||
for (Class<?> clazz : all) { | ||
LOGGER.info("registering " + clazz.getName() + " for reflection"); | ||
hints.reflection().registerType(clazz, allMemberCategories); | ||
} | ||
} | ||
|
||
private <R extends Annotation> Set<Class<?>> findJsonAdapters(Reflections reflections) { | ||
Class<JsonAdapter> jsonAdapterClass = JsonAdapter.class; | ||
Set<Class<?>> classes = new HashSet<>(); | ||
for (Class<?> clazz : reflections.getTypesAnnotatedWith(jsonAdapterClass)) { | ||
JsonAdapter annotation = clazz.getAnnotation(jsonAdapterClass); | ||
if (null != annotation) { | ||
classes.add(annotation.value()); | ||
} | ||
classes.add(clazz); | ||
} | ||
return classes; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor=io.kubernetes.client.spring.extended.controller.config.aot.KubernetesBeanFactoryInitializationAotProcessor |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
io.kubernetes.client.spring.extended.controller.config.KubernetesInformerAutoConfiguration | ||
io.kubernetes.client.spring.extended.controller.config.KubernetesReconcilerAutoConfiguration | ||
io.kubernetes.client.spring.extended.manifests.config.KubernetesManifestsAutoConfiguration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove these whitespace changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe this has now been addressed.