Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy null checks in AbstractGenerateMojo.java #128

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package io.github.ascopes.protobufmavenplugin;

import static java.util.Objects.requireNonNullElse;
import static java.util.Objects.requireNonNullElseGet;

import io.github.ascopes.protobufmavenplugin.dependency.ResolutionException;
import io.github.ascopes.protobufmavenplugin.generate.ImmutableGenerationRequest;
import io.github.ascopes.protobufmavenplugin.generate.SourceCodeGenerator;
Expand Down Expand Up @@ -376,12 +373,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

var request = ImmutableGenerationRequest.builder()
.additionalImportPaths(nonNullList(additionalImportPaths))
.additionalImportPaths(nonNullOr(additionalImportPaths, List.of()))
.allowedDependencyScopes(allowedScopes())
.binaryMavenPlugins(nonNullList(binaryMavenPlugins))
.binaryPathPlugins(nonNullList(binaryPathPlugins))
.binaryUrlPlugins(nonNullList(binaryUrlPlugins))
.jvmMavenPlugins(nonNullList(jvmMavenPlugins))
.binaryMavenPlugins(nonNullOr(binaryMavenPlugins, List.of()))
.binaryPathPlugins(nonNullOr(binaryPathPlugins, List.of()))
.binaryUrlPlugins(nonNullOr(binaryUrlPlugins, List.of()))
.isCppEnabled(cppEnabled)
.isCsharpEnabled(csharpEnabled)
.isFailOnMissingSources(failOnMissingSources)
Expand All @@ -396,15 +392,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.isRegisterAsCompilationRoot(registerAsCompilationRoot)
.isRubyEnabled(rubyEnabled)
.isRustEnabled(rustEnabled)
.jvmMavenPlugins(nonNullOr(jvmMavenPlugins, List.of()))
.mavenSession(session)
.outputDirectory(requireNonNullElseGet(
outputDirectory, () -> defaultOutputDirectory(session)
))
.outputDirectory(nonNullOr(outputDirectory, defaultOutputDirectory(session)))
.protocVersion(protocVersion())
.sourceRootRegistrar(sourceRootRegistrar())
.sourceRoots(requireNonNullElseGet(
sourceDirectories, () -> List.of(defaultSourceDirectory(session))
))
.sourceRoots(nonNullOr(sourceDirectories, List.of(defaultSourceDirectory(session))))
.build();

try {
Expand Down Expand Up @@ -493,11 +486,10 @@ protected void validate() {
private String protocVersion() {
// Give precedence to overriding the protoc version via the command line
// in case the Maven binaries are incompatible with the current system.
var overriddenVersion = System.getProperty("protoc.version");
return requireNonNullElse(overriddenVersion, protocVersion);
return System.getProperty("protoc.version", protocVersion);
}

private <T> List<T> nonNullList(@Nullable List<T> list) {
return requireNonNullElseGet(list, List::of);
private <T> T nonNullOr(@Nullable T item, T otherwise) {
return item == null ? otherwise : item;
}
}
Loading