1919import logging
2020import requests
2121import pkg_resources
22+ import yaml
2223
23- VERSION = "3.0.4 "
24+ VERSION = "3.0.5 "
2425
2526# Check the manifest file
2627manifest_array = [["pip" , "requirements.txt" ], ["npm" , "package.json" ], ["maven" , "pom.xml" ],
27- ["gradle" , "build.gradle" ], ["pub" , "pubspec.yaml" ]]
28+ ["gradle" , "build.gradle" ], ["pub" , "pubspec.yaml" ], [ "cocoapods" , "Podfile.lock" ] ]
2829
2930# binary url to check license text
3031license_scanner_url_linux = "third_party/nomos/nomossa"
@@ -897,6 +898,80 @@ def parse_and_generate_output_pub(tmp_file_name):
897898 os .remove (tmp_license_txt_file_name )
898899
899900
901+ def compile_pods_item (pods_item , spec_repo_list , pod_in_sepc_list ):
902+ pods_item_re = re .findall (r'(\S*)\s{1}\((.*)\)' , pods_item )
903+
904+ oss_name = pods_item_re [0 ][0 ]
905+ oss_version = pods_item_re [0 ][1 ]
906+
907+ oss_info = []
908+ if oss_name in spec_repo_list :
909+ oss_info .append (oss_name )
910+ oss_info .append (oss_version )
911+ pod_in_sepc_list .append (oss_info )
912+
913+ return pod_in_sepc_list
914+
915+
916+ def parse_and_generate_output_cocoapods (input_fp ):
917+ global source_type
918+
919+ pod_in_sepc_list = []
920+ spec_repo_list = []
921+ podfile_yaml = yaml .load (input_fp , Loader = yaml .FullLoader )
922+
923+ for spec_item_key in podfile_yaml ['SPEC REPOS' ]:
924+ for spec_item in podfile_yaml ['SPEC REPOS' ][spec_item_key ]:
925+ spec_repo_list .append (spec_item )
926+
927+ for pods_list in podfile_yaml ['PODS' ]:
928+ if not isinstance (pods_list , str ):
929+ for pods_list_key , pods_list_item in pods_list .items ():
930+ pod_in_sepc_list = compile_pods_item (pods_list_key , spec_repo_list , pod_in_sepc_list )
931+ else :
932+ pod_in_sepc_list = compile_pods_item (pods_list , spec_repo_list , pod_in_sepc_list )
933+
934+ wb = generate_oss_report ()
935+
936+ idx = 1
937+ for pod_oss in pod_in_sepc_list :
938+ tmp_file_name = 'tmp_spec.json'
939+
940+ command = 'pod spec cat ' + pod_oss [0 ] + ' > ' + tmp_file_name
941+ command_ret = subprocess .call (command , shell = True )
942+ if command_ret != 0 :
943+ logging .error ("### Error Message ###" )
944+ logging .error ("This command(" + command + ") returns an error" )
945+ sys .exit (1 )
946+
947+ with open (tmp_file_name , 'r' , encoding = 'utf8' ) as json_file :
948+ json_data = json .load (json_file )
949+
950+ keys = [key for key in json_data ]
951+
952+ oss_name = json_data ['name' ]
953+ oss_version = json_data ['version' ]
954+ homepage = json_data ['homepage' ]
955+
956+ if not isinstance (json_data ['license' ], str ):
957+ if 'type' in json_data ['license' ]:
958+ license_name = json_data ['license' ]['type' ]
959+ else :
960+ license_name = json_data ['license' ]
961+
962+ source_keys = [key for key in json_data ['source' ]]
963+ for src_type_i in source_type :
964+ if src_type_i in source_keys :
965+ dn_loc = json_data ['source' ][src_type_i ]
966+
967+ insert_oss_report (wb .active ,
968+ [str (idx ), 'Podfile.lock' , oss_name , oss_version , license_name , dn_loc , homepage , '' , '' , '' , '' ])
969+ idx += 1
970+
971+ save_oss_report (wb )
972+
973+
974+
900975###########################################
901976# Main functions for each package manager #
902977###########################################
@@ -967,10 +1042,20 @@ def main_pub():
9671042 close_input_file (input_fp )
9681043
9691044
1045+ def main_cocoapods ():
1046+
1047+ # open Podfile.lock
1048+ input_fp = open_input_file ()
1049+
1050+ parse_and_generate_output_cocoapods (input_fp )
1051+
1052+ close_input_file (input_fp )
1053+
1054+
9701055def main ():
9711056 # Global variables
9721057 global PACKAGE , output_file_name , input_file_name , CUR_PATH , OUTPUT_RESULT_DIR , MANUAL_DETECT , OUTPUT_CUSTOM_DIR , dn_url , PIP_ACTIVATE , PIP_DEACTIVATE
973- global license_scanner_url , license_scanner_bin , venv_tmp_dir , pom_backup , is_maven_first_try , tmp_license_txt_file_name
1058+ global license_scanner_url , license_scanner_bin , venv_tmp_dir , pom_backup , is_maven_first_try , tmp_license_txt_file_name , source_type
9741059
9751060 # Init logging
9761061 logging .basicConfig (level = logging .INFO , format = '%(message)s' )
@@ -1012,10 +1097,16 @@ def main():
10121097 output_file_name = "pub_dependency_output.xlsx"
10131098 tmp_license_txt_file_name = "tmp_license.txt"
10141099
1100+ elif PACKAGE == "cocoapods" :
1101+ dn_url = "https://cocoapods/org/"
1102+ input_file_name = "Podfile.lock"
1103+ output_file_name = "cocoapods_dependency_output.xlsx"
1104+ source_type = ['git' , 'http' , 'svn' , 'hg' ]
1105+
10151106 else :
10161107 logging .error ("### Error Message ###" )
10171108 logging .error ("You enter the wrong first argument." )
1018- logging .error ("Please enter the package manager into (pip, npm, maven, gradle )" )
1109+ logging .error ("Please enter the supported package manager. (Check the help message with (-h) option. )" )
10191110 sys .exit (1 )
10201111
10211112 if PACKAGE == "pip" :
@@ -1028,6 +1119,13 @@ def main():
10281119 main_gradle ()
10291120 elif PACKAGE == "pub" :
10301121 main_pub ()
1122+ elif PACKAGE == "cocoapods" :
1123+ main_cocoapods ()
1124+ else :
1125+ logging .error ("### Error Message ###" )
1126+ logging .error ("Please enter the supported package manager. (Check the help message with (-h) option.)" )
1127+ sys .exit (1 )
1128+
10311129
10321130 logging .info ("### FINISH!! ###" )
10331131
0 commit comments