Commit 0b264e6e authored by Fabio Pelosin's avatar Fabio Pelosin

Add Installer::FileReferencesInstaller

parent b2fcbbb2
module Pod
class Installer
# Controller class responsible of installing the file references of the
# specifications in the Pods project.
#
class FileReferencesInstaller
# @return [Sandbox] The sandbox of the installation.
#
attr_reader :sandbox
# @return [Array<Library>] The libraries of the installation.
#
attr_reader :libraries
# @return [Project] The Pods project.
#
attr_reader :pods_project
# @param [Sandbox] sandbox @see sandbox
# @param [Array<Library>] libraries @see libraries
# @param [Project] libraries @see libraries
#
def initialize(sandbox, libraries, pods_project)
@sandbox = sandbox
@libraries = libraries
@pods_project = pods_project
end
# Installs the file references.
#
# @return [void]
#
def install!
add_source_files_references
add_resources_references
end
#-----------------------------------------------------------------------#
private
# @!group Installation Steps
# Adds the source files of the Pods to the Pods project.
#
# @note The source files are grouped by Pod and in turn by subspec
# (recursively).
#
# @note Pods are generally added to the `Pods` group, however, if they
# have a local source they are added to the
# `Local Pods` group.
#
# @return [void]
#
def add_source_files_references
UI.message "- Adding source files to Pods project" do
file_accessors.each do |file_accessor|
files = file_accessor.source_files
spec_name = file_accessor.spec.name
local = file_accessor.spec.local?
parent_group = local ? pods_project.local_pods : pods_project.pods
parent_group = pods_project.pods
pods_project.add_file_references(files, spec_name, parent_group)
end
end
end
# Adds the resources of the Pods to the Pods project.
#
# @note The source files are grouped by Pod and in turn by subspec
# (recursively) in the resources group.
#
# @return [void]
#
def add_resources_references
UI.message "- Adding resources to Pods project" do
file_accessors.each do |file_accessor|
file_accessor.resources.each do |destination, resources|
next if resources.empty?
files = file_accessor.resources.values.flatten
spec_name = file_accessor.spec.name
parent_group = pods_project.resources
pods_project.add_file_references(files, spec_name, parent_group)
end
end
end
end
#-----------------------------------------------------------------------#
private
# @!group Private Helpers
# @return [Array<Sandbox::FileAccessor>] The file accessors for all the
# specs platform combinations.
#
# TODO Ideally the file accessors should be created one per spec per
# platform in a single installation.
#
def file_accessors
@file_accessors ||= libraries.map(&:file_accessors).flatten
end
#-----------------------------------------------------------------------#
end
end
end
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Installer::PodSourceInstaller do
before do
file_accessor = fixture_file_accessor('banana-lib/BananaLib.podspec')
@library = Library.new(nil)
@library.file_accessors = [file_accessor]
@project = Project.new(config.sandbox.project_path)
@installer = Installer::FileReferencesInstaller.new(config.sandbox, [@library], @project)
end
#-------------------------------------------------------------------------#
describe "Installation" do
it "adds the files references of the source files the Pods project" do
@installer.install!
group_ref = @installer.pods_project['Pods/BananaLib']
group_ref.should.be.not.nil
file_ref = @installer.pods_project['Pods/BananaLib/Banana.m']
file_ref.should.be.not.nil
file_ref.path.should == "../../spec/fixtures/banana-lib/Classes/Banana.m"
end
it "adds the files references of the resources the Pods project" do
@installer.install!
group_ref = @installer.pods_project['Resources/BananaLib']
group_ref.should.be.not.nil
file_ref = @installer.pods_project['Resources/BananaLib/logo-sidebar.png']
file_ref.should.be.not.nil
file_ref.path.should == "../../spec/fixtures/banana-lib/Resources/logo-sidebar.png"
end
end
#-------------------------------------------------------------------------#
describe "Private Helpers" do
xit "returns the unique file accessors" do
library_1 = Library.new(nil)
library_1.file_accessors = [fixture_file_accessor('banana-lib/BananaLib.podspec')]
library_2 = Library.new(nil)
library_2.file_accessors = [fixture_file_accessor('banana-lib/BananaLib.podspec')]
installer = Installer::FileReferencesInstaller.new(config.sandbox, [library_1, library_2], @project)
installer.send(:file_accessors).count.should == 1
end
end
#-------------------------------------------------------------------------#
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment