in sarif/src/main/java/com/jetbrains/qodana/sarif/baseline/DescriptorWithLocation.java [32:62]
void addTo(Run run) {
Tool tool = run.getTool();
if (tool == null) return;
Stream<ToolComponent> fromDriver = Optional.ofNullable(tool.getDriver())
.map(Stream::of)
.orElseGet(Stream::empty);
Stream<ToolComponent> fromExtensions = Optional.ofNullable(tool.getExtensions())
.map(Collection::stream)
.orElseGet(Stream::empty);
Optional<ToolComponent> existing = Stream.concat(fromDriver, fromExtensions)
.filter(e -> Objects.equals(e.getFullName(), location.getFullName()) &&
Objects.equals(e.getVersion(), location.getVersion())
)
.findFirst();
if (existing.isPresent()) {
ToolComponent e = existing.get();
getOrCreate(e::getRules, e::setRules, ArrayList::new)
.add(descriptor);
} else {
getOrCreate(tool::getExtensions, tool::setExtensions, HashSet::new)
// we don't want to copy all rules from the source AND not override them
.add(location.shallowCopy()
.withIsComprehensive(false)
.withRules(new ArrayList<>(Collections.singletonList(descriptor)))
);
}
}