@@ -37,6 +37,10 @@ def __del__(self):
37
37
shutil .rmtree (self .tmp_dir )
38
38
39
39
def run_plugin (self ):
40
+ if os .path .exists (self .input_file_name ):
41
+ logger .info (f"Found { self .input_file_name } , skip the flutter cmd to analyze dependency." )
42
+ return True
43
+
40
44
if not os .path .exists (const .SUPPORT_PACKAE .get (self .package_manager_name )):
41
45
logger .error (f"Cannot find the file({ const .SUPPORT_PACKAE .get (self .package_manager_name )} )" )
42
46
return False
@@ -66,11 +70,7 @@ def run_plugin(self):
66
70
ret = subprocess .check_output (cmd , shell = True )
67
71
if ret != 0 :
68
72
pub_deps = ret .decode ('utf8' )
69
- for line in pub_deps .split ('\n ' ):
70
- re_result = re .findall (r'\-\-\s(\S+[^.\s])[.|\s]' , line )
71
- if re_result :
72
- self .total_dep_list .append (re_result [0 ])
73
- self .total_dep_list = list (set (self .total_dep_list ))
73
+ self .parse_no_deps_file (pub_deps )
74
74
75
75
cmd = f"flutter pub run flutter_oss_licenses:generate.dart -o { self .input_file_name } --json"
76
76
ret = subprocess .call (cmd , shell = True )
@@ -81,10 +81,23 @@ def run_plugin(self):
81
81
82
82
return True
83
83
84
+ def parse_no_deps_file (self , f ):
85
+ for line in f .split ('\n ' ):
86
+ re_result = re .findall (r'\-\-\s(\S+[^.\s])[.|\s]' , line )
87
+ if re_result :
88
+ self .total_dep_list .append (re_result [0 ])
89
+ self .total_dep_list = list (set (self .total_dep_list ))
90
+
84
91
def parse_oss_information (self , f_name ):
85
92
tmp_license_txt_file_name = 'tmp_license.txt'
86
93
json_data = ''
87
94
comment = ''
95
+ tmp_no_deps_file = 'tmp_no_deps_result.txt'
96
+
97
+ if os .path .exists (tmp_no_deps_file ):
98
+ with open (tmp_no_deps_file , 'r' , encoding = 'utf8' ) as deps_f :
99
+ deps_l = deps_f .read ()
100
+ self .parse_no_deps_file (deps_l )
88
101
89
102
with open (f_name , 'r' , encoding = 'utf8' ) as pub_file :
90
103
json_f = json .load (pub_file )
@@ -94,34 +107,35 @@ def parse_oss_information(self, f_name):
94
107
95
108
for json_data in json_f :
96
109
oss_origin_name = json_data ['name' ]
97
- if oss_origin_name in self .total_dep_list :
98
- oss_name = f"{ self .package_manager_name } :{ oss_origin_name } "
99
- oss_version = json_data ['version' ]
100
- homepage = json_data ['homepage' ]
101
- dn_loc = f"{ self .dn_url } { oss_origin_name } /versions/{ oss_version } "
102
- license_txt = json_data ['license' ]
103
-
104
- tmp_license_txt = open (tmp_license_txt_file_name , 'w' , encoding = 'utf-8' )
105
- tmp_license_txt .write (license_txt )
106
- tmp_license_txt .close ()
107
-
108
- license_name_with_license_scanner = check_and_run_license_scanner (self .platform ,
109
- self .license_scanner_bin ,
110
- tmp_license_txt_file_name )
111
-
112
- if license_name_with_license_scanner != "" :
113
- license_name = license_name_with_license_scanner
110
+ if self .total_dep_list != [] and oss_origin_name not in self .total_dep_list :
111
+ continue
112
+ oss_name = f"{ self .package_manager_name } :{ oss_origin_name } "
113
+ oss_version = json_data ['version' ]
114
+ homepage = json_data ['homepage' ]
115
+ dn_loc = f"{ self .dn_url } { oss_origin_name } /versions/{ oss_version } "
116
+ license_txt = json_data ['license' ]
117
+
118
+ tmp_license_txt = open (tmp_license_txt_file_name , 'w' , encoding = 'utf-8' )
119
+ tmp_license_txt .write (license_txt )
120
+ tmp_license_txt .close ()
121
+
122
+ license_name_with_license_scanner = check_and_run_license_scanner (self .platform ,
123
+ self .license_scanner_bin ,
124
+ tmp_license_txt_file_name )
125
+
126
+ if license_name_with_license_scanner != "" :
127
+ license_name = license_name_with_license_scanner
128
+ else :
129
+ license_name = ''
130
+
131
+ if self .direct_dep :
132
+ if json_data ['isDirectDependency' ]:
133
+ comment = 'direct'
114
134
else :
115
- license_name = ''
116
-
117
- if self .direct_dep :
118
- if json_data ['isDirectDependency' ]:
119
- comment = 'direct'
120
- else :
121
- comment = 'transitive'
135
+ comment = 'transitive'
122
136
123
- sheet_list .append ([const .SUPPORT_PACKAE .get (self .package_manager_name ),
124
- oss_name , oss_version , license_name , dn_loc , homepage , '' , '' , comment ])
137
+ sheet_list .append ([const .SUPPORT_PACKAE .get (self .package_manager_name ),
138
+ oss_name , oss_version , license_name , dn_loc , homepage , '' , '' , comment ])
125
139
except Exception as e :
126
140
logger .error (f"Fail to parse pub oss information: { e } " )
127
141
0 commit comments