Commit 5bead517 authored by Fabio Pelosin's avatar Fabio Pelosin

[UserProjectIntegrator] Add support for Xcodeproj::Workspace::FileReference

See https://github.com/CocoaPods/Xcodeproj/pull/150
parent 4cc28f76
......@@ -18,7 +18,7 @@ GIT
GIT
remote: https://github.com/CocoaPods/Xcodeproj.git
revision: 6d0bc86794e1bc727cbec76e6ffc5393b8c04306
revision: 60c297e6dd8b04ba055b1350d72a7ef0f1092879
branch: master
specs:
xcodeproj (0.16.1)
......@@ -27,7 +27,7 @@ GIT
GIT
remote: https://github.com/CocoaPods/cocoapods-downloader.git
revision: c004c28547c0a670a15bc7cef195d7b9e1944c0d
revision: 224c8a191ef6b98d538d6228b0549d05194944ee
branch: master
specs:
cocoapods-downloader (0.5.0)
......
......@@ -81,21 +81,22 @@ module Pod
#
def create_workspace
all_projects = user_project_paths.sort.push(sandbox.project_path).uniq
projpaths = all_projects.map do |path|
path.relative_path_from(workspace_path.dirname).to_s
file_references = all_projects.map do |path|
relative_path = path.relative_path_from(workspace_path.dirname).to_s
Xcodeproj::Workspace::FileReference.new(relative_path, 'group')
end
if workspace_path.exist?
workspace = Xcodeproj::Workspace.new_from_xcworkspace(workspace_path)
new_projpaths = projpaths - workspace.projpaths
unless new_projpaths.empty?
workspace.projpaths.concat(new_projpaths)
new_file_references = file_references - workspace.file_references
unless new_file_references.empty?
workspace.file_references.concat(new_file_references)
workspace.save_as(workspace_path)
end
else
UI.notice "From now on use `#{workspace_path.basename}`."
workspace = Xcodeproj::Workspace.new(*projpaths)
workspace = Xcodeproj::Workspace.new(*file_references)
workspace.save_as(workspace_path)
end
end
......
......@@ -34,7 +34,10 @@ module Pod
@integrator.integrate!
workspace_path = @integrator.send(:workspace_path)
workspace = Xcodeproj::Workspace.new_from_xcworkspace(workspace_path)
workspace.projpaths.find { |path| path =~ /Pods.xcodeproj/ }.should.not.be.nil
pods_project_ref = workspace.file_references.find do |ref|
ref.path =~ /Pods.xcodeproj/
end
pods_project_ref.should.not.be.nil
end
it "integrates the user targets" do
......@@ -60,7 +63,7 @@ module Pod
@integrator.send(:create_workspace)
workspace_path = @integrator.send(:workspace_path)
saved = Xcodeproj::Workspace.new_from_xcworkspace(workspace_path)
saved.projpaths.should == [
saved.file_references.map(&:path).should == [
"SampleProject/SampleProject.xcodeproj",
"Pods/Pods.xcodeproj"
]
......@@ -68,22 +71,24 @@ module Pod
it "updates an existing workspace if needed" do
workspace_path = @integrator.send(:workspace_path)
workspace = Xcodeproj::Workspace.new('SampleProject/SampleProject.xcodeproj')
ref = Xcodeproj::Workspace::FileReference.new('SampleProject/SampleProject.xcodeproj', 'group')
workspace = Xcodeproj::Workspace.new(ref)
workspace.save_as(workspace_path)
@integrator.send(:create_workspace)
saved = Xcodeproj::Workspace.new_from_xcworkspace(workspace_path)
saved.projpaths.should == [
saved.file_references.map(&:path).should == [
"SampleProject/SampleProject.xcodeproj",
"Pods/Pods.xcodeproj"
]
end
it "doesn't write the workspace if not needed" do
projpaths = [
"SampleProject/SampleProject.xcodeproj",
"Pods/Pods.xcodeproj"
file_references = [
Xcodeproj::Workspace::FileReference.new('SampleProject/SampleProject.xcodeproj', 'group'),
Xcodeproj::Workspace::FileReference.new('Pods/Pods.xcodeproj', 'group')
]
workspace = Xcodeproj::Workspace.new(projpaths)
workspace = Xcodeproj::Workspace.new(file_references)
workspace_path = @integrator.send(:workspace_path)
workspace.save_as(workspace_path)
Xcodeproj::Workspace.expects(:save_as).never
......@@ -91,12 +96,13 @@ module Pod
end
it "only appends projects to the workspace and never deletes one" do
workspace = Xcodeproj::Workspace.new('user_added_project.xcodeproj')
ref = Xcodeproj::Workspace::FileReference.new('user_added_project.xcodeproj', 'group')
workspace = Xcodeproj::Workspace.new(ref)
workspace_path = @integrator.send(:workspace_path)
workspace.save_as(workspace_path)
@integrator.send(:create_workspace)
saved = Xcodeproj::Workspace.new_from_xcworkspace(workspace_path)
saved.projpaths.should == [
saved.file_references.map(&:path).should == [
'user_added_project.xcodeproj',
"SampleProject/SampleProject.xcodeproj",
"Pods/Pods.xcodeproj"
......@@ -104,16 +110,17 @@ module Pod
end
it "preserves the order of the projects in the workspace" do
projpaths = [
"Pods/Pods.xcodeproj",
"SampleProject/SampleProject.xcodeproj",
file_references = [
Xcodeproj::Workspace::FileReference.new('Pods/Pods.xcodeproj', 'group'),
Xcodeproj::Workspace::FileReference.new('SampleProject/SampleProject.xcodeproj', 'group'),
]
workspace = Xcodeproj::Workspace.new(projpaths)
workspace = Xcodeproj::Workspace.new(file_references)
workspace_path = @integrator.send(:workspace_path)
workspace.save_as(workspace_path)
@integrator.send(:create_workspace)
saved = Xcodeproj::Workspace.new_from_xcworkspace(workspace_path)
saved.projpaths.should == [
saved.file_references.map(&:path).should == [
"Pods/Pods.xcodeproj",
"SampleProject/SampleProject.xcodeproj",
]
......
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