-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GraalVM Native Image support (#856)
Fixes #468, #673, #1021, #1040 --------- Co-authored-by: Maciej Walkowiak <walkowiak.maciej@yahoo.com>
- Loading branch information
1 parent
98a7863
commit a08ebc1
Showing
19 changed files
with
430 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...nfigure/src/main/java/io/awspring/cloud/autoconfigure/config/ConfigStoreRuntimeHints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2013-2023 the original author or 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 | ||
* | ||
* https://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 io.awspring.cloud.autoconfigure.config; | ||
|
||
import io.awspring.cloud.autoconfigure.config.parameterstore.ParameterStorePropertySources; | ||
import io.awspring.cloud.autoconfigure.config.secretsmanager.SecretsManagerPropertySources; | ||
import io.awspring.cloud.parameterstore.ParameterStorePropertySource; | ||
import io.awspring.cloud.secretsmanager.SecretsManagerPropertySource; | ||
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.util.ClassUtils; | ||
|
||
public class ConfigStoreRuntimeHints implements RuntimeHintsRegistrar { | ||
|
||
@Override | ||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { | ||
if (ClassUtils.isPresent("io.awspring.cloud.parameterstore.ParameterStorePropertySource", classLoader)) { | ||
hints.reflection().registerType(TypeReference.of(ParameterStorePropertySources.class), | ||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, | ||
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS)); | ||
hints.reflection().registerType(TypeReference.of(ParameterStorePropertySource.class), | ||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, | ||
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS)); | ||
} | ||
|
||
if (ClassUtils.isPresent("io.awspring.cloud.secretsmanager.SecretsManagerPropertySource", classLoader)) { | ||
hints.reflection().registerType(TypeReference.of(SecretsManagerPropertySources.class), | ||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, | ||
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS)); | ||
|
||
hints.reflection().registerType(TypeReference.of(SecretsManagerPropertySource.class), | ||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, | ||
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS)); | ||
} | ||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...g-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/core/CoreAOT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2013-2023 the original author or 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 | ||
* | ||
* https://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 io.awspring.cloud.autoconfigure.core; | ||
|
||
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.util.ClassUtils; | ||
|
||
public class CoreAOT implements RuntimeHintsRegistrar { | ||
|
||
private static final String STS_WEB_IDENTITY_TOKEN_FILE_CREDENTIALS_PROVIDER = "software.amazon.awssdk.services.sts.auth.StsWebIdentityTokenFileCredentialsProvider"; | ||
|
||
@Override | ||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { | ||
if (ClassUtils.isPresent(STS_WEB_IDENTITY_TOKEN_FILE_CREDENTIALS_PROVIDER, classLoader)) { | ||
hints.reflection().registerType(TypeReference.of(STS_WEB_IDENTITY_TOKEN_FILE_CREDENTIALS_PROVIDER), | ||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, | ||
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS)); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring/aot.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
org.springframework.aot.hint.RuntimeHintsRegistrar=\ | ||
io.awspring.cloud.autoconfigure.config.ConfigStoreRuntimeHints,\ | ||
io.awspring.cloud.autoconfigure.core.CoreAOT |
27 changes: 27 additions & 0 deletions
27
spring-cloud-aws-core/src/main/java/io/awspring/cloud/core/AWSCoreRuntimeHints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2013-2023 the original author or 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 | ||
* | ||
* https://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 io.awspring.cloud.core; | ||
|
||
import org.springframework.aot.hint.RuntimeHints; | ||
import org.springframework.aot.hint.RuntimeHintsRegistrar; | ||
|
||
public class AWSCoreRuntimeHints implements RuntimeHintsRegistrar { | ||
|
||
@Override | ||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { | ||
hints.resources().registerPattern("io/awspring/cloud/core/SpringCloudClientConfiguration.properties"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
spring-cloud-aws-core/src/main/resources/META-INF/spring/aot.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
org.springframework.aot.hint.RuntimeHintsRegistrar=\ | ||
io.awspring.cloud.core.AWSCoreRuntimeHints |
2 changes: 2 additions & 0 deletions
2
...-cloud-aws-s3-parent/spring-cloud-aws-s3/src/main/resources/META-INF/spring/aot.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
org.springframework.aot.hint.RuntimeHintsRegistrar=\ | ||
io.awspring.cloud.s3.S3RuntimeHints |
26 changes: 26 additions & 0 deletions
26
spring-cloud-aws-s3/src/main/java/io/awspring/cloud/s3/S3RuntimeHints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2013-2023 the original author or 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 | ||
* | ||
* https://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 io.awspring.cloud.s3; | ||
|
||
import org.springframework.aot.hint.RuntimeHints; | ||
import org.springframework.aot.hint.RuntimeHintsRegistrar; | ||
|
||
public class S3RuntimeHints implements RuntimeHintsRegistrar { | ||
@Override | ||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { | ||
hints.resources().registerPattern("io/awspring/cloud/s3/S3ObjectContentTypeResolver.properties"); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
spring-cloud-aws-sns/src/main/java/io/awspring/cloud/sns/SnsRuntimeHints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2013-2023 the original author or 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 | ||
* | ||
* https://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 io.awspring.cloud.sns; | ||
|
||
import io.awspring.cloud.sns.handlers.NotificationMessageHandlerMethodArgumentResolver; | ||
import io.awspring.cloud.sns.handlers.NotificationStatus; | ||
import io.awspring.cloud.sns.handlers.NotificationStatusHandlerMethodArgumentResolver; | ||
import io.awspring.cloud.sns.handlers.NotificationSubjectHandlerMethodArgumentResolver; | ||
import java.util.stream.Stream; | ||
import org.springframework.aot.hint.MemberCategory; | ||
import org.springframework.aot.hint.RuntimeHints; | ||
import org.springframework.aot.hint.RuntimeHintsRegistrar; | ||
import org.springframework.aot.hint.TypeReference; | ||
|
||
public class SnsRuntimeHints implements RuntimeHintsRegistrar { | ||
@Override | ||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { | ||
Stream.of(NotificationStatusHandlerMethodArgumentResolver.class, | ||
NotificationStatusHandlerMethodArgumentResolver.AmazonSnsNotificationStatus.class, | ||
NotificationMessageHandlerMethodArgumentResolver.class, | ||
NotificationMessageHandlerMethodArgumentResolver.ByteArrayHttpInputMessage.class, | ||
NotificationSubjectHandlerMethodArgumentResolver.class, NotificationStatus.class) | ||
.forEach(type -> hints.reflection().registerType(TypeReference.of(type), | ||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, | ||
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...va/io/awspring/cloud/sns/annotation/endpoint/SnsControllerMappingReflectiveProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2013-2023 the original author or 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 | ||
* | ||
* https://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 io.awspring.cloud.sns.annotation.endpoint; | ||
|
||
import java.lang.reflect.AnnotatedElement; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Parameter; | ||
import java.lang.reflect.Type; | ||
import org.springframework.aot.hint.BindingReflectionHintsRegistrar; | ||
import org.springframework.aot.hint.ExecutableMode; | ||
import org.springframework.aot.hint.ReflectionHints; | ||
import org.springframework.aot.hint.annotation.ReflectiveProcessor; | ||
import org.springframework.core.MethodParameter; | ||
|
||
/** | ||
* Heavily inspired by Spring Frameworks ControllerMappingReflectiveProcessor. | ||
* | ||
* @author Matej Nedic | ||
* @author Stephane Nicoll | ||
* @author Sebastien Deleuze | ||
* @since 3.0.2 | ||
*/ | ||
public class SnsControllerMappingReflectiveProcessor implements ReflectiveProcessor { | ||
private final BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar(); | ||
|
||
@Override | ||
public void registerReflectionHints(ReflectionHints hints, AnnotatedElement element) { | ||
if (element instanceof Class<?> type) { | ||
registerTypeHints(hints, type); | ||
} | ||
else if (element instanceof Method method) { | ||
registerMethodHints(hints, method); | ||
} | ||
} | ||
|
||
protected void registerTypeHints(ReflectionHints hints, Class<?> type) { | ||
hints.registerType(type); | ||
} | ||
|
||
protected void registerMethodHints(ReflectionHints hints, Method method) { | ||
hints.registerMethod(method, ExecutableMode.INVOKE); | ||
for (Parameter parameter : method.getParameters()) { | ||
registerParameterTypeHints(hints, MethodParameter.forParameter(parameter)); | ||
} | ||
registerReturnTypeHints(hints, MethodParameter.forExecutable(method, -1)); | ||
} | ||
|
||
protected void registerParameterTypeHints(ReflectionHints hints, MethodParameter methodParameter) { | ||
this.bindingRegistrar.registerReflectionHints(hints, methodParameter.getGenericParameterType()); | ||
} | ||
|
||
protected void registerReturnTypeHints(ReflectionHints hints, MethodParameter returnTypeParameter) { | ||
this.bindingRegistrar.registerReflectionHints(hints, getEntityType(returnTypeParameter)); | ||
} | ||
|
||
private Type getEntityType(MethodParameter parameter) { | ||
MethodParameter nestedParameter = parameter.nested(); | ||
return (nestedParameter.getNestedParameterType() == nestedParameter.getParameterType() ? null | ||
: nestedParameter.getNestedParameterType()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
spring-cloud-aws-sns/src/main/resources/META-INF/spring/aot.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
org.springframework.aot.hint.RuntimeHintsRegistrar=\ | ||
io.awspring.cloud.sns.SnsRuntimeHints |
Oops, something went wrong.