This commit is contained in:
Stéphane Nicoll 2023-11-03 12:10:01 +01:00
parent 30e4a0a300
commit 24aa6163f0
8 changed files with 18 additions and 15 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,7 +17,6 @@
package org.springframework.aot.generate; package org.springframework.aot.generate;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -42,7 +41,7 @@ class AppendableConsumerInputStreamSource implements InputStreamSource {
@Override @Override
public InputStream getInputStream() throws IOException { public InputStream getInputStream() {
return new ByteArrayInputStream(toString().getBytes(StandardCharsets.UTF_8)); return new ByteArrayInputStream(toString().getBytes(StandardCharsets.UTF_8));
} }

View File

@ -187,7 +187,7 @@ public class BindingReflectionHintsRegistrar {
.from(element, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY) .from(element, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY)
.stream(JACKSON_ANNOTATION) .stream(JACKSON_ANNOTATION)
.filter(MergedAnnotation::isMetaPresent) .filter(MergedAnnotation::isMetaPresent)
.forEach(action::accept); .forEach(action);
} }
private void registerHintsForClassAttributes(ReflectionHints hints, MergedAnnotation<Annotation> annotation) { private void registerHintsForClassAttributes(ReflectionHints hints, MergedAnnotation<Annotation> annotation) {

View File

@ -124,6 +124,6 @@ public enum MemberCategory {
* reflection for inner classes but rather makes sure they are available * reflection for inner classes but rather makes sure they are available
* via a call to {@link Class#getDeclaredClasses}. * via a call to {@link Class#getDeclaredClasses}.
*/ */
DECLARED_CLASSES; DECLARED_CLASSES
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -143,7 +143,7 @@ public final class ResourcePatternHints {
* @param excludes the exclude patterns (see {@link ResourcePatternHint} documentation) * @param excludes the exclude patterns (see {@link ResourcePatternHint} documentation)
* @return {@code this}, to facilitate method chaining * @return {@code this}, to facilitate method chaining
*/ */
public Builder excludes(TypeReference reachableType, String... excludes) { public Builder excludes(@Nullable TypeReference reachableType, String... excludes) {
List<ResourcePatternHint> newExcludes = Arrays.stream(excludes) List<ResourcePatternHint> newExcludes = Arrays.stream(excludes)
.map(include -> new ResourcePatternHint(include, reachableType)).toList(); .map(include -> new ResourcePatternHint(include, reachableType)).toList();
this.excludes.addAll(newExcludes); this.excludes.addAll(newExcludes);

View File

@ -19,6 +19,7 @@ package org.springframework.aot.hint.support;
import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeReference; import org.springframework.aot.hint.TypeReference;
import org.springframework.lang.Nullable;
/** /**
* {@link RuntimeHintsRegistrar} to register hints for {@link org.springframework.core.KotlinDetector}. * {@link RuntimeHintsRegistrar} to register hints for {@link org.springframework.core.KotlinDetector}.
@ -29,7 +30,7 @@ import org.springframework.aot.hint.TypeReference;
class KotlinDetectorRuntimeHints implements RuntimeHintsRegistrar { class KotlinDetectorRuntimeHints implements RuntimeHintsRegistrar {
@Override @Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
hints.reflection().registerType(TypeReference.of("kotlin.Metadata")) hints.reflection().registerType(TypeReference.of("kotlin.Metadata"))
.registerType(TypeReference.of("kotlin.reflect.full.KClasses")); .registerType(TypeReference.of("kotlin.reflect.full.KClasses"));
} }

View File

@ -20,6 +20,7 @@ import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeReference; import org.springframework.aot.hint.TypeReference;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.lang.Nullable;
/** /**
* {@link RuntimeHintsRegistrar} for {@link PathMatchingResourcePatternResolver}. * {@link RuntimeHintsRegistrar} for {@link PathMatchingResourcePatternResolver}.
@ -28,7 +29,7 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
class PathMatchingResourcePatternResolverRuntimeHints implements RuntimeHintsRegistrar { class PathMatchingResourcePatternResolverRuntimeHints implements RuntimeHintsRegistrar {
@Override @Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
hints.reflection().registerType(TypeReference.of("org.eclipse.core.runtime.FileLocator")); hints.reflection().registerType(TypeReference.of("org.eclipse.core.runtime.FileLocator"));
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -47,9 +47,11 @@ class SpringFactoriesLoaderRuntimeHints implements RuntimeHintsRegistrar {
@Override @Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
ClassLoader classLoaderToUse = (classLoader != null ? classLoader
: SpringFactoriesLoaderRuntimeHints.class.getClassLoader());
for (String resourceLocation : RESOURCE_LOCATIONS) { for (String resourceLocation : RESOURCE_LOCATIONS) {
registerHints(hints, classLoader, resourceLocation); registerHints(hints, classLoaderToUse, resourceLocation);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -60,8 +60,8 @@ class ResourceHintsWriter {
return attributes; return attributes;
} }
private void handleResourceBundles(Map<String, Object> attributes, Stream<ResourceBundleHint> ressourceBundles) { private void handleResourceBundles(Map<String, Object> attributes, Stream<ResourceBundleHint> resourceBundles) {
addIfNotEmpty(attributes, "bundles", ressourceBundles.map(this::toAttributes).toList()); addIfNotEmpty(attributes, "bundles", resourceBundles.map(this::toAttributes).toList());
} }
private Map<String, Object> toAttributes(ResourceBundleHint hint) { private Map<String, Object> toAttributes(ResourceBundleHint hint) {