Closed Lutzifer closed 7 years ago
You can pass a Proc
to the plugin:
plugin 'cocoapods-acknowledgements', :settings_bundle => true , :settings_post_process => Proc.new { |settings_plist_path, umbrella_target|
puts settings_plist_path
puts umbrella_target.cocoapods_target_label
}
Inside the closure, you have settings_plist_path
which can be used to open the file and add your extra dependencies.
thank you I thought there was more functionality included for this, will have another try 😉
If you manage to do this, please add the snippet here or open a PR adding it to the README 💯
Here's how I did it. This will take the contents of a manually generated plist and insert them at the end of the one that Cocoapods generates. This should be generic enough to copy/paste.
Code suggestions welcome -- I don't write much Ruby.
plugin 'cocoapods-acknowledgements', :settings_bundle => true, :settings_post_process => Proc.new { |settings_plist_path, umbrella_target|
# Merge in licenses for non-Cocoapods libraries.
#
# 1. If your target is named "Target", create a file called "Pods-Target-other.plist" in the Settings bundle
# 2. This plist must contain an array as the root object
# 3. Each object in the array is a dictionary
# 4. The structure of each dictionary is the same as that of an item in the Cocoapods-generated file's PreferenceSpecifiers array:
# Type: PSGroupSpecifier
# Title: <Library Title>
# FooterText: <License Text>
plistbuddy = '/usr/libexec/PlistBuddy'
settings_dir = File.dirname(settings_plist_path)
otherlibs_plist = "#{settings_dir}/#{umbrella_target.cocoapods_target_label}-other.plist"
if File.exist?(otherlibs_plist)
before_count = `#{plistbuddy} -c "Print PreferenceSpecifiers:" #{settings_plist_path} | grep "Dict" | wc -l`.strip!.to_i
footer_index = before_count - 1
`#{plistbuddy} -x -c "Merge #{otherlibs_plist} PreferenceSpecifiers" '#{settings_plist_path}'`
after_count = `#{plistbuddy} -c "Print PreferenceSpecifiers:" #{settings_plist_path} | grep "Dict" | wc -l`.strip!.to_i
`#{plistbuddy} -c "Copy PreferenceSpecifiers:#{footer_index} PreferenceSpecifiers:#{after_count}" #{settings_plist_path}`
`#{plistbuddy} -c "Delete PreferenceSpecifiers:#{footer_index}" #{settings_plist_path}`
merge_count = after_count - before_count
puts "Merged #{merge_count} items from #{otherlibs_plist}"
end
}
And here's an example of Pods-Target-other.plist
that you might manually generate:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>FooterText</key>
<string>Copyright (c) 2015 Somebody
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.</string>
<key>Title</key>
<string>Library Name</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
</array>
</plist>
The README states "With a Settings.bundle compatible plist, offering the chance to run post-processing on the plist ( to add non-CocoaPods dependencies for example )"
How can we achieve this and is it documented somewhere?