def parse_packages(self, output: str, configuration: dict, directory: str = None) -> List[Package]: return [ Package('starlette', '0.14.1', 'BSD License'), Package('demo1234', '0.14.1', 'GPL'), Package('urllib3', '1.26.4', 'MIT License'), ]
def test_parse_packages(self): configuration = Configuration() packages = self.checker.parse_packages(self.DEMO_LICENSE_OUTPUT, configuration, self.directory.name) assert packages == [ Package('starlette', '0.14.1', 'BSD License'), Package('demo1234', '0.14.1', 'GPL'), Package('urllib3', '1.26.4', 'MIT License'), Package('uvicorn', '0.13.3', 'BSD License'), Package('zipp', '3.4.1', 'MIT License')]
def test_parse_packages(self): packages = self.checker.parse_packages( self.DEMO_LICENSE_OUTPUT, Configuration(allowed_licenses=[], excluded_packages=[]), self.directory.name) assert packages == [ Package('xtend', '4.0.2', 'MIT'), Package('y18n', '4.0.0', 'ISC'), Package('y18n', '5.0.5', 'ISC'), ]
def test_find_invalid_packages(self): packages = [ Package('starlette', '0.14.1', 'BSD License'), Package('demo1234', '0.14.1', 'GPL'), Package('urllib3', '1.26.4', 'MIT License'), ] invalid_packages = self.checker.find_invalid_packages( packages, Configuration(allowed_licenses=['BSD License', 'MIT License'])) assert invalid_packages == [Package('demo1234', '0.14.1', 'GPL')]
def test_remove_excluded_packages(self): packages = [ Package('starlette', '0.14.1', 'BSD License'), Package('demo1234', '0.14.1', 'GPL'), Package('urllib3', '1.26.4', 'MIT License'), ] filtered_packages = BaseLicenseChecker.remove_excluded_packages( packages, Configuration(excluded_packages=['demo1234'])) assert filtered_packages == [ Package('starlette', '0.14.1', 'BSD License'), Package('urllib3', '1.26.4', 'MIT License'), ]
def parse_packages(self, output: str, configuration: Configuration, directory: str) -> List[Package]: packages = [] licenses_file_path = Path(directory, 'build', 'reports', 'licenses', 'licenseReport.json') logger.debug('Loading license data from [%s]', licenses_file_path.absolute()) with open(licenses_file_path.absolute()) as license_file: dependencies = load(license_file) for dependency in dependencies: artifact_name = dependency['dependency'] version = '' index = artifact_name.rfind(':') if index > -1: version = artifact_name[index + 1:] artifact_name = artifact_name[:index] license_names = [] for license_entry in dependency['licenses']: license_names.append(license_entry['license']) license_names.sort() packages.append( Package(artifact_name, version, ';'.join(license_names))) logger.debug('Found %s packages in license file.', len(packages)) return packages
def test_parse_packages(self): target_directory = Path(self.directory.name, 'build', 'reports', 'licenses') target_directory.mkdir(parents=True) with open(join(target_directory.absolute(), 'licenseReport.json'), 'w') as licenses_file: licenses_file.write(self.LICENSE_REPORT_JSON) packages = self.checker.parse_packages( '', Configuration(allowed_licenses=[], excluded_packages=[]), self.directory.name) assert packages == [ Package('org.apache.logging.log4j:log4j-api', '2.13.3', 'Apache License, Version 2.0'), Package('org.apache.logging.log4j:log4j-to-slf4j', '2.13.3', 'Apache License, Version 2.0'), Package('com.fasterxml.jackson.datatype:jackson-datatype-jdk8', '2.11.4', 'The Apache Software License, Version 2.0'), ]
def parse_packages(self, output: str, configuration: Configuration, directory: str) -> List[Package]: values = loads(output) packages = [] for license_structure in values: if not license_structure['Name'] in configuration.excluded_packages: packages.append( Package(license_structure['Name'], license_structure['Version'], license_structure['License'])) return packages
def test_parse_packages(self): target_directory = Path(self.directory.name, 'target', 'generated-resources') target_directory.mkdir(parents=True) with open(join(target_directory.absolute(), 'licenses.xml'), 'w') as licenses_file: licenses_file.write(self.LICENSES_XML) packages = self.checker.parse_packages( '', Configuration(allowed_licenses=[], excluded_packages=[]), self.directory.name) assert packages == [ Package( 'ch.qos.logback:logback-classic', '1.2.3', 'Eclipse Public License - v 1.0;GNU Lesser General Public License' ), Package( 'ch.qos.logback:logback-core', '1.2.3', 'Eclipse Public License - v 1.0;GNU Lesser General Public License' ), Package('com.fasterxml.jackson.core:jackson-annotations', '2.11.4', 'The Apache Software License, Version 2.0') ]
def parse_packages(self, output: str, configuration: dict, directory: str) -> List[Package]: packages = [] package_reader = csv.DictReader(output.splitlines()) for row in package_reader: module = row['module name'] name = module version = module index = module.find('@') if index > 0: name = module[:index] version = module[index + 1:] packages.append(Package(name, version, row['license'])) return packages
def parse_packages(self, output: str, configuration: Configuration, directory: str) -> List[Package]: packages = [] licenses_file_path = Path(directory, 'target', 'generated-resources', 'licenses.xml') tree = ElementTree.parse(licenses_file_path.absolute()) root = tree.getroot() for dependency in root.findall('./dependencies/dependency'): group_id = dependency.find('groupId') artifact_id = dependency.find('artifactId') version = dependency.find('version') license_names = [] for license_element in dependency.findall('./licenses/license'): license_names.append(license_element.find('name').text) license_names.sort() packages.append( Package(f'{group_id.text}:{artifact_id.text}', version.text, ';'.join(license_names))) return packages
def test_render_demo_config_file_with_file(self): Configuration().save_to_directory(self.directory.name) text = self.checker.render_demo_config_file( self.directory.name, [Package('demo1234', '0.14.1', 'GPL')]) assert text == ''
def test_render_demo_config_file_without_file(self): text = self.checker.render_demo_config_file( self.directory.name, [Package('demo1234', '0.14.1', 'GPL')]) assert text != ''
def test_eq(self): assert Package('starlette', '0.14.1', 'BSD License').__eq__( Package('starlette', '0.14.1', 'BSD License')) == True
def test_repr(self): assert repr(Package('starlette', '0.14.1', 'BSD License')) == 'Package(name=starlette,version=0.14.1,license=BSD License)'