From e9666ae698255bb306224db4b42d2afd9b8418a7 Mon Sep 17 00:00:00 2001 From: yimajo Date: Tue, 15 Apr 2025 16:35:16 +0900 Subject: [PATCH 1/2] Exclude empty exceptions from PBXFileSystemSynchronizedRootGroup serialization --- .../object/file_system_synchronized_root_group.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/xcodeproj/project/object/file_system_synchronized_root_group.rb b/lib/xcodeproj/project/object/file_system_synchronized_root_group.rb index 4a26bc6a..466ebd54 100644 --- a/lib/xcodeproj/project/object/file_system_synchronized_root_group.rb +++ b/lib/xcodeproj/project/object/file_system_synchronized_root_group.rb @@ -68,6 +68,21 @@ def display_name return path if path super end + + def to_hash_as(method = :to_hash) + hash_as = super + excluded_keys_for_serialization_when_empty.each do |key| + if !hash_as[key].nil? && hash_as[key].empty? + hash_as.delete(key) + end + end + hash_as + end + + # @return [Array] array of keys to exclude from serialization when the value is empty + def excluded_keys_for_serialization_when_empty + %w(exceptions) + end end end end From 5ffe0ad9f20dbbe1ed691d824e94f3bf58d04266 Mon Sep 17 00:00:00 2001 From: yimajo Date: Tue, 15 Apr 2025 16:36:08 +0900 Subject: [PATCH 2/2] Add tests for excluding empty exceptions in PBXFileSystemSynchronizedRootGroup --- ...ile_system_synchronized_root_group_spec.rb | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 spec/project/object/file_system_synchronized_root_group_spec.rb diff --git a/spec/project/object/file_system_synchronized_root_group_spec.rb b/spec/project/object/file_system_synchronized_root_group_spec.rb new file mode 100644 index 00000000..e6c6f5f8 --- /dev/null +++ b/spec/project/object/file_system_synchronized_root_group_spec.rb @@ -0,0 +1,27 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +module ProjectSpecs + describe PBXFileSystemSynchronizedRootGroup do + before do + @project = Project.new('/path/to/Dummy.xcodeproj') + @root_group = @project.new(PBXFileSystemSynchronizedRootGroup) + end + + describe '#to_hash' do + it "does not include exceptions in its hash if there aren't any" do + @root_group.to_hash['exceptions'].should.be.nil + end + + it 'includes exceptions in its hash if it contains at least one' do + target = @project.new(PBXNativeTarget) + target.name = "TestTarget" + + exception = @project.new(PBXFileSystemSynchronizedBuildFileExceptionSet) + exception.target = target + @root_group.exceptions << exception + + @root_group.to_hash['exceptions'].should == [exception.uuid] + end + end + end +end