diff --git a/ament_copyright/ament_copyright/licenses.py b/ament_copyright/ament_copyright/licenses.py index 28b60b4f..697dd111 100644 --- a/ament_copyright/ament_copyright/licenses.py +++ b/ament_copyright/ament_copyright/licenses.py @@ -38,3 +38,4 @@ def read_license_data(path, name, prefix): apache2 = read_license_data(TEMPLATE_DIRECTORY, 'Apache License, Version 2.0', 'apache2') +bsd2 = read_license_data(TEMPLATE_DIRECTORY, 'BSD License 2.0', 'bsd2') diff --git a/ament_copyright/ament_copyright/parser.py b/ament_copyright/ament_copyright/parser.py index 430ef641..d41fe42b 100644 --- a/ament_copyright/ament_copyright/parser.py +++ b/ament_copyright/ament_copyright/parser.py @@ -44,6 +44,7 @@ def __init__(self, filetype, path): self.path = path self.exists = os.path.exists(path) self.content = None + self.license_identifier = UNKNOWN_IDENTIFIER def read(self): if not self.exists: @@ -54,24 +55,26 @@ def read(self): def parse(self): raise NotImplemented() - def identify_copyright(self): - known_copyrights = get_copyright_names() - for c in self.copyrights: - found_name = c.name - for identifier, name in known_copyrights.items(): - if name == found_name: - self.copyright_identifiers.append(identifier) - break - else: - self.copyright_identifiers.append(UNKNOWN_IDENTIFIER) - def identify_license(self, content, license_part): + if content is None: + return + for name, license in get_licenses().items(): - if content is not None and getattr(license, license_part) == content: + template = getattr(license, license_part).replace('\n', ' ').strip() + last_index = -1 + for license_section in template.split('{company}'): + # OK, now look for each section of the license in the incoming + # content. + index = content.replace('\n', ' ').strip().find(license_section.strip()) + if index == -1 or index <= last_index: + # Some part of the license is not in the content, or the license + # is rearranged, this license doesn't match. + break + last_index = index + else: + # We found the license, so set it self.license_identifier = name break - else: - self.license_identifier = UNKNOWN_IDENTIFIER class SourceDescriptor(FileDescriptor): @@ -82,7 +85,17 @@ def __init__(self, path): self.copyrights = [] self.copyright_identifiers = [] - self.license_identifier = None + + def identify_copyright(self): + known_copyrights = get_copyright_names() + for c in self.copyrights: + found_name = c.name + for identifier, name in known_copyrights.items(): + if name == found_name: + self.copyright_identifiers.append(identifier) + break + else: + self.copyright_identifiers.append(UNKNOWN_IDENTIFIER) def parse(self): self.read() @@ -114,8 +127,6 @@ class ContributingDescriptor(FileDescriptor): def __init__(self, path): super(ContributingDescriptor, self).__init__(CONTRIBUTING_FILETYPE, path) - self.license_identifier = None - def parse(self): self.read() if not self.content: @@ -129,8 +140,6 @@ class LicenseDescriptor(FileDescriptor): def __init__(self, path): super(LicenseDescriptor, self).__init__(LICENSE_FILETYPE, path) - self.license_identifier = None - def parse(self): self.read() if not self.content: @@ -166,7 +175,7 @@ def search_copyright_information(content): year = '\d{4}' year_range = '%s-%s' % (year, year) year_or_year_range = '(?:%s|%s)' % (year, year_range) - pattern = '^[^\n\r]?\s*Copyright\s+(%s(?:,\s*%s)*)\s+([^\n\r]+)$' % \ + pattern = '^[^\n\r]?\s*Copyright(?:\s+\(c\))?\s+(%s(?:,\s*%s)*),?\s+([^\n\r]+)$' % \ (year_or_year_range, year_or_year_range) regex = re.compile(pattern, re.DOTALL | re.MULTILINE) diff --git a/ament_copyright/ament_copyright/template/bsd2_contributing.txt b/ament_copyright/ament_copyright/template/bsd2_contributing.txt new file mode 100644 index 00000000..58e7bfaa --- /dev/null +++ b/ament_copyright/ament_copyright/template/bsd2_contributing.txt @@ -0,0 +1,3 @@ +Any contribution that you make to this repository will +be under the BSD license 2.0, as dictated by that +[license](https://en.wikipedia.org/wiki/BSD_licenses#3-clause_license_.28.22BSD_License_2.0.22.2C_.22Revised_BSD_License.22.2C_.22New_BSD_License.22.2C_or_.22Modified_BSD_License.22.29). diff --git a/ament_copyright/ament_copyright/template/bsd2_header.txt b/ament_copyright/ament_copyright/template/bsd2_header.txt new file mode 100644 index 00000000..619efdf3 --- /dev/null +++ b/ament_copyright/ament_copyright/template/bsd2_header.txt @@ -0,0 +1,31 @@ +{copyright} +All rights reserved. + +Software License Agreement (BSD License 2.0) + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the {company} nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/ament_copyright/ament_copyright/template/bsd2_license.txt b/ament_copyright/ament_copyright/template/bsd2_license.txt new file mode 100644 index 00000000..24d43da7 --- /dev/null +++ b/ament_copyright/ament_copyright/template/bsd2_license.txt @@ -0,0 +1,30 @@ +All rights reserved. + +Software License Agreement (BSD License 2.0) + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/ament_copyright/setup.py b/ament_copyright/setup.py index 5fe857f8..bf2d32c3 100644 --- a/ament_copyright/setup.py +++ b/ament_copyright/setup.py @@ -33,6 +33,7 @@ ], 'ament_copyright.license': [ 'apache2 = ament_copyright.licenses:apache2', + 'bsd2 = ament_copyright.licenses:bsd2', ], 'console_scripts': [ 'ament_copyright = ament_copyright.main:main',