Skip to content

Commit

Permalink
Feature/adapt tests for warning (#70)
Browse files Browse the repository at this point in the history
* changed each test to also check for warnings and specified which warning must be displayed

Signed-off-by: Anton Utz <[email protected]>

* implemented change requests

Signed-off-by: Anton Utz <[email protected]>

* linter issues

Signed-off-by: Anton Utz <[email protected]>

* added location of check

Signed-off-by: Anton Utz <[email protected]>

* added check class

Signed-off-by: Anton Utz <[email protected]>

* added test for xml conformity

Signed-off-by: Anton Utz <[email protected]>

* added check for validating xml with scheme, output not yet processed though

Signed-off-by: Anton Utz <[email protected]>

* created whole check out of validation function. introduced success and failure messages

Signed-off-by: Anton Utz <[email protected]>

* corrected double code

Signed-off-by: Anton Utz <[email protected]>

* moved check to extra file

Signed-off-by: Anton Utz <[email protected]>

* fixed imports and whitespaces

Signed-off-by: Anton Utz <[email protected]>

* changed if structure of _check method

Signed-off-by: Anton Utz <[email protected]>

* changed tests to all fullfill scheme version

Signed-off-by: Anton Utz <[email protected]>

* changed test data with source-file attribute to version 4

Signed-off-by: Anton Utz <[email protected]>

* added case for package.xml version 4

Signed-off-by: Anton Utz <[email protected]>

* removed todo

Signed-off-by: Anton Utz <[email protected]>

* adapted wrong test

Signed-off-by: Anton Utz <[email protected]>

* moved version checking and xml tree conversion to package.py

Signed-off-by: Anton Utz <[email protected]>

* refactor of schema check

Signed-off-by: Anton Utz <[email protected]>

* fixed bug

Signed-off-by: Anton Utz <[email protected]>

* implemented suggestions

Signed-off-by: Anton Utz <[email protected]>

---------

Signed-off-by: Anton Utz <[email protected]>
  • Loading branch information
ant-u authored Dec 9, 2024
1 parent 6d7a45d commit 38e165a
Show file tree
Hide file tree
Showing 40 changed files with 624 additions and 21 deletions.
89 changes: 89 additions & 0 deletions schemas/package_common.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="VersionType">
<xs:annotation>
<xs:documentation>
The version number must have the form "X.Y.Z" where X, Y, and Z
are non-negative integers, and must not contain leading zeroes.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:token">
<xs:pattern value="(0|[1-9][0-9]*)(.(0|[1-9][0-9]*)){2}"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="DescriptionType" mixed="true">
<xs:annotation>
<xs:documentation>
The description allows any content but should be limited to XHTML.
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:simpleType name="EmailType">
<xs:annotation>
<xs:documentation>
A valid email address must follow several complex rules
(see https://en.wikipedia.org/wiki/Email_address).
For ROS packages only a few are enforced, and not the full character set
is supported.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:token">
<xs:pattern value="[-a-zA-Z0-9_%+]+(\.[-a-zA-Z0-9_%+]+)*@[-a-zA-Z0-9%]+(\.[-a-zA-Z0-9%]+)*\.[a-zA-Z]{2,}"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="PersonWithEmailType">
<xs:simpleContent>
<xs:extension base="xs:token">
<xs:attribute name="email" type="EmailType" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="PersonWithOptionalEmailType">
<xs:simpleContent>
<xs:extension base="xs:token">
<xs:attribute name="email" type="EmailType" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:simpleType name="UrlTypeEnum">
<xs:restriction base="xs:token">
<xs:enumeration value="website"/>
<xs:enumeration value="bugtracker"/>
<xs:enumeration value="repository"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="UrlType">
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:attribute name="type" type="UrlTypeEnum" use="optional" default="website"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:simpleType name="VersionLimitType">
<xs:annotation>
<xs:documentation>
The version limit must have the form "X.Y.Z", "X.Y", or "X".
See documentation for VersionType for further details.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:token">
<xs:pattern value="(0|[1-9][0-9]*)(.(0|[1-9][0-9]*)){0,2}"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="ExportType">
<xs:sequence>
<xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
69 changes: 69 additions & 0 deletions schemas/package_format1.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="package_common.xsd"/>

<xs:complexType name="DependencyType">
<xs:simpleContent>
<xs:extension base="xs:token">
<!-- The dependency must have a version less than the specified limit. -->
<xs:attribute name="version_lt" type="VersionLimitType" use="optional"/>
<!-- The dependency must have a version less than or equal to the specified limit. -->
<xs:attribute name="version_lte" type="VersionLimitType" use="optional"/>
<!-- The dependency must have a version equal to the specified limit. -->
<xs:attribute name="version_eq" type="VersionLimitType" use="optional"/>
<!-- The dependency must have a version greater than or equal to the specified limit. -->
<xs:attribute name="version_gte" type="VersionLimitType" use="optional"/>
<!-- The dependency must have a version greater than the specified limit. -->
<xs:attribute name="version_gt" type="VersionLimitType" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:element name="package">
<xs:annotation>
<xs:documentation>
Specified in REP 127 (see http://www.ros.org/reps/rep-0127.html).
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="name" minOccurs="1" maxOccurs="1">
<xs:annotation>
<xs:documentation>
The package name should be unique within the ROS community.
It may differ from the folder name into which it is checked out,
but that is not recommended.
It must start with a lower-case letter and consist of only
lower-case letters, numbers and underscores.
It must not have two consecutive underscores.
</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:pattern value="[a-z](_?[a-z0-9]+)*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="version" type="VersionType" minOccurs="1" maxOccurs="1"/>
<xs:element name="description" type="DescriptionType" minOccurs="1" maxOccurs="1"/>
<xs:element name="maintainer" type="PersonWithEmailType" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="license" type="xs:token" minOccurs="1" maxOccurs="unbounded"/>

<xs:element name="url" type="UrlType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="author" type="PersonWithOptionalEmailType" minOccurs="0" maxOccurs="unbounded"/>

<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element type="DependencyType" name="build_depend"/>
<xs:element type="DependencyType" name="buildtool_depend"/>
<xs:element type="DependencyType" name="run_depend"/>
<xs:element type="DependencyType" name="test_depend"/>
<xs:element type="DependencyType" name="conflict"/>
<xs:element type="DependencyType" name="replace"/>
</xs:choice>

<xs:element name="export" type="ExportType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="format" fixed="1" use="optional"/>
</xs:complexType>
</xs:element>
</xs:schema>
73 changes: 73 additions & 0 deletions schemas/package_format2.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="package_common.xsd"/>

<xs:complexType name="DependencyType">
<xs:simpleContent>
<xs:extension base="xs:token">
<!-- The dependency must have a version less than the specified limit. -->
<xs:attribute name="version_lt" type="VersionLimitType" use="optional"/>
<!-- The dependency must have a version less than or equal to the specified limit. -->
<xs:attribute name="version_lte" type="VersionLimitType" use="optional"/>
<!-- The dependency must have a version equal to the specified limit. -->
<xs:attribute name="version_eq" type="VersionLimitType" use="optional"/>
<!-- The dependency must have a version greater than or equal to the specified limit. -->
<xs:attribute name="version_gte" type="VersionLimitType" use="optional"/>
<!-- The dependency must have a version greater than the specified limit. -->
<xs:attribute name="version_gt" type="VersionLimitType" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:element name="package">
<xs:annotation>
<xs:documentation>
Specified in REP 140 (see http://www.ros.org/reps/rep-0140.html).
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="name" minOccurs="1" maxOccurs="1">
<xs:annotation>
<xs:documentation>
The package name should be unique within the ROS community.
It may differ from the folder name into which it is checked out,
but that is not recommended.
It must start with a lower-case letter and consist of only
lower-case letters, numbers and underscores.
It must not have two consecutive underscores.
</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:pattern value="[a-z](_?[a-z0-9]+)*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="version" type="VersionType" minOccurs="1" maxOccurs="1"/>
<xs:element name="description" type="DescriptionType" minOccurs="1" maxOccurs="1"/>
<xs:element name="maintainer" type="PersonWithEmailType" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="license" type="xs:token" minOccurs="1" maxOccurs="unbounded"/>

<xs:element name="url" type="UrlType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="author" type="PersonWithOptionalEmailType" minOccurs="0" maxOccurs="unbounded"/>

<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element type="DependencyType" name="build_depend"/>
<xs:element type="DependencyType" name="build_export_depend"/>
<xs:element type="DependencyType" name="buildtool_depend"/>
<xs:element type="DependencyType" name="buildtool_export_depend"/>
<xs:element type="DependencyType" name="exec_depend"/>
<xs:element type="DependencyType" name="depend"/>
<xs:element type="DependencyType" name="doc_depend"/>
<xs:element type="DependencyType" name="test_depend"/>
<xs:element type="DependencyType" name="conflict"/>
<xs:element type="DependencyType" name="replace"/>
</xs:choice>

<xs:element name="export" type="ExportType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="format" fixed="2" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
113 changes: 113 additions & 0 deletions schemas/package_format3.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="package_common.xsd"/>

<xs:complexType name="ConditionalType">
<xs:simpleContent>
<xs:extension base="xs:token">
<xs:attribute name="condition" use="optional">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:pattern value="[$A-Za-z0-9_\s&lt;&gt;!=()-]*"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="DependencyType">
<xs:simpleContent>
<xs:extension base="xs:token">
<!-- The dependency must have a version less than the specified limit. -->
<xs:attribute name="version_lt" type="VersionLimitType" use="optional"/>
<!-- The dependency must have a version less than or equal to the specified limit. -->
<xs:attribute name="version_lte" type="VersionLimitType" use="optional"/>
<!-- The dependency must have a version equal to the specified limit. -->
<xs:attribute name="version_eq" type="VersionLimitType" use="optional"/>
<!-- The dependency must have a version greater than or equal to the specified limit. -->
<xs:attribute name="version_gte" type="VersionLimitType" use="optional"/>
<!-- The dependency must have a version greater than the specified limit. -->
<xs:attribute name="version_gt" type="VersionLimitType" use="optional"/>
<xs:attribute name="condition" use="optional">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:pattern value="[$A-Za-z0-9_\s&quot;'&lt;&gt;!=()-]*"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="LicenseType">
<xs:simpleContent>
<xs:extension base="xs:token">
<xs:attribute name="file" type="xs:token" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="VersionWithOptionalCompatibilityType">
<xs:simpleContent>
<xs:extension base="VersionType">
<xs:attribute name="compatibility" type="VersionLimitType" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:element name="package">
<xs:annotation>
<xs:documentation>
Specified in REP 149 (see http://www.ros.org/reps/rep-0149.html).
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="name" minOccurs="1" maxOccurs="1">
<xs:annotation>
<xs:documentation>
The package name should be unique within the ROS community.
It may differ from the folder name into which it is checked out,
but that is not recommended.
It must start with a lower-case letter and consist of only
lower-case letters, numbers and underscores.
It must not have two consecutive underscores.
</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:pattern value="[a-z](_?[a-z0-9]+)*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="version" type="VersionType" minOccurs="1" maxOccurs="1"/>
<xs:element name="description" type="DescriptionType" minOccurs="1" maxOccurs="1"/>
<xs:element name="maintainer" type="PersonWithEmailType" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="license" type="LicenseType" minOccurs="1" maxOccurs="unbounded"/>

<xs:element name="url" type="UrlType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="author" type="PersonWithOptionalEmailType" minOccurs="0" maxOccurs="unbounded"/>

<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element type="DependencyType" name="build_depend"/>
<xs:element type="DependencyType" name="build_export_depend"/>
<xs:element type="DependencyType" name="buildtool_depend"/>
<xs:element type="DependencyType" name="buildtool_export_depend"/>
<xs:element type="DependencyType" name="exec_depend"/>
<xs:element type="DependencyType" name="depend"/>
<xs:element type="DependencyType" name="doc_depend"/>
<xs:element type="DependencyType" name="test_depend"/>
<xs:element type="DependencyType" name="conflict"/>
<xs:element type="DependencyType" name="replace"/>
</xs:choice>

<xs:element name="group_depend" type="ConditionalType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="member_of_group" type="ConditionalType" minOccurs="0" maxOccurs="unbounded"/>

<xs:element name="export" type="ExportType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="format" fixed="3" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
22 changes: 11 additions & 11 deletions src/ros_license_toolkit/license_checks/license_in_code_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self: 'LicensesInCodeCheck'):
self.declared_licenses: Dict[str, LicenseTag] = {}
self.files_with_uncovered_licenses: Dict[str, List[str]] = {}
self.files_not_matched_by_any_license_tag: Dict[str, List[str]] = {}
self.files_with_inofficial_tag: Dict[str, List[str]] = {}
self.files_with_unofficial_tag: Dict[str, List[str]] = {}

def _check(self, package: Package):
if len(package.license_tags) == 0:
Expand All @@ -55,18 +55,18 @@ def _check_license_files(self, package: Package) -> None:
licenses = found_licenses_str.split(' AND ')
for license_str in licenses:
if license_str not in self.declared_licenses:
# this license has an inofficial tag
inofficial_licenses = {
# this license has an unofficial tag
unofficial_licenses = {
lic_tag.id_from_license_text: key
for key, lic_tag in package.license_tags.items()
if lic_tag.id_from_license_text != ''}
if license_str in inofficial_licenses.keys():
if fname not in self.files_with_inofficial_tag:
self.files_with_inofficial_tag[fname] = []
self.files_with_inofficial_tag[fname].append(
if license_str in unofficial_licenses.keys():
if fname not in self.files_with_unofficial_tag:
self.files_with_unofficial_tag[fname] = []
self.files_with_unofficial_tag[fname].append(
license_str)
self.files_with_inofficial_tag[fname].append(
inofficial_licenses[license_str])
self.files_with_unofficial_tag[fname].append(
unofficial_licenses[license_str])
continue
# this license is not declared by any license tag
if fname not in self.files_with_uncovered_licenses:
Expand Down Expand Up @@ -97,13 +97,13 @@ def _evaluate_result(self, package: Package) -> None:
self.files_not_matched_by_any_license_tag,
package,
)
elif self.files_with_inofficial_tag:
elif self.files_with_unofficial_tag:
info_str = ''
info_str += 'For the following files, please change the ' +\
'License Tag in the package file to SPDX format:\n' +\
'\n'.join(
[f" '{x[0]}' is of {x[1][0]} but its Tag is {x[1][1]}."
for x in self.files_with_inofficial_tag.items()])
for x in self.files_with_unofficial_tag.items()])
self._warning(info_str)
elif len(self.files_not_matched_by_any_license_tag) > 0:
info_str = ''
Expand Down
Loading

0 comments on commit 38e165a

Please sign in to comment.