|
|
@ -17,11 +17,7 @@
|
|
|
|
package org.springframework.boot.autoconfigure.condition;
|
|
|
|
package org.springframework.boot.autoconfigure.condition;
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
import java.net.URLClassLoader;
|
|
|
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.ServiceLoader;
|
|
|
|
import java.util.ServiceLoader;
|
|
|
|
import java.util.function.Function;
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
|
|
|
@ -110,8 +106,7 @@ public class ConditionalOnJavaTests {
|
|
|
|
|
|
|
|
|
|
|
|
private String getJavaVersion(Class<?>... hiddenClasses) throws Exception {
|
|
|
|
private String getJavaVersion(Class<?>... hiddenClasses) throws Exception {
|
|
|
|
HideClassesClassLoader classLoader = new HideClassesClassLoader(hiddenClasses);
|
|
|
|
HideClassesClassLoader classLoader = new HideClassesClassLoader(hiddenClasses);
|
|
|
|
Class<?> javaVersionClass = classLoader
|
|
|
|
Class<?> javaVersionClass = classLoader.loadClass(JavaVersion.class.getName());
|
|
|
|
.loadClass(JavaVersion.class.getName());
|
|
|
|
|
|
|
|
Method getJavaVersionMethod = ReflectionUtils.findMethod(javaVersionClass,
|
|
|
|
Method getJavaVersionMethod = ReflectionUtils.findMethod(javaVersionClass,
|
|
|
|
"getJavaVersion");
|
|
|
|
"getJavaVersion");
|
|
|
|
Object javaVersion = ReflectionUtils.invokeMethod(getJavaVersionMethod, null);
|
|
|
|
Object javaVersion = ReflectionUtils.invokeMethod(getJavaVersionMethod, null);
|
|
|
@ -126,34 +121,6 @@ public class ConditionalOnJavaTests {
|
|
|
|
assertThat(outcome.isMatch()).as(outcome.getMessage()).isEqualTo(expected);
|
|
|
|
assertThat(outcome.isMatch()).as(outcome.getMessage()).isEqualTo(expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private final class ClassHidingClassLoader extends URLClassLoader {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final List<Class<?>> hiddenClasses;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ClassHidingClassLoader(URL[] urls, Class<?>... hiddenClasses) {
|
|
|
|
|
|
|
|
super(urls, null);
|
|
|
|
|
|
|
|
this.hiddenClasses = Arrays.asList(hiddenClasses);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Class<?> loadClass(String name) throws ClassNotFoundException {
|
|
|
|
|
|
|
|
if (isHidden(name)) {
|
|
|
|
|
|
|
|
throw new ClassNotFoundException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.loadClass(name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isHidden(String name) {
|
|
|
|
|
|
|
|
for (Class<?> hiddenClass : this.hiddenClasses) {
|
|
|
|
|
|
|
|
if (hiddenClass.getName().equals(name)) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
@ConditionalOnJava(JavaVersion.NINE)
|
|
|
|
@ConditionalOnJava(JavaVersion.NINE)
|
|
|
|
static class Java9Required {
|
|
|
|
static class Java9Required {
|
|
|
|