Polishing
This commit is contained in:
@@ -67,6 +67,15 @@ public abstract class ContextAotProcessor extends AbstractAotProcessor {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the the application entry point.
|
||||
*/
|
||||
protected Class<?> getApplication() {
|
||||
return this.application;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invoke the processing by clearing output directories first, followed by
|
||||
* {@link #performAotProcessing(GenericApplicationContext)}.
|
||||
@@ -75,7 +84,7 @@ public abstract class ContextAotProcessor extends AbstractAotProcessor {
|
||||
*/
|
||||
public ClassName process() {
|
||||
deleteExistingOutput();
|
||||
GenericApplicationContext applicationContext = prepareApplicationContext(this.application);
|
||||
GenericApplicationContext applicationContext = prepareApplicationContext(getApplication());
|
||||
return performAotProcessing(applicationContext);
|
||||
}
|
||||
|
||||
@@ -102,7 +111,7 @@ public abstract class ContextAotProcessor extends AbstractAotProcessor {
|
||||
registerEntryPointHint(generationContext, generatedInitializerClassName);
|
||||
generationContext.writeGeneratedContent();
|
||||
writeHints(generationContext.getRuntimeHints());
|
||||
writeNativeImageProperties(getDefaultNativeImageArguments(this.application.getName()));
|
||||
writeNativeImageProperties(getDefaultNativeImageArguments(getApplication().getName()));
|
||||
return generatedInitializerClassName;
|
||||
}
|
||||
|
||||
@@ -113,7 +122,7 @@ public abstract class ContextAotProcessor extends AbstractAotProcessor {
|
||||
* @return the class name generator
|
||||
*/
|
||||
protected ClassNameGenerator createClassNameGenerator() {
|
||||
return new ClassNameGenerator(ClassName.get(this.application));
|
||||
return new ClassNameGenerator(ClassName.get(getApplication()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +146,7 @@ public abstract class ContextAotProcessor extends AbstractAotProcessor {
|
||||
ClassName generatedInitializerClassName) {
|
||||
|
||||
TypeReference generatedType = TypeReference.of(generatedInitializerClassName.canonicalName());
|
||||
TypeReference applicationType = TypeReference.of(this.application);
|
||||
TypeReference applicationType = TypeReference.of(getApplication());
|
||||
ReflectionHints reflection = generationContext.getRuntimeHints().reflection();
|
||||
reflection.registerType(applicationType);
|
||||
reflection.registerType(generatedType, typeHint -> typeHint.onReachableType(applicationType)
|
||||
|
||||
@@ -61,6 +61,14 @@ public abstract class TestAotProcessor extends AbstractAotProcessor {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the classpath roots to scan for test classes.
|
||||
*/
|
||||
protected Set<Path> getClasspathRoots() {
|
||||
return this.classpathRoots;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Trigger processing of the test classes by
|
||||
* {@linkplain #deleteExistingOutput() clearing output directories} first and
|
||||
@@ -79,7 +87,7 @@ public abstract class TestAotProcessor extends AbstractAotProcessor {
|
||||
* components used by the tests.
|
||||
*/
|
||||
protected void performAotProcessing() {
|
||||
TestClassScanner scanner = new TestClassScanner(this.classpathRoots);
|
||||
TestClassScanner scanner = new TestClassScanner(getClasspathRoots());
|
||||
Stream<Class<?>> testClasses = scanner.scan();
|
||||
|
||||
GeneratedFiles generatedFiles = createFileSystemGeneratedFiles();
|
||||
|
||||
@@ -103,7 +103,7 @@ class TestClassScanner {
|
||||
* absolute path to the project's {@code build/classes/java/test} folder.
|
||||
* @param classpathRoots the classpath roots to scan
|
||||
*/
|
||||
public TestClassScanner(Set<Path> classpathRoots) {
|
||||
TestClassScanner(Set<Path> classpathRoots) {
|
||||
this.classpathRoots = assertPreconditions(classpathRoots);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ class TestClassScanner {
|
||||
/**
|
||||
* Scan the configured classpath roots for Spring integration test classes.
|
||||
*/
|
||||
public Stream<Class<?>> scan() {
|
||||
Stream<Class<?>> scan() {
|
||||
return scan(new String[0]);
|
||||
}
|
||||
|
||||
@@ -206,7 +206,6 @@ class TestClassScanner {
|
||||
mergedAnnotations.isPresent(BootstrapWith.class));
|
||||
}
|
||||
|
||||
|
||||
private static Set<Path> assertPreconditions(Set<Path> classpathRoots) {
|
||||
Assert.notEmpty(classpathRoots, "'classpathRoots' must not be null or empty");
|
||||
Assert.noNullElements(classpathRoots, "'classpathRoots' must not contain null elements");
|
||||
|
||||
@@ -126,8 +126,8 @@ public class TestContextAotGenerator {
|
||||
});
|
||||
MultiValueMap<ClassName, Class<?>> initializerClassMappings = processAheadOfTime(mergedConfigMappings);
|
||||
|
||||
generateTestAotMappings(initializerClassMappings);
|
||||
generateAotTestAttributes();
|
||||
generateAotTestContextInitializerMappings(initializerClassMappings);
|
||||
generateAotTestAttributeMappings();
|
||||
}
|
||||
finally {
|
||||
resetAotFactories();
|
||||
@@ -139,7 +139,9 @@ public class TestContextAotGenerator {
|
||||
AotTestContextInitializersFactory.reset();
|
||||
}
|
||||
|
||||
private MultiValueMap<ClassName, Class<?>> processAheadOfTime(MultiValueMap<MergedContextConfiguration, Class<?>> mergedConfigMappings) {
|
||||
private MultiValueMap<ClassName, Class<?>> processAheadOfTime(
|
||||
MultiValueMap<MergedContextConfiguration, Class<?>> mergedConfigMappings) {
|
||||
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
MultiValueMap<ClassName, Class<?>> initializerClassMappings = new LinkedMultiValueMap<>();
|
||||
mergedConfigMappings.forEach((mergedConfig, testClasses) -> {
|
||||
@@ -251,9 +253,8 @@ public class TestContextAotGenerator {
|
||||
return "TestContext%03d_".formatted(this.sequence.incrementAndGet());
|
||||
}
|
||||
|
||||
private void generateTestAotMappings(MultiValueMap<ClassName, Class<?>> initializerClassMappings) {
|
||||
ClassNameGenerator classNameGenerator = new ClassNameGenerator(
|
||||
ClassName.get(AotTestContextInitializers.class));
|
||||
private void generateAotTestContextInitializerMappings(MultiValueMap<ClassName, Class<?>> initializerClassMappings) {
|
||||
ClassNameGenerator classNameGenerator = new ClassNameGenerator(ClassName.get(AotTestContextInitializers.class));
|
||||
DefaultGenerationContext generationContext =
|
||||
new DefaultGenerationContext(classNameGenerator, this.generatedFiles, this.runtimeHints);
|
||||
GeneratedClasses generatedClasses = generationContext.getGeneratedClasses();
|
||||
@@ -265,9 +266,8 @@ public class TestContextAotGenerator {
|
||||
registerPublicMethods(className);
|
||||
}
|
||||
|
||||
private void generateAotTestAttributes() {
|
||||
ClassNameGenerator classNameGenerator = new ClassNameGenerator(
|
||||
ClassName.get(AotTestAttributes.class));
|
||||
private void generateAotTestAttributeMappings() {
|
||||
ClassNameGenerator classNameGenerator = new ClassNameGenerator(ClassName.get(AotTestAttributes.class));
|
||||
DefaultGenerationContext generationContext =
|
||||
new DefaultGenerationContext(classNameGenerator, this.generatedFiles, this.runtimeHints);
|
||||
GeneratedClasses generatedClasses = generationContext.getGeneratedClasses();
|
||||
|
||||
Reference in New Issue
Block a user