Skip to content

Commit 8d00280

Browse files
committed
Merge commit 'cc137eb13987010bd140f08d5581cc579f695d1c' into develop
2 parents fb4d21a + cc137eb commit 8d00280

118 files changed

Lines changed: 1236 additions & 242 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/packagedcode/maven.py

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,20 @@
3737

3838
import attr
3939
import javaproperties
40+
from license_expression import Licensing
4041
from lxml import etree
4142
from packageurl import PackageURL
42-
from pymaven import pom
4343
from pymaven import artifact
44+
from pymaven import pom
4445

4546
from commoncode import filetype
4647
from commoncode import fileutils
4748
from packagedcode import models
49+
from packagedcode.models import Package
4850
from packagedcode.utils import normalize_vcs_url
4951
from packagedcode.utils import VCS_URLS
5052
from textcode import analysis
5153
from typecode import contenttype
52-
from packagedcode.models import Package
5354

5455

5556
TRACE = False
@@ -97,7 +98,7 @@ def get_package_root(cls, manifest_resource, codebase):
9798
if ancestor.name == 'META-INF':
9899
jar_root_dir = ancestor.parent(codebase)
99100
return jar_root_dir
100-
101+
101102
return manifest_resource.parent(codebase)
102103

103104
elif manifest_resource.path.endswith('META-INF/MANIFEST.MF'):
@@ -145,6 +146,85 @@ def api_data_url(self, baseurl=default_api_baseurl):
145146
filename=filename,
146147
baseurl=baseurl)
147148

149+
def compute_normalized_license(self):
150+
return compute_normalized_license(self.declared_license)
151+
152+
153+
def compute_normalized_license(declared_license):
154+
"""
155+
Return a detected license expression from a declared license mapping.
156+
"""
157+
if not declared_license:
158+
return
159+
160+
licensing = Licensing()
161+
162+
detected_licenses = []
163+
164+
for license_declaration in declared_license:
165+
# 1. try detection on the value of name if not empty and keep this
166+
name = license_declaration.get('name')
167+
via_name = models.compute_normalized_license(name)
168+
169+
# 2. try detection on the value of url if not empty and keep this
170+
url = license_declaration.get('url')
171+
via_url = models.compute_normalized_license(url)
172+
173+
# 3. try detection on the value of comment if not empty and keep this
174+
comments = license_declaration.get('comments')
175+
via_comments = models.compute_normalized_license(comments)
176+
177+
178+
if via_name:
179+
# The name should have precedence and any unknowns
180+
# in url and comment should be ignored.
181+
if via_url == 'unknown':
182+
via_url = None
183+
if via_comments == 'unknown':
184+
via_comments = None
185+
186+
# Check the three detections to decide which license to keep
187+
name_and_url = via_name == via_url
188+
name_and_comment = via_name == via_comments
189+
all_same = name_and_url and name_and_comment
190+
191+
if via_name:
192+
if all_same:
193+
detected_licenses.append(via_name)
194+
195+
# name and (url or comment) are same
196+
elif name_and_url and not via_comments:
197+
detected_licenses.append(via_name)
198+
elif name_and_comment and not via_url:
199+
detected_licenses.append(via_name)
200+
201+
else:
202+
# we have some non-unknown license detected in url or comment
203+
detections = via_name, via_url, via_comments
204+
detections = [l for l in detections if l]
205+
if detections:
206+
if len(detections) == 1:
207+
combined_expression = detections[0]
208+
else:
209+
expressions = [
210+
licensing.parse(le, simple=True) for le in detections]
211+
combined_expression = str(licensing.AND(*expressions))
212+
detected_licenses.append(combined_expression)
213+
214+
elif via_url:
215+
detected_licenses.append(via_url)
216+
elif via_comments:
217+
detected_licenses.append(via_comments)
218+
219+
if len(detected_licenses) == 1:
220+
return detected_licenses[0]
221+
222+
if detected_licenses:
223+
# Combine if pom contains more than one licenses declarations.
224+
expressions = [licensing.parse(le, simple=True) for le in detected_licenses]
225+
combined_expression = licensing.AND(*expressions)
226+
return str(combined_expression)
227+
148228

149229
def build_url(group_id, artifact_id, version, filename, baseurl='http://repo1.maven.org/maven2'):
150230
"""
@@ -973,12 +1053,7 @@ def parse(location=None, text=None, check_is_pom=True, extra_properties=None):
9731053
# complex defeinition in Maven
9741054
qualifiers['type'] = extension
9751055

976-
# TODO: we join all data in a single text: this may not be right
977-
declared_license = []
978-
for lic in pom.licenses:
979-
lt = (l for l in [lic['name'], lic['url'], lic['comments']] if l)
980-
declared_license.extend(lt)
981-
declared_license = '\n'.join(declared_license)
1056+
declared_license = pom.licenses
9821057

9831058
source_packages = []
9841059
# TODO: what does this mean????

tests/packagedcode/data/m2/aopalliance/aopalliance/1.0/aopalliance-1.0.pom.package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@
2121
"code_view_url": null,
2222
"vcs_url": null,
2323
"copyright": null,
24-
"license_expression": null,
25-
"declared_license": "Public Domain",
24+
"license_expression": "public-domain",
25+
"declared_license": [
26+
{
27+
"name": "Public Domain",
28+
"url": null,
29+
"comments": null,
30+
"distribution": null
31+
}
32+
],
2633
"notice_text": null,
2734
"manifest_path": null,
2835
"dependencies": [],

tests/packagedcode/data/m2/aspectj/aspectjrt/1.5.3/aspectjrt-1.5.3.pom.package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@
2121
"code_view_url": null,
2222
"vcs_url": null,
2323
"copyright": null,
24-
"license_expression": null,
25-
"declared_license": "Eclipse Public License - v 1.0\nhttp://www.eclipse.org/legal/epl-v10.html",
24+
"license_expression": "epl-1.0",
25+
"declared_license": [
26+
{
27+
"name": "Eclipse Public License - v 1.0",
28+
"url": "http://www.eclipse.org/legal/epl-v10.html",
29+
"comments": null,
30+
"distribution": "repo"
31+
}
32+
],
2633
"notice_text": null,
2734
"manifest_path": null,
2835
"dependencies": [],

tests/packagedcode/data/m2/biz/aQute/bndlib/0.0.203/bndlib-0.0.203.pom.package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@
2929
"code_view_url": null,
3030
"vcs_url": null,
3131
"copyright": null,
32-
"license_expression": null,
33-
"declared_license": "This material is licensed under the Apache Software License, Version 2.0\nhttp://www.apache.org/licenses/LICENSE-2.0",
32+
"license_expression": "(apache-2.0 AND unknown) AND apache-2.0",
33+
"declared_license": [
34+
{
35+
"name": "This material is licensed under the Apache Software License, Version 2.0",
36+
"url": "http://www.apache.org/licenses/LICENSE-2.0",
37+
"comments": null,
38+
"distribution": "repo"
39+
}
40+
],
3441
"notice_text": null,
3542
"manifest_path": null,
3643
"dependencies": [],

tests/packagedcode/data/m2/biz/aQute/bndlib/0.0.238/bndlib-0.0.238.pom.package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@
2929
"code_view_url": null,
3030
"vcs_url": null,
3131
"copyright": null,
32-
"license_expression": null,
33-
"declared_license": "This material is licensed under the Apache Software License, Version 2.0\nhttp://www.apache.org/licenses/LICENSE-2.0",
32+
"license_expression": "(apache-2.0 AND unknown) AND apache-2.0",
33+
"declared_license": [
34+
{
35+
"name": "This material is licensed under the Apache Software License, Version 2.0",
36+
"url": "http://www.apache.org/licenses/LICENSE-2.0",
37+
"comments": null,
38+
"distribution": "repo"
39+
}
40+
],
3441
"notice_text": null,
3542
"manifest_path": null,
3643
"dependencies": [],

tests/packagedcode/data/m2/bytebuddy/pom.xml.package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@
2929
"code_view_url": "https://github.com/raphw/byte-buddy.git",
3030
"vcs_url": "git+https://github.com/raphw/byte-buddy.git",
3131
"copyright": null,
32-
"license_expression": null,
33-
"declared_license": "The Apache Software License, Version 2.0\nhttp://www.apache.org/licenses/LICENSE-2.0.txt\nA business-friendly OSS license",
32+
"license_expression": "apache-2.0",
33+
"declared_license": [
34+
{
35+
"name": "The Apache Software License, Version 2.0",
36+
"url": "http://www.apache.org/licenses/LICENSE-2.0.txt",
37+
"comments": "A business-friendly OSS license",
38+
"distribution": "repo"
39+
}
40+
],
3441
"notice_text": null,
3542
"manifest_path": null,
3643
"dependencies": [

tests/packagedcode/data/m2/c3p0/c3p0/0.9.0.4/c3p0-0.9.0.4.pom.package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@
2121
"code_view_url": null,
2222
"vcs_url": null,
2323
"copyright": null,
24-
"license_expression": null,
25-
"declared_license": "GNU LESSER GENERAL PUBLIC LICENSE\nhttp://www.gnu.org/licenses/lgpl.txt",
24+
"license_expression": "lgpl-2.0-plus AND ((gpl-1.0-plus AND lgpl-2.1-plus) AND unknown)",
25+
"declared_license": [
26+
{
27+
"name": "GNU LESSER GENERAL PUBLIC LICENSE",
28+
"url": "http://www.gnu.org/licenses/lgpl.txt",
29+
"comments": null,
30+
"distribution": null
31+
}
32+
],
2633
"notice_text": null,
2734
"manifest_path": null,
2835
"dependencies": [],

tests/packagedcode/data/m2/codec/commons-codec/1.3/commons-codec-1.3.pom.package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,15 @@
148148
"code_view_url": "http://cvs.apache.org/viewcvs/jakarta-commons/codec/",
149149
"vcs_url": "cvs+pserver:anoncvs@cvs.apache.org:/home/cvspublic:jakarta-commons/codec",
150150
"copyright": null,
151-
"license_expression": null,
152-
"declared_license": "The Apache Software License, Version 2.0\n/LICENSE.txt",
151+
"license_expression": "apache-2.0",
152+
"declared_license": [
153+
{
154+
"name": "The Apache Software License, Version 2.0",
155+
"url": "/LICENSE.txt",
156+
"comments": null,
157+
"distribution": null
158+
}
159+
],
153160
"notice_text": null,
154161
"manifest_path": null,
155162
"dependencies": [

tests/packagedcode/data/m2/collections/commons-collections/3.2/commons-collections-3.2.pom.package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,15 @@
687687
"code_view_url": "http://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk",
688688
"vcs_url": "svn+http://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk",
689689
"copyright": null,
690-
"license_expression": null,
691-
"declared_license": "The Apache Software License, Version 2.0\n/LICENSE.txt",
690+
"license_expression": "apache-2.0",
691+
"declared_license": [
692+
{
693+
"name": "The Apache Software License, Version 2.0",
694+
"url": "/LICENSE.txt",
695+
"comments": null,
696+
"distribution": null
697+
}
698+
],
692699
"notice_text": null,
693700
"manifest_path": null,
694701
"dependencies": [

tests/packagedcode/data/m2/com/jcraft/jsch/0.1.23/jsch-0.1.23.pom.package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@
2929
"code_view_url": null,
3030
"vcs_url": null,
3131
"copyright": null,
32-
"license_expression": null,
33-
"declared_license": "BSD\nhttp://www.jcraft.com/jsch/LICENSE.txt\nLicense information from http://www.jcraft.com/jsch",
32+
"license_expression": "unknown AND bsd-new",
33+
"declared_license": [
34+
{
35+
"name": "BSD",
36+
"url": "http://www.jcraft.com/jsch/LICENSE.txt",
37+
"comments": "License information from http://www.jcraft.com/jsch",
38+
"distribution": null
39+
}
40+
],
3441
"notice_text": null,
3542
"manifest_path": null,
3643
"dependencies": [],

0 commit comments

Comments
 (0)