Annotated the generated code by helpmojo with NullSafe suppressions

See gh-46587
This commit is contained in:
Moritz Halbritter
2025-08-11 13:12:53 +02:00
parent 6f41eb4915
commit d74cfbad6e
@@ -97,6 +97,7 @@ import org.springframework.core.CollectionFactory;
*
* @author Andy Wilkinson
* @author Phillip Webb
* @author Moritz Halbritter
*/
public class MavenPluginPlugin implements Plugin<Project> {
@@ -377,13 +378,27 @@ public class MavenPluginPlugin implements Plugin<Project> {
Path outputLocation = getOutputDir().getAsFile().get().toPath().resolve(relativePath);
try {
Files.createDirectories(outputLocation.getParent());
Files.writeString(outputLocation, edit.getFormattedContent());
String content = edit.getFormattedContent();
content = addNullAwaySuppression(content);
Files.writeString(outputLocation, content);
}
catch (Exception ex) {
throw new TaskExecutionException(this, ex);
}
}
private String addNullAwaySuppression(String content) {
String[] lines = content.split("\n");
StringBuilder result = new StringBuilder();
for (String line : lines) {
if (line.startsWith("public class ")) {
result.append("@SuppressWarnings(\"NullAway\")").append("\n");
}
result.append(line).append("\n");
}
return result.toString();
}
}
public static class MavenRepositoryComponentMetadataRule implements ComponentMetadataRule {