Skip to content

Commit edd7974

Browse files
Fix unknown license clues bug
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent 0988c72 commit edd7974

File tree

10 files changed

+396
-13
lines changed

10 files changed

+396
-13
lines changed

etc/scripts/licenses/buildrules-template.txt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
----------------------------------------
2-
license_expression:
3-
relevance: 100
4-
minimum_coverage: 90
2+
license_expression: apache-2.0
53
is_license_notice: yes
6-
is_license_text: yes
7-
is_license_reference: yes
8-
is_license_tag: yes
9-
is_false_positive: yes
10-
is_license_intro: yes
11-
is_license_clue: yes
124
referenced_filenames:
13-
notes:
5+
- ASL2.0
6+
notes: seen in woodstox
147
---
8+
This copy of is licensed under the
9+
{{Apache (Software) License, version 2.0 ("the License")}}.
10+
See the License for details about distribution rights, and the
11+
specific rights regarding derivate works.
12+
13+
You may obtain a copy of the License at:
14+
15+
http://www.apache.org/licenses/
1516

17+
A copy is also included in the downloadable source code package
18+
containing , in file {{"ASL2.0"}}, under the same directory
19+
as this file.
1620
----------------------------------------
1721
license_expression:
1822
relevance: 100
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
license_expression: unknown-license-reference
3+
is_license_clue: yes
4+
notes: Seen in woodstox
5+
---
6+
7+
This product currently only contains code developed by authors of specific components, as identified by the source code files.

src/licensedcode/data/rules/unknown-license-reference_354.RULE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
license_expression: unknown-license-reference
33
is_license_reference: yes
4+
is_deprecated: yes
45
notes: Seen in woodstox
56
---
67

src/licensedcode/detection.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,21 @@ def is_undetected_license_matches(license_matches):
927927
return True
928928

929929

930+
def is_correct_detection_non_unknown(license_matches):
931+
"""
932+
Return True if all the matches in ``license_matches`` List of LicenseMatch
933+
are correct/perfect license detections and also there aren't any unknowns.
934+
"""
935+
return (
936+
is_correct_detection(license_matches)
937+
and not has_unknown_matches(license_matches)
938+
)
939+
940+
930941
def is_correct_detection(license_matches):
931942
"""
932943
Return True if all the matches in ``license_matches`` List of LicenseMatch
933-
are correct license detections.
944+
are perfect license detections.
934945
"""
935946
matchers = (license_match.matcher for license_match in license_matches)
936947
is_match_coverage_perfect = [
@@ -940,7 +951,7 @@ def is_correct_detection(license_matches):
940951

941952
return (
942953
all(matcher in ("1-hash", "1-spdx-id", "2-aho") for matcher in matchers)
943-
and all(is_match_coverage_perfect) and not has_unknown_matches(license_matches)
954+
and all(is_match_coverage_perfect)
944955
)
945956

946957

@@ -1088,6 +1099,14 @@ def is_unknown_intro(license_match):
10881099
)
10891100

10901101

1102+
def has_correct_license_clue_matches(license_matches):
1103+
"""
1104+
Return True if all the matches in ``license_matches`` List of LicenseMatch
1105+
has True for the `is_license_clue` rule attribute.
1106+
"""
1107+
return is_correct_detection(license_matches) and all(match.rule.is_license_clue for match in license_matches)
1108+
1109+
10911110
def is_license_clues(license_matches):
10921111
"""
10931112
Return True if the license_matches are not part of a correct
@@ -1480,9 +1499,12 @@ def analyze_detection(license_matches, package_license=False):
14801499
return DetectionCategory.FALSE_POSITVE.value
14811500

14821501
# Case where all matches have `matcher` as `1-hash` or `4-spdx-id`
1483-
elif is_correct_detection(license_matches=license_matches):
1502+
elif is_correct_detection_non_unknown(license_matches=license_matches):
14841503
return DetectionCategory.PERFECT_DETECTION.value
14851504

1505+
elif has_correct_license_clue_matches(license_matches=license_matches):
1506+
return DetectionCategory.LICENSE_CLUES.value
1507+
14861508
# Case where even though the matches have perfect coverage, they have
14871509
# matches with `unknown` rule identifiers
14881510
elif has_unknown_matches(license_matches=license_matches):

tests/licensedcode/data/plugin_license/clues/woodstox.expected.json

Lines changed: 293 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
Apache License
3+
Version 2.0, January 2004
4+
http://www.apache.org/licenses/
5+
6+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
This copy of Woodstox XML processor is licensed under the
2+
Apache (Software) License, version 2.0 ("the License").
3+
See the License for details about distribution rights, and the
4+
specific rights regarding derivate works.
5+
6+
You may obtain a copy of the License at:
7+
8+
http://www.apache.org/licenses/
9+
10+
A copy is also included in the downloadable source code package
11+
containing Woodstox, in file "ASL2.0", under the same directory
12+
as this file.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Manifest-Version: 1.0
2+
Ant-Version: Apache Ant 1.6.5
3+
Created-By: 1.5.0_14-b03 (Sun Microsystems Inc.)
4+
Built-By: tatu
5+
Specification-Title: StAX 1.0 API
6+
Specification-Version: 1.0
7+
Specification-Vendor: http://jcp.org/en/jsr/detail?id=173
8+
Implementation-Title: WoodSToX XML-processor
9+
Implementation-Version: 3.2.8
10+
Implementation-Vendor: woodstox.codehaus.org
11+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This product currently only contains code developed by authors
2+
of specific components, as identified by the source code files.
3+
4+
Since product implements StAX API, it has dependencies to StAX API
5+
classes.
6+
7+
For additional credits (generally to people who reported problems)
8+
see CREDITS file.

tests/licensedcode/test_plugin_license_detection.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ def test_license_match_unknown_license_intro_with_dual_license():
7474
check_json_scan(test_loc, result_file, regen=REGEN_TEST_FIXTURES)
7575

7676

77+
def test_license_match_unknown_clues_is_not_in_expression():
78+
test_dir = test_env.get_test_loc('plugin_license/clues/woodstox/', copy=True)
79+
result_file = test_env.get_temp_file('json')
80+
args = [
81+
'--license',
82+
'--license-text',
83+
'--license-text-diagnostics',
84+
'--license-diagnostics',
85+
'--license-references',
86+
'--strip-root',
87+
'--verbose',
88+
'--json', result_file,
89+
test_dir,
90+
]
91+
run_scan_click(args)
92+
test_loc = test_env.get_test_loc('plugin_license/clues/woodstox.expected.json')
93+
check_json_scan(test_loc, result_file, regen=REGEN_TEST_FIXTURES)
94+
95+
7796
def test_license_match_unknown_license_intro_eclipse_foundation():
7897
test_dir = test_env.get_test_loc('plugin_license/unknown_intro/scan-unknown-intro-eclipse-foundation/', copy=True)
7998
result_file = test_env.get_temp_file('json')

0 commit comments

Comments
 (0)