Class: LgPodPlugin::LDownloader
- Inherits:
-
Object
- Object
- LgPodPlugin::LDownloader
- Defined in:
- lib/lg_pod_plugin/downloader/downloader.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
Returns the value of attribute request.
Instance Method Summary collapse
-
#download_repository_strategy(path, checkout_options = {}) ⇒ Object
根据不同 git 源 选择下载策略.
-
#initialize(pod) ⇒ LDownloader
constructor
A new instance of LDownloader.
- #pre_download_git_repository(checkout_options = {}) ⇒ Object
-
#pre_download_pod ⇒ Object
预下载处理.
Constructor Details
#initialize(pod) ⇒ LDownloader
Returns a new instance of LDownloader.
11 12 13 |
# File 'lib/lg_pod_plugin/downloader/downloader.rb', line 11 def initialize(pod) self.request = LRequest.new(pod) end |
Instance Attribute Details
#request ⇒ Object
Returns the value of attribute request.
9 10 11 |
# File 'lib/lg_pod_plugin/downloader/downloader.rb', line 9 def request @request end |
Instance Method Details
#download_repository_strategy(path, checkout_options = {}) ⇒ Object
根据不同 git 源 选择下载策略
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/lg_pod_plugin/downloader/downloader.rb', line 120 def download_repository_strategy(path, = {}) FileUtils.chdir(path) git = [:git] http = [:http] if http begin [:path] = path http_download = LgPodPlugin::HTTPDownloader.new() http_download.download rescue => exception LgPodPlugin.log_red "异常信息: #{$!}" LgPodPlugin.log_yellow " 异常位置: #{$@}" return nil end elsif git [:path] = path [:config] = self.request.config if self.request.config git_download = LgPodPlugin::GitDownloader.new() return git_download.download else return nil end end |
#pre_download_git_repository(checkout_options = {}) ⇒ Object
113 114 115 116 117 |
# File 'lib/lg_pod_plugin/downloader/downloader.rb', line 113 def pre_download_git_repository( = {}) lg_pod_path = LFileManager.cache_workspace(LProject.shared.workspace) lg_pod_path.mkdir(0700) unless lg_pod_path.exist? download_repository_strategy(lg_pod_path, ) end |
#pre_download_pod ⇒ Object
预下载处理
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/lg_pod_plugin/downloader/downloader.rb', line 16 def pre_download_pod name = self.request.name if self.request.lg_spec podspec = self.request.lg_spec.spec else podspec = nil end = Hash.new.merge!(self.request.) http = [:http] git = [:git] tag = [:tag] branch = [:branch] [:name] = name if name [:spec] = self.request.lg_spec if podspec unless branch branch = self.request.params[:branch] if self.request.params[:branch] [:branch] = branch if branch end commit = [:commit] unless commit commit = self.request.params[:commit] if self.request.params[:commit] [:commit] = commit if commit end if branch LgPodPlugin.log_green "Using `#{name}` (#{branch})" elsif tag LgPodPlugin.log_green "Using `#{name}` (#{tag})" elsif commit LgPodPlugin.log_green "Using `#{name}` (#{commit})" elsif http version = [:version] LgPodPlugin.log_green "Using `#{name}` (#{version})" else LgPodPlugin.log_green "Using `#{name}`" end hash_map = self.request.get_cache_key_params self.request..delete(:branch) if commit self.request.[:commit] = commit if commit # 发现本地有缓存, 不需要更新缓存 pod_is_exist, destination, cache_pod_spec = LCache.new.pod_cache_exist(name, hash_map, podspec, self.request.released_pod) if pod_is_exist LgPodPlugin.log_green "find the cache of `#{name}`, you can use it now." return nil else LgPodPlugin.log_green "find the new commit of `#{name}`, Git downloading now." # 本地 git 下载 pod 目录 download_params = self.pre_download_git_repository() if download_params && download_params.is_a?(Hash) download_params["destination"] = destination download_params["cache_pod_spec_path"] = cache_pod_spec podspec = download_params["podspec"] podspec_content = download_params["podspec_content"] if podspec podspec_json = podspec.to_pretty_json download_params["podspec_json"] = podspec_json if podspec download_params["prepare_command"] = podspec.prepare_command if podspec download_params.delete("podspec") unless self.request.lg_spec self.request.lg_spec = podspec end elsif podspec_content path = download_params["path"] podspec_path = path + "/#{name}.podspec" begin File.open(podspec_path,"w+") do|f| f.write podspec_content end end if File.exist?(podspec_path) lg_spec = LgPodPlugin::PodSpec.form_file podspec_path if lg_spec self.request.lg_spec = lg_spec download_params["podspec_json"] = lg_spec.to_pretty_json download_params["source_files"] = lg_spec.source_files.keys download_params["prepare_command"] = lg_spec.prepare_command if lg_spec.prepare_command download_params.delete("podspec_content") else download_params["source_files"] = ["All"] download_params["prepare_command"] = nil download_params["podspec_json"] = podspec_content download_params.delete("podspec_content") end end end return download_params elsif File.exist?(download_params.to_s) && download_params FileUtils.chdir download_params LgPodPlugin::LCache.cache_pod(name, download_params, { :git => git }, podspec, self.request.released_pod) if self.request.single_git LgPodPlugin::LCache.cache_pod(name, download_params, self.request.get_cache_key_params,podspec, self.request.released_pod) FileUtils.chdir(LFileManager.download_director) FileUtils.rm_rf(download_params) end nil end end |