Polishing
This commit is contained in:
@@ -430,6 +430,10 @@ public class ReflectUtils {
|
||||
}
|
||||
|
||||
// SPRING PATCH BEGIN
|
||||
public static void setGeneratedClassHandler(BiConsumer<String, byte[]> handler) {
|
||||
generatedClassHandler = handler;
|
||||
}
|
||||
|
||||
public static Class defineClass(String className, byte[] b, ClassLoader loader) throws Exception {
|
||||
return defineClass(className, b, loader, null, null);
|
||||
}
|
||||
@@ -440,10 +444,6 @@ public class ReflectUtils {
|
||||
return defineClass(className, b, loader, protectionDomain, null);
|
||||
}
|
||||
|
||||
public static void setGeneratedClassHandler(BiConsumer<String, byte[]> handler) {
|
||||
generatedClassHandler = handler;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"deprecation", "serial"})
|
||||
public static Class defineClass(String className, byte[] b, ClassLoader loader,
|
||||
ProtectionDomain protectionDomain, Class<?> contextClass) throws Exception {
|
||||
|
||||
@@ -97,10 +97,6 @@ public class SpringFactoriesLoader {
|
||||
*/
|
||||
public static final String FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories";
|
||||
|
||||
private static final ArgumentResolver NO_ARGUMENT_RESOLVER = null;
|
||||
|
||||
private static final FailureHandler NO_FAILURE_HANDLER = null;
|
||||
|
||||
private static final FailureHandler THROWING_FAILURE_HANDLER = FailureHandler.throwing();
|
||||
|
||||
private static final Log logger = LogFactory.getLog(SpringFactoriesLoader.class);
|
||||
@@ -143,7 +139,7 @@ public class SpringFactoriesLoader {
|
||||
* @since 6.0
|
||||
*/
|
||||
public <T> List<T> load(Class<T> factoryType) {
|
||||
return load(factoryType, NO_ARGUMENT_RESOLVER, NO_FAILURE_HANDLER);
|
||||
return load(factoryType, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +157,7 @@ public class SpringFactoriesLoader {
|
||||
* @since 6.0
|
||||
*/
|
||||
public <T> List<T> load(Class<T> factoryType, @Nullable ArgumentResolver argumentResolver) {
|
||||
return load(factoryType, argumentResolver, NO_FAILURE_HANDLER);
|
||||
return load(factoryType, argumentResolver, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,7 +175,7 @@ public class SpringFactoriesLoader {
|
||||
* @since 6.0
|
||||
*/
|
||||
public <T> List<T> load(Class<T> factoryType, @Nullable FailureHandler failureHandler) {
|
||||
return load(factoryType, NO_ARGUMENT_RESOLVER, failureHandler);
|
||||
return load(factoryType, null, failureHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,7 +194,9 @@ public class SpringFactoriesLoader {
|
||||
* @param failureHandler strategy used to handle factory instantiation failures
|
||||
* @since 6.0
|
||||
*/
|
||||
public <T> List<T> load(Class<T> factoryType, @Nullable ArgumentResolver argumentResolver, @Nullable FailureHandler failureHandler) {
|
||||
public <T> List<T> load(Class<T> factoryType, @Nullable ArgumentResolver argumentResolver,
|
||||
@Nullable FailureHandler failureHandler) {
|
||||
|
||||
Assert.notNull(factoryType, "'factoryType' must not be null");
|
||||
List<String> implementationNames = loadFactoryNames(factoryType);
|
||||
logger.trace(LogMessage.format("Loaded [%s] names: %s", factoryType.getName(), implementationNames));
|
||||
@@ -224,8 +222,8 @@ public class SpringFactoriesLoader {
|
||||
|
||||
try {
|
||||
Class<?> factoryImplementationClass = ClassUtils.forName(implementationName, this.classLoader);
|
||||
Assert.isTrue(type.isAssignableFrom(factoryImplementationClass),
|
||||
() -> "Class [%s] is not assignable to factory type [%s]".formatted(implementationName, type.getName()));
|
||||
Assert.isTrue(type.isAssignableFrom(factoryImplementationClass), () ->
|
||||
"Class [%s] is not assignable to factory type [%s]".formatted(implementationName, type.getName()));
|
||||
FactoryInstantiator<T> factoryInstantiator = FactoryInstantiator.forClass(factoryImplementationClass);
|
||||
return factoryInstantiator.instantiate(argumentResolver);
|
||||
}
|
||||
@@ -303,8 +301,8 @@ public class SpringFactoriesLoader {
|
||||
|
||||
/**
|
||||
* Create a {@link SpringFactoriesLoader} instance that will load and
|
||||
* instantiate the factory implementations from the given location, using
|
||||
* the default class loader.
|
||||
* instantiate the factory implementations from the given location,
|
||||
* using the default class loader.
|
||||
* @param resourceLocation the resource location to look for factories
|
||||
* @return a {@link SpringFactoriesLoader} instance
|
||||
* @since 6.0
|
||||
@@ -316,11 +314,11 @@ public class SpringFactoriesLoader {
|
||||
|
||||
/**
|
||||
* Create a {@link SpringFactoriesLoader} instance that will load and
|
||||
* instantiate the factory implementations from the given location, using
|
||||
* the given class loader.
|
||||
* instantiate the factory implementations from the given location,
|
||||
* using the given class loader.
|
||||
* @param resourceLocation the resource location to look for factories
|
||||
* @param classLoader the ClassLoader to use for loading resources; can be
|
||||
* {@code null} to use the default
|
||||
* @param classLoader the ClassLoader to use for loading resources;
|
||||
* can be {@code null} to use the default
|
||||
* @return a {@link SpringFactoriesLoader} instance
|
||||
* @since 6.0
|
||||
* @see #forResourceLocation(String)
|
||||
@@ -329,7 +327,7 @@ public class SpringFactoriesLoader {
|
||||
Assert.hasText(resourceLocation, "'resourceLocation' must not be empty");
|
||||
ClassLoader resourceClassLoader = (classLoader != null ? classLoader :
|
||||
SpringFactoriesLoader.class.getClassLoader());
|
||||
Map<String, SpringFactoriesLoader> loaders = SpringFactoriesLoader.cache.computeIfAbsent(
|
||||
Map<String, SpringFactoriesLoader> loaders = cache.computeIfAbsent(
|
||||
resourceClassLoader, key -> new ConcurrentReferenceHashMap<>());
|
||||
return loaders.computeIfAbsent(resourceLocation, key ->
|
||||
new SpringFactoriesLoader(classLoader, loadFactoriesResource(resourceClassLoader, resourceLocation)));
|
||||
@@ -345,7 +343,7 @@ public class SpringFactoriesLoader {
|
||||
properties.forEach((name, value) -> {
|
||||
List<String> implementations = result.computeIfAbsent(((String) name).trim(), key -> new ArrayList<>());
|
||||
Arrays.stream(StringUtils.commaDelimitedListToStringArray((String) value))
|
||||
.map(String::trim).forEach(implementations::add);
|
||||
.map(String::trim).forEach(implementations::add);
|
||||
});
|
||||
}
|
||||
result.replaceAll(SpringFactoriesLoader::toDistinctUnmodifiableList);
|
||||
@@ -370,13 +368,11 @@ public class SpringFactoriesLoader {
|
||||
|
||||
private final Constructor<T> constructor;
|
||||
|
||||
|
||||
private FactoryInstantiator(Constructor<T> constructor) {
|
||||
ReflectionUtils.makeAccessible(constructor);
|
||||
this.constructor = constructor;
|
||||
}
|
||||
|
||||
|
||||
T instantiate(@Nullable ArgumentResolver argumentResolver) throws Exception {
|
||||
Object[] args = resolveArgs(argumentResolver);
|
||||
if (isKotlinType(this.constructor.getDeclaringClass())) {
|
||||
@@ -437,7 +433,6 @@ public class SpringFactoriesLoader {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -497,7 +492,6 @@ public class SpringFactoriesLoader {
|
||||
private static <T> T instantiate(KFunction<T> kotlinConstructor, Map<KParameter, Object> args) {
|
||||
return kotlinConstructor.callBy(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -609,7 +603,6 @@ public class SpringFactoriesLoader {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -681,7 +674,6 @@ public class SpringFactoriesLoader {
|
||||
messageHandler.accept(messageSupplier, failure);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,9 +47,9 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
class PathMatchingResourcePatternResolverTests {
|
||||
|
||||
private static final String[] CLASSES_IN_CORE_IO_SUPPORT = { "EncodedResource.class",
|
||||
"LocalizedResourceHelper.class", "PathMatchingResourcePatternResolver.class", "PropertiesLoaderSupport.class",
|
||||
"PropertiesLoaderUtils.class", "ResourceArrayPropertyEditor.class", "ResourcePatternResolver.class",
|
||||
"ResourcePatternUtils.class", "SpringFactoriesLoader.class" };
|
||||
"LocalizedResourceHelper.class", "PathMatchingResourcePatternResolver.class", "PropertiesLoaderSupport.class",
|
||||
"PropertiesLoaderUtils.class", "ResourceArrayPropertyEditor.class", "ResourcePatternResolver.class",
|
||||
"ResourcePatternUtils.class", "SpringFactoriesLoader.class" };
|
||||
|
||||
private static final String[] TEST_CLASSES_IN_CORE_IO_SUPPORT = { "PathMatchingResourcePatternResolverTests.class" };
|
||||
|
||||
@@ -99,7 +99,7 @@ class PathMatchingResourcePatternResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void usingFilePrototol() {
|
||||
void usingFileProtocol() {
|
||||
Path testResourcesDir = Path.of("src/test/resources").toAbsolutePath();
|
||||
String pattern = "file:%s/scanned-resources/**".formatted(testResourcesDir);
|
||||
String pathPrefix = ".+scanned-resources/";
|
||||
@@ -107,9 +107,7 @@ class PathMatchingResourcePatternResolverTests {
|
||||
assertExactFilenames(pattern, "resource#test1.txt", "resource#test2.txt");
|
||||
assertExactSubPaths(pattern, pathPrefix, "resource#test1.txt", "resource#test2.txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +145,6 @@ class PathMatchingResourcePatternResolverTests {
|
||||
.as("Could not find aspectj_1_5_0.dtd in the root of the aspectjweaver jar")
|
||||
.containsExactly("aspectj_1_5_0.dtd");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user