Class: Pod::Downloader::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-bb-PodAssistant/source_provider_hook.rb

Instance Method Summary collapse

Instance Method Details

#download_file(_full_filename) ⇒ Object



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
# File 'lib/cocoapods-bb-PodAssistant/source_provider_hook.rb', line 212

def download_file(_full_filename)
  # 捕获一下异常,不会因为plugin的原因导致pod失败
  begin
    if _full_filename.to_s.include?($pluginCurrentTarget)
      # 说明是之前被赋值的开始下载了

      # 获取CDN下载执行前时间点
      time1 = Time.new
      # 执行原来的CDN下载方法
      origin_download_file(_full_filename)
      # 获取CDN下载执行后时间点
      time2 = Time.new
      # 赋值CDN下载耗时给全局变量,用于之后输出以及写在csv中
      $cdnDownloadTime = time2 - time1
    else
      # 说明不是之前被赋值的开始下载了,输出一下,然后清空
      puts "\e[31m[PodAssistant] unzip warning: #{$pluginCurrentTarget} target error\e[0m"
      puts "\e[31m[PodAssistant] unzip warning: #{$pluginCurrentPodName} name error\e[0m"
      $pluginCurrentTarget = ""
      $pluginCurrentPodName = ""
    end
  rescue => exception
    # 输出CDM下载方法异常
    puts "\e[31m[PodAssistant] download_file error(已捕获): #{exception}\e[0m"
  end
  
end

#extract_with_type(full_filename, type = :zip) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/cocoapods-bb-PodAssistant/source_provider_hook.rb', line 240

def extract_with_type(full_filename, type = :zip)
  # 捕获一下异常,不会因为plugin的原因导致pod失败
  begin
    if full_filename.to_s.include?($pluginCurrentTarget)
      # 说明是之前被赋值的下载完成了,开始进行解压了

      # 计算拷贝到的目录下所有文件总大小,单位为M
      dirSum = File.size(full_filename.to_s)/1000.0/1000.0
      # 赋值给当前正在解压的zip大小,之后输出到csv要用
      $pluginCurrentZipSize = dirSum
    else
      # 说明不是之前被赋值的下载完成了,输出一下,然后清空
      puts "\e[31m[PodAssistant] unzip warning: #{$pluginCurrentTarget} target error\e[0m"
      puts "\e[31m[PodAssistant] unzip warning: #{$pluginCurrentPodName} name error\e[0m"
      $pluginCurrentTarget = ""
      $pluginCurrentPodName = ""
    end
  rescue => exception
    # 输出CDN解压方法异常
    puts "\e[31m[PodAssistant] extract_with_type error(已捕获): #{exception}\e[0m"
  end
  # 获取CDN解压前时间点
  time1 = Time.new
  # 执行之前的解压方法
  origin_extract_with_type(full_filename, type)
  # 获取CDN解压后时间点
  time2 = Time.new
  # 赋值CDN解压耗时给全局变量,用于之后输出以及写在csv中
  $cdnUnZipTime = time2 - time1
end

#origin_download_fileObject

使用方法别名hook解压方法,获取解压之前的文件大小



209
# File 'lib/cocoapods-bb-PodAssistant/source_provider_hook.rb', line 209

alias :origin_download_file :download_file

#origin_extract_with_typeObject



210
# File 'lib/cocoapods-bb-PodAssistant/source_provider_hook.rb', line 210

alias :origin_extract_with_type :extract_with_type