Class: LgPodPlugin::ReleasePod

Inherits:
ExternalPod show all
Defined in:
lib/lg_pod_plugin/pod/release-pod.rb

Instance Attribute Summary

Attributes inherited from ExternalPod

#checkout_options, #name, #released_pod, #spec, #target

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, name, hash, spec) ⇒ ReleasePod

Returns a new instance of ReleasePod.



10
11
12
13
14
15
16
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 10

def initialize(target, name, hash, spec)
  @spec = spec
  @name = name
  @target = target
  @released_pod = true
  @checkout_options = hash
end

Class Method Details

.check_release_pod_exist(name, requirements, spec, released_pod) ⇒ Object



18
19
20
21
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 18

def self.check_release_pod_exist(name, requirements, spec, released_pod)
  is_exist, _, _ = (LCache.new.pod_cache_exist(name, requirements, spec, released_pod))
  return is_exist
end

.download_dependencies(installer) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 78

def self.download_dependencies(installer)
  installer.send(:download_dependencies)
  installer.send(:validate_targets)
  installer.send(:clean_sandbox)
  installation_options = installer.send(:installation_options)
  skip_pods_project_generation = installation_options.send(:skip_pods_project_generation)
  if skip_pods_project_generation
    installer.show_skip_pods_project_generation_message
    installer.send(:run_podfile_post_install_hooks)
  else
    installer.integrate
  end
  self.write_lockfiles(installer)
  installer.send(:perform_post_install_actions)
end

.install_release_pod(update, repo_update, verbose, clean_install) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 138

def self.install_release_pod(update, repo_update, verbose, clean_install)
  #切换工作目录到当前工程下, 开始执行pod install
  workspace = LProject.shared.workspace
  FileUtils.chdir(workspace)
  # 安装 release_pod
  LgPodPlugin.log_blue "Pre-downloading Release Pods"
  Pod::Config.instance.verbose = verbose
  pods_path = LProject.shared.workspace.join('Pods')
  podfile = LProject.shared.podfile
  lockfile = LProject.shared.lockfile
  sandbox = Pod::Sandbox.new(pods_path)
  installer = Pod::Installer.new(sandbox, podfile, lockfile)
  installer.repo_update = repo_update
  if update
    need_update_pods = LProject.shared.need_update_pods ||= Hash.new
    pods = need_update_pods.keys ||= []
    begin
      verify_lockfile_exists!(lockfile)
      verify_pods_are_installed!(pods, lockfile)
      internal_data = lockfile.send(:internal_data)
      flag = internal_data["LOCKFILE TYPE"]
      if flag != nil
        if pods.empty?
          installer.update = true
        else
          installer.update = { :pods => pods }
        end
      else
        installer.update = false
      end
    rescue
      installer.update = false
    end
  else
    installer.update = false
  end
  installer.deployment = false
  installer.clean_install = clean_install
  installer.prepare
  resolve_dependencies(lockfile, installer)
  download_dependencies(installer)
end

.lockfile_missing_pods(pods, lockfile) ⇒ Object



110
111
112
113
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 110

def self.lockfile_missing_pods(pods, lockfile)
  lockfile_roots = lockfile.pod_names.map { |pod| Pod::Specification.root_name(pod) }
  pods.map { |pod| Pod::Specification.root_name(pod) }.uniq - lockfile_roots
end

.resolve_dependencies(lockfile, installer) ⇒ Object



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
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 23

def self.resolve_dependencies(lockfile, installer)
  installer.send(:resolve_dependencies)
  external_pods = LProject.shared.external_pods ||= {}
  analysis_result = installer.send(:analysis_result)
  return unless analysis_result
  root_specs = analysis_result.specifications.map(&:root).uniq
  root_specs = root_specs.reject! do |spec|
    spec_name = spec.send(:attributes_hash)["name"]
    external_pods[spec_name] || external_pods[spec_name.split("/").first]
  end unless external_pods.empty?
  return unless root_specs
  all_installers = Array.new
  root_specs.sort_by(&:name).each do |spec|
    attributes_hash = spec.send(:attributes_hash)
    next unless attributes_hash.is_a?(Hash)
    pod_name = attributes_hash["name"]
    source = attributes_hash['source']
    next unless source.is_a?(Hash)
    git = source["git"]
    tag = source["tag"]
    http = source["http"]
    checksum = spec.send(:checksum)
    if http
      if http.include?("https://github.com") && http.include?("releases/download")
        http = "https://ghproxy.com/" + http
        source["http"] = http
      end
      requirements = {:http => http }
    elsif git && tag
      tag = tag.to_s unless LUtils.is_a_string? tag
      requirements = { :git => git, :tag => tag }
    else
      next
    end
    pod_exist = check_release_pod_exist(pod_name, requirements, spec, true)
    if lockfile && checksum
      internal_data = lockfile.send(:internal_data)
      lock_checksums = internal_data["SPEC CHECKSUMS"] ||= {}
      lock_checksum = lock_checksums[pod_name]
      next if (lock_checksum == checksum) && (pod_exist)
    else
      next if pod_exist
    end
    LProject.shared.cache_specs[pod_name] = spec
    lg_spec = LgPodPlugin::PodSpec.form_pod_spec spec
    release_pod = ReleasePod.new(nil, pod_name, requirements, lg_spec)
    pod_install = LgPodPlugin::LPodInstaller.new
    download_params = pod_install.install(release_pod)
    all_installers.append pod_install if download_params
  end
  # 通过 swift 可执行文件进行异步下载任务
  LgPodPlugin::Concurrency.async_download_pods all_installers
end

.verify_lockfile_exists!(lockfile) ⇒ Object



132
133
134
135
136
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 132

def self.verify_lockfile_exists!(lockfile)
  unless lockfile
    raise Pod::Informative, "No `Podfile.lock' found in the project directory, run `pod install'."
  end
end

.verify_pods_are_installed!(pods, lockfile) ⇒ Object

Check if all given pods are installed



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 117

def self.verify_pods_are_installed!(pods, lockfile)
  missing_pods = lockfile_missing_pods(pods, lockfile)

  unless missing_pods.empty?
    message = if missing_pods.length > 1
                "Pods `#{missing_pods.join('`, `')}` are not " \
                      'installed and cannot be updated'
              else
                "The `#{missing_pods.first}` Pod is not installed " \
                      'and cannot be updated'
              end
    raise Pod::Informative, message
  end
end

.write_lockfiles(installer) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 94

def self.write_lockfiles(installer)
  config = Pod::Config.instance
  lockfile = installer.send(:generate_lockfile)
  Pod::UI.message "- Writing Lockfile in #{Pod::UI.path config.lockfile_path}" do hash = lockfile.send(:internal_data)
    hash["LOCKFILE TYPE"] = "LgPodPlugin"
    lockfile.write_to_disk(config.lockfile_path)
  end

  sandbox = installer.send(:sandbox)
  Pod::UI.message "- Writing Manifest in #{Pod::UI.path sandbox.manifest_path}" do
    hash = lockfile.send(:internal_data)
    hash["LOCKFILE TYPE"] = "LgPodPlugin"
    lockfile.write_to_disk(sandbox.manifest_path)
  end
end