se.bjurr.violations.lib.model.sarif.SarifTransformer Maven / Gradle / Ivy
package se.bjurr.violations.lib.model.sarif;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;
import se.bjurr.violations.lib.model.ViolationUtils;
import se.bjurr.violations.lib.model.generated.sarif.ArtifactLocation;
import se.bjurr.violations.lib.model.generated.sarif.Location;
import se.bjurr.violations.lib.model.generated.sarif.Message;
import se.bjurr.violations.lib.model.generated.sarif.PhysicalLocation;
import se.bjurr.violations.lib.model.generated.sarif.Region;
import se.bjurr.violations.lib.model.generated.sarif.Result;
import se.bjurr.violations.lib.model.generated.sarif.Run;
import se.bjurr.violations.lib.model.generated.sarif.SarifSchema;
import se.bjurr.violations.lib.model.generated.sarif.Tool;
import se.bjurr.violations.lib.model.generated.sarif.ToolComponent;
public class SarifTransformer {
public static SarifSchema fromViolations(final Set from) {
final List allFiles = ViolationUtils.getAllFiles();
final List results = toResults(allFiles, from);
final Tool tool = toTool();
final Run run = new Run();
run.setTool(tool);
run.withResults(results);
final List runs = new ArrayList<>();
runs.add(run);
return new SarifSchema().withVersion("2.1.0").withRuns(runs);
}
private static Tool toTool() {
final Set