Commit 3ed1918d authored by Fabio Pelosin's avatar Fabio Pelosin

[Project] Major improvements to support PodsProjectGenerator

parent b14f3708
......@@ -15,24 +15,47 @@ module Pod
#
def initialize(path, skip_initialization = false)
super(path, skip_initialization)
@support_files_group = new_group('Targets Support Files')
@refs_by_absolute_path = {}
@pods = new_group('Pods')
@development_pods = new_group('Development Pods')
end
# @return [Hash] The names of the specification subgroups by key.
#
ROOT_GROUPS = {
:support_files => 'Targets Support Files',
:pods => 'Pods',
:development_pods => 'Development Pods',
}
# @return [PBXGroup] The group for the support files of the aggregate
# targets.
#
attr_reader :support_files_group
def support_files_group
create_group_if_needed(ROOT_GROUPS[:support_files])
end
# @return [PBXGroup] The group for the Pods.
#
attr_reader :pods
def pods
name = 'Pods'
create_group_if_needed(ROOT_GROUPS[:pods])
end
# @return [PBXGroup] The group for Development Pods.
#
attr_reader :development_pods
def development_pods
name = 'Development Pods'
create_group_if_needed(ROOT_GROUPS[:development_pods])
end
# Cleans up the project to prepare it for serialization.
#
# @return [void]
#
def prepare_for_serialization
pods.remove_from_project if pods.empty?
development_pods.remove_from_project if development_pods.empty?
main_group.recursively_sort_by_type
end
public
......@@ -172,17 +195,39 @@ module Pod
#
def add_podfile(podfile_path)
podfile_ref = new_file(podfile_path, :project)
podfile_ref.name = 'Podfile'
podfile_ref.xc_language_specification_identifier = 'xcode.lang.ruby'
podfile_ref.last_known_file_type = 'text'
podfile_ref
end
# @return [PBXFileReference] The file reference of the Podfile.
#
def podfile
main_group['Podfile']
end
private
# @!group Private helpers
#-------------------------------------------------------------------------#
# Returns the group with the given name, creating it if needed.
#
# @param [String] name
# The name of the group.
#
# @param [String] parent
# The parent group. If nil resolves to the maingroup.
#
# @return [PBXGroup] The group.
#
def create_group_if_needed(name, parent = nil)
parent ||= main_group
parent[name] || parent.new_group(name)
end
# @return [Hash{String => PBXFileReference}] The file references grouped
# by absolute path.
#
......@@ -202,7 +247,7 @@ module Pod
if spec_name != pod_name
subspecs_names = spec_name.gsub(pod_name + '/', '').split('/')
subspecs_names.each do |name|
subspecs_group = group[SPEC_SUBGROUPS[:subspecs]] || group.new_group(SPEC_SUBGROUPS[:subspecs])
subspecs_group = create_group_if_needed(SPEC_SUBGROUPS[:subspecs], group)
group = subspecs_group[name] || subspecs_group.new_group(name)
end
end
......
......@@ -11,18 +11,33 @@ module Pod
describe "In general" do
it "creates the support files group on initialization" do
it "returns the support files group" do
@project.support_files_group.name.should == 'Targets Support Files'
end
it "creates the Pods group on initialization" do
it "returns the pods group" do
@project.pods.name.should == 'Pods'
end
it "creates the development Pods group on initialization" do
it "returns development Pods group" do
@project.development_pods.name.should == 'Development Pods'
end
describe "#prepare_for_serialization" do
it "deletes the Pod and the Development Pods groups if empty" do
@project.prepare_for_serialization
@project[Project::ROOT_GROUPS[:pods]].should.be.nil
@project[Project::ROOT_GROUPS[:development_pods]].should.be.nil
end
it "sorts the groups recursively" do
@project.pods.new_group('group_2')
@project.pods.new_group('group_1')
@project.prepare_for_serialization
@project.pods.children.map(&:name).should == ["group_1", "group_2"]
end
end
end
#-------------------------------------------------------------------------#
......@@ -202,12 +217,39 @@ module Pod
f.path.should == '../Podfile'
end
it "returns the file reference of the Podfile" do
ref = @project.add_podfile(config.sandbox.root + '../Podfile')
@project.podfile.should.equal(ref)
end
end
#-------------------------------------------------------------------------#
describe "Private helpers" do
describe "#create_group_if_needed" do
it "creates a new group" do
group = @project.send(:create_group_if_needed, 'Group')
group.hierarchy_path.should == '/Group'
end
it "creates a new group" do
group = @project.send(:create_group_if_needed, 'Group', @project.pods)
group.hierarchy_path.should == '/Pods/Group'
end
it "returns an already existing group" do
group_1 = @project.send(:create_group_if_needed, 'Group')
group_2 = @project.send(:create_group_if_needed, 'Group')
group_1.should.be.equal(group_2)
end
end
#----------------------------------------#
describe "#spec_group" do
before do
......
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