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.



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

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



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

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

.dependencies(installer) ⇒ Object



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

def self.dependencies(installer)
  installer.download_dependencies
  installer.send(:validate_targets)
  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
  else
    installer.integrate
  end
  installer.send(:write_lockfiles)
  installer.send(:perform_post_install_actions)
end

.install_release_pod(update, repo_update, verbose) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 119

def self.install_release_pod(update, repo_update, verbose)
  #切换工作目录到当前工程下, 开始执行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)
      if pods.empty?
        installer.update = true
      else
        installer.update = { :pods => pods }
      end
    rescue
      installer.update = false
    end
  else
    installer.update = false
  end
  installer.deployment = false
  installer.clean_install = false
  installer.prepare
  resolve_dependencies(lockfile, installer)
  dependencies(installer)
end

.lockfile_missing_pods(pods, lockfile) ⇒ Object



91
92
93
94
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 91

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



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

def self.resolve_dependencies(lockfile, installer)
  installer.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
      version = attributes_hash["version"]
      requirements = {:http => http, :version => version}
    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



113
114
115
116
117
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 113

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



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/lg_pod_plugin/pod/release-pod.rb', line 98

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