Skip to content

Commit 924910f

Browse files
committed
Add nullability annotations to build-plugin/spring-boot-maven-plugin
See gh-46587
1 parent d74cfba commit 924910f

29 files changed

+295
-198
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.maven.plugins.annotations.Parameter;
4545
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
4646
import org.apache.maven.toolchain.ToolchainManager;
47+
import org.jspecify.annotations.Nullable;
4748

4849
/**
4950
* Abstract base class for AOT processing MOJOs.
@@ -59,6 +60,7 @@ public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo {
5960
* The current Maven session. This is used for toolchain manager API calls.
6061
*/
6162
@Parameter(defaultValue = "${session}", readonly = true)
63+
@SuppressWarnings("NullAway.Init")
6264
private MavenSession session;
6365

6466
/**
@@ -76,21 +78,21 @@ public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo {
7678
* List of JVM system properties to pass to the AOT process.
7779
*/
7880
@Parameter
79-
private Map<String, String> systemPropertyVariables;
81+
private @Nullable Map<String, String> systemPropertyVariables;
8082

8183
/**
8284
* JVM arguments that should be associated with the AOT process. On command line, make
8385
* sure to wrap multiple values between quotes.
8486
*/
8587
@Parameter(property = "spring-boot.aot.jvmArguments")
86-
private String jvmArguments;
88+
private @Nullable String jvmArguments;
8789

8890
/**
8991
* Arguments that should be provided to the AOT compile process. On command line, make
9092
* sure to wrap multiple values between quotes.
9193
*/
9294
@Parameter(property = "spring-boot.aot.compilerArguments")
93-
private String compilerArguments;
95+
private @Nullable String compilerArguments;
9496

9597
protected AbstractAotMojo(ToolchainManager toolchainManager) {
9698
this.toolchainManager = toolchainManager;

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
3737
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
3838
import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
39+
import org.jspecify.annotations.Nullable;
3940

4041
/**
4142
* A base mojo filtering the dependencies of the project.
@@ -67,6 +68,7 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
6768
* @since 3.0.0
6869
*/
6970
@Parameter(defaultValue = "${project}", readonly = true, required = true)
71+
@SuppressWarnings("NullAway.Init")
7072
protected MavenProject project;
7173

7274
/**
@@ -78,7 +80,7 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
7880
* @since 1.2.0
7981
*/
8082
@Parameter(property = "spring-boot.includes")
81-
private List<Include> includes;
83+
private @Nullable List<Include> includes;
8284

8385
/**
8486
* Collection of artifact definitions to exclude. The {@link Exclude} element defines
@@ -89,20 +91,20 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
8991
* @since 1.1.0
9092
*/
9193
@Parameter(property = "spring-boot.excludes")
92-
private List<Exclude> excludes;
94+
private @Nullable List<Exclude> excludes;
9395

9496
/**
9597
* Comma separated list of groupId names to exclude (exact match).
9698
* @since 1.1.0
9799
*/
98100
@Parameter(property = "spring-boot.excludeGroupIds", defaultValue = "")
99-
private String excludeGroupIds;
101+
private @Nullable String excludeGroupIds;
100102

101-
protected void setExcludes(List<Exclude> excludes) {
103+
protected void setExcludes(@Nullable List<Exclude> excludes) {
102104
this.excludes = excludes;
103105
}
104106

105-
protected void setIncludes(List<Include> includes) {
107+
protected void setIncludes(@Nullable List<Include> includes) {
106108
this.includes = includes;
107109
}
108110

@@ -163,7 +165,7 @@ private FilterArtifacts getFilters(ArtifactsFilter... additionalFilters) {
163165
return filters;
164166
}
165167

166-
private String cleanFilterConfig(String content) {
168+
private String cleanFilterConfig(@Nullable String content) {
167169
if (content == null || content.trim().isEmpty()) {
168170
return "";
169171
}

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.maven.project.MavenProjectHelper;
3737
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
3838
import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
39+
import org.jspecify.annotations.Nullable;
3940
import org.w3c.dom.Document;
4041
import org.xml.sax.InputSource;
4142

@@ -67,13 +68,15 @@ public abstract class AbstractPackagerMojo extends AbstractDependencyFilterMojo
6768
* @since 1.0.0
6869
*/
6970
@Parameter(defaultValue = "${project}", readonly = true, required = true)
71+
@SuppressWarnings("NullAway.Init")
7072
protected MavenProject project;
7173

7274
/**
7375
* The Maven session.
7476
* @since 2.4.0
7577
*/
7678
@Parameter(defaultValue = "${session}", readonly = true, required = true)
79+
@SuppressWarnings("NullAway.Init")
7780
protected MavenSession session;
7881

7982
/**
@@ -88,7 +91,7 @@ public abstract class AbstractPackagerMojo extends AbstractDependencyFilterMojo
8891
* @since 1.0.0
8992
*/
9093
@Parameter
91-
private String mainClass;
94+
private @Nullable String mainClass;
9295

9396
/**
9497
* Exclude Spring Boot devtools from the repackaged archive.
@@ -135,7 +138,7 @@ protected AbstractPackagerMojo(MavenProjectHelper projectHelper) {
135138
* @return {@code null}, indicating a layout type will be chosen based on the original
136139
* archive type
137140
*/
138-
protected LayoutType getLayout() {
141+
protected @Nullable LayoutType getLayout() {
139142
return null;
140143
}
141144

@@ -144,7 +147,7 @@ protected LayoutType getLayout() {
144147
* @return the loader implementation or {@code null}
145148
* @since 3.2.0
146149
*/
147-
protected LoaderImplementation getLoaderImplementation() {
150+
protected @Nullable LoaderImplementation getLoaderImplementation() {
148151
return null;
149152
}
150153

@@ -153,7 +156,7 @@ protected LoaderImplementation getLoaderImplementation() {
153156
* no explicit layout is set.
154157
* @return {@code null}, indicating a default layout factory will be chosen
155158
*/
156-
protected LayoutFactory getLayoutFactory() {
159+
protected @Nullable LayoutFactory getLayoutFactory() {
157160
return null;
158161
}
159162

@@ -211,7 +214,7 @@ private Document getDocumentIfAvailable(File xmlFile) throws Exception {
211214
* @return the libraries to use
212215
* @throws MojoExecutionException on execution error
213216
*/
214-
protected final Libraries getLibraries(Collection<Dependency> unpacks) throws MojoExecutionException {
217+
protected final Libraries getLibraries(@Nullable Collection<Dependency> unpacks) throws MojoExecutionException {
215218
Set<Artifact> artifacts = this.project.getArtifacts();
216219
Set<Artifact> includedArtifacts = filterDependencies(artifacts, getAdditionalFilters());
217220
return new ArtifactsLibraries(artifacts, includedArtifacts, this.session.getProjects(), unpacks, getLog());
@@ -238,12 +241,12 @@ private ArtifactsFilter[] getAdditionalFilters() {
238241
* @param classifier the artifact classifier
239242
* @return the source artifact to repackage
240243
*/
241-
protected Artifact getSourceArtifact(String classifier) {
244+
protected Artifact getSourceArtifact(@Nullable String classifier) {
242245
Artifact sourceArtifact = getArtifact(classifier);
243246
return (sourceArtifact != null) ? sourceArtifact : this.project.getArtifact();
244247
}
245248

246-
private Artifact getArtifact(String classifier) {
249+
private @Nullable Artifact getArtifact(@Nullable String classifier) {
247250
if (classifier != null) {
248251
for (Artifact attachedArtifact : this.project.getAttachedArtifacts()) {
249252
if (classifier.equals(attachedArtifact.getClassifier()) && attachedArtifact.getFile() != null
@@ -255,7 +258,7 @@ private Artifact getArtifact(String classifier) {
255258
return null;
256259
}
257260

258-
protected File getTargetFile(String finalName, String classifier, File targetDirectory) {
261+
protected File getTargetFile(String finalName, @Nullable String classifier, File targetDirectory) {
259262
String classifierSuffix = (classifier != null) ? classifier.trim() : "";
260263
if (!classifierSuffix.isEmpty() && !classifierSuffix.startsWith("-")) {
261264
classifierSuffix = "-" + classifierSuffix;

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.maven.plugins.annotations.Parameter;
3737
import org.apache.maven.project.MavenProject;
3838
import org.apache.maven.toolchain.ToolchainManager;
39+
import org.jspecify.annotations.Nullable;
3940

4041
import org.springframework.boot.loader.tools.FileUtils;
4142

@@ -60,6 +61,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
6061
* @since 1.0.0
6162
*/
6263
@Parameter(defaultValue = "${project}", readonly = true, required = true)
64+
@SuppressWarnings("NullAway.Init")
6365
private MavenProject project;
6466

6567
/**
@@ -68,6 +70,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
6870
* @since 2.3.0
6971
*/
7072
@Parameter(defaultValue = "${session}", readonly = true)
73+
@SuppressWarnings("NullAway.Init")
7174
private MavenSession session;
7275

7376
/**
@@ -95,6 +98,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
9598
* @since 2.2.0
9699
*/
97100
@Parameter(property = "spring-boot.run.agents")
101+
@SuppressWarnings("NullAway") // maven-maven-plugin can't handle annotated arrays
98102
private File[] agents;
99103

100104
/**
@@ -112,7 +116,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
112116
* @since 1.5.0
113117
*/
114118
@Parameter(property = "spring-boot.run.workingDirectory")
115-
private File workingDirectory;
119+
private @Nullable File workingDirectory;
116120

117121
/**
118122
* JVM arguments that should be associated with the forked process used to run the
@@ -121,15 +125,15 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
121125
* @since 1.1.0
122126
*/
123127
@Parameter(property = "spring-boot.run.jvmArguments")
124-
private String jvmArguments;
128+
private @Nullable String jvmArguments;
125129

126130
/**
127131
* List of JVM system properties to pass to the process.
128132
*
129133
* @since 2.1.0
130134
*/
131135
@Parameter
132-
private Map<String, String> systemPropertyVariables;
136+
private @Nullable Map<String, String> systemPropertyVariables;
133137

134138
/**
135139
* List of Environment variables that should be associated with the forked process
@@ -138,14 +142,15 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
138142
* @since 2.1.0
139143
*/
140144
@Parameter
141-
private Map<String, String> environmentVariables;
145+
private @Nullable Map<String, String> environmentVariables;
142146

143147
/**
144148
* Arguments that should be passed to the application.
145149
*
146150
* @since 1.0.0
147151
*/
148152
@Parameter
153+
@SuppressWarnings("NullAway") // maven-maven-plugin can't handle annotated arrays
149154
private String[] arguments;
150155

151156
/**
@@ -156,7 +161,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
156161
* @since 2.2.3
157162
*/
158163
@Parameter(property = "spring-boot.run.arguments")
159-
private String commandlineArguments;
164+
private @Nullable String commandlineArguments;
160165

161166
/**
162167
* The spring profiles to activate. Convenience shortcut of specifying the
@@ -166,6 +171,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
166171
* @since 1.3.0
167172
*/
168173
@Parameter(property = "spring-boot.run.profiles")
174+
@SuppressWarnings("NullAway") // maven-maven-plugin can't handle annotated arrays
169175
private String[] profiles;
170176

171177
/**
@@ -175,7 +181,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
175181
* @since 1.0.0
176182
*/
177183
@Parameter(property = "spring-boot.run.main-class")
178-
private String mainClass;
184+
private @Nullable String mainClass;
179185

180186
/**
181187
* Additional classpath elements that should be added to the classpath. An element can
@@ -184,6 +190,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
184190
* @since 3.2.0
185191
*/
186192
@Parameter(property = "spring-boot.run.additional-classpath-elements")
193+
@SuppressWarnings("NullAway") // maven-maven-plugin can't handle annotated arrays
187194
private String[] additionalClasspathElements;
188195

189196
/**
@@ -193,6 +200,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
193200
* @since 1.0.0
194201
*/
195202
@Parameter(defaultValue = "${project.build.outputDirectory}", required = true)
203+
@SuppressWarnings("NullAway.Init")
196204
private File classesDirectory;
197205

198206
/**
@@ -336,7 +344,7 @@ private void addAgents(List<String> args) {
336344
}
337345

338346
private void addActiveProfileArgument(RunArguments arguments) {
339-
if (this.profiles.length > 0) {
347+
if (this.profiles != null && this.profiles.length > 0) {
340348
StringBuilder arg = new StringBuilder("--spring.profiles.active=");
341349
for (int i = 0; i < this.profiles.length; i++) {
342350
arg.append(this.profiles[i]);
@@ -424,7 +432,7 @@ private void logArguments(String name, String[] args) {
424432
*/
425433
static class SystemPropertyFormatter {
426434

427-
static String format(String key, String value) {
435+
static String format(@Nullable String key, @Nullable String value) {
428436
if (key == null) {
429437
return "";
430438
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.maven.model.Dependency;
3030
import org.apache.maven.plugin.logging.Log;
3131
import org.apache.maven.project.MavenProject;
32+
import org.jspecify.annotations.Nullable;
3233

3334
import org.springframework.boot.loader.tools.Libraries;
3435
import org.springframework.boot.loader.tools.Library;
@@ -64,7 +65,7 @@ public class ArtifactsLibraries implements Libraries {
6465

6566
private final Collection<MavenProject> localProjects;
6667

67-
private final Collection<Dependency> unpacks;
68+
private final @Nullable Collection<Dependency> unpacks;
6869

6970
private final Log log;
7071

@@ -93,7 +94,7 @@ public ArtifactsLibraries(Set<Artifact> artifacts, Collection<MavenProject> loca
9394
* @since 2.4.8
9495
*/
9596
public ArtifactsLibraries(Set<Artifact> artifacts, Set<Artifact> includedArtifacts,
96-
Collection<MavenProject> localProjects, Collection<Dependency> unpacks, Log log) {
97+
Collection<MavenProject> localProjects, @Nullable Collection<Dependency> unpacks, Log log) {
9798
this.artifacts = artifacts;
9899
this.includedArtifacts = includedArtifacts;
99100
this.localProjects = localProjects;

0 commit comments

Comments
 (0)