Skip to content

Commit fcea58e

Browse files
committed
Add NONE and default config and better sorting
1 parent 7a65065 commit fcea58e

File tree

1 file changed

+54
-24
lines changed

1 file changed

+54
-24
lines changed

.github/scripts/ort-scanner.es

+54-24
Original file line numberDiff line numberDiff line change
@@ -236,25 +236,33 @@ scan(#{ input := InputScanResult, strategy := Strategy, tool := Tool, path := Pa
236236

237237
Area = setup_scan_area(InputScanner, Path, Strategy),
238238

239-
Mappings = maps:get(~"detected_license_mapping", maps:get(~"config", InputScanner, #{}),
240-
#{ ~"LicenseRef-scancode-agpl-generic-additional-terms" => ~"NOASSERTION",
241-
~"LicenseRef-scancode-free-unknown" => ~"NOASSERTION",
242-
~"LicenseRef-scancode-generic-cla" => ~"NOASSERTION",
243-
~"LicenseRef-scancode-generic-exception" => ~"NOASSERTION",
244-
~"LicenseRef-scancode-generic-export-compliance" => ~"NOASSERTION",
245-
~"LicenseRef-scancode-generic-tos" => ~"NOASSERTION",
246-
~"LicenseRef-scancode-generic-trademark" => ~"NOASSERTION",
247-
~"LicenseRef-scancode-gpl-generic-additional-terms" => ~"NOASSERTION",
248-
~"LicenseRef-scancode-other-copyleft" => ~"NOASSERTION",
249-
~"LicenseRef-scancode-other-permissive" => ~"NOASSERTION",
250-
~"LicenseRef-scancode-patent-disclaimer" => ~"NOASSERTION",
251-
~"LicenseRef-scancode-unknown" => ~"NOASSERTION",
252-
~"LicenseRef-scancode-unknown-license-reference" => ~"NOASSERTION",
253-
~"LicenseRef-scancode-unknown-spdx" => ~"NOASSERTION",
254-
~"LicenseRef-scancode-warranty-disclaimer" => ~"NOASSERTION"}),
239+
Config = maps:get(~"config", InputScanner,
240+
#{ "skip_concluded" => false,
241+
~"skip_excluded" => false,
242+
~"include_files_without_findings" => true,
243+
~"detected_license_mapping" => #{
244+
~"LicenseRef-scancode-agpl-generic-additional-terms" => ~"NOASSERTION",
245+
~"LicenseRef-scancode-free-unknown" => ~"NOASSERTION",
246+
~"LicenseRef-scancode-generic-cla" => ~"NOASSERTION",
247+
~"LicenseRef-scancode-generic-exception" => ~"NOASSERTION",
248+
~"LicenseRef-scancode-generic-export-compliance" => ~"NOASSERTION",
249+
~"LicenseRef-scancode-generic-tos" => ~"NOASSERTION",
250+
~"LicenseRef-scancode-generic-trademark" => ~"NOASSERTION",
251+
~"LicenseRef-scancode-gpl-generic-additional-terms" => ~"NOASSERTION",
252+
~"LicenseRef-scancode-other-copyleft" => ~"NOASSERTION",
253+
~"LicenseRef-scancode-other-permissive" => ~"NOASSERTION",
254+
~"LicenseRef-scancode-patent-disclaimer" => ~"NOASSERTION",
255+
~"LicenseRef-scancode-unknown" => ~"NOASSERTION",
256+
~"LicenseRef-scancode-unknown-license-reference" => ~"NOASSERTION",
257+
~"LicenseRef-scancode-unknown-spdx" => ~"NOASSERTION",
258+
~"LicenseRef-scancode-warranty-disclaimer" => ~"NOASSERTION"
259+
},
260+
~"ignore_patterns" => [ ~"**/*.ort.yml", ~"**/*.spdx.yml", ~"**/*.spdx.yaml", ~"**/*.spdx.json", ~"**/META-INF/DEPENDENCIES", ~"**/META-INF/DEPENDENCIES.txt", ~"**/META-INF/NOTICE", ~"**/META-INF/NOTICE.txt" ]
261+
}),
255262

256263
#{ ~"scanner" := #{ ~"name" := ScannerName }} = NewScanResult =
257-
scan_area(Area, InputProvenance, Mappings, Tool),
264+
scan_area(Area, InputProvenance,
265+
maps:get(~"detected_license_mapping", Config), Tool),
258266

259267
NewScanners = #{ K => lists:usort([ScannerName | V]) || K := V <- Scanners},
260268

@@ -266,11 +274,12 @@ scan(#{ input := InputScanResult, strategy := Strategy, tool := Tool, path := Pa
266274
ok = file:write_file(
267275
maps:get(output, Args),
268276
format_scan_results(
269-
Input#{ ~"scanner" :=
270-
InputScanner#{ ~"scan_results" := deduplicate([NewScanResult | ScanResults]),
271-
~"scanners" := NewScanners }})),
277+
Input#{ ~"scanner" :=
278+
InputScanner#{ ~"config" => Config,
279+
~"scan_results" := deduplicate([NewScanResult | ScanResults]),
280+
~"scanners" := NewScanners }})),
272281

273-
do_cleanup(),
282+
%% do_cleanup()
274283

275284
ok.
276285

@@ -371,7 +380,15 @@ scan_area(Area, Provenance, Mappings, "scancode") ->
371380

372381
%% Dig deep into the scancode result and fetch all license and copyright data from it.
373382
get_new_results(#{ ~"files" := Files }, Area, Mappings) ->
374-
lists:flatmap(fun(File) -> get_new_results(File, Area, Mappings) end, Files);
383+
lists:flatmap(fun(File) -> get_new_results(File, Area, Mappings) end, Files);
384+
get_new_results(#{ ~"type" := ~"file",
385+
~"license_detections" := []
386+
} = F, Area, Mappings) ->
387+
NONEMatch = [#{ ~"matches" => [#{~"license_expression_spdx" => "NONE",
388+
~"score" => 100.0,
389+
~"start_line" => -1,
390+
~"end_line" => -1}]}],
391+
get_new_results(F#{ ~"license_detections" := NONEMatch}, Area, Mappings);
375392
get_new_results(#{ ~"type" := ~"file", ~"path" := Path,
376393
~"license_detections" := Licenses,
377394
~"copyrights" := Copyrights
@@ -455,7 +472,18 @@ batch(Filter, Batch, [H | T], Acc, Curr, Cnt) ->
455472
end.
456473

457474
format_scan_results(ScanResult) ->
458-
json:format(sort_arrays(ScanResult, fun(Key) -> Key =/= ~"scan_results" end)).
475+
json:format(sort_arrays(ScanResult,
476+
fun(Key) ->
477+
if Key =:= ~"scan_results" -> false;
478+
Key =:= ~"licenses"; Key =:= ~"copyrights" ->
479+
fun(#{ ~"location" := #{ ~"path" := AP }} = A, #{ ~"location" := #{ ~"path" := BP }} = B) ->
480+
if AP =:= BP -> A =< B;
481+
true -> AP =< BP
482+
end
483+
end;
484+
true -> true
485+
end
486+
end)).
459487

460488
sort_arrays(JSon) ->
461489
sort_arrays(JSon, fun(_) -> true end).
@@ -468,7 +496,9 @@ sort_arrays(List, KeyFun, Sort) when is_list(List) ->
468496
if Sort ->
469497
lists:sort(UnsortedArray);
470498
not Sort ->
471-
UnsortedArray
499+
UnsortedArray;
500+
is_function(Sort) ->
501+
lists:sort(Sort, UnsortedArray)
472502
end;
473503
sort_arrays(Value, _KeyFun, _Sort) -> Value.
474504

0 commit comments

Comments
 (0)