Skip to content

Commit 4f5ed6d

Browse files
Fix bug in identifier for modified detection
Fixes a bug in LicenseDetection identifier where we were only returning UUID as identifier, and without the license-expression in the case where a detection is modified and we are calculating a new identifier. Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 95a5f33 commit 4f5ed6d

17 files changed

Lines changed: 50 additions & 46 deletions

src/licensedcode/detection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def detections_from_license_detection_mappings(
522522
return license_detections
523523

524524

525-
def get_new_identifier_from_detections(initial_detection, detections_added):
525+
def get_new_identifier_from_detections(initial_detection, detections_added, license_expression):
526526
"""
527527
Return a new UUID based on two sets of detections: `initial_detection` is
528528
the detection being modified with a list of detections (from another file region)
@@ -533,7 +533,8 @@ def get_new_identifier_from_detections(initial_detection, detections_added):
533533
for detection_mapping in detections_added
534534
]
535535
identifiers.append(initial_detection["identifier"])
536-
return get_uuid_on_content(content=sorted(identifiers))
536+
uuid = get_uuid_on_content(content=sorted(identifiers))
537+
return f"{license_expression}-{uuid}"
537538

538539

539540
@attr.s

src/licensedcode/plugin_license.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ def add_referenced_filenames_license_matches_for_detections(resource, codebase):
354354
license_detection_mapping["identifier"] = get_new_identifier_from_detections(
355355
initial_detection=license_detection_mapping,
356356
detections_added=detections_added,
357+
license_expression=license_expression,
357358
)
358359

359360
if modified:

src/packagedcode/licensing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def add_referenced_license_matches_for_package(resource, codebase, no_licenses):
136136
license_detection_mapping["identifier"] = get_new_identifier_from_detections(
137137
initial_detection=license_detection_mapping,
138138
detections_added=referenced_license_detections,
139+
license_expression=license_expression,
139140
)
140141

141142
if modified:
@@ -252,6 +253,7 @@ def add_referenced_license_detection_from_package(resource, codebase, no_license
252253
license_detection_mapping["identifier"] = get_new_identifier_from_detections(
253254
initial_detection=license_detection_mapping,
254255
detections_added=detections_added,
256+
license_expression=license_expression,
255257
)
256258

257259
if modified:

tests/licensedcode/data/plugin_license/license_reference/license-ref-see-copying.expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"detection_log": [
8585
"unknown-reference-to-local-file"
8686
],
87-
"identifier": "1c807a43-2040-70af-75aa-c343d5f2b90c"
87+
"identifier": "apache-2.0-1c807a43-2040-70af-75aa-c343d5f2b90c"
8888
}
8989
],
9090
"license_clues": [],

tests/licensedcode/data/plugin_license/license_reference/scan-ref.expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"detection_log": [
8585
"unknown-reference-to-local-file"
8686
],
87-
"identifier": "20c01557-97bd-0022-052e-56c5ed8465ea"
87+
"identifier": "mit-20c01557-97bd-0022-052e-56c5ed8465ea"
8888
}
8989
],
9090
"license_clues": [],

tests/licensedcode/data/plugin_license/license_reference/scan-unknown-reference-copyright.expected.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"detection_log": [
9191
"unknown-reference-to-local-file"
9292
],
93-
"identifier": "61f804f6-d484-92ca-09b5-26be51ac974e"
93+
"identifier": "x11-xconsortium-veillard-61f804f6-d484-92ca-09b5-26be51ac974e"
9494
}
9595
],
9696
"license_clues": [],
@@ -136,7 +136,7 @@
136136
"detection_log": [
137137
"unknown-reference-to-local-file"
138138
],
139-
"identifier": "61f804f6-d484-92ca-09b5-26be51ac974e"
139+
"identifier": "x11-xconsortium-veillard-61f804f6-d484-92ca-09b5-26be51ac974e"
140140
}
141141
],
142142
"license_clues": [],
@@ -202,7 +202,7 @@
202202
"detection_log": [
203203
"unknown-reference-to-local-file"
204204
],
205-
"identifier": "50c015bd-e4e1-c6fe-eb82-9551473dd8e1"
205+
"identifier": "x11-xconsortium-veillard-50c015bd-e4e1-c6fe-eb82-9551473dd8e1"
206206
}
207207
],
208208
"license_clues": [],

tests/licensedcode/data/plugin_license/license_reference/unknown-ref-to-key-file-root.expected.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
"detection_log": [
166166
"unknown-reference-to-local-file"
167167
],
168-
"identifier": "e46a912c-b32a-30d5-dc27-c13824253230"
168+
"identifier": "mit-e46a912c-b32a-30d5-dc27-c13824253230"
169169
}
170170
],
171171
"license_clues": [],
@@ -224,7 +224,7 @@
224224
"detection_log": [
225225
"unknown-reference-to-local-file"
226226
],
227-
"identifier": "e46a912c-b32a-30d5-dc27-c13824253230"
227+
"identifier": "mit-e46a912c-b32a-30d5-dc27-c13824253230"
228228
}
229229
],
230230
"license_clues": [],
@@ -283,7 +283,7 @@
283283
"detection_log": [
284284
"unknown-reference-to-local-file"
285285
],
286-
"identifier": "e46a912c-b32a-30d5-dc27-c13824253230"
286+
"identifier": "mit-e46a912c-b32a-30d5-dc27-c13824253230"
287287
}
288288
],
289289
"license_clues": [],
@@ -404,7 +404,7 @@
404404
"detection_log": [
405405
"unknown-reference-to-local-file"
406406
],
407-
"identifier": "ad99a349-2a14-9fe5-c6a6-366fd3b9067b"
407+
"identifier": "mit-ad99a349-2a14-9fe5-c6a6-366fd3b9067b"
408408
}
409409
],
410410
"license_clues": [],
@@ -473,7 +473,7 @@
473473
"detection_log": [
474474
"unknown-reference-to-local-file"
475475
],
476-
"identifier": "e46a912c-b32a-30d5-dc27-c13824253230"
476+
"identifier": "mit-e46a912c-b32a-30d5-dc27-c13824253230"
477477
}
478478
],
479479
"license_clues": [],

tests/packagedcode/data/license_detection/reference-at-manifest/flutter_playtabs_bridge.expected.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"matched_text": "Permission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE."
7878
}
7979
],
80-
"identifier": "a979a2a3-dfdb-02aa-2450-71641a61a264",
80+
"identifier": "mit-a979a2a3-dfdb-02aa-2450-71641a61a264",
8181
"detection_log": [
8282
"package-unknown-reference-to-local-file"
8383
]
@@ -246,7 +246,7 @@
246246
"matched_text": "Permission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE."
247247
}
248248
],
249-
"identifier": "a979a2a3-dfdb-02aa-2450-71641a61a264",
249+
"identifier": "mit-a979a2a3-dfdb-02aa-2450-71641a61a264",
250250
"detection_log": [
251251
"package-unknown-reference-to-local-file"
252252
]
@@ -320,7 +320,7 @@
320320
"detection_log": [
321321
"unknown-reference-to-local-file"
322322
],
323-
"identifier": "a979a2a3-dfdb-02aa-2450-71641a61a264"
323+
"identifier": "mit-a979a2a3-dfdb-02aa-2450-71641a61a264"
324324
}
325325
],
326326
"license_clues": [],

tests/packagedcode/data/license_detection/reference-at-manifest/flutter_playtabs_bridge_without_license.expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"matched_text": "Permission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE."
7878
}
7979
],
80-
"identifier": "a979a2a3-dfdb-02aa-2450-71641a61a264",
80+
"identifier": "mit-a979a2a3-dfdb-02aa-2450-71641a61a264",
8181
"detection_log": [
8282
"package-unknown-reference-to-local-file"
8383
]
@@ -193,7 +193,7 @@
193193
"matched_text": "Permission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE."
194194
}
195195
],
196-
"identifier": "a979a2a3-dfdb-02aa-2450-71641a61a264",
196+
"identifier": "mit-a979a2a3-dfdb-02aa-2450-71641a61a264",
197197
"detection_log": [
198198
"package-unknown-reference-to-local-file"
199199
]

tests/packagedcode/data/license_detection/reference-at-manifest/nanopb.expected.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"matched_text": "This software is provided 'as-is', without any express or \nimplied warranty. In no event will the authors be held liable \nfor any damages arising from the use of this software.\n\nPermission is granted to anyone to use this software for any \npurpose, including commercial applications, and to alter it and \nredistribute it freely, subject to the following restrictions:\n\n1. The origin of this software must not be misrepresented; you \n must not claim that you wrote the original software. If you use \n this software in a product, an acknowledgment in the product \n documentation would be appreciated but is not required.\n\n2. Altered source versions must be plainly marked as such, and \n must not be misrepresented as being the original software.\n\n3. This notice may not be removed or altered from any source \n distribution."
6565
}
6666
],
67-
"identifier": "9531c668-be8d-7a25-49eb-c18c9dcd616b",
67+
"identifier": "zlib-9531c668-be8d-7a25-49eb-c18c9dcd616b",
6868
"detection_log": [
6969
"package-unknown-reference-to-local-file"
7070
]
@@ -105,7 +105,7 @@
105105
"detection_log": []
106106
},
107107
{
108-
"identifier": "9531c668-be8d-7a25-49eb-c18c9dcd616b",
108+
"identifier": "zlib-9531c668-be8d-7a25-49eb-c18c9dcd616b",
109109
"license_expression": "zlib",
110110
"detection_count": 1,
111111
"detection_log": []
@@ -213,7 +213,7 @@
213213
"matched_text": "This software is provided 'as-is', without any express or \nimplied warranty. In no event will the authors be held liable \nfor any damages arising from the use of this software.\n\nPermission is granted to anyone to use this software for any \npurpose, including commercial applications, and to alter it and \nredistribute it freely, subject to the following restrictions:\n\n1. The origin of this software must not be misrepresented; you \n must not claim that you wrote the original software. If you use \n this software in a product, an acknowledgment in the product \n documentation would be appreciated but is not required.\n\n2. Altered source versions must be plainly marked as such, and \n must not be misrepresented as being the original software.\n\n3. This notice may not be removed or altered from any source \n distribution."
214214
}
215215
],
216-
"identifier": "9531c668-be8d-7a25-49eb-c18c9dcd616b",
216+
"identifier": "zlib-9531c668-be8d-7a25-49eb-c18c9dcd616b",
217217
"detection_log": [
218218
"package-unknown-reference-to-local-file"
219219
]
@@ -274,7 +274,7 @@
274274
"detection_log": [
275275
"unknown-reference-to-local-file"
276276
],
277-
"identifier": "9531c668-be8d-7a25-49eb-c18c9dcd616b"
277+
"identifier": "zlib-9531c668-be8d-7a25-49eb-c18c9dcd616b"
278278
}
279279
],
280280
"license_clues": [],

0 commit comments

Comments
 (0)