Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Object] Discard missings UUIDs without raising.

  • Loading branch information...
commit 608883ba4e4a6e6d7abb8848d9b536fbc987f351 1 parent 3c1b7b8
@fabiopelosin fabiopelosin authored
Showing with 30 additions and 10 deletions.
  1. +12 −9 lib/xcodeproj/project/object.rb
  2. +18 −1 spec/project/object_spec.rb
View
21 lib/xcodeproj/project/object.rb
@@ -206,7 +206,7 @@ def configure_with_plist(objects_by_uuid_plist)
ref_uuid = object_plist[attrb.plist_name]
if ref_uuid
ref = object_with_uuid(ref_uuid, objects_by_uuid_plist, attrb)
- attrb.set_value(self, ref)
+ attrb.set_value(self, ref) if ref
end
object_plist.delete(attrb.plist_name)
end
@@ -215,7 +215,8 @@ def configure_with_plist(objects_by_uuid_plist)
ref_uuids = object_plist[attrb.plist_name] || []
list = attrb.get_value(self)
ref_uuids.each do |uuid|
- list << object_with_uuid(uuid, objects_by_uuid_plist, attrb)
+ ref = object_with_uuid(uuid, objects_by_uuid_plist, attrb)
+ list << ref if ref
end
object_plist.delete(attrb.plist_name)
end
@@ -226,7 +227,8 @@ def configure_with_plist(objects_by_uuid_plist)
hashes.each do |hash|
dictionary = ObjectDictionary.new(attrb, self)
hash.each do |key, uuid|
- dictionary[key] = object_with_uuid(uuid, objects_by_uuid_plist, attrb)
+ ref = object_with_uuid(uuid, objects_by_uuid_plist, attrb)
+ dictionary[key] = ref if ref
end
list << dictionary
end
@@ -240,7 +242,7 @@ def configure_with_plist(objects_by_uuid_plist)
end
end
- # Initializes and returns the object with the given uuid.
+ # Initializes and returns the object with the given UUID.
#
# @param [String] uuid
# The UUID of the object that should be initialized.
@@ -255,17 +257,18 @@ def configure_with_plist(objects_by_uuid_plist)
#
# @raise If the hash for the given UUID contains an unknown ISA.
#
- # @raise If the UUID can't be found in the objects hash.
- #
# @return [AbstractObject] the initialized object.
+ # @return [Nil] if the UUID could not be found in the objects hash. In
+ # this case a warning is printed to STDERR.
#
# @visibility private
#
def object_with_uuid(uuid, objects_by_uuid_plist, attribute)
unless object = project.objects_by_uuid[uuid] || project.new_from_plist(uuid, objects_by_uuid_plist)
- raise "`#{inspect}` attempted to initialize an object with an unknown UUID: "\
- "`#{uuid}` for attribute: `#{attribute.name}`\n" \
- "Please file and issue: https://github.com/CocoaPods/Xcodeproj/issues/new"
+ STDERR.puts "`#{inspect}` attempted to initialize an object with "\
+ "an unknown UUID. `#{uuid}` for attribute: `#{attribute.name}`."\
+ " This can be the result of a merge and the unkonw UUID is " \
+ "being discarded."
end
object
rescue NameError => exception
View
19 spec/project/object_spec.rb
@@ -133,7 +133,24 @@ module ProjectSpecs
group.children.first.equal?(file).should.be.true
end
- it "it raises if it encounters an unknown attribute in a plist" do
+ # TODO: use UI class
+ it "discards UUIDs which cannot be found in the objects hash" do
+ uuid_file = 'file_uuid'
+ uuid_group = 'group_uuid'
+ objects_by_uuid_plist = {
+ uuid_group => { 'children' => [uuid_file], 'isa' => 'PBXGroup'}
+ }
+ group = PBXGroup.new(@project, uuid_group)
+ group.configure_with_plist(objects_by_uuid_plist)
+ group.files.should.be.empty
+ end
+
+ it "raises if it encounters an unknown attribute in a plist" do
+ @objects_by_uuid_plist[@object.uuid]['unknown_attribute'] = 'might be a reference'
+ lambda { @object.configure_with_plist(@objects_by_uuid_plist) }.should.raise
+ end
+
+ it "raises if it encounters an unknown attribute in a plist" do
@objects_by_uuid_plist[@object.uuid]['unknown_attribute'] = 'might be a reference'
lambda { @object.configure_with_plist(@objects_by_uuid_plist) }.should.raise
end
Please sign in to comment.
Something went wrong with that request. Please try again.