cocoapods-acknowledgements-addons 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/run_tests.yml +25 -0
- data/.travis.yml +3 -3
- data/CHANGELOG.md +13 -0
- data/Gemfile +0 -2
- data/Gemfile.lock +28 -23
- data/README.md +20 -2
- data/Rakefile +68 -10
- data/example/App.xcodeproj/project.pbxproj +48 -8
- data/example/App.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +43 -0
- data/example/App.xcworkspace/xcshareddata/swiftpm/Package.resolved +43 -0
- data/example/App/Info.plist +1 -1
- data/example/App/MethodSwizzler.m +1 -1
- data/example/App/Settings.bundle/Pods-App-settings-metadata.plist +235 -4
- data/example/AppTests/AppTests.swift +12 -2
- data/example/AppTests/Info.plist +1 -1
- data/example/Gemfile +0 -1
- data/example/Gemfile.lock +26 -25
- data/example/Makefile +3 -3
- data/example/Podfile +9 -4
- data/example/Podfile.lock +3 -3
- data/example/README.md +1 -1
- data/lib/cocoapods_acknowledgements/addons.rb +18 -7
- data/lib/cocoapods_acknowledgements/addons/acknowledgement.rb +4 -3
- data/lib/cocoapods_acknowledgements/addons/{plist_modifier.rb → modifiers/metadata_plist_modifier.rb} +26 -6
- data/lib/cocoapods_acknowledgements/addons/modifiers/pods_plist_modifier.rb +133 -0
- data/lib/cocoapods_acknowledgements/addons/swift_package_accumulator.rb +28 -0
- data/lib/version.rb +1 -1
- metadata +9 -6
- data/lib/cocoapods_acknowledgements/addons/settings_plist_modifier.rb +0 -58
data/example/Makefile
CHANGED
data/example/Podfile
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
platform :ios, "12.0"
|
2
|
+
use_frameworks!
|
3
|
+
inhibit_all_warnings!
|
2
4
|
|
3
5
|
target :App do
|
4
|
-
use_frameworks!
|
5
6
|
pod "Alamofire", git: "https://github.com/Alamofire/Alamofire.git", tag: "4.8.2"
|
6
|
-
pod "CPDAcknowledgements"
|
7
|
+
pod "CPDAcknowledgements"
|
8
|
+
end
|
9
|
+
|
10
|
+
target :AppTests do
|
7
11
|
end
|
8
12
|
|
9
13
|
# Generates a plist of dependencies installed via CocoaPods
|
10
|
-
plugin "cocoapods-acknowledgements"
|
14
|
+
plugin "cocoapods-acknowledgements", settings_bundle: true
|
11
15
|
|
12
16
|
# Adds additional acknowledgements to the generated plist
|
13
17
|
plugin "cocoapods-acknowledgements-addons",
|
14
18
|
add: ["Acknowledgements", "Carthage/Checkouts", "Dependencies"],
|
15
|
-
|
19
|
+
with_spm: true,
|
20
|
+
exclude: ["Quick*"]
|
data/example/Podfile.lock
CHANGED
@@ -7,7 +7,7 @@ DEPENDENCIES:
|
|
7
7
|
- CPDAcknowledgements
|
8
8
|
|
9
9
|
SPEC REPOS:
|
10
|
-
https://github.com/
|
10
|
+
https://github.com/CocoaPods/Specs.git:
|
11
11
|
- CPDAcknowledgements
|
12
12
|
|
13
13
|
EXTERNAL SOURCES:
|
@@ -24,6 +24,6 @@ SPEC CHECKSUMS:
|
|
24
24
|
Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3
|
25
25
|
CPDAcknowledgements: 6e15e71849ba4ad5e8a17a0bb9d20938ad23bac8
|
26
26
|
|
27
|
-
PODFILE CHECKSUM:
|
27
|
+
PODFILE CHECKSUM: 510b2adb00afb6eb355a2f628b554a1370e84972
|
28
28
|
|
29
|
-
COCOAPODS: 1.
|
29
|
+
COCOAPODS: 1.8.4
|
data/example/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
```rb
|
6
6
|
plugin "cocoapods-acknowledgements-addons",
|
7
7
|
add: ["Acknowledgements", "Carthage/Checkouts", "Dependencies"],
|
8
|
-
exclude: ["
|
8
|
+
exclude: ["Quick*"]
|
9
9
|
```
|
10
10
|
|
11
11
|
The plugin finds additional acknowledgements from the following directories:
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require "cocoapods"
|
2
2
|
require "cocoapods_acknowledgements"
|
3
3
|
require "cocoapods_acknowledgements/addons/podspec_accumulator"
|
4
|
-
require "cocoapods_acknowledgements/addons/
|
5
|
-
require "cocoapods_acknowledgements/addons/
|
4
|
+
require "cocoapods_acknowledgements/addons/swift_package_accumulator"
|
5
|
+
require "cocoapods_acknowledgements/addons/modifiers/pods_plist_modifier"
|
6
|
+
require "cocoapods_acknowledgements/addons/modifiers/metadata_plist_modifier"
|
6
7
|
|
7
8
|
module CocoaPodsAcknowledgements
|
8
9
|
module AddOns
|
@@ -10,21 +11,31 @@ module CocoaPodsAcknowledgements
|
|
10
11
|
Pod::HooksManager.register("cocoapods-acknowledgements-addons", :post_install) do |context, user_options|
|
11
12
|
paths = [*user_options[:add]]
|
12
13
|
excluded_names = [*user_options[:exclude]]
|
14
|
+
includes_spm = user_options[:with_spm] || false
|
13
15
|
|
14
16
|
acknowledgements = paths.reduce([]) do |results, path|
|
15
17
|
accumulator = PodspecAccumulator.new(Pathname(path).expand_path)
|
16
|
-
results + accumulator.acknowledgements
|
18
|
+
(results + accumulator.acknowledgements).uniq { |a| a.spec.name }
|
19
|
+
end
|
20
|
+
|
21
|
+
if includes_spm
|
22
|
+
spm_acknowledgements = context.umbrella_targets.reduce([]) do |results, target|
|
23
|
+
accumulator = SwiftPackageAccumulator.new(target.user_project.path)
|
24
|
+
(results + accumulator.acknowledgements).uniq { |a| a.spec.name }
|
25
|
+
end
|
26
|
+
acknowledgements += spm_acknowledgements
|
27
|
+
Pod::UI.info %(Found #{spm_acknowledgements.count} Swift Package(s)).green
|
17
28
|
end
|
18
29
|
|
19
30
|
sandbox = context.sandbox if defined? context.sandbox
|
20
31
|
sandbox ||= Pod::Sandbox.new(context.sandbox_root)
|
21
32
|
|
22
33
|
context.umbrella_targets.each do |target|
|
23
|
-
|
24
|
-
|
34
|
+
metadata_plist_modifier = MetadataPlistModifier.new(target, sandbox)
|
35
|
+
metadata_plist_modifier.add(acknowledgements.map(&:metadata_plist_item), excluded_names)
|
25
36
|
|
26
|
-
|
27
|
-
|
37
|
+
pods_plist_modifier = PodsPlistModifier.new(target, sandbox)
|
38
|
+
pods_plist_modifier.add(acknowledgements.map(&:settings_plist_item), excluded_names)
|
28
39
|
end
|
29
40
|
end
|
30
41
|
|
@@ -3,6 +3,7 @@ require "cocoapods-core"
|
|
3
3
|
module CocoaPodsAcknowledgements
|
4
4
|
module AddOns
|
5
5
|
class Acknowledgement
|
6
|
+
attr_reader :spec
|
6
7
|
|
7
8
|
# @param path [String] the path string to a pod spec.
|
8
9
|
#
|
@@ -34,10 +35,10 @@ module CocoaPodsAcknowledgements
|
|
34
35
|
text
|
35
36
|
end
|
36
37
|
|
37
|
-
# @return [Hash] the acknowledgement info for the plist.
|
38
|
+
# @return [Hash] the acknowledgement info for the Pods metadata plist.
|
38
39
|
# @return [Nil] if the license text is missing.
|
39
40
|
#
|
40
|
-
def
|
41
|
+
def metadata_plist_item
|
41
42
|
return nil unless @spec and @license_text
|
42
43
|
{
|
43
44
|
name: @spec.name,
|
@@ -54,7 +55,7 @@ module CocoaPodsAcknowledgements
|
|
54
55
|
# @return [Hash] the acknowledgement info for the Settings.bundle plist.
|
55
56
|
# @return [Nil] if the license text is missing.
|
56
57
|
#
|
57
|
-
def
|
58
|
+
def settings_plist_item
|
58
59
|
return nil unless @spec and @license_text
|
59
60
|
{
|
60
61
|
Title: @spec.name,
|
@@ -4,8 +4,10 @@ require "cocoapods_acknowledgements/addons/acknowledgement"
|
|
4
4
|
|
5
5
|
module CocoaPodsAcknowledgements
|
6
6
|
module AddOns
|
7
|
-
class
|
7
|
+
class MetadataPlistModifier
|
8
8
|
|
9
|
+
# A modifier to update Pods/Pods-#{app_name}-metadata.plist.
|
10
|
+
#
|
9
11
|
# @param target [Pod::Installer::PostInstallHooksContext::UmbrellaTargetDescription] the xcodeproj target.
|
10
12
|
# @param sandbox [Pod::Sandbox] the CocoaPods sandbox
|
11
13
|
#
|
@@ -13,6 +15,13 @@ module CocoaPodsAcknowledgements
|
|
13
15
|
@plist_path = sandbox.root + "#{target.cocoapods_target_label}-metadata.plist"
|
14
16
|
end
|
15
17
|
|
18
|
+
# @return [CFPropertyList::List] the acknowledgement plist at Pods/Pods-#{app_name}-metadata.plist.
|
19
|
+
#
|
20
|
+
def plist
|
21
|
+
return nil unless @plist_path&.readable?
|
22
|
+
CFPropertyList::List.new(file: @plist_path)
|
23
|
+
end
|
24
|
+
|
16
25
|
# Adds acknowledgements to the plist except the excluded ones.
|
17
26
|
#
|
18
27
|
# @param plist_metadata [Array<Hash>] the array of acknowledgement plist metadata.
|
@@ -27,19 +36,30 @@ module CocoaPodsAcknowledgements
|
|
27
36
|
plist = CFPropertyList::List.new(file: @plist_path)
|
28
37
|
entries = plist.value.value["specs"].value
|
29
38
|
existing_titles = entries.map { |spec| spec.value["name"].value }
|
30
|
-
excluded_names
|
39
|
+
excluded_names.uniq!
|
31
40
|
|
32
|
-
additions = plist_metadata.map
|
33
|
-
next if metadata.nil? or
|
41
|
+
additions = plist_metadata.map do |metadata|
|
42
|
+
next if metadata.nil? or existing_titles.include? metadata[:name]
|
34
43
|
Pod::UI.info "Adding #{metadata[:name]} to #{@plist_path.basename}"
|
35
44
|
CFPropertyList.guess(metadata)
|
36
|
-
|
45
|
+
end.reject(&:nil?)
|
37
46
|
|
38
47
|
acknowledgements = entries + additions
|
39
|
-
acknowledgements
|
48
|
+
acknowledgements
|
49
|
+
.sort! { |a, b| a.value["name"].value <=> b.value["name"].value }
|
50
|
+
.reject! do |entry|
|
51
|
+
matches = excluded_names.any? do |excluded_name|
|
52
|
+
pattern = %r(^#{Regexp.escape(excluded_name).gsub("\*", ".*?")})
|
53
|
+
entry.value["name"].value =~ pattern
|
54
|
+
end
|
55
|
+
Pod::UI.info %(Removing #{entry.value["name"].value} from #{@plist_path.basename}) if matches
|
56
|
+
matches
|
57
|
+
end
|
40
58
|
|
41
59
|
plist.value.value["specs"].value = acknowledgements
|
42
60
|
plist.save(@plist_path, CFPropertyList::List::FORMAT_XML)
|
61
|
+
|
62
|
+
Pod::UI.puts "Saving #{@plist_path}".green
|
43
63
|
end
|
44
64
|
|
45
65
|
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require "cfpropertylist"
|
2
|
+
require "cocoapods"
|
3
|
+
require "cocoapods_acknowledgements/addons/acknowledgement"
|
4
|
+
|
5
|
+
module CocoaPodsAcknowledgements
|
6
|
+
module AddOns
|
7
|
+
class PodsPlistModifier
|
8
|
+
|
9
|
+
# A modifier to update:
|
10
|
+
#
|
11
|
+
# - Pods/Target Support Files/Pods-#{app_name}/Pods-#{app_name}-acknowledgements.{plist|markdown}
|
12
|
+
# - settings_bundle/#{app_name}-settings-metadata.plist"
|
13
|
+
#
|
14
|
+
# @param target [Pod::Installer::PostInstallHooksContext::UmbrellaTargetDescription] the xcodeproj target.
|
15
|
+
# @param sandbox [Pod::Sandbox] the CocoaPods sandbox
|
16
|
+
#
|
17
|
+
def initialize(target, sandbox)
|
18
|
+
@markdown_path = sandbox.target_support_files_root + target.cocoapods_target_label + "#{target.cocoapods_target_label}-acknowledgements.markdown"
|
19
|
+
@plist_path = sandbox.target_support_files_root + target.cocoapods_target_label + "#{target.cocoapods_target_label}-acknowledgements.plist"
|
20
|
+
|
21
|
+
project = Xcodeproj::Project.open(target.user_project_path)
|
22
|
+
file = project.files.find { |f| f.path =~ /Settings\.bundle$/ }
|
23
|
+
settings_bundle = file&.real_path
|
24
|
+
@settings_plist = settings_bundle + "#{target.cocoapods_target_label}-settings-metadata.plist" if settings_bundle&.exist?
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [String] the acknowledgement texts at Pods/Target Support Files/Pods-#{app_name}/Pods-#{app_name}-acknowledgements.markdown.
|
28
|
+
#
|
29
|
+
def markdown
|
30
|
+
return nil unless @markdown_path&.readable?
|
31
|
+
File.read @markdown_path
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [CFPropertyList::List] the acknowledgement plist at Pods/Target Support Files/Pods-#{app_name}/Pods-#{app_name}-acknowledgements.plist.
|
35
|
+
#
|
36
|
+
def plist
|
37
|
+
return nil unless @plist_path&.readable?
|
38
|
+
CFPropertyList::List.new(file: @plist_path)
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [CFPropertyList::List] the acknowledgement plist in the app Settings.bundle.
|
42
|
+
#
|
43
|
+
def settings_plist
|
44
|
+
return nil unless @settings_plist&.readable?
|
45
|
+
CFPropertyList::List.new(file: @settings_plist)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Adds acknowledgements to the CocoaPods generated plist and markdown files except the excluded ones.
|
49
|
+
#
|
50
|
+
# @param plist_metadata [Array<Hash>] the array of acknowledgement plist metadata.
|
51
|
+
# @param excluded_names [Array<String>] the array of names to ignore.
|
52
|
+
#
|
53
|
+
def add(plist_metadata, excluded_names)
|
54
|
+
plist_metadata = [*plist_metadata]
|
55
|
+
excluded_names = [*excluded_names]
|
56
|
+
|
57
|
+
return if plist_metadata.empty?
|
58
|
+
plist = plist_with_additional_metadata(plist_metadata, excluded_names)
|
59
|
+
|
60
|
+
[@plist_path, @settings_plist].each do |path|
|
61
|
+
next unless path&.writable?
|
62
|
+
Pod::UI.puts "Saving #{path}".green
|
63
|
+
plist.save(path, CFPropertyList::List::FORMAT_XML)
|
64
|
+
end
|
65
|
+
|
66
|
+
File.write @markdown_path, markdown_text_with(plist)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def plist_with_additional_metadata(plist_metadata, excluded_names)
|
72
|
+
return nil unless @plist_path&.readable?
|
73
|
+
|
74
|
+
plist = CFPropertyList::List.new(file: @plist_path)
|
75
|
+
entries = plist.value.value["PreferenceSpecifiers"].value
|
76
|
+
|
77
|
+
header = entries.first
|
78
|
+
footer = entries.last
|
79
|
+
attributes = [header.value["Title"].value, footer.value["Title"].value]
|
80
|
+
|
81
|
+
existing_titles = entries
|
82
|
+
.map { |spec| spec.value["Title"].value }
|
83
|
+
.reject { |title| attributes.include? title }
|
84
|
+
excluded_names.uniq!
|
85
|
+
|
86
|
+
additions = plist_metadata.map do |metadata|
|
87
|
+
next if metadata.nil? or existing_titles.include? metadata[:Title]
|
88
|
+
Pod::UI.info "Adding #{metadata[:Title]} to #{@plist_path.basename}"
|
89
|
+
CFPropertyList.guess(metadata)
|
90
|
+
end.reject(&:nil?)
|
91
|
+
|
92
|
+
acknowledgements = entries[1...-1] + additions
|
93
|
+
acknowledgements
|
94
|
+
.sort! { |a, b| a.value["Title"].value <=> b.value["Title"].value }
|
95
|
+
.reject! do |entry|
|
96
|
+
matches = excluded_names.any? do |excluded_name|
|
97
|
+
pattern = %r(^#{Regexp.escape(excluded_name).gsub("\*", ".*?")})
|
98
|
+
entry.value["Title"].value =~ pattern
|
99
|
+
end
|
100
|
+
Pod::UI.info %(Removing #{entry.value["Title"].value} from #{@plist_path.basename}) if matches
|
101
|
+
matches
|
102
|
+
end
|
103
|
+
|
104
|
+
footer.value["FooterText"].value.gsub!("http:", "https:")
|
105
|
+
|
106
|
+
plist.value.value["PreferenceSpecifiers"].value = [header] + acknowledgements + [footer]
|
107
|
+
plist
|
108
|
+
end
|
109
|
+
|
110
|
+
def markdown_text_with(plist)
|
111
|
+
entries = plist.value.value["PreferenceSpecifiers"].value
|
112
|
+
header = entries.first
|
113
|
+
footer = entries.last
|
114
|
+
acknowledgements = entries[1...-1].map do |entry|
|
115
|
+
<<~ACKNOWLEDGEMENT.strip
|
116
|
+
## #{entry.value["Title"].value}
|
117
|
+
|
118
|
+
#{entry.value["FooterText"].value}
|
119
|
+
ACKNOWLEDGEMENT
|
120
|
+
end
|
121
|
+
|
122
|
+
texts = <<~MARKDOWN
|
123
|
+
# #{header.value["Title"].value}
|
124
|
+
#{header.value["FooterText"].value}
|
125
|
+
|
126
|
+
#{acknowledgements.join("\n\n\n")}
|
127
|
+
|
128
|
+
#{footer.value["FooterText"].value}
|
129
|
+
MARKDOWN
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "cocoapods-core"
|
2
|
+
require "cocoapods_acknowledgements/addons/acknowledgement"
|
3
|
+
|
4
|
+
module CocoaPodsAcknowledgements
|
5
|
+
module AddOns
|
6
|
+
class SwiftPackageAccumulator
|
7
|
+
|
8
|
+
# @param xcodeproj_path [Pathname] the directory to look for podspecs.
|
9
|
+
#
|
10
|
+
def initialize(xcodeproj_path = nil)
|
11
|
+
if xcodeproj_path.nil?
|
12
|
+
@files = []
|
13
|
+
else
|
14
|
+
build_dir = %x{xcodebuild -project "#{xcodeproj_path}" -showBuildSettings | grep -m 1 BUILD_DIR | grep -oEi "\/.*"}.strip
|
15
|
+
source_packages_dir = Pathname(build_dir) + "../../SourcePackages/checkouts"
|
16
|
+
@files = Dir[source_packages_dir + "*/*.podspec"] # skip nested git submodules
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Array<Acknowledgement>] the array of Acknowledgement objects.
|
21
|
+
#
|
22
|
+
def acknowledgements
|
23
|
+
@files.map { |file| Acknowledgement.new(file) }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocoapods-acknowledgements-addons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bcylin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cocoapods
|
@@ -72,6 +72,7 @@ executables: []
|
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
|
+
- ".github/workflows/run_tests.yml"
|
75
76
|
- ".gitignore"
|
76
77
|
- ".gitmodules"
|
77
78
|
- ".travis.yml"
|
@@ -87,9 +88,11 @@ files:
|
|
87
88
|
- example/App.xcodeproj/project.pbxproj
|
88
89
|
- example/App.xcodeproj/project.xcworkspace/contents.xcworkspacedata
|
89
90
|
- example/App.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
|
91
|
+
- example/App.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
|
90
92
|
- example/App.xcodeproj/xcshareddata/xcschemes/App.xcscheme
|
91
93
|
- example/App.xcworkspace/contents.xcworkspacedata
|
92
94
|
- example/App.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
|
95
|
+
- example/App.xcworkspace/xcshareddata/swiftpm/Package.resolved
|
93
96
|
- example/App/App-Bridging-Header.h
|
94
97
|
- example/App/AppDelegate.swift
|
95
98
|
- example/App/Assets.xcassets/AppIcon.appiconset/Contents.json
|
@@ -113,9 +116,10 @@ files:
|
|
113
116
|
- example/README.md
|
114
117
|
- lib/cocoapods_acknowledgements/addons.rb
|
115
118
|
- lib/cocoapods_acknowledgements/addons/acknowledgement.rb
|
116
|
-
- lib/cocoapods_acknowledgements/addons/
|
119
|
+
- lib/cocoapods_acknowledgements/addons/modifiers/metadata_plist_modifier.rb
|
120
|
+
- lib/cocoapods_acknowledgements/addons/modifiers/pods_plist_modifier.rb
|
117
121
|
- lib/cocoapods_acknowledgements/addons/podspec_accumulator.rb
|
118
|
-
- lib/cocoapods_acknowledgements/addons/
|
122
|
+
- lib/cocoapods_acknowledgements/addons/swift_package_accumulator.rb
|
119
123
|
- lib/cocoapods_plugin.rb
|
120
124
|
- lib/version.rb
|
121
125
|
homepage: https://github.com/bcylin/cocoapods-acknowledgements-addons
|
@@ -137,8 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
141
|
- !ruby/object:Gem::Version
|
138
142
|
version: '0'
|
139
143
|
requirements: []
|
140
|
-
|
141
|
-
rubygems_version: 2.6.14.1
|
144
|
+
rubygems_version: 3.0.3
|
142
145
|
signing_key:
|
143
146
|
specification_version: 4
|
144
147
|
summary: A CocoaPods plugin that adds additional acknowledgements to the plist generated
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require "cfpropertylist"
|
2
|
-
require "cocoapods"
|
3
|
-
require "cocoapods_acknowledgements/addons/acknowledgement"
|
4
|
-
|
5
|
-
module CocoaPodsAcknowledgements
|
6
|
-
module AddOns
|
7
|
-
class SettingsPlistModifier
|
8
|
-
|
9
|
-
# @param target [Pod::Installer::PostInstallHooksContext::UmbrellaTargetDescription] the xcodeproj target.
|
10
|
-
#
|
11
|
-
def initialize(target)
|
12
|
-
project = Xcodeproj::Project.open(target.user_project_path)
|
13
|
-
file = project.files.find { |f| f.path =~ /Settings\.bundle$/ }
|
14
|
-
settings_bundle = file&.real_path
|
15
|
-
|
16
|
-
return unless settings_bundle&.exist?
|
17
|
-
@plist_path = settings_bundle + "#{target.cocoapods_target_label}-settings-metadata.plist"
|
18
|
-
end
|
19
|
-
|
20
|
-
# Adds acknowledgements to the plist except the excluded ones.
|
21
|
-
#
|
22
|
-
# @param plist_metadata [Array<Hash>] the array of acknowledgement plist metadata.
|
23
|
-
# @param excluded_names [Array<String>] the array of names to ignore.
|
24
|
-
#
|
25
|
-
def add(plist_metadata, excluded_names)
|
26
|
-
plist_metadata = [*plist_metadata]
|
27
|
-
excluded_names = [*excluded_names]
|
28
|
-
|
29
|
-
return if plist_metadata.empty? or not @plist_path&.writable?
|
30
|
-
|
31
|
-
plist = CFPropertyList::List.new(file: @plist_path)
|
32
|
-
entries = plist.value.value["PreferenceSpecifiers"].value
|
33
|
-
|
34
|
-
header = entries.first
|
35
|
-
footer = entries.last
|
36
|
-
attributes = [header.value["Title"].value, footer.value["Title"].value]
|
37
|
-
|
38
|
-
existing_titles = entries
|
39
|
-
.map { |spec| spec.value["Title"].value }
|
40
|
-
.reject { |title| attributes.include? title }
|
41
|
-
excluded_names += existing_titles
|
42
|
-
|
43
|
-
additions = plist_metadata.map { |metadata|
|
44
|
-
next if metadata.nil? or excluded_names.include? metadata[:Title]
|
45
|
-
Pod::UI.info "Adding #{metadata[:Title]} to #{@plist_path.basename}"
|
46
|
-
CFPropertyList.guess(metadata)
|
47
|
-
}.reject(&:nil?)
|
48
|
-
|
49
|
-
acknowledgements = entries[1...-1] + additions
|
50
|
-
acknowledgements.sort! { |a, b| a.value["Title"].value <=> b.value["Title"].value }
|
51
|
-
|
52
|
-
plist.value.value["PreferenceSpecifiers"].value = [header] + acknowledgements + [footer]
|
53
|
-
plist.save(@plist_path, CFPropertyList::List::FORMAT_XML)
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|