edu.umd.cs.findbugs.sarif.Invocation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spotbugs Show documentation
Show all versions of spotbugs Show documentation
SpotBugs: Because it's easy!
package edu.umd.cs.findbugs.sarif;
import edu.umd.cs.findbugs.annotations.NonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonArray;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* @see 3.20 invocation object
*/
class Invocation {
private final int exitCode;
@NonNull
private final String exitCodeDescription;
private final boolean executionSuccessful;
@NonNull
private final List toolExecutionNotifications;
@NonNull
private final List toolConfigurationNotifications;
Invocation(int exitCode, @NonNull String exitCodeDescription, boolean executionSuccessful, @NonNull List toolExecutionNotifications,
@NonNull List toolConfigurationNotifications) {
this.exitCode = exitCode;
this.exitCodeDescription = Objects.requireNonNull(exitCodeDescription);
this.executionSuccessful = executionSuccessful;
this.toolExecutionNotifications = Collections.unmodifiableList(toolExecutionNotifications);
this.toolConfigurationNotifications = Collections.unmodifiableList(toolConfigurationNotifications);
}
@NonNull
JsonObject toJsonObject() {
JsonObject result = new JsonObject();
result.addProperty("exitCode", exitCode);
result.addProperty("exitCodeDescription", exitCodeDescription);
result.addProperty("executionSuccessful", executionSuccessful);
JsonArray execNotificationArray = new JsonArray();
toolExecutionNotifications.stream()
.map(Notification::toJsonObject)
.forEach(json -> execNotificationArray.add(json));
if (execNotificationArray.size() > 0) {
result.add("toolExecutionNotifications", execNotificationArray);
}
JsonArray configNotificationArray = new JsonArray();
toolConfigurationNotifications.stream()
.map(Notification::toJsonObject)
.forEach(json -> configNotificationArray.add(json));
if (configNotificationArray.size() > 0) {
result.add("toolConfigurationNotifications", configNotificationArray);
}
return result;
}
}