|
|
@ -25,10 +25,9 @@ import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aot.generate.ClassNameGenerator;
|
|
|
|
import org.springframework.aot.generate.DefaultGenerationContext;
|
|
|
|
import org.springframework.aot.generate.DefaultGenerationContext;
|
|
|
|
import org.springframework.aot.generate.FileSystemGeneratedFiles;
|
|
|
|
import org.springframework.aot.generate.FileSystemGeneratedFiles;
|
|
|
|
import org.springframework.aot.generate.GeneratedFiles.Kind;
|
|
|
|
import org.springframework.aot.generate.GeneratedFiles.Kind;
|
|
|
@ -62,8 +61,6 @@ public class AotProcessor {
|
|
|
|
private static final Consumer<ExecutableHint.Builder> INVOKE_CONSTRUCTOR_HINT = (hint) -> hint
|
|
|
|
private static final Consumer<ExecutableHint.Builder> INVOKE_CONSTRUCTOR_HINT = (hint) -> hint
|
|
|
|
.setModes(ExecutableMode.INVOKE);
|
|
|
|
.setModes(ExecutableMode.INVOKE);
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<ApplicationContext, AotProcessor> aotProcessors = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Class<?> application;
|
|
|
|
private final Class<?> application;
|
|
|
|
|
|
|
|
|
|
|
|
private final String[] applicationArgs;
|
|
|
|
private final String[] applicationArgs;
|
|
|
@ -101,32 +98,18 @@ public class AotProcessor {
|
|
|
|
this.artifactId = artifactId;
|
|
|
|
this.artifactId = artifactId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Return the application class being processed.
|
|
|
|
|
|
|
|
* @return the application class
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public Class<?> getApplication() {
|
|
|
|
|
|
|
|
return this.application;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Trigger the processing of the application managed by this instance.
|
|
|
|
* Trigger the processing of the application managed by this instance.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void process() {
|
|
|
|
public void process() {
|
|
|
|
deleteExistingOutput();
|
|
|
|
deleteExistingOutput();
|
|
|
|
AotProcessorHook hook = new AotProcessorHook();
|
|
|
|
AotProcessorHook hook = new AotProcessorHook();
|
|
|
|
SpringApplicationHooks.withHook(hook, this::callApplicationMainMethod);
|
|
|
|
SpringApplicationHooks.withHook(hook, this::callApplicationMainMethod);
|
|
|
|
GenericApplicationContext applicationContext = hook.getApplicationContext();
|
|
|
|
GenericApplicationContext applicationContext = hook.getApplicationContext();
|
|
|
|
Assert.notNull(applicationContext, "No application context available after calling main method of '"
|
|
|
|
Assert.notNull(applicationContext, "No application context available after calling main method of '"
|
|
|
|
+ this.application.getName() + "'. Does it run a SpringApplication?");
|
|
|
|
+ this.application.getName() + "'. Does it run a SpringApplication?");
|
|
|
|
aotProcessors.put(applicationContext, this);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
performAotProcessing(applicationContext);
|
|
|
|
performAotProcessing(applicationContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
|
|
|
|
aotProcessors.remove(applicationContext);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void deleteExistingOutput() {
|
|
|
|
private void deleteExistingOutput() {
|
|
|
|
deleteExistingOutput(this.sourceOutput, this.resourceOutput, this.classOutput);
|
|
|
|
deleteExistingOutput(this.sourceOutput, this.resourceOutput, this.classOutput);
|
|
|
@ -161,12 +144,11 @@ public class AotProcessor {
|
|
|
|
|
|
|
|
|
|
|
|
private void performAotProcessing(GenericApplicationContext applicationContext) {
|
|
|
|
private void performAotProcessing(GenericApplicationContext applicationContext) {
|
|
|
|
FileSystemGeneratedFiles generatedFiles = new FileSystemGeneratedFiles(this::getRoot);
|
|
|
|
FileSystemGeneratedFiles generatedFiles = new FileSystemGeneratedFiles(this::getRoot);
|
|
|
|
DefaultGenerationContext generationContext = new DefaultGenerationContext(generatedFiles);
|
|
|
|
DefaultGenerationContext generationContext = new DefaultGenerationContext(
|
|
|
|
|
|
|
|
new ClassNameGenerator(this.application), generatedFiles);
|
|
|
|
ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator();
|
|
|
|
ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator();
|
|
|
|
ClassName generatedInitializerClassName = generationContext.getClassNameGenerator()
|
|
|
|
ClassName generatedInitializerClassName = generator.generateApplicationContext(applicationContext,
|
|
|
|
.generateClassName(this.application, "ApplicationContextInitializer");
|
|
|
|
generationContext);
|
|
|
|
generator.generateApplicationContext(applicationContext, this.application, "", generationContext,
|
|
|
|
|
|
|
|
generatedInitializerClassName);
|
|
|
|
|
|
|
|
registerEntryPointHint(generationContext, generatedInitializerClassName);
|
|
|
|
registerEntryPointHint(generationContext, generatedInitializerClassName);
|
|
|
|
generationContext.writeGeneratedContent();
|
|
|
|
generationContext.writeGeneratedContent();
|
|
|
|
writeHints(generationContext.getRuntimeHints());
|
|
|
|
writeHints(generationContext.getRuntimeHints());
|
|
|
@ -243,16 +225,6 @@ public class AotProcessor {
|
|
|
|
.process();
|
|
|
|
.process();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Return the AOT processor that is actively processing the given
|
|
|
|
|
|
|
|
* {@link ApplicationContext}.
|
|
|
|
|
|
|
|
* @param applicationContext the application context to check
|
|
|
|
|
|
|
|
* @return the {@link AotProcessor} or {@code null}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static AotProcessor getActive(ApplicationContext applicationContext) {
|
|
|
|
|
|
|
|
return aotProcessors.get(applicationContext);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Hook used to capture the {@link ApplicationContext} and trigger early exit of main
|
|
|
|
* Hook used to capture the {@link ApplicationContext} and trigger early exit of main
|
|
|
|
* method.
|
|
|
|
* method.
|
|
|
|