Fix package tangle between o.s.core and o.s.aot

Closes gh-28496
This commit is contained in:
Stephane Nicoll
2022-06-08 11:50:17 +02:00
parent 875ee546e5
commit 16eff68357
6 changed files with 30 additions and 11 deletions

View File

@@ -14,13 +14,14 @@
* limitations under the License.
*/
package org.springframework.core.annotation;
package org.springframework.aot.hint.support;
import java.util.stream.Stream;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.support.RuntimeHintsUtils;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.annotation.Order;
import org.springframework.lang.Nullable;
/**

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.core.io.support;
package org.springframework.aot.hint.support;
import java.util.List;
import java.util.Map;
@@ -27,6 +27,7 @@ import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeHint;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.core.log.LogMessage;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
@@ -41,13 +42,13 @@ import org.springframework.util.ClassUtils;
*/
class SpringFactoriesLoaderRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
private static List<String> RESOURCE_LOCATIONS =
private static final List<String> RESOURCE_LOCATIONS =
List.of(SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION);
private static final Consumer<TypeHint.Builder> HINT = builder ->
builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
private final Log logger = LogFactory.getLog(SpringFactoriesLoaderRuntimeHintsRegistrar.class);
private static final Log logger = LogFactory.getLog(SpringFactoriesLoaderRuntimeHintsRegistrar.class);
@Override
@@ -60,7 +61,7 @@ class SpringFactoriesLoaderRuntimeHintsRegistrar implements RuntimeHintsRegistra
private void registerHints(RuntimeHints hints, ClassLoader classLoader, String resourceLocation) {
hints.resources().registerPattern(resourceLocation);
Map<String, List<String>> factories =
SpringFactoriesLoader.loadFactoriesResource(classLoader, resourceLocation);
ExtendedSpringFactoriesLoader.accessLoadFactoriesResource(classLoader, resourceLocation);
factories.forEach((factoryClassName, implementationClassNames) ->
registerHints(hints, classLoader, factoryClassName, implementationClassNames));
}
@@ -104,4 +105,16 @@ class SpringFactoriesLoaderRuntimeHintsRegistrar implements RuntimeHintsRegistra
}
}
private static class ExtendedSpringFactoriesLoader extends SpringFactoriesLoader {
public ExtendedSpringFactoriesLoader(@Nullable ClassLoader classLoader, Map<String, List<String>> factories) {
super(classLoader, factories);
}
static Map<String, List<String>> accessLoadFactoriesResource(ClassLoader classLoader, String resourceLocation) {
return SpringFactoriesLoader.loadFactoriesResource(classLoader, resourceLocation);
}
}
}

View File

@@ -327,7 +327,7 @@ public class SpringFactoriesLoader {
new SpringFactoriesLoader(classLoader, loadFactoriesResource(resourceClassLoader, resourceLocation)));
}
static Map<String, List<String>> loadFactoriesResource(ClassLoader classLoader, String resourceLocation) {
protected static Map<String, List<String>> loadFactoriesResource(ClassLoader classLoader, String resourceLocation) {
Map<String, List<String>> result = new LinkedHashMap<>();
try {
Enumeration<URL> urls = classLoader.getResources(resourceLocation);

View File

@@ -1,3 +1,3 @@
org.springframework.aot.hint.RuntimeHintsRegistrar=\
org.springframework.core.annotation.CoreAnnotationsRuntimeHintsRegistrar,\
org.springframework.core.io.support.SpringFactoriesLoaderRuntimeHintsRegistrar
org.springframework.aot.hint.support.CoreAnnotationsRuntimeHintsRegistrar,\
org.springframework.aot.hint.support.SpringFactoriesLoaderRuntimeHintsRegistrar

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.core.annotation;
package org.springframework.aot.hint.support;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -23,6 +23,8 @@ 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.core.annotation.AliasFor;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.util.ClassUtils;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.core.io.support;
package org.springframework.aot.hint.support;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -25,6 +25,9 @@ import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeHint;
import org.springframework.aot.hint.TypeReference;
import org.springframework.core.io.support.DummyFactory;
import org.springframework.core.io.support.MyDummyFactory1;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.assertThat;