Class: Pod::Installer::Analyzer::SandboxAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/installer/analyzer/sandbox_analyzer.rb

Overview

Analyze the sandbox to detect which Pods should be removed, and which ones should be reinstalled.

The logic is the following:

Added

  • If not present in the sandbox lockfile.
  • The directory of the Pod doesn't exits.

Changed

  • The version of the Pod changed.
  • The SHA of the specification file changed.
  • The specific installed (sub)specs of the same Pod changed.
  • The specification is from an external source and the installation process is in update mode.
  • The directory of the Pod is empty.
  • The Pod has been pre-downloaded.

Removed

  • If a specification is present in the lockfile but not in the resolved specs.

Unchanged

  • If none of the above conditions match.

Instance Attribute Summary collapse

Pod state collapse

Private helpers collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox, specs, update_mode) ⇒ SandboxAnalyzer

Init a new SandboxAnalyzer

Parameters:

  • sandbox (Sandbox)

    @see sandbox

  • specs (Array<Specifications>)

    @see specs

  • update_mode (Bool)

    @see update_mode


51
52
53
54
55
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 51

def initialize(sandbox, specs, update_mode)
  @sandbox = sandbox
  @specs = specs
  @update_mode = update_mode
end

Instance Attribute Details

#sandboxSandbox (readonly)

Returns The sandbox to analyze.

Returns:

  • (Sandbox)

    The sandbox to analyze.


32
33
34
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 32

def sandbox
  @sandbox
end

#specsArray<Specifications> (readonly)

Returns The specifications returned by the resolver.

Returns:

  • (Array<Specifications>)

    The specifications returned by the resolver.


37
38
39
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 37

def specs
  @specs
end

#update_modeBool (readonly) Also known as: update_mode?

Returns Whether the installation is performed in update mode.

Returns:

  • (Bool)

    Whether the installation is performed in update mode.


41
42
43
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 41

def update_mode
  @update_mode
end

Instance Method Details

#analyzevoid

This method returns an undefined value.

Performs the analysis to the detect the state of the sandbox respect to the resolved specifications.


62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 62

def analyze
  state = SpecsState.new
  if sandbox_manifest
    all_names = (resolved_pods + sandbox_pods).uniq.sort
    all_names.sort.each do |name|
      state.add_name(name, pod_state(name))
    end
  else
    state.added.merge(resolved_pods)
  end
  state
end

#folder_empty?(pod) ⇒ Boolean (private)

Returns:

  • (Boolean)

232
233
234
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 232

def folder_empty?(pod)
  Dir.glob(sandbox.pod_dir(pod) + '*').empty?
end

#folder_exist?(pod) ⇒ Boolean (private)

--------------------------------------#

Returns:

  • (Boolean)

228
229
230
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 228

def folder_exist?(pod)
  sandbox.pod_dir(pod).exist?
end

#pod_added?(pod) ⇒ Bool (private)

Note:

A Pod whose folder doesn't exists is considered added.

Returns whether the Pod with the given name should be installed.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Bool)

    Whether the Pod is added.


104
105
106
107
108
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 104

def pod_added?(pod)
  return true if resolved_pods.include?(pod) && !sandbox_pods.include?(pod)
  return true if !folder_exist?(pod) && !sandbox.local?(pod)
  false
end

#pod_changed?(pod) ⇒ Bool (private)

Note:

In update mode, as there is no way to know if a remote source hash changed the Pods from external sources are always marked as changed.

Note:

A Pod whose folder is empty is considered changed.

Returns whether the Pod with the given name should be considered changed and thus should be reinstalled.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Bool)

    Whether the Pod is changed.


137
138
139
140
141
142
143
144
145
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 137

def pod_changed?(pod)
  spec = root_spec(pod)
  return true if spec.version != sandbox_version(pod)
  return true if spec.checksum != sandbox_checksum(pod)
  return true if resolved_spec_names(pod) != sandbox_spec_names(pod)
  return true if sandbox.predownloaded?(pod)
  return true if folder_empty?(pod)
  false
end

#pod_deleted?(pod) ⇒ Bool (private)

Returns whether the Pod with the given name should be removed from the installation.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Bool)

    Whether the Pod is deleted.


118
119
120
121
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 118

def pod_deleted?(pod)
  return true if !resolved_pods.include?(pod) && sandbox_pods.include?(pod)
  false
end

#pod_state(pod) ⇒ Symbol (private)

Returns the state of the Pod with the given name.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Symbol)

    The state


88
89
90
91
92
93
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 88

def pod_state(pod)
  return :added   if pod_added?(pod)
  return :deleted if pod_deleted?(pod)
  return :changed if pod_changed?(pod)
  :unchanged
end

#resolved_podsArray<String> (private)

Returns The name of the resolved Pods.

Returns:

  • (Array<String>)

    The name of the resolved Pods.


163
164
165
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 163

def resolved_pods
  specs.map { |spec| spec.root.name }.uniq
end

#resolved_spec_names(pod) ⇒ Array<String> (private)

Returns The name of the resolved specifications (includes subspecs).

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Array<String>)

    The name of the resolved specifications (includes subspecs).


180
181
182
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 180

def resolved_spec_names(pod)
  specs.select { |s| s.root.name == pod }.map(&:name).uniq.sort
end

#root_spec(pod) ⇒ Specification (private)

Returns The root specification for the Pod with the given name.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Specification)

    The root specification for the Pod with the given name.


200
201
202
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 200

def root_spec(pod)
  specs.find { |s| s.root.name == pod }.root
end

#sandbox_checksum(pod) ⇒ String (private)

Returns The checksum of the specification of the Pod with the given name stored in the sandbox.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (String)

    The checksum of the specification of the Pod with the given name stored in the sandbox.


222
223
224
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 222

def sandbox_checksum(pod)
  sandbox_manifest.checksum(pod)
end

#sandbox_manifestLockfile (private)

Returns The manifest to use for the sandbox.

Returns:

  • (Lockfile)

    The manifest to use for the sandbox.


155
156
157
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 155

def sandbox_manifest
  sandbox.manifest
end

#sandbox_podsArray<String> (private)

Returns The name of the Pods stored in the sandbox manifest.

Returns:

  • (Array<String>)

    The name of the Pods stored in the sandbox manifest.


170
171
172
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 170

def sandbox_pods
  sandbox_manifest.pod_names.map { |name| Specification.root_name(name) }.uniq
end

#sandbox_spec_names(pod) ⇒ Array<String> (private)

Returns The name of the specifications stored in the sandbox manifest (includes subspecs).

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Array<String>)

    The name of the specifications stored in the sandbox manifest (includes subspecs).


190
191
192
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 190

def sandbox_spec_names(pod)
  sandbox_manifest.pod_names.select { |name| Specification.root_name(name) == pod }.uniq.sort
end

#sandbox_version(pod) ⇒ Version (private)

Returns The version of Pod with the given name stored in the sandbox.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Version)

    The version of Pod with the given name stored in the sandbox.


212
213
214
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 212

def sandbox_version(pod)
  sandbox_manifest.version(pod)
end