This commit is contained in:
Phillip Webb
2022-07-29 12:07:36 +01:00
parent 41e8697445
commit e08c16dfd6
17 changed files with 134 additions and 111 deletions

View File

@@ -157,9 +157,9 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
return cleaned.toString();
}
static class TestArtifactFilter extends AbstractArtifactFeatureFilter {
protected static class TestScopeArtifactFilter extends AbstractArtifactFeatureFilter {
TestArtifactFilter() {
TestScopeArtifactFilter() {
super("", Artifact.SCOPE_TEST);
}

View File

@@ -371,7 +371,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
private void addDependencies(List<URL> urls) throws MalformedURLException, MojoExecutionException {
Set<Artifact> artifacts = (this.useTestClasspath) ? filterDependencies(this.project.getArtifacts())
: filterDependencies(this.project.getArtifacts(), new TestArtifactFilter());
: filterDependencies(this.project.getArtifacts(), new TestScopeArtifactFilter());
for (Artifact artifact : artifacts) {
if (artifact.getFile() != null) {
urls.add(artifact.getFile().toURI().toURL());

View File

@@ -154,6 +154,18 @@ public class AotGenerateMojo extends AbstractDependencyFilterMojo {
private void generateAotAssets() throws MojoExecutionException {
String applicationClass = (this.mainClass != null) ? this.mainClass
: SpringBootApplicationClassFinder.findSingleClass(this.classesDirectory);
List<String> command = CommandLineBuilder.forMainClass(AOT_PROCESSOR_CLASS_NAME)
.withSystemProperties(this.systemPropertyVariables)
.withJvmArguments(new RunArguments(this.jvmArguments).asArray()).withClasspath(getClassPathUrls())
.withArguments(getAotArguments(applicationClass)).build();
if (getLog().isDebugEnabled()) {
getLog().debug("Generating AOT assets using command: " + command);
}
JavaProcessExecutor processExecutor = new JavaProcessExecutor(this.session, this.toolchainManager);
processExecutor.run(this.project.getBasedir(), command, Collections.emptyMap());
}
private String[] getAotArguments(String applicationClass) {
List<String> aotArguments = new ArrayList<>();
aotArguments.add(applicationClass);
aotArguments.add(this.generatedSources.toString());
@@ -164,25 +176,13 @@ public class AotGenerateMojo extends AbstractDependencyFilterMojo {
if (!ObjectUtils.isEmpty(this.profiles)) {
aotArguments.add("--spring.profiles.active=" + String.join(",", this.profiles));
}
// @formatter:off
List<String> args = CommandLineBuilder.forMainClass(AOT_PROCESSOR_CLASS_NAME)
.withSystemProperties(this.systemPropertyVariables)
.withJvmArguments(new RunArguments(this.jvmArguments).asArray())
.withClasspath(getClassPathUrls())
.withArguments(aotArguments.toArray(String[]::new))
.build();
// @formatter:on
if (getLog().isDebugEnabled()) {
getLog().debug("Generating AOT assets using command: " + args);
}
JavaProcessExecutor processExecutor = new JavaProcessExecutor(this.session, this.toolchainManager);
processExecutor.run(this.project.getBasedir(), args, Collections.emptyMap());
return aotArguments.toArray(String[]::new);
}
private URL[] getClassPathUrls() throws MojoExecutionException {
List<URL> urls = new ArrayList<>();
urls.add(toURL(this.classesDirectory));
urls.addAll(getDependencyURLs(new TestArtifactFilter()));
urls.addAll(getDependencyURLs(new TestScopeArtifactFilter()));
return urls.toArray(URL[]::new);
}