Class: Pod::Installer::PodSourceInstaller

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

Overview

Note:

This class needs to consider all the activated specs of a Pod.

Controller class responsible of installing the activated specifications of a single Pod.

Constant Summary collapse

UNENCRYPTED_PROTOCOLS =
%w(http git).freeze

Instance Attribute Summary collapse

Installation collapse

Installation Steps collapse

Convenience methods. collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox, podfile, specs_by_platform, can_cache: true) ⇒ PodSourceInstaller

Initialize a new instance

Parameters:

  • sandbox (Sandbox)

    @see #sandbox

  • podfile (Podfile)

    @see #podfile

  • specs_by_platform (Hash{Symbol=>Array})

    @see #specs_by_platform

  • can_cache (Boolean) (defaults to: true)

    @see #can_cache


39
40
41
42
43
44
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 39

def initialize(sandbox, podfile, specs_by_platform, can_cache: true)
  @sandbox = sandbox
  @podfile = podfile
  @specs_by_platform = specs_by_platform
  @can_cache = can_cache
end

Instance Attribute Details

#can_cacheBoolean (readonly) Also known as: can_cache?

Returns Whether the installer is allowed to touch the cache.

Returns:

  • (Boolean)

    Whether the installer is allowed to touch the cache.


29
30
31
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 29

def can_cache
  @can_cache
end

#podfilePodfile (readonly)

Returns the podfile that should be integrated with the user projects.

Returns:

  • (Podfile)

    the podfile that should be integrated with the user projects.


20
21
22
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 20

def podfile
  @podfile
end

#sandboxSandbox (readonly)

Returns The installation target.

Returns:

  • (Sandbox)

    The installation target.


15
16
17
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 15

def sandbox
  @sandbox
end

#specs_by_platformHash{Symbol=>Array} (readonly)

Returns The specifications that need to be installed grouped by platform.

Returns:

  • (Hash{Symbol=>Array})

    The specifications that need to be installed grouped by platform.


25
26
27
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 25

def specs_by_platform
  @specs_by_platform
end

Instance Method Details

#clean!void

This method returns an undefined value.

Cleans the installations if appropriate.

Cleaning the installation will remove any files that are not used during the build process, based on the podspec and platforms of the target that the pod is integrated into.

See Also:

  • Pod::Installer::PodSourceInstaller.{{#clean_installation}

83
84
85
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 83

def clean!
  clean_installation unless local?
end

#clean_installationvoid (private)

This method returns an undefined value.

Removes all the files not needed for the installation according to the specs by platform.


163
164
165
166
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 163

def clean_installation
  cleaner = Sandbox::PodDirCleaner.new(root, specs_by_platform)
  cleaner.clean!
end

#download_requestObject (private)


147
148
149
150
151
152
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 147

def download_request
  Downloader::Request.new(
    :spec => root_spec,
    :released => released?,
  )
end

#download_sourcevoid (private)

This method returns an undefined value.

Downloads the source of the Pod.


116
117
118
119
120
121
122
123
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 116

def download_source
  verify_source_is_secure(root_spec)
  download_result = Downloader.download(download_request, root, :can_cache => can_cache?)

  if (specific_source = download_result.checkout_options) && specific_source != root_spec.source
    sandbox.store_checkout_source(root_spec.name, specific_source)
  end
end

#external?Boolean (private)

Returns whether the pod uses an external source (e.g. :podspec) in the resolution process to retrieve its podspec.

Returns:

  • (Boolean)

    whether the pod uses an external source (e.g. :podspec) in the resolution process to retrieve its podspec.


206
207
208
209
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 206

def external?
  @dependencies ||= podfile.dependencies.select(&:external?).map(&:name)
  @dependencies.include?(root_spec.name)
end

#inspectString

Returns A string suitable for debugging.

Returns:

  • (String)

    A string suitable for debugging.


48
49
50
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 48

def inspect
  "<#{self.class} sandbox=#{sandbox.root} pod=#{root_spec.name}"
end

#install!void

This method returns an undefined value.

Creates the target in the Pods project and the relative support files.


68
69
70
71
72
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 68

def install!
  download_source unless predownloaded? || local?
  PodSourcePreparer.new(root_spec, root).prepare! if local?
  sandbox.remove_local_podspec(name) unless predownloaded? || local? || external?
end

#local?Boolean (private)

Returns whether the pod uses the local option and thus CocoaPods should not interfere with the files of the user.

Returns:

  • (Boolean)

    whether the pod uses the local option and thus CocoaPods should not interfere with the files of the user.


199
200
201
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 199

def local?
  sandbox.local?(root_spec.name)
end

#lock_files!(file_accessors) ⇒ void

This method returns an undefined value.

Locks the source files if appropriate.


91
92
93
94
95
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 91

def lock_files!(file_accessors)
  return if local?
  unlocked_files = source_files(file_accessors).reject { |f| (File.stat(f).mode & 0o200).zero? }
  FileUtils.chmod('u-w', unlocked_files)
end

#nameString

Returns The name of the pod this installer is installing.

Returns:

  • (String)

    The name of the pod this installer is installing.


54
55
56
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 54

def name
  root_spec.name
end

#predownloaded?Boolean (private)

Returns whether the source has been pre downloaded in the resolution process to retrieve its podspec.

Returns:

  • (Boolean)

    whether the source has been pre downloaded in the resolution process to retrieve its podspec.


192
193
194
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 192

def predownloaded?
  sandbox.predownloaded_pods.include?(root_spec.name)
end

#released?Boolean (private)

Returns:

  • (Boolean)

211
212
213
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 211

def released?
  !local? && !predownloaded? && sandbox.specification(root_spec.name) != root_spec
end

#rootPathname (private)

Returns the folder where the source of the Pod is located.

Returns:

  • (Pathname)

    the folder where the source of the Pod is located.


185
186
187
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 185

def root
  sandbox.pod_dir(root_spec.name)
end

#root_specSpecification (private)

Returns the root specification of the Pod.

Returns:


179
180
181
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 179

def root_spec
  specs.first.root
end

#source_files(file_accessors) ⇒ Array<Pathname> (private)

Returns The paths of the source files.

Returns:

  • (Array<Pathname>)

    The paths of the source files


217
218
219
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 217

def source_files(file_accessors)
  file_accessors.flat_map(&:source_files)
end

#specsArray<Specifications> (private)

Returns the specification of the Pod used in this installation.

Returns:

  • (Array<Specifications>)

    the specification of the Pod used in this installation.


173
174
175
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 173

def specs
  specs_by_platform.values.flatten
end

#unlock_files!(file_accessors) ⇒ void

This method returns an undefined value.

Unlocks the source files if appropriate.


101
102
103
104
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 101

def unlock_files!(file_accessors)
  return if local?
  FileUtils.chmod('u+w', source_files(file_accessors))
end

#verify_source_is_secure(root_spec) ⇒ void (private)

This method returns an undefined value.

Verify the source of the spec is secure, which is used to show a warning to the user if that isn't the case This method doesn't verify all protocols, but currently only prohibits unencrypted 'http://' and 'git://'' connections.


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/cocoapods/installer/pod_source_installer.rb', line 131

def verify_source_is_secure(root_spec)
  return if root_spec.source.nil? || (root_spec.source[:http].nil? && root_spec.source[:git].nil?)
  source = if !root_spec.source[:http].nil?
             URI(root_spec.source[:http].to_s)
           elsif !root_spec.source[:git].nil?
             git_source = root_spec.source[:git].to_s
             return unless git_source =~ /^#{URI.regexp}$/
             URI(git_source)
           end
  if UNENCRYPTED_PROTOCOLS.include?(source.scheme) && source.host != 'localhost'
    UI.warn "'#{root_spec.name}' uses the unencrypted '#{source.scheme}' protocol to transfer the Pod. " \
          'Please be sure you\'re in a safe network with only trusted hosts. ' \
          'Otherwise, please reach out to the library author to notify them of this security issue.'
  end
end