Polishing

This commit is contained in:
Sam Brannen
2022-10-10 16:52:22 +02:00
parent 26c6a742d9
commit de609e5d45
4 changed files with 33 additions and 17 deletions

View File

@@ -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();

View File

@@ -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");

View File

@@ -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();