Module: PrivacyModule
- Defined in:
- lib/cocoapods-privacy/privacy/PrivacyModule.rb
Class Method Summary collapse
- .check(podspec_file_path) ⇒ Object
-
.load_module(podspec_file_path) ⇒ Object
处理组件.
-
.load_project(folds, exclude_folds) ⇒ Object
处理工程.
Class Method Details
.check(podspec_file_path) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/cocoapods-privacy/privacy/PrivacyModule.rb', line 263 def self.check(podspec_file_path) # Step 1: 读取podspec lines = read_podspec(podspec_file_path) # Step 2: 逐行解析并转位BBRow 模型 rows = parse_row(lines) # Step 3.1:如果Row 是属于Spec 内,那么聚拢成BBSpec, # Step 3.2:BBSpec 内使用数组存储其Spec 内的行 # Step 3.3 在合适位置给每个有效的spec都创建一个 隐私模版,并修改其podspec 引用 combin_sepcs_and_rows = combin_sepc_if_need(rows,podspec_file_path) # Step 4: 展开修改后的Spec,重新转换成 BBRow rows = unfold_sepc_if_need(combin_sepcs_and_rows) # Step 5: 打开隐私模版,并修改其podspec文件,并逐行写入 File.open(podspec_file_path, 'w') do |file| # 逐行写入 rows rows.each do |row| file.puts(row.content) end end # Step 6: 获取privacy 相关信息,传递给后续处理 privacy_hash = fetch_privacy_hash(combin_sepcs_and_rows,podspec_file_path).compact filtered_privacy_hash = privacy_hash.reject { |_, value| value.empty? } filtered_privacy_hash end |
.load_module(podspec_file_path) ⇒ Object
处理组件
248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/cocoapods-privacy/privacy/PrivacyModule.rb', line 248 def self.load_module(podspec_file_path) puts "👇👇👇👇👇👇 Start analysis component privacy 👇👇👇👇👇👇" PrivacyLog.clean_result_log() privacy_hash = PrivacyModule.check(podspec_file_path) privacy_hash.each do |privacy_file_path, hash| PrivacyLog.write_to_result_log("#{privacy_file_path}: \n") source_files = hash[KSource_Files_Key] exclude_files = hash[KExclude_Files_Key] data = PrivacyHunter.search_pricacy_apis(source_files,exclude_files) PrivacyHunter.write_to_privacy(data,privacy_file_path) unless data.empty? end PrivacyLog.result_log_tip() puts "👆👆👆👆👆👆 End analysis component privacy 👆👆👆👆👆👆" end |
.load_project(folds, exclude_folds) ⇒ Object
处理工程
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/cocoapods-privacy/privacy/PrivacyModule.rb', line 207 def self.load_project(folds,exclude_folds) project_path = PrivacyUtils.project_path() resources_folder_path = File.join(File.basename(project_path, File.extname(project_path)),'Resources') privacy_file_path = File.join(resources_folder_path,PrivacyUtils.privacy_name) # 如果隐私文件不存在,创建隐私协议模版 unless File.exist?(privacy_file_path) PrivacyUtils.create_privacy_if_empty(privacy_file_path) end # 如果没有隐私文件,那么新建一个添加到工程中 # 打开 Xcode 项目,在Resources 下创建 project = Xcodeproj::Project.open(File.basename(project_path)) main_group = project.main_group resources_group = main_group.find_subpath('Resources',false) if resources_group.nil? resources_group = main_group.new_group('Resources',resources_folder_path) end # 如果不存在引用,创建新的引入xcode引用 if resources_group.find_file_by_path(PrivacyUtils.privacy_name).nil? privacy_file_ref = resources_group.new_reference(PrivacyUtils.privacy_name,:group) privacy_file_ref.last_known_file_type = 'text.xml' target = project.targets.first resources_build_phase = target.resources_build_phase resources_build_phase.add_file_reference(privacy_file_ref) # 将文件引用添加到 resources 构建阶段中 # target.add_file_references([privacy_file_ref]) # 将文件引用添加到 target 中 # resources_group.new_file(privacy_file_path) end project.save # 开始检索api,并返回json 字符串数据 PrivacyLog.clean_result_log() json_data = PrivacyHunter.search_pricacy_apis(folds,exclude_folds) # 将数据写入隐私清单文件 PrivacyHunter.write_to_privacy(json_data,privacy_file_path) PrivacyLog.result_log_tip() end |