From a0ad00c54256b337b2c7874187cf1a20488398b9 Mon Sep 17 00:00:00 2001 From: omaryaya Date: Mon, 14 Aug 2023 16:26:40 +0300 Subject: [PATCH 1/2] Avoid setting null compiler option See gh-36971 --- .../boot/maven/AbstractAotMojo.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java index 7438dbe8ca..eeda61f53e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java @@ -53,6 +53,7 @@ import org.springframework.boot.maven.CommandLineBuilder.ClasspathBuilder; * * @author Phillip Webb * @author Scott Frederick + * @author Omar YAYA * @since 3.0.0 */ public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo { @@ -152,10 +153,7 @@ public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo { options.add(releaseVersion); } else { - options.add("--source"); - options.add(compilerConfiguration.getSourceMajorVersion()); - options.add("--target"); - options.add(compilerConfiguration.getTargetMajorVersion()); + setSourceAndTargetVersions(compilerConfiguration, options); } options.addAll(new RunArguments(this.compilerArguments).getArgs()); Iterable compilationUnits = fileManager.getJavaFileObjectsFromPaths(sourceFiles); @@ -167,6 +165,19 @@ public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo { } } } + private static void setSourceAndTargetVersions(JavaCompilerPluginConfiguration compilerConfiguration, + List options) { + String sourceMajorVersion = compilerConfiguration.getSourceMajorVersion(); + if (sourceMajorVersion != null && !sourceMajorVersion.isEmpty()) { + options.add("--source"); + options.add(sourceMajorVersion); + } + String targetMajorVersion = compilerConfiguration.getTargetMajorVersion(); + if (targetMajorVersion != null && !targetMajorVersion.isEmpty()) { + options.add("--target"); + options.add(targetMajorVersion); + } + } protected final URL[] getClassPath(File[] directories, ArtifactsFilter... artifactFilters) throws MojoExecutionException { From 0271efae4c111afb481e1f0fc3e039f30b8ba61e Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 14 Aug 2023 16:07:25 +0200 Subject: [PATCH 2/2] Polish "Avoid setting null compiler option" See gh-36971 --- .../boot/maven/AbstractAotMojo.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java index eeda61f53e..53881fff3e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java @@ -153,7 +153,16 @@ public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo { options.add(releaseVersion); } else { - setSourceAndTargetVersions(compilerConfiguration, options); + String source = compilerConfiguration.getSourceMajorVersion(); + if (source != null) { + options.add("--source"); + options.add(source); + } + String target = compilerConfiguration.getTargetMajorVersion(); + if (target != null) { + options.add("--target"); + options.add(target); + } } options.addAll(new RunArguments(this.compilerArguments).getArgs()); Iterable compilationUnits = fileManager.getJavaFileObjectsFromPaths(sourceFiles); @@ -165,19 +174,6 @@ public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo { } } } - private static void setSourceAndTargetVersions(JavaCompilerPluginConfiguration compilerConfiguration, - List options) { - String sourceMajorVersion = compilerConfiguration.getSourceMajorVersion(); - if (sourceMajorVersion != null && !sourceMajorVersion.isEmpty()) { - options.add("--source"); - options.add(sourceMajorVersion); - } - String targetMajorVersion = compilerConfiguration.getTargetMajorVersion(); - if (targetMajorVersion != null && !targetMajorVersion.isEmpty()) { - options.add("--target"); - options.add(targetMajorVersion); - } - } protected final URL[] getClassPath(File[] directories, ArtifactsFilter... artifactFilters) throws MojoExecutionException {