19
19
import logging
20
20
import requests
21
21
import pkg_resources
22
+ import yaml
22
23
23
- VERSION = "3.0.4 "
24
+ VERSION = "3.0.5 "
24
25
25
26
# Check the manifest file
26
27
manifest_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" ] ]
28
29
29
30
# binary url to check license text
30
31
license_scanner_url_linux = "third_party/nomos/nomossa"
@@ -897,6 +898,80 @@ def parse_and_generate_output_pub(tmp_file_name):
897
898
os .remove (tmp_license_txt_file_name )
898
899
899
900
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
+
900
975
###########################################
901
976
# Main functions for each package manager #
902
977
###########################################
@@ -967,10 +1042,20 @@ def main_pub():
967
1042
close_input_file (input_fp )
968
1043
969
1044
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
+
970
1055
def main ():
971
1056
# Global variables
972
1057
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
974
1059
975
1060
# Init logging
976
1061
logging .basicConfig (level = logging .INFO , format = '%(message)s' )
@@ -1012,10 +1097,16 @@ def main():
1012
1097
output_file_name = "pub_dependency_output.xlsx"
1013
1098
tmp_license_txt_file_name = "tmp_license.txt"
1014
1099
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
+
1015
1106
else :
1016
1107
logging .error ("### Error Message ###" )
1017
1108
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. )" )
1019
1110
sys .exit (1 )
1020
1111
1021
1112
if PACKAGE == "pip" :
@@ -1028,6 +1119,13 @@ def main():
1028
1119
main_gradle ()
1029
1120
elif PACKAGE == "pub" :
1030
1121
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
+
1031
1129
1032
1130
logging .info ("### FINISH!! ###" )
1033
1131
0 commit comments