vendor 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/CHANGELOG.md +6 -0
  2. data/Gemfile.lock +1 -1
  3. data/LICENSE +1 -1
  4. data/Readme.markdown +2 -1
  5. data/VERSION +1 -1
  6. data/lib/vendor/cli/app.rb +13 -17
  7. data/lib/vendor/spec.rb +244 -55
  8. data/lib/vendor/vendor_file/library/base.rb +43 -63
  9. data/lib/vendor/vendor_file/loader.rb +8 -0
  10. data/lib/vendor/vendor_spec/builder.rb +19 -8
  11. data/lib/vendor/xcode.rb +0 -1
  12. data/lib/vendor/xcode/project.rb +198 -469
  13. data/spec/lib/vendor/spec_spec.rb +34 -10
  14. data/spec/lib/vendor/vendor_file/library/base_spec.rb +41 -49
  15. data/spec/lib/vendor/vendor_spec/builder_spec.rb +26 -0
  16. data/spec/support/resources/cache/base/DKBenchmark-0.1-Manifest/vendor.json +1 -1
  17. data/spec/support/resources/cache/base/DKBenchmark-0.1-Vendorspec/DKBenchmark.vendorspec +2 -0
  18. data/spec/support/resources/vendors/DKBenchmark/DKBenchmark.vendorspec +2 -0
  19. data/spec/support/resources/vendors/DKBenchmarkFramework/DKBenchmark.framework/DKBenchmark +0 -0
  20. data/spec/support/resources/vendors/DKBenchmarkFramework/DKBenchmark.framework/Versions/A/DKBenchmark +0 -0
  21. data/spec/support/resources/vendors/DKBenchmarkFramework/DKBenchmark.framework/Versions/A/Headers/DKBenchmark.h +18 -0
  22. data/spec/support/resources/vendors/DKBenchmarkFramework/DKBenchmark.vendorspec +23 -0
  23. data/vendor.gemspec +1 -0
  24. metadata +111 -63
  25. data/lib/vendor/xcode/proxy.rb +0 -31
  26. data/lib/vendor/xcode/proxy/base.rb +0 -129
  27. data/lib/vendor/xcode/proxy/pbx_aggregate_target.rb +0 -11
  28. data/lib/vendor/xcode/proxy/pbx_build_file.rb +0 -9
  29. data/lib/vendor/xcode/proxy/pbx_container_item_proxy.rb +0 -8
  30. data/lib/vendor/xcode/proxy/pbx_file_reference.rb +0 -41
  31. data/lib/vendor/xcode/proxy/pbx_frameworks_build_phase.rb +0 -15
  32. data/lib/vendor/xcode/proxy/pbx_group.rb +0 -35
  33. data/lib/vendor/xcode/proxy/pbx_native_target.rb +0 -11
  34. data/lib/vendor/xcode/proxy/pbx_project.rb +0 -12
  35. data/lib/vendor/xcode/proxy/pbx_reference_proxy.rb +0 -7
  36. data/lib/vendor/xcode/proxy/pbx_resources_build_phase.rb +0 -15
  37. data/lib/vendor/xcode/proxy/pbx_shell_script_build_phase.rb +0 -15
  38. data/lib/vendor/xcode/proxy/pbx_sources_build_phase.rb +0 -15
  39. data/lib/vendor/xcode/proxy/pbx_target_dependency.rb +0 -7
  40. data/lib/vendor/xcode/proxy/pbx_variant_group.rb +0 -7
  41. data/lib/vendor/xcode/proxy/unknown.rb +0 -8
  42. data/lib/vendor/xcode/proxy/xc_build_configuration.rb +0 -7
  43. data/lib/vendor/xcode/proxy/xc_configuration_list.rb +0 -9
  44. data/lib/vendor/xcode/proxy/xc_version_group.rb +0 -7
  45. data/spec/lib/vendor/xcode/project_spec.rb +0 -635
  46. data/spec/lib/vendor/xcode/proxy/base_spec.rb +0 -88
  47. data/spec/lib/vendor/xcode/proxy/pbx_file_reference_spec.rb +0 -26
  48. data/spec/lib/vendor/xcode/proxy/pbx_group_spec.rb +0 -27
  49. data/spec/lib/vendor/xcode/proxy/pbx_project_spec.rb +0 -29
@@ -1,31 +0,0 @@
1
- module Vendor
2
-
3
- module XCode
4
-
5
- module Proxy
6
-
7
- autoload :Base, "vendor/xcode/proxy/base"
8
- autoload :PBXAggregateTarget, "vendor/xcode/proxy/pbx_aggregate_target"
9
- autoload :PBXProject, "vendor/xcode/proxy/pbx_project"
10
- autoload :PBXFileReference, "vendor/xcode/proxy/pbx_file_reference"
11
- autoload :PBXGroup, "vendor/xcode/proxy/pbx_group"
12
- autoload :PBXSourcesBuildPhase, "vendor/xcode/proxy/pbx_sources_build_phase"
13
- autoload :PBXBuildFile, "vendor/xcode/proxy/pbx_build_file"
14
- autoload :PBXFrameworksBuildPhase, "vendor/xcode/proxy/pbx_frameworks_build_phase"
15
- autoload :PBXResourcesBuildPhase, "vendor/xcode/proxy/pbx_resources_build_phase"
16
- autoload :PBXNativeTarget, "vendor/xcode/proxy/pbx_native_target"
17
- autoload :PBXContainerItemProxy, "vendor/xcode/proxy/pbx_container_item_proxy"
18
- autoload :PBXTargetDependency, "vendor/xcode/proxy/pbx_target_dependency"
19
- autoload :PBXVariantGroup, "vendor/xcode/proxy/pbx_variant_group"
20
- autoload :PBXShellScriptBuildPhase, "vendor/xcode/proxy/pbx_shell_script_build_phase"
21
- autoload :PBXReferenceProxy, "vendor/xcode/proxy/pbx_reference_proxy"
22
- autoload :XCBuildConfiguration, "vendor/xcode/proxy/xc_build_configuration"
23
- autoload :XCConfigurationList, "vendor/xcode/proxy/xc_configuration_list"
24
- autoload :XCVersionGroup, "vendor/xcode/proxy/xc_version_group"
25
- autoload :Unknown, "vendor/xcode/proxy/unknown"
26
-
27
- end
28
-
29
- end
30
-
31
- end
@@ -1,129 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class Base
4
-
5
- attr_accessor :id
6
- attr_accessor :parent
7
- attr_reader :attributes
8
-
9
- class << self
10
-
11
- # I don't know what the ID's are made up of in XCode,
12
- # so lets just generate a 24 character string.
13
- def generate_id
14
- (0...24).map { '%02X' % rand(256) }.join
15
- end
16
-
17
- def object_references
18
- @references || []
19
- end
20
-
21
- def reference(name)
22
- attribute = attribute_name(name)
23
-
24
- define_method name do
25
- value = @attributes[attribute]
26
- if value.kind_of?(Array)
27
- value.map { |id| @project.find_object(id) }
28
- else
29
- @project.find_object(value)
30
- end
31
- end
32
-
33
- @references ||= []
34
- @references << name
35
- end
36
-
37
- # References are stored in camel case in the project file
38
- def attribute_name(name)
39
- camelized = name.to_s.gsub(/[^\w]/, '').gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
40
- camelized[0].chr.downcase + camelized[1..-1]
41
- end
42
-
43
- end
44
-
45
- def initialize(options)
46
- @id = options[:id]
47
- @project = options[:project]
48
- @attributes = options[:attributes]
49
-
50
- @attributes['isa'] = self.class.name.split('::').last unless @attributes['isa']
51
- end
52
-
53
- def inspect
54
- properties = { "id" => @id }.merge(@attributes)
55
-
56
- # The class name contains the ISA (the type of the object)
57
- properties.delete("isa")
58
-
59
- # Always show the ID first
60
- keys = properties.keys.map(&:to_s)
61
- keys.delete("id")
62
- keys.unshift("id")
63
-
64
- "#<#{self.class.name} #{keys.map{ |key| "#{underscore(key)}: #{properties[key].inspect}" }.join(', ')}>"
65
- end
66
-
67
- def method_missing(v, *args)
68
- setting = v.to_s.match(/\=$/)
69
- name = self.class.attribute_name(v)
70
-
71
- if @attributes.has_key?(name)
72
- if setting
73
- write_attribute(name, args.first)
74
- else
75
- read_attribute(name)
76
- end
77
- else
78
- super
79
- end
80
- end
81
-
82
- def respond_to?(method)
83
- name = self.class.attribute_name(method)
84
-
85
- if @attributes.has_key?(name)
86
- true
87
- else
88
- super
89
- end
90
- end
91
-
92
- def write_attribute(name, value)
93
- @attributes[name.to_s] = value
94
- end
95
-
96
- def read_attribute(name)
97
- @attributes[name.to_s]
98
- end
99
-
100
- def to_ascii_plist
101
- @attributes.to_ascii_plist
102
- end
103
-
104
- def group?
105
- false
106
- end
107
-
108
- def file?
109
- false
110
- end
111
-
112
- private
113
-
114
- def after_initialize
115
- # Do nothing by default
116
- end
117
-
118
- # I miss active support...
119
- def underscore(string)
120
- string.gsub(/::/, '/').
121
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
122
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
123
- tr("-", "_").
124
- downcase
125
- end
126
-
127
- end
128
-
129
- end
@@ -1,11 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXAggregateTarget < Vendor::XCode::Proxy::Base
4
-
5
- reference :build_phases
6
- reference :dependencies
7
- reference :build_configuration_list
8
-
9
- end
10
-
11
- end
@@ -1,9 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXBuildFile < Vendor::XCode::Proxy::Base
4
-
5
- reference :file_ref
6
-
7
- end
8
-
9
- end
@@ -1,8 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXContainerItemProxy < Vendor::XCode::Proxy::Base
4
-
5
-
6
- end
7
-
8
- end
@@ -1,41 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXFileReference < Vendor::XCode::Proxy::Base
4
-
5
- reference :file_ref
6
-
7
- def file?
8
- true
9
- end
10
-
11
- def full_path
12
- parts = []
13
- current = self
14
-
15
- while current
16
- parts.push current.path if current.respond_to?(:path) && !current.path.nil?
17
- current = current.parent
18
- end
19
-
20
- parts.reverse.join("/")
21
- end
22
-
23
- def self.file_type_from_extension(extension)
24
- case extension
25
- when /.(png|jpg)/ then "image.#{$1}"
26
- when ".h" then "sourcecode.c.h"
27
- when ".m" then "sourcecode.c.objc"
28
- when ".c" then "sourcecode.c.c"
29
- when ".bundle" then "wrapper.plug-in"
30
- when ".framework" then "wrapper.framework"
31
- when ".a" then "archive.ar"
32
- when ".strings" then "text.plist.strings"
33
- when ".plist" then "text.plist.xml"
34
- when ".dylib" then "compiled.mach-o.dylib"
35
- else "unknown"
36
- end
37
- end
38
-
39
- end
40
-
41
- end
@@ -1,15 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXFrameworksBuildPhase < Vendor::XCode::Proxy::Base
4
-
5
- reference :files
6
-
7
- private
8
-
9
- def after_initialize
10
- files.each { |child| child.parent = self }
11
- end
12
-
13
- end
14
-
15
- end
@@ -1,35 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXGroup < Vendor::XCode::Proxy::Base
4
-
5
- reference :children
6
-
7
- def name
8
- @attributes['name'] || @attributes['path']
9
- end
10
-
11
- def full_path
12
- parts = []
13
- current = self
14
-
15
- while current
16
- parts.push current.name
17
- current = current.parent
18
- end
19
-
20
- parts.reverse.compact.join("/")
21
- end
22
-
23
- def group?
24
- true
25
- end
26
-
27
- private
28
-
29
- def after_initialize
30
- children.each { |child| child.parent = self }
31
- end
32
-
33
- end
34
-
35
- end
@@ -1,11 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXNativeTarget < Vendor::XCode::Proxy::Base
4
-
5
- reference :build_phases
6
- reference :product_reference
7
- reference :build_configuration_list
8
-
9
- end
10
-
11
- end
@@ -1,12 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXProject < Vendor::XCode::Proxy::Base
4
-
5
- reference :build_configuration_list
6
- reference :product_ref_group
7
- reference :main_group
8
- reference :targets
9
-
10
- end
11
-
12
- end
@@ -1,7 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXReferenceProxy < Vendor::XCode::Proxy::Base
4
-
5
- end
6
-
7
- end
@@ -1,15 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXResourcesBuildPhase < Vendor::XCode::Proxy::Base
4
-
5
- reference :files
6
-
7
- private
8
-
9
- def after_initialize
10
- files.each { |child| child.parent = self }
11
- end
12
-
13
- end
14
-
15
- end
@@ -1,15 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXShellScriptBuildPhase < Vendor::XCode::Proxy::Base
4
-
5
- reference :files
6
-
7
- private
8
-
9
- def after_initialize
10
- files.each { |child| child.parent = self }
11
- end
12
-
13
- end
14
-
15
- end
@@ -1,15 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXSourcesBuildPhase < Vendor::XCode::Proxy::Base
4
-
5
- reference :files
6
-
7
- private
8
-
9
- def after_initialize
10
- files.each { |child| child.parent = self }
11
- end
12
-
13
- end
14
-
15
- end
@@ -1,7 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXTargetDependency < Vendor::XCode::Proxy::Base
4
-
5
- end
6
-
7
- end
@@ -1,7 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class PBXVariantGroup < Vendor::XCode::Proxy::PBXGroup
4
-
5
- end
6
-
7
- end
@@ -1,8 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- # This is a wrapper for any object that I haven't already covered
4
- class Unknown < Vendor::XCode::Proxy::Base
5
-
6
- end
7
-
8
- end
@@ -1,7 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class XCBuildConfiguration < Vendor::XCode::Proxy::Base
4
-
5
- end
6
-
7
- end
@@ -1,9 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class XCConfigurationList < Vendor::XCode::Proxy::Base
4
-
5
- reference :build_configurations
6
-
7
- end
8
-
9
- end
@@ -1,7 +0,0 @@
1
- module Vendor::XCode::Proxy
2
-
3
- class XCVersionGroup < Vendor::XCode::Proxy::Base
4
-
5
- end
6
-
7
- end
@@ -1,635 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Vendor::XCode::Project do
4
-
5
- before :each do
6
- @project = Vendor::XCode::Project.new(File.join(PROJECT_RESOURCE_PATH, "ProjectWithSpecs/ProjectWithSpecs.xcodeproj"))
7
- end
8
-
9
- context "#initialize" do
10
-
11
- context "ProjectWithSpecs.xcodeproj" do
12
-
13
- it "should load all the objects" do
14
- @project.objects.length.should == 52
15
- end
16
-
17
- it "should load the object version" do
18
- @project.object_version.should == 46
19
- end
20
-
21
- it "should load the archive version" do
22
- @project.archive_version.should == 1
23
- end
24
-
25
- it "should populate the root object" do
26
- @project.root_object.should_not be_nil
27
- end
28
-
29
- it "should not be dirty" do
30
- @project.dirty?.should be_false
31
- end
32
-
33
- end
34
-
35
- context "TabBarWithUnitTests.xcodeproj" do
36
-
37
- it "should parse and load all the objects" do
38
- project = Vendor::XCode::Project.new(File.join(PROJECT_RESOURCE_PATH, "TabBarWithUnitTests/TabBarWithUnitTests.xcodeproj"))
39
-
40
- project.objects.length.should == 78
41
- end
42
-
43
- end
44
-
45
- context "RestKitProject.xcodeproj" do
46
-
47
- it "should parse and load all the objects" do
48
- project = Vendor::XCode::Project.new(File.join(PROJECT_RESOURCE_PATH, "RestKitProject/RestKitProject.xcodeproj"))
49
-
50
- project.objects.length.should == 69
51
- end
52
-
53
- end
54
-
55
- context "other projects in the ProjectsToTestParsing folder" do
56
-
57
- projects = Dir[File.join(PROJECT_RESOURCE_PATH, "ProjectsToTestParsing/*.xcodeproj")]
58
-
59
- projects.each do |p|
60
- it "should correctly load and save '#{p}'" do
61
- project = Vendor::XCode::Project.new(p)
62
- contents = File.readlines(File.join(p, "project.pbxproj")).join("\n")
63
- original = Vendor::Plist.parse_ascii(contents)
64
- saved = Vendor::Plist.parse_ascii(project.to_ascii_plist)
65
-
66
- original.should == saved
67
- end
68
- end
69
-
70
- end
71
-
72
- end
73
-
74
- context "#name" do
75
-
76
- it "should have the correct project name" do
77
- @project.name.should == "ProjectWithSpecs"
78
- end
79
-
80
- end
81
-
82
- context "#find_object" do
83
-
84
- it "should return the object mapped to the id" do
85
- @project.find_object('5378747F140109AE00D9B746').should == @project.root_object
86
- end
87
-
88
- end
89
-
90
- context "#find_target" do
91
-
92
- it "should return the target" do
93
- @project.find_target('Specs').should == @project.root_object.targets.first
94
- end
95
-
96
- it "should return nil if one cannot be found" do
97
- @project.find_target('Ruut').should be_nil
98
- end
99
-
100
- end
101
-
102
- context "#find_group" do
103
-
104
- context 'when finding an existing group' do
105
-
106
- it "should return the group" do
107
- @project.find_group("Specs/Supporting Files").should == @project.root_object.main_group.children.first.children.first
108
- end
109
-
110
- end
111
-
112
- context "when looking for a group that doens't exist" do
113
-
114
- it "should return nil" do
115
- @project.find_group("Does/Not/Exist").should == nil
116
- end
117
-
118
- end
119
-
120
- end
121
-
122
- context '#create_group' do
123
-
124
- context 'when finding an existing group' do
125
-
126
- it "should return the group" do
127
- @project.create_group("Specs/Supporting Files").should == @project.root_object.main_group.children.first.children.first
128
- end
129
-
130
- end
131
-
132
- context 'when creating a group' do
133
-
134
- before :each do
135
- @group = @project.create_group("Specs/Supporting Files/Something/Goes Inside/Here")
136
-
137
- @supporting_files_group = @project.root_object.main_group.children.first.children.first
138
- @something_group = @supporting_files_group.children.last
139
- @inside_group = @something_group.children.last
140
- @here_group = @inside_group.children.last
141
- end
142
-
143
- it "should mark the project as dirty" do
144
- @project.dirty.should be_true
145
- end
146
-
147
- it 'should create it in the correct location' do
148
- @here_group.should_not be_nil
149
- end
150
-
151
- it 'should give the new groups the right names' do
152
- @something_group.name.should == "Something"
153
- @inside_group.name.should == "Goes Inside"
154
- @here_group.name.should == "Here"
155
- end
156
-
157
- it 'should give the new groups the correct source tree property' do
158
- @here_group.source_tree.should == "<group>"
159
- end
160
-
161
- it 'should give the new groups an ID' do
162
- @here_group.source_tree.should_not be_nil
163
- end
164
-
165
- it 'should give the new groups a valid ISA' do
166
- @here_group.isa.should == 'PBXGroup'
167
- end
168
-
169
- it "should set the parent" do
170
- @here_group.parent.should == @inside_group
171
- end
172
-
173
- end
174
-
175
- end
176
-
177
- context "#remove_group" do
178
-
179
- before :each do
180
- @temp_path = TempProject.create(File.join(PROJECT_RESOURCE_PATH, "UtilityApplication"))
181
- @temp_project = Vendor::XCode::Project.new(File.join(@temp_path, "UtilityApplication.xcodeproj"))
182
-
183
- @group = @temp_project.find_group("UtilityApplication/Supporting Files")
184
- end
185
-
186
- context "removing an existing group" do
187
-
188
- it "should mark the project as dirty" do
189
- remove_group
190
-
191
- @temp_project.dirty.should be_true
192
- end
193
-
194
- it "should return true" do
195
- remove_group.should be_true
196
- end
197
-
198
- it "should remove the group" do
199
- remove_group
200
-
201
- @temp_project.find_group("UtilityApplication/Supporting Files").should be_nil
202
- end
203
-
204
- it "should remove the children from the group" do
205
- remove_group
206
-
207
- @temp_project.find_group("UtilityApplication").children.map(&:id).should_not include(@group.id)
208
- end
209
-
210
- it "should remove the files from the file system" do
211
- file = File.join(@temp_path, "UtilityApplication", "main.m")
212
- File.exist?(file).should be_true
213
-
214
- remove_group
215
- File.exist?(file).should be_false
216
- end
217
-
218
- it "should remove the files from all the targets" do
219
- ids = @temp_project.find_group("UtilityApplication/Classes").children.map(&:id)
220
- @temp_project.remove_group("UtilityApplication/Classes")
221
-
222
- @temp_project.root_object.targets.each do |target|
223
- ids.each do |id|
224
- target.build_phases.each do |phase|
225
- phase.files.map(&:file_ref).map(&:id).should_not include(id)
226
- end
227
- end
228
- end
229
- end
230
-
231
- private
232
-
233
- def remove_group
234
- @temp_project.remove_group("UtilityApplication/Supporting Files")
235
- end
236
-
237
- end
238
-
239
- context "removing a group that doesn't exist" do
240
-
241
- subject { @temp_project.remove_group("Doest/Not/Exist") }
242
-
243
- it "should return false" do
244
- subject.should be_false
245
- end
246
-
247
- end
248
-
249
- end
250
-
251
- context "#add_framework" do
252
-
253
- before :each do
254
- @temp_path = TempProject.create(File.join(PROJECT_RESOURCE_PATH, "MultipleTargets"))
255
- @temp_project = Vendor::XCode::Project.new(File.join(@temp_path, "MultipleTargets.xcodeproj"))
256
- end
257
-
258
- it "should add the framework to the right targets" do
259
- @temp_project.should_receive(:add_file).with({ :targets => @temp_project.find_target("Integration"),
260
- :file => "System/Library/Frameworks/KeithPitt.framework",
261
- :path => "Frameworks", :name => "KeithPitt.framework",
262
- :source_tree => :sdkroot })
263
-
264
- @temp_project.add_framework "KeithPitt.framework", :targets => [ "Integration", "AggregateTarget" ]
265
- end
266
-
267
- it "should add the dylibs to the right targets" do
268
- @temp_project.should_receive(:add_file).with({ :targets => @temp_project.find_target("Integration"),
269
- :file => "usr/lib/libz.dylib",
270
- :path => "Frameworks", :name => "libz.dylib",
271
- :source_tree => :sdkroot })
272
-
273
- @temp_project.add_framework "libz.dylib", :targets => "Integration"
274
- end
275
-
276
- it "shouldn't add the framework if it already exists" do
277
- @temp_project.should_not_receive(:add_file)
278
-
279
- @temp_project.add_framework "Foundation.framework", :targets => "Integration"
280
- end
281
-
282
- end
283
-
284
- context "#add_build_setting" do
285
-
286
- before :each do
287
- @temp_path = TempProject.create(File.join(PROJECT_RESOURCE_PATH, "MultipleTargets"))
288
- @temp_project = Vendor::XCode::Project.new(File.join(@temp_path, "MultipleTargets.xcodeproj"))
289
- @target = @temp_project.find_target("Specs")
290
- end
291
-
292
- it "should add build settings if they are not there" do
293
- @temp_project.add_build_setting "SOMETHING", "YES", :targets => "Specs", :changer => "SomeLib"
294
-
295
- @target.build_configuration_list.build_configurations.each do |config|
296
- config.build_settings.keys.should include("SOMETHING")
297
- config.build_settings["SOMETHING"].should == "YES"
298
- end
299
- end
300
-
301
- it "should create an array of options if the setting is known to be a selection" do
302
- @temp_project.add_build_setting "OTHER_LDFLAGS", "-ObjC", :targets => "Specs", :changer => "SomeLib"
303
- @temp_project.add_build_setting "OTHER_LDFLAGS", "-Something", :targets => "Specs", :changer => "SomeLib"
304
-
305
- @target.build_configuration_list.build_configurations.each do |config|
306
- config.build_settings["OTHER_LDFLAGS"].should == [ "-ObjC", "-Something" ]
307
- end
308
- end
309
-
310
- it "should not duplicate build settings" do
311
- @temp_project.add_build_setting "OTHER_LDFLAGS", "-ObjC", :targets => "Specs", :changer => "SomeLib"
312
- @temp_project.add_build_setting "OTHER_LDFLAGS", "-ObjC", :targets => "Specs", :changer => "SomeLib"
313
-
314
- @target.build_configuration_list.build_configurations.each do |config|
315
- config.build_settings["OTHER_LDFLAGS"].should == "-ObjC"
316
- end
317
- end
318
-
319
- it "shouldn't change a build setting if it already exists" do
320
- @temp_project.add_build_setting "SOMETHING", "YES", :targets => "Specs", :changer => "SomeLib"
321
-
322
- Vendor.ui.should_receive(:warn).with(" Build setting \"SOMETHING\" wanted to change to \"NO\", but it was already \"YES\" in \"Specs/Debug\"").ordered
323
- Vendor.ui.should_receive(:warn).with(" Build setting \"SOMETHING\" wanted to change to \"NO\", but it was already \"YES\" in \"Specs/Release\"").ordered
324
- @temp_project.add_build_setting "SOMETHING", "NO", :targets => "Specs", :changer => "SomeLib"
325
-
326
- @target.build_configuration_list.build_configurations.each do |config|
327
- config.build_settings.keys.should include("SOMETHING")
328
- config.build_settings["SOMETHING"].should == "YES"
329
- end
330
- end
331
-
332
- it "should mark the project as dirty" do
333
- @temp_project.add_build_setting "SOMETHING", "YES", :targets => "Specs", :changer => "SomeLib"
334
-
335
- @temp_project.dirty?.should be_true
336
- end
337
-
338
- end
339
-
340
- context '#add_file' do
341
-
342
- let(:first_file) { File.join(SOURCE_RESOURCE_PATH, "SecondViewController.h") }
343
- let(:second_file) { File.join(SOURCE_RESOURCE_PATH, "SecondViewController.m") }
344
-
345
- before :each do
346
- @temp_path = TempProject.create(File.join(PROJECT_RESOURCE_PATH, "ProjectWithSpecs"))
347
- @temp_project = Vendor::XCode::Project.new(File.join(@temp_path, "ProjectWithSpecs.xcodeproj"))
348
-
349
- @target = @temp_project.find_target("Specs")
350
- end
351
-
352
- context "with a source tree of :group" do
353
-
354
- before :each do
355
- @first_file_added = @temp_project.add_file :targets => [ @target ], :file => first_file,
356
- :path => "Controllers/SecondViewController", :source_tree => :group
357
- @second_file_added = @temp_project.add_file :targets => [ @target ], :file => second_file,
358
- :path => "Controllers/SecondViewController", :source_tree => :group
359
- end
360
-
361
- it "should mark the project as dirty" do
362
- @temp_project.dirty.should be_true
363
- end
364
-
365
- it 'should add the file to the filesystem' do
366
- new_first_path = File.join(@temp_path, "Controllers", "SecondViewController", "SecondViewController.h")
367
- new_second_path = File.join(@temp_path, "Controllers", "SecondViewController", "SecondViewController.m")
368
-
369
- File.exists?(new_first_path).should be_true
370
- File.exists?(new_second_path).should be_true
371
- end
372
-
373
- it 'should add it as the correct file type' do
374
- @first_file_added.last_known_file_type.should == "sourcecode.c.h"
375
- @second_file_added.last_known_file_type.should == "sourcecode.c.objc"
376
- end
377
-
378
- it 'should add the files with the correct path' do
379
- @first_file_added.path.should == "SecondViewController.h"
380
- @second_file_added.path.should == "SecondViewController.m"
381
- end
382
-
383
- it 'should have the correct ISA' do
384
- @first_file_added.isa.should == "PBXFileReference"
385
- @second_file_added.isa.should == "PBXFileReference"
386
- end
387
-
388
- it 'should have an ID' do
389
- @first_file_added.id.should_not be_nil
390
- @second_file_added.id.should_not be_nil
391
- end
392
-
393
- it 'should add it to the correct group' do
394
- group = @temp_project.create_group("Controllers/SecondViewController")
395
-
396
- group.children[0].should == @first_file_added
397
- group.children[1].should == @second_file_added
398
- end
399
-
400
- it "should set the parent" do
401
- @first_file_added.parent.should == @temp_project.find_group("Controllers/SecondViewController")
402
- end
403
-
404
- it 'should still save' do
405
- @temp_project.save
406
- end
407
-
408
- it 'should add it to the build targets specified' do
409
- build_phase = @target.build_phases.first
410
-
411
- build_phase.files[-2].file_ref.should_not == @first_file_added
412
-
413
- build_phase.files[-1].isa.should == "PBXBuildFile"
414
- build_phase.files[-1].should be_kind_of(Vendor::XCode::Proxy::PBXBuildFile)
415
- build_phase.files[-1].file_ref.should == @second_file_added
416
- end
417
-
418
- it "should throw an error if you try and add to a target that doesn't exist" do
419
- expect do
420
- @temp_project.add_file :targets => [ "Blah" ], :file => first_file,
421
- :path => "Controllers/SecondViewController", :source_tree => :group
422
- end.should raise_error(StandardError, "Could not find target 'Blah' in project 'ProjectWithSpecs'")
423
- end
424
-
425
- end
426
-
427
- context "with a source tree of :sdkroot" do
428
-
429
- before :each do
430
- @first_file_added = @temp_project.add_file :targets => [ @target ], :file => "System/Library/Frameworks/Foundation.framework",
431
- :path => "Frameworks", :source_tree => :sdkroot
432
- @second_file_added = @temp_project.add_file :targets => [ @target ], :file => "System/Library/Frameworks/CoreGraphics.framework",
433
- :path => "Frameworks", :source_tree => :sdkroot
434
- end
435
-
436
- it "should mark the project as dirty" do
437
- @temp_project.dirty.should be_true
438
- end
439
-
440
- it 'should add it as the correct file type' do
441
- @first_file_added.last_known_file_type.should == "wrapper.framework"
442
- @second_file_added.last_known_file_type.should == "wrapper.framework"
443
- end
444
-
445
- it 'should add the files with the correct path' do
446
- @first_file_added.path.should == "System/Library/Frameworks/Foundation.framework"
447
- @second_file_added.path.should == "System/Library/Frameworks/CoreGraphics.framework"
448
- end
449
-
450
- it 'should have an ID' do
451
- @first_file_added.id.should_not be_nil
452
- @second_file_added.id.should_not be_nil
453
- end
454
-
455
- it 'should add it to the correct group' do
456
- group = @temp_project.create_group("Frameworks")
457
-
458
- group.children[-2].should == @first_file_added
459
- group.children[-1].should == @second_file_added
460
- end
461
-
462
- it 'should still save' do
463
- @temp_project.save
464
- end
465
-
466
- it 'should add it to the build targets specified' do
467
- build_phase = @target.build_phases[1]
468
-
469
- build_phase.files[-2].should be_kind_of(Vendor::XCode::Proxy::PBXBuildFile)
470
- build_phase.files[-2].file_ref.should == @first_file_added
471
- build_phase.files[-1].should be_kind_of(Vendor::XCode::Proxy::PBXBuildFile)
472
- build_phase.files[-1].file_ref.should == @second_file_added
473
- end
474
-
475
- end
476
-
477
- context "with a source tree of :absoulte" do
478
-
479
- before :each do
480
- @first_file_added = @temp_project.add_file :targets => [ @target ], :file => first_file,
481
- :path => "Controllers/SecondViewController", :source_tree => :absolute
482
- @second_file_added = @temp_project.add_file :targets => [ @target ], :file => second_file,
483
- :path => "Controllers/SecondViewController", :source_tree => :absolute
484
- end
485
-
486
- it "should mark the project as dirty" do
487
- @temp_project.dirty.should be_true
488
- end
489
-
490
- it 'should add it as the correct file type' do
491
- @first_file_added.last_known_file_type.should == "sourcecode.c.h"
492
- @second_file_added.last_known_file_type.should == "sourcecode.c.objc"
493
- end
494
-
495
-
496
- it 'should add the files with the correct path' do
497
- @first_file_added.path.should == first_file
498
- @second_file_added.path.should == second_file
499
- end
500
-
501
- it 'should add the files with the correct names' do
502
- @first_file_added.name.should == "SecondViewController.h"
503
- @second_file_added.name.should == "SecondViewController.m"
504
- end
505
-
506
- it 'should have the correct ISA' do
507
- @first_file_added.isa.should == "PBXFileReference"
508
- @second_file_added.isa.should == "PBXFileReference"
509
- end
510
-
511
- it 'should have an ID' do
512
- @first_file_added.id.should_not be_nil
513
- @second_file_added.id.should_not be_nil
514
- end
515
-
516
- it 'should add it to the correct group' do
517
- group = @temp_project.create_group("Controllers/SecondViewController")
518
-
519
- group.children[0].should == @first_file_added
520
- group.children[1].should == @second_file_added
521
- end
522
-
523
- it 'should still save' do
524
- @temp_project.save
525
- end
526
-
527
- it 'should add it to the build targets specified' do
528
- build_phase = @target.build_phases.first
529
-
530
- build_phase.files[-2].file_ref.should_not == @first_file_added
531
-
532
- build_phase.files[-1].should be_kind_of(Vendor::XCode::Proxy::PBXBuildFile)
533
- build_phase.files[-1].file_ref.should == @second_file_added
534
- end
535
-
536
- end
537
-
538
- context 'should raise an error if' do
539
-
540
- it 'there is no path set' do
541
- expect do
542
- @temp_project.add_file :targets => "Specs", :file => first_file
543
- end.to raise_exception(StandardError, "Missing :path option")
544
- end
545
-
546
- it 'there is no file set' do
547
- expect do
548
- @temp_project.add_file :targets => "Specs", :path => "ASD"
549
- end.to raise_exception(StandardError, "Missing :file option")
550
- end
551
-
552
- it "the file doesn't exist" do
553
- expect do
554
- @temp_project.add_file :targets => "Ruut", :file => "foo",
555
- :path => "Controllers/SecondViewController", :source_tree => :group
556
- end.to raise_exception(StandardError, "Could not find file `foo`")
557
- end
558
-
559
- it "you don't pass a source tree option" do
560
- expect do
561
- @temp_project.add_file :targets => "Specs", :path => "ASD", :file => "foo"
562
- end.to raise_exception(StandardError, "Missing :source_tree option")
563
- end
564
-
565
- it "the source tree option is invalid" do
566
- expect do
567
- @temp_project.add_file :targets => "Specs", :path => "ASD",
568
- :file => first_file, :source_tree => :foo
569
- end.to raise_exception(StandardError, "Invalid :source_tree option `foo`")
570
- end
571
-
572
- end
573
-
574
- end
575
-
576
- context "#valid?" do
577
-
578
- it "should return true the plist format is valid" do
579
- @project.valid?.should be_true
580
- end
581
-
582
- it "should raise an error if there is an invalid format" do
583
- @project.should_receive(:to_ascii_plist).twice.and_return { "asd; { f5him" }
584
-
585
- @project.valid?.should be_false
586
- end
587
-
588
- end
589
-
590
- context "#save" do
591
-
592
- before :each do
593
- @temp_path = TempProject.create(File.join(PROJECT_RESOURCE_PATH, "UtilityApplication"))
594
- @temp_project = Vendor::XCode::Project.new(File.join(@temp_path, "UtilityApplication.xcodeproj"))
595
- end
596
-
597
- it "should save a backup of the project" do
598
- @temp_project.create_group("Specs/Supporting Files/Something/Goes Inside/Here")
599
- @temp_project.save
600
-
601
- File.exist?(File.join(File.dirname(@temp_project.project_folder), "UtilityApplication.vendorbackup")).should be_true
602
- end
603
-
604
- it "should save another backup if the project exists" do
605
- @temp_project.create_group("Specs/Supporting Files/Something/Goes Inside/Here")
606
- @temp_project.save
607
- File.exist?(File.join(File.dirname(@temp_project.project_folder), "UtilityApplication.vendorbackup")).should be_true
608
-
609
- @temp_project.create_group("Specs/Supporting Files/Something/Goes Inside/Here/I/Think")
610
- @temp_project.save
611
- File.exist?(File.join(File.dirname(@temp_project.project_folder), "UtilityApplication.vendorbackup.1")).should be_true
612
-
613
- @temp_project.create_group("Specs/Supporting Files/Something/Goes Inside/Here/I/Think")
614
- @temp_project.save
615
- File.exist?(File.join(File.dirname(@temp_project.project_folder), "UtilityApplication.vendorbackup.2")).should be_true
616
- end
617
-
618
- end
619
-
620
- context "#to_ascii_plist" do
621
-
622
- it "should convert it to the correct format" do
623
- # Reload the project from the filesystem
624
- @project.reload
625
-
626
- contents = File.readlines(File.join(PROJECT_RESOURCE_PATH, "ProjectWithSpecs/ProjectWithSpecs.xcodeproj", "project.pbxproj")).join("\n")
627
- original = Vendor::Plist.parse_ascii(contents)
628
- saved = Vendor::Plist.parse_ascii(@project.to_ascii_plist)
629
-
630
- original.should == saved
631
- end
632
-
633
- end
634
-
635
- end