8
8
import json
9
9
import yaml
10
10
import re
11
+ import traceback
11
12
import fosslight_util .constant as constant
12
13
import fosslight_dependency .constant as const
13
14
from fosslight_dependency ._package_manager import PackageManager
14
15
15
16
logger = logging .getLogger (constant .LOGGER_NAME )
16
17
17
18
_spec_repos = 'SPEC REPOS'
19
+ _external_sources = 'EXTERNAL SOURCES'
18
20
_source_type = ['git' , 'http' , 'svn' , 'hg' ]
19
21
20
22
@@ -35,10 +37,19 @@ def parse_oss_information(self, f_name):
35
37
pod_in_sepc_list = []
36
38
pod_not_in_spec_list = []
37
39
spec_repo_list = []
38
-
39
- for spec_item_key in podfile_yaml [_spec_repos ]:
40
- for spec_item in podfile_yaml [_spec_repos ][spec_item_key ]:
41
- spec_repo_list .append (spec_item )
40
+ external_source_list = []
41
+
42
+ if _spec_repos in podfile_yaml :
43
+ for spec_item_key in podfile_yaml [_spec_repos ]:
44
+ for spec_item in podfile_yaml [_spec_repos ][spec_item_key ]:
45
+ spec_repo_list .append (spec_item )
46
+ if _external_sources in podfile_yaml :
47
+ for external_sources_key in podfile_yaml [_external_sources ]:
48
+ external_source_list .append (external_sources_key )
49
+ spec_repo_list .append (external_sources_key )
50
+ if len (spec_repo_list ) == 0 :
51
+ logger .error ("Cannot fint SPEC REPOS or EXTERNAL SOURCES in Podfile.lock." )
52
+ return ''
42
53
43
54
for pods_list in podfile_yaml ['PODS' ]:
44
55
if not isinstance (pods_list , str ):
@@ -59,54 +70,66 @@ def parse_oss_information(self, f_name):
59
70
sheet_list = []
60
71
61
72
for pod_oss in pod_in_sepc_list :
62
-
63
- search_oss_name = ""
64
- for alphabet_oss in pod_oss [0 ]:
65
- if not alphabet_oss .isalnum ():
66
- search_oss_name += "\\ \\ " + alphabet_oss
73
+ try :
74
+ if pod_oss [0 ] in external_source_list :
75
+ podspec_filename = pod_oss [0 ] + '.podspec.json'
76
+ spec_file_path = os .path .join ("Pods" , "Local Podspecs" , podspec_filename )
67
77
else :
68
- search_oss_name += alphabet_oss
69
-
70
- command = 'pod spec which --regex ' + '^' + search_oss_name + '$'
71
- spec_which = os .popen (command ).readline ()
72
- if spec_which .startswith ('[!]' ):
73
- logger .error ("This command(" + command + ") returns an error" )
74
- return ''
78
+ search_oss_name = ""
79
+ for alphabet_oss in pod_oss [0 ]:
80
+ if not alphabet_oss .isalnum ():
81
+ search_oss_name += "\\ \\ " + alphabet_oss
82
+ else :
83
+ search_oss_name += alphabet_oss
84
+
85
+ command = 'pod spec which --regex ' + '^' + search_oss_name + '$'
86
+ spec_which = os .popen (command ).readline ()
87
+ if spec_which .startswith ('[!]' ):
88
+ logger .error ("This command(" + command + ") returns an error" )
89
+ return ''
90
+
91
+ file_path = spec_which .rstrip ().split (os .path .sep )
92
+ if file_path [0 ] == '' :
93
+ file_path_without_version = os .path .join (os .sep , * file_path [:- 2 ])
94
+ else :
95
+ file_path_without_version = os .path .join (* file_path [:- 2 ])
96
+ spec_file_path = os .path .join (file_path_without_version , pod_oss [1 ], file_path [- 1 ])
97
+
98
+ oss_name , oss_version , license_name , dn_loc , homepage = self .get_oss_in_podspec (spec_file_path )
75
99
76
- file_path = spec_which .rstrip ().split (os .path .sep )
77
- if file_path [0 ] == '' :
78
- file_path_without_version = os .path .join (os .sep , * file_path [:- 2 ])
79
- else :
80
- file_path_without_version = os .path .join (* file_path [:- 2 ])
81
- spec_file_path = os .path .join (file_path_without_version , pod_oss [1 ], file_path [- 1 ])
100
+ sheet_list .append ([const .SUPPORT_PACKAE .get (self .package_manager_name ),
101
+ oss_name , oss_version , license_name , dn_loc , homepage , '' , '' , '' ])
102
+ except Exception as e :
103
+ logger .warning ('It failed to get ' + pod_oss [0 ] + ': ' + str (e ))
104
+ logger .warning (traceback .format_exc ())
82
105
83
- with open (spec_file_path , 'r' , encoding = 'utf8' ) as json_file :
84
- json_data = json .load (json_file )
106
+ return sheet_list
85
107
86
- oss_origin_name = json_data ['name' ]
87
- oss_name = self .package_manager_name + ":" + oss_origin_name
88
- oss_version = json_data ['version' ]
89
- homepage = self .dn_url + 'pods/' + oss_origin_name
108
+ def get_oss_in_podspec (self , spec_file_path ):
109
+ with open (spec_file_path , 'r' , encoding = 'utf8' ) as json_file :
110
+ json_data = json .load (json_file )
90
111
91
- if not isinstance (json_data ['license' ], str ):
92
- if 'type' in json_data ['license' ]:
93
- license_name = json_data ['license' ]['type' ]
94
- else :
95
- license_name = json_data ['license' ]
112
+ oss_origin_name = json_data ['name' ]
113
+ oss_name = self .package_manager_name + ":" + oss_origin_name
114
+ oss_version = json_data ['version' ]
115
+ homepage = self .dn_url + 'pods/' + oss_origin_name
96
116
97
- license_name = license_name .replace ("," , "" )
117
+ if not isinstance (json_data ['license' ], str ):
118
+ if 'type' in json_data ['license' ]:
119
+ license_name = json_data ['license' ]['type' ]
120
+ else :
121
+ license_name = json_data ['license' ]
98
122
99
- source_keys = [key for key in json_data ['source' ]]
100
- for src_type_i in _source_type :
101
- if src_type_i in source_keys :
102
- dn_loc = json_data ['source' ][src_type_i ]
103
- if dn_loc .endswith ('.git' ):
104
- dn_loc = dn_loc [:- 4 ]
123
+ license_name = license_name .replace ("," , "" )
105
124
106
- sheet_list .append ([const .SUPPORT_PACKAE .get (self .package_manager_name ),
107
- oss_name , oss_version , license_name , dn_loc , homepage , '' , '' , '' ])
125
+ source_keys = [key for key in json_data ['source' ]]
126
+ for src_type_i in _source_type :
127
+ if src_type_i in source_keys :
128
+ dn_loc = json_data ['source' ][src_type_i ]
129
+ if dn_loc .endswith ('.git' ):
130
+ dn_loc = dn_loc [:- 4 ]
108
131
109
- return sheet_list
132
+ return oss_name , oss_version , license_name , dn_loc , homepage
110
133
111
134
112
135
def compile_pods_item (pods_item , spec_repo_list , pod_in_sepc_list , pod_not_in_spec_list ):
0 commit comments