Browse Source

Improve null-safety of build-plugin/spring-boot-maven-plugin

See gh-47263
pull/47665/head
Moritz Halbritter 2 months ago
parent
commit
c2548e204e
  1. 2
      build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ArtifactsLibraries.java
  2. 6
      build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ClassPath.java
  3. 6
      build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/CommandLineBuilder.java
  4. 3
      build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Docker.java

2
build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ArtifactsLibraries.java

@ -79,7 +79,7 @@ public class ArtifactsLibraries implements Libraries {
* @since 2.4.0 * @since 2.4.0
*/ */
public ArtifactsLibraries(Set<Artifact> artifacts, Collection<MavenProject> localProjects, public ArtifactsLibraries(Set<Artifact> artifacts, Collection<MavenProject> localProjects,
Collection<Dependency> unpacks, Log log) { @Nullable Collection<Dependency> unpacks, Log log) {
this(artifacts, artifacts, localProjects, unpacks, log); this(artifacts, artifacts, localProjects, unpacks, log);
} }

6
build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ClassPath.java

@ -33,6 +33,8 @@ import java.util.function.UnaryOperator;
import java.util.stream.Collector; import java.util.stream.Collector;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.jspecify.annotations.Nullable;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -125,12 +127,12 @@ final class ClassPath {
* @param urls the class path URLs * @param urls the class path URLs
* @return a new {@link ClassPath} instance * @return a new {@link ClassPath} instance
*/ */
static ClassPath of(UnaryOperator<String> getSystemProperty, List<URL> urls) { static ClassPath of(UnaryOperator<@Nullable String> getSystemProperty, List<URL> urls) {
boolean preferArgFile = urls.size() > 1 && isWindows(getSystemProperty); boolean preferArgFile = urls.size() > 1 && isWindows(getSystemProperty);
return new ClassPath(preferArgFile, urls.stream().map(ClassPath::toPathString).collect(JOIN_BY_PATH_SEPARATOR)); return new ClassPath(preferArgFile, urls.stream().map(ClassPath::toPathString).collect(JOIN_BY_PATH_SEPARATOR));
} }
private static boolean isWindows(UnaryOperator<String> getSystemProperty) { private static boolean isWindows(UnaryOperator<@Nullable String> getSystemProperty) {
String os = getSystemProperty.apply("os.name"); String os = getSystemProperty.apply("os.name");
return StringUtils.hasText(os) && os.toLowerCase(Locale.ROOT).contains("win"); return StringUtils.hasText(os) && os.toLowerCase(Locale.ROOT).contains("win");
} }

6
build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/CommandLineBuilder.java

@ -51,7 +51,8 @@ final class CommandLineBuilder {
return new CommandLineBuilder(mainClass); return new CommandLineBuilder(mainClass);
} }
CommandLineBuilder withJvmArguments(String... jvmArguments) { // Do not use String @Nullable ... jvmArguments, Maven can't deal with that
CommandLineBuilder withJvmArguments(@Nullable String... jvmArguments) {
if (jvmArguments != null) { if (jvmArguments != null) {
this.options.addAll(Arrays.stream(jvmArguments).filter(Objects::nonNull).toList()); this.options.addAll(Arrays.stream(jvmArguments).filter(Objects::nonNull).toList());
} }
@ -75,7 +76,8 @@ final class CommandLineBuilder {
return this; return this;
} }
CommandLineBuilder withArguments(String... arguments) { // Do not use String @Nullable ... arguments, Maven can't deal with that
CommandLineBuilder withArguments(@Nullable String... arguments) {
if (arguments != null) { if (arguments != null) {
this.arguments.addAll(Arrays.stream(arguments).filter(Objects::nonNull).toList()); this.arguments.addAll(Arrays.stream(arguments).filter(Objects::nonNull).toList());
} }

3
build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Docker.java

@ -230,7 +230,8 @@ public class Docker {
public DockerRegistry() { public DockerRegistry() {
} }
public DockerRegistry(String username, String password, String url, String email) { public DockerRegistry(@Nullable String username, @Nullable String password, @Nullable String url,
@Nullable String email) {
this.username = username; this.username = username;
this.password = password; this.password = password;
this.url = url; this.url = url;

Loading…
Cancel
Save