|
32 | 32 | _PKG_NAME = "fosslight_dependency"
|
33 | 33 |
|
34 | 34 | # Check the manifest file
|
35 |
| -SUPPORT_PACKAE = ["pip", "npm", "maven", "gradle", "pub", "cocoapods", "android", "swift"] |
| 35 | +SUPPORT_PACKAE = ["pip", "npm", "maven", "gradle", "pub", "cocoapods", "android", "swift", "carthage"] |
36 | 36 | manifest_array = [[SUPPORT_PACKAE[0], "requirements.txt"], [SUPPORT_PACKAE[1], "package.json"], [SUPPORT_PACKAE[2], "pom.xml"],
|
37 | 37 | [SUPPORT_PACKAE[3], "build.gradle"], [SUPPORT_PACKAE[4], "pubspec.yaml"], [SUPPORT_PACKAE[5], "Podfile.lock"],
|
38 |
| - [SUPPORT_PACKAE[7], "Package.resolved"]] |
| 38 | + [SUPPORT_PACKAE[7], "Package.resolved"], [SUPPORT_PACKAE[8], "Cartfile.resolved"]] |
39 | 39 |
|
40 | 40 | # binary url to check license text
|
41 | 41 | license_scanner_url_linux = "third_party/nomos/nomossa"
|
@@ -999,7 +999,69 @@ def parse_and_generate_output_swift(input_fp):
|
999 | 999 | except Exception:
|
1000 | 1000 | logger.info("Cannot find the license name with github api.")
|
1001 | 1001 |
|
1002 |
| - if license_name == "": |
| 1002 | + if license_name == "" or license_name == "NOASSERTION": |
| 1003 | + try: |
| 1004 | + license_txt_data = base64.b64decode(repository.get_license().content).decode('utf-8') |
| 1005 | + tmp_license_txt = open(tmp_license_txt_file_name, 'w', encoding='utf-8') |
| 1006 | + tmp_license_txt.write(license_txt_data) |
| 1007 | + tmp_license_txt.close() |
| 1008 | + license_name = check_and_run_license_scanner(tmp_license_txt_file_name, os_name) |
| 1009 | + except Exception: |
| 1010 | + logger.info("Cannot find the license name with license scanner binary.") |
| 1011 | + |
| 1012 | + if os.path.isfile(tmp_license_txt_file_name): |
| 1013 | + os.remove(tmp_license_txt_file_name) |
| 1014 | + |
| 1015 | + sheet_list["SRC"].append(['Package.resolved', oss_name, oss_version, license_name, dn_loc, homepage, '', '', '']) |
| 1016 | + |
| 1017 | + return sheet_list |
| 1018 | + |
| 1019 | + |
| 1020 | +def parse_and_generate_output_carthge(input_fp): |
| 1021 | + global GITHUB_TOKEN |
| 1022 | + |
| 1023 | + sheet_list = {} |
| 1024 | + sheet_list["SRC"] = [] |
| 1025 | + |
| 1026 | + os_name = check_os() |
| 1027 | + check_license_scanner(os_name) |
| 1028 | + |
| 1029 | + if GITHUB_TOKEN is not None: |
| 1030 | + g = Github(GITHUB_TOKEN) |
| 1031 | + else: |
| 1032 | + g = Github() |
| 1033 | + |
| 1034 | + for i, line in enumerate(input_fp.readlines()): |
| 1035 | + |
| 1036 | + re_result = re.findall(r'github[\s]\"(\S*)\"[\s]\"(\S*)\"', line) |
| 1037 | + try: |
| 1038 | + github_repo = re_result[0][0] |
| 1039 | + oss_origin_name = github_repo.split('/')[1] |
| 1040 | + oss_name = "carthage:" + oss_origin_name |
| 1041 | + oss_version = re_result[0][1] |
| 1042 | + homepage = "https://github.com/" + github_repo |
| 1043 | + dn_loc = homepage |
| 1044 | + |
| 1045 | + license_name = '' |
| 1046 | + except Exception: |
| 1047 | + logger.error("It cannot find the github oss information. So skip it.") |
| 1048 | + break |
| 1049 | + |
| 1050 | + try: |
| 1051 | + repository = g.get_repo(github_repo) |
| 1052 | + except Exception: |
| 1053 | + logger.error("It cannot find the license name. Please use '-t' option with github token.") |
| 1054 | + logger.error("{0}{1}".format("refer:https://docs.github.com/en/github/authenticating-to-github/", |
| 1055 | + "keeping-your-account-and-data-secure/creating-a-personal-access-token")) |
| 1056 | + repository = '' |
| 1057 | + |
| 1058 | + if repository is not None: |
| 1059 | + try: |
| 1060 | + license_name = repository.get_license().license.spdx_id |
| 1061 | + except Exception: |
| 1062 | + logger.info("Cannot find the license name with github api.") |
| 1063 | + |
| 1064 | + if license_name == "" or license_name == "NOASSERTION": |
1003 | 1065 | try:
|
1004 | 1066 | license_txt_data = base64.b64decode(repository.get_license().content).decode('utf-8')
|
1005 | 1067 | tmp_license_txt = open(tmp_license_txt_file_name, 'w', encoding='utf-8')
|
@@ -1145,6 +1207,17 @@ def main_swift():
|
1145 | 1207 | return sheet_list
|
1146 | 1208 |
|
1147 | 1209 |
|
| 1210 | +def main_carthage(): |
| 1211 | + |
| 1212 | + input_fp = open_input_file() |
| 1213 | + |
| 1214 | + sheet_list = parse_and_generate_output_carthge(input_fp) |
| 1215 | + |
| 1216 | + close_input_file(input_fp) |
| 1217 | + |
| 1218 | + return sheet_list |
| 1219 | + |
| 1220 | + |
1148 | 1221 | def set_package_variables(package):
|
1149 | 1222 | global PACKAGE, dn_url, output_file_name, input_file_name, venv_tmp_dir, pom_backup, is_maven_first_try, \
|
1150 | 1223 | tmp_license_txt_file_name, source_type
|
@@ -1193,6 +1266,11 @@ def set_package_variables(package):
|
1193 | 1266 | output_file_name = "swift_dependency_output"
|
1194 | 1267 | tmp_license_txt_file_name = "tmp_license.txt"
|
1195 | 1268 |
|
| 1269 | + elif PACKAGE == "carthage": |
| 1270 | + input_file_name = "Cartfile.resolved" |
| 1271 | + output_file_name = "carthage_dependency_output" |
| 1272 | + tmp_license_txt_file_name = "tmp_license.txt" |
| 1273 | + |
1196 | 1274 | else:
|
1197 | 1275 | logger.error("### Error Message ###")
|
1198 | 1276 | logger.error("You enter the wrong first argument.")
|
@@ -1240,6 +1318,8 @@ def main():
|
1240 | 1318 | sheet_list = main_android()
|
1241 | 1319 | elif PACKAGE == "swift":
|
1242 | 1320 | sheet_list = main_swift()
|
| 1321 | + elif PACKAGE == "carthage": |
| 1322 | + sheet_list = main_carthage() |
1243 | 1323 | else:
|
1244 | 1324 | logger.error("### Error Message ###")
|
1245 | 1325 | logger.error("Please enter the supported package manager. (Check the help message with (-h) option.)")
|
|
0 commit comments