Skip to content

Commit 38e165a

Browse files
authored
Feature/adapt tests for warning (#70)
* changed each test to also check for warnings and specified which warning must be displayed Signed-off-by: Anton Utz <uta5fe@bosch.com> * implemented change requests Signed-off-by: Anton Utz <uta5fe@bosch.com> * linter issues Signed-off-by: Anton Utz <uta5fe@bosch.com> * added location of check Signed-off-by: Anton Utz <uta5fe@bosch.com> * added check class Signed-off-by: Anton Utz <uta5fe@bosch.com> * added test for xml conformity Signed-off-by: Anton Utz <uta5fe@bosch.com> * added check for validating xml with scheme, output not yet processed though Signed-off-by: Anton Utz <uta5fe@bosch.com> * created whole check out of validation function. introduced success and failure messages Signed-off-by: Anton Utz <uta5fe@bosch.com> * corrected double code Signed-off-by: Anton Utz <uta5fe@bosch.com> * moved check to extra file Signed-off-by: Anton Utz <uta5fe@bosch.com> * fixed imports and whitespaces Signed-off-by: Anton Utz <uta5fe@bosch.com> * changed if structure of _check method Signed-off-by: Anton Utz <uta5fe@bosch.com> * changed tests to all fullfill scheme version Signed-off-by: Anton Utz <uta5fe@bosch.com> * changed test data with source-file attribute to version 4 Signed-off-by: Anton Utz <uta5fe@bosch.com> * added case for package.xml version 4 Signed-off-by: Anton Utz <uta5fe@bosch.com> * removed todo Signed-off-by: Anton Utz <uta5fe@bosch.com> * adapted wrong test Signed-off-by: Anton Utz <uta5fe@bosch.com> * moved version checking and xml tree conversion to package.py Signed-off-by: Anton Utz <uta5fe@bosch.com> * refactor of schema check Signed-off-by: Anton Utz <uta5fe@bosch.com> * fixed bug Signed-off-by: Anton Utz <uta5fe@bosch.com> * implemented suggestions Signed-off-by: Anton Utz <uta5fe@bosch.com> --------- Signed-off-by: Anton Utz <uta5fe@bosch.com>
1 parent 6d7a45d commit 38e165a

File tree

40 files changed

+624
-21
lines changed

40 files changed

+624
-21
lines changed

schemas/package_common.xsd

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<xs:simpleType name="VersionType">
4+
<xs:annotation>
5+
<xs:documentation>
6+
The version number must have the form "X.Y.Z" where X, Y, and Z
7+
are non-negative integers, and must not contain leading zeroes.
8+
</xs:documentation>
9+
</xs:annotation>
10+
<xs:restriction base="xs:token">
11+
<xs:pattern value="(0|[1-9][0-9]*)(.(0|[1-9][0-9]*)){2}"/>
12+
</xs:restriction>
13+
</xs:simpleType>
14+
15+
<xs:complexType name="DescriptionType" mixed="true">
16+
<xs:annotation>
17+
<xs:documentation>
18+
The description allows any content but should be limited to XHTML.
19+
</xs:documentation>
20+
</xs:annotation>
21+
<xs:sequence>
22+
<xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
23+
</xs:sequence>
24+
</xs:complexType>
25+
26+
<xs:simpleType name="EmailType">
27+
<xs:annotation>
28+
<xs:documentation>
29+
A valid email address must follow several complex rules
30+
(see https://en.wikipedia.org/wiki/Email_address).
31+
For ROS packages only a few are enforced, and not the full character set
32+
is supported.
33+
</xs:documentation>
34+
</xs:annotation>
35+
<xs:restriction base="xs:token">
36+
<xs:pattern value="[-a-zA-Z0-9_%+]+(\.[-a-zA-Z0-9_%+]+)*@[-a-zA-Z0-9%]+(\.[-a-zA-Z0-9%]+)*\.[a-zA-Z]{2,}"/>
37+
</xs:restriction>
38+
</xs:simpleType>
39+
40+
<xs:complexType name="PersonWithEmailType">
41+
<xs:simpleContent>
42+
<xs:extension base="xs:token">
43+
<xs:attribute name="email" type="EmailType" use="required"/>
44+
</xs:extension>
45+
</xs:simpleContent>
46+
</xs:complexType>
47+
48+
<xs:complexType name="PersonWithOptionalEmailType">
49+
<xs:simpleContent>
50+
<xs:extension base="xs:token">
51+
<xs:attribute name="email" type="EmailType" use="optional"/>
52+
</xs:extension>
53+
</xs:simpleContent>
54+
</xs:complexType>
55+
56+
<xs:simpleType name="UrlTypeEnum">
57+
<xs:restriction base="xs:token">
58+
<xs:enumeration value="website"/>
59+
<xs:enumeration value="bugtracker"/>
60+
<xs:enumeration value="repository"/>
61+
</xs:restriction>
62+
</xs:simpleType>
63+
64+
<xs:complexType name="UrlType">
65+
<xs:simpleContent>
66+
<xs:extension base="xs:anyURI">
67+
<xs:attribute name="type" type="UrlTypeEnum" use="optional" default="website"/>
68+
</xs:extension>
69+
</xs:simpleContent>
70+
</xs:complexType>
71+
72+
<xs:simpleType name="VersionLimitType">
73+
<xs:annotation>
74+
<xs:documentation>
75+
The version limit must have the form "X.Y.Z", "X.Y", or "X".
76+
See documentation for VersionType for further details.
77+
</xs:documentation>
78+
</xs:annotation>
79+
<xs:restriction base="xs:token">
80+
<xs:pattern value="(0|[1-9][0-9]*)(.(0|[1-9][0-9]*)){0,2}"/>
81+
</xs:restriction>
82+
</xs:simpleType>
83+
84+
<xs:complexType name="ExportType">
85+
<xs:sequence>
86+
<xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
87+
</xs:sequence>
88+
</xs:complexType>
89+
</xs:schema>

schemas/package_format1.xsd

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<xs:include schemaLocation="package_common.xsd"/>
4+
5+
<xs:complexType name="DependencyType">
6+
<xs:simpleContent>
7+
<xs:extension base="xs:token">
8+
<!-- The dependency must have a version less than the specified limit. -->
9+
<xs:attribute name="version_lt" type="VersionLimitType" use="optional"/>
10+
<!-- The dependency must have a version less than or equal to the specified limit. -->
11+
<xs:attribute name="version_lte" type="VersionLimitType" use="optional"/>
12+
<!-- The dependency must have a version equal to the specified limit. -->
13+
<xs:attribute name="version_eq" type="VersionLimitType" use="optional"/>
14+
<!-- The dependency must have a version greater than or equal to the specified limit. -->
15+
<xs:attribute name="version_gte" type="VersionLimitType" use="optional"/>
16+
<!-- The dependency must have a version greater than the specified limit. -->
17+
<xs:attribute name="version_gt" type="VersionLimitType" use="optional"/>
18+
</xs:extension>
19+
</xs:simpleContent>
20+
</xs:complexType>
21+
22+
<xs:element name="package">
23+
<xs:annotation>
24+
<xs:documentation>
25+
Specified in REP 127 (see http://www.ros.org/reps/rep-0127.html).
26+
</xs:documentation>
27+
</xs:annotation>
28+
<xs:complexType>
29+
<xs:sequence>
30+
<xs:element name="name" minOccurs="1" maxOccurs="1">
31+
<xs:annotation>
32+
<xs:documentation>
33+
The package name should be unique within the ROS community.
34+
It may differ from the folder name into which it is checked out,
35+
but that is not recommended.
36+
It must start with a lower-case letter and consist of only
37+
lower-case letters, numbers and underscores.
38+
It must not have two consecutive underscores.
39+
</xs:documentation>
40+
</xs:annotation>
41+
<xs:simpleType>
42+
<xs:restriction base="xs:token">
43+
<xs:pattern value="[a-z](_?[a-z0-9]+)*"/>
44+
</xs:restriction>
45+
</xs:simpleType>
46+
</xs:element>
47+
<xs:element name="version" type="VersionType" minOccurs="1" maxOccurs="1"/>
48+
<xs:element name="description" type="DescriptionType" minOccurs="1" maxOccurs="1"/>
49+
<xs:element name="maintainer" type="PersonWithEmailType" minOccurs="1" maxOccurs="unbounded"/>
50+
<xs:element name="license" type="xs:token" minOccurs="1" maxOccurs="unbounded"/>
51+
52+
<xs:element name="url" type="UrlType" minOccurs="0" maxOccurs="unbounded"/>
53+
<xs:element name="author" type="PersonWithOptionalEmailType" minOccurs="0" maxOccurs="unbounded"/>
54+
55+
<xs:choice minOccurs="0" maxOccurs="unbounded">
56+
<xs:element type="DependencyType" name="build_depend"/>
57+
<xs:element type="DependencyType" name="buildtool_depend"/>
58+
<xs:element type="DependencyType" name="run_depend"/>
59+
<xs:element type="DependencyType" name="test_depend"/>
60+
<xs:element type="DependencyType" name="conflict"/>
61+
<xs:element type="DependencyType" name="replace"/>
62+
</xs:choice>
63+
64+
<xs:element name="export" type="ExportType" minOccurs="0" maxOccurs="1"/>
65+
</xs:sequence>
66+
<xs:attribute name="format" fixed="1" use="optional"/>
67+
</xs:complexType>
68+
</xs:element>
69+
</xs:schema>

schemas/package_format2.xsd

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<xs:include schemaLocation="package_common.xsd"/>
4+
5+
<xs:complexType name="DependencyType">
6+
<xs:simpleContent>
7+
<xs:extension base="xs:token">
8+
<!-- The dependency must have a version less than the specified limit. -->
9+
<xs:attribute name="version_lt" type="VersionLimitType" use="optional"/>
10+
<!-- The dependency must have a version less than or equal to the specified limit. -->
11+
<xs:attribute name="version_lte" type="VersionLimitType" use="optional"/>
12+
<!-- The dependency must have a version equal to the specified limit. -->
13+
<xs:attribute name="version_eq" type="VersionLimitType" use="optional"/>
14+
<!-- The dependency must have a version greater than or equal to the specified limit. -->
15+
<xs:attribute name="version_gte" type="VersionLimitType" use="optional"/>
16+
<!-- The dependency must have a version greater than the specified limit. -->
17+
<xs:attribute name="version_gt" type="VersionLimitType" use="optional"/>
18+
</xs:extension>
19+
</xs:simpleContent>
20+
</xs:complexType>
21+
22+
<xs:element name="package">
23+
<xs:annotation>
24+
<xs:documentation>
25+
Specified in REP 140 (see http://www.ros.org/reps/rep-0140.html).
26+
</xs:documentation>
27+
</xs:annotation>
28+
<xs:complexType>
29+
<xs:sequence>
30+
<xs:element name="name" minOccurs="1" maxOccurs="1">
31+
<xs:annotation>
32+
<xs:documentation>
33+
The package name should be unique within the ROS community.
34+
It may differ from the folder name into which it is checked out,
35+
but that is not recommended.
36+
It must start with a lower-case letter and consist of only
37+
lower-case letters, numbers and underscores.
38+
It must not have two consecutive underscores.
39+
</xs:documentation>
40+
</xs:annotation>
41+
<xs:simpleType>
42+
<xs:restriction base="xs:token">
43+
<xs:pattern value="[a-z](_?[a-z0-9]+)*"/>
44+
</xs:restriction>
45+
</xs:simpleType>
46+
</xs:element>
47+
<xs:element name="version" type="VersionType" minOccurs="1" maxOccurs="1"/>
48+
<xs:element name="description" type="DescriptionType" minOccurs="1" maxOccurs="1"/>
49+
<xs:element name="maintainer" type="PersonWithEmailType" minOccurs="1" maxOccurs="unbounded"/>
50+
<xs:element name="license" type="xs:token" minOccurs="1" maxOccurs="unbounded"/>
51+
52+
<xs:element name="url" type="UrlType" minOccurs="0" maxOccurs="unbounded"/>
53+
<xs:element name="author" type="PersonWithOptionalEmailType" minOccurs="0" maxOccurs="unbounded"/>
54+
55+
<xs:choice minOccurs="0" maxOccurs="unbounded">
56+
<xs:element type="DependencyType" name="build_depend"/>
57+
<xs:element type="DependencyType" name="build_export_depend"/>
58+
<xs:element type="DependencyType" name="buildtool_depend"/>
59+
<xs:element type="DependencyType" name="buildtool_export_depend"/>
60+
<xs:element type="DependencyType" name="exec_depend"/>
61+
<xs:element type="DependencyType" name="depend"/>
62+
<xs:element type="DependencyType" name="doc_depend"/>
63+
<xs:element type="DependencyType" name="test_depend"/>
64+
<xs:element type="DependencyType" name="conflict"/>
65+
<xs:element type="DependencyType" name="replace"/>
66+
</xs:choice>
67+
68+
<xs:element name="export" type="ExportType" minOccurs="0" maxOccurs="1"/>
69+
</xs:sequence>
70+
<xs:attribute name="format" fixed="2" use="required"/>
71+
</xs:complexType>
72+
</xs:element>
73+
</xs:schema>

schemas/package_format3.xsd

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<xs:include schemaLocation="package_common.xsd"/>
4+
5+
<xs:complexType name="ConditionalType">
6+
<xs:simpleContent>
7+
<xs:extension base="xs:token">
8+
<xs:attribute name="condition" use="optional">
9+
<xs:simpleType>
10+
<xs:restriction base="xs:token">
11+
<xs:pattern value="[$A-Za-z0-9_\s&lt;&gt;!=()-]*"/>
12+
</xs:restriction>
13+
</xs:simpleType>
14+
</xs:attribute>
15+
</xs:extension>
16+
</xs:simpleContent>
17+
</xs:complexType>
18+
19+
<xs:complexType name="DependencyType">
20+
<xs:simpleContent>
21+
<xs:extension base="xs:token">
22+
<!-- The dependency must have a version less than the specified limit. -->
23+
<xs:attribute name="version_lt" type="VersionLimitType" use="optional"/>
24+
<!-- The dependency must have a version less than or equal to the specified limit. -->
25+
<xs:attribute name="version_lte" type="VersionLimitType" use="optional"/>
26+
<!-- The dependency must have a version equal to the specified limit. -->
27+
<xs:attribute name="version_eq" type="VersionLimitType" use="optional"/>
28+
<!-- The dependency must have a version greater than or equal to the specified limit. -->
29+
<xs:attribute name="version_gte" type="VersionLimitType" use="optional"/>
30+
<!-- The dependency must have a version greater than the specified limit. -->
31+
<xs:attribute name="version_gt" type="VersionLimitType" use="optional"/>
32+
<xs:attribute name="condition" use="optional">
33+
<xs:simpleType>
34+
<xs:restriction base="xs:token">
35+
<xs:pattern value="[$A-Za-z0-9_\s&quot;'&lt;&gt;!=()-]*"/>
36+
</xs:restriction>
37+
</xs:simpleType>
38+
</xs:attribute>
39+
</xs:extension>
40+
</xs:simpleContent>
41+
</xs:complexType>
42+
43+
<xs:complexType name="LicenseType">
44+
<xs:simpleContent>
45+
<xs:extension base="xs:token">
46+
<xs:attribute name="file" type="xs:token" use="optional"/>
47+
</xs:extension>
48+
</xs:simpleContent>
49+
</xs:complexType>
50+
51+
<xs:complexType name="VersionWithOptionalCompatibilityType">
52+
<xs:simpleContent>
53+
<xs:extension base="VersionType">
54+
<xs:attribute name="compatibility" type="VersionLimitType" use="optional"/>
55+
</xs:extension>
56+
</xs:simpleContent>
57+
</xs:complexType>
58+
59+
<xs:element name="package">
60+
<xs:annotation>
61+
<xs:documentation>
62+
Specified in REP 149 (see http://www.ros.org/reps/rep-0149.html).
63+
</xs:documentation>
64+
</xs:annotation>
65+
<xs:complexType>
66+
<xs:sequence>
67+
<xs:element name="name" minOccurs="1" maxOccurs="1">
68+
<xs:annotation>
69+
<xs:documentation>
70+
The package name should be unique within the ROS community.
71+
It may differ from the folder name into which it is checked out,
72+
but that is not recommended.
73+
It must start with a lower-case letter and consist of only
74+
lower-case letters, numbers and underscores.
75+
It must not have two consecutive underscores.
76+
</xs:documentation>
77+
</xs:annotation>
78+
<xs:simpleType>
79+
<xs:restriction base="xs:token">
80+
<xs:pattern value="[a-z](_?[a-z0-9]+)*"/>
81+
</xs:restriction>
82+
</xs:simpleType>
83+
</xs:element>
84+
<xs:element name="version" type="VersionType" minOccurs="1" maxOccurs="1"/>
85+
<xs:element name="description" type="DescriptionType" minOccurs="1" maxOccurs="1"/>
86+
<xs:element name="maintainer" type="PersonWithEmailType" minOccurs="1" maxOccurs="unbounded"/>
87+
<xs:element name="license" type="LicenseType" minOccurs="1" maxOccurs="unbounded"/>
88+
89+
<xs:element name="url" type="UrlType" minOccurs="0" maxOccurs="unbounded"/>
90+
<xs:element name="author" type="PersonWithOptionalEmailType" minOccurs="0" maxOccurs="unbounded"/>
91+
92+
<xs:choice minOccurs="0" maxOccurs="unbounded">
93+
<xs:element type="DependencyType" name="build_depend"/>
94+
<xs:element type="DependencyType" name="build_export_depend"/>
95+
<xs:element type="DependencyType" name="buildtool_depend"/>
96+
<xs:element type="DependencyType" name="buildtool_export_depend"/>
97+
<xs:element type="DependencyType" name="exec_depend"/>
98+
<xs:element type="DependencyType" name="depend"/>
99+
<xs:element type="DependencyType" name="doc_depend"/>
100+
<xs:element type="DependencyType" name="test_depend"/>
101+
<xs:element type="DependencyType" name="conflict"/>
102+
<xs:element type="DependencyType" name="replace"/>
103+
</xs:choice>
104+
105+
<xs:element name="group_depend" type="ConditionalType" minOccurs="0" maxOccurs="unbounded"/>
106+
<xs:element name="member_of_group" type="ConditionalType" minOccurs="0" maxOccurs="unbounded"/>
107+
108+
<xs:element name="export" type="ExportType" minOccurs="0" maxOccurs="1"/>
109+
</xs:sequence>
110+
<xs:attribute name="format" fixed="3" use="required"/>
111+
</xs:complexType>
112+
</xs:element>
113+
</xs:schema>

src/ros_license_toolkit/license_checks/license_in_code_check.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self: 'LicensesInCodeCheck'):
3333
self.declared_licenses: Dict[str, LicenseTag] = {}
3434
self.files_with_uncovered_licenses: Dict[str, List[str]] = {}
3535
self.files_not_matched_by_any_license_tag: Dict[str, List[str]] = {}
36-
self.files_with_inofficial_tag: Dict[str, List[str]] = {}
36+
self.files_with_unofficial_tag: Dict[str, List[str]] = {}
3737

3838
def _check(self, package: Package):
3939
if len(package.license_tags) == 0:
@@ -55,18 +55,18 @@ def _check_license_files(self, package: Package) -> None:
5555
licenses = found_licenses_str.split(' AND ')
5656
for license_str in licenses:
5757
if license_str not in self.declared_licenses:
58-
# this license has an inofficial tag
59-
inofficial_licenses = {
58+
# this license has an unofficial tag
59+
unofficial_licenses = {
6060
lic_tag.id_from_license_text: key
6161
for key, lic_tag in package.license_tags.items()
6262
if lic_tag.id_from_license_text != ''}
63-
if license_str in inofficial_licenses.keys():
64-
if fname not in self.files_with_inofficial_tag:
65-
self.files_with_inofficial_tag[fname] = []
66-
self.files_with_inofficial_tag[fname].append(
63+
if license_str in unofficial_licenses.keys():
64+
if fname not in self.files_with_unofficial_tag:
65+
self.files_with_unofficial_tag[fname] = []
66+
self.files_with_unofficial_tag[fname].append(
6767
license_str)
68-
self.files_with_inofficial_tag[fname].append(
69-
inofficial_licenses[license_str])
68+
self.files_with_unofficial_tag[fname].append(
69+
unofficial_licenses[license_str])
7070
continue
7171
# this license is not declared by any license tag
7272
if fname not in self.files_with_uncovered_licenses:
@@ -97,13 +97,13 @@ def _evaluate_result(self, package: Package) -> None:
9797
self.files_not_matched_by_any_license_tag,
9898
package,
9999
)
100-
elif self.files_with_inofficial_tag:
100+
elif self.files_with_unofficial_tag:
101101
info_str = ''
102102
info_str += 'For the following files, please change the ' +\
103103
'License Tag in the package file to SPDX format:\n' +\
104104
'\n'.join(
105105
[f" '{x[0]}' is of {x[1][0]} but its Tag is {x[1][1]}."
106-
for x in self.files_with_inofficial_tag.items()])
106+
for x in self.files_with_unofficial_tag.items()])
107107
self._warning(info_str)
108108
elif len(self.files_not_matched_by_any_license_tag) > 0:
109109
info_str = ''

0 commit comments

Comments
 (0)