Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to add plist to target or not #43

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ spec/reports
test/tmp
test/version_tmp
tmp

.idea/.rakeTasks

.idea/cocoapods-acknowledgements-inhouse.iml

.idea/misc.xml

.idea/modules.xml

.idea/vcs.xml

.idea/workspace.xml
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* Update matching for `Settings.bundle` file in project.
[Jim Hildensperger](https://github.com/jhildensperger)

* Add option to add generated plist to target or not.
[Justin Fincher](https://github.com/justinfincher)

##### Bug Fixes

* None.
Expand Down
2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gem build cocoapods_acknowledgements.gemspec
sudo gem install cocoapods-acknowledgements-1.1.2.gem
33 changes: 19 additions & 14 deletions lib/cocoapods_acknowledgements.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module CocoaPodsAcknowledgements
require 'cocoapods_acknowledgements/plist_generator'
require 'cocoapods_acknowledgements/settings_plist_generator'

def self.save_metadata(metadata, plist_path, project, sandbox, user_target_uuid)
def self.save_metadata(metadata, plist_path, project, sandbox, user_target_uuid, should_add_to_target)
if defined? Xcodeproj::Plist.write_to_path
Xcodeproj::Plist.write_to_path(metadata, plist_path)
else
Expand All @@ -22,19 +22,21 @@ def self.save_metadata(metadata, plist_path, project, sandbox, user_target_uuid)
file_ref = cocoapods_group.new_file(plist_path)
end

# Ensure that the plist is added to target
target = project.objects_by_uuid[user_target_uuid]
unless target.resources_build_phase.files_references.include?(file_ref)
target.add_resources([file_ref])
end
if should_add_to_target
# Ensure that the plist is added to target
target = project.objects_by_uuid[user_target_uuid]
unless target.resources_build_phase.files_references.include?(file_ref)
target.add_resources([file_ref])
end
end

project.save

end

def self.settings_bundle_in_project(project)
file = project.files.find { |f| f.path =~ /Settings\.bundle$/ }
file.hierarchy_path.sub('/', '') unless file.nil?
# TODO: Code golf this
def self.settings_bundle_in_project
Dir.glob("**/*Settings.bundle").first
end

Pod::HooksManager.register('cocoapods-acknowledgements', :post_install) do |context, user_options|
Expand All @@ -52,6 +54,7 @@ def self.settings_bundle_in_project(project)
Pod::UI.section 'Adding Acknowledgements' do

should_include_settings = user_options["settings_bundle"] != nil
should_add_to_target = (user_options["add_to_target"] != nil) ? user_options["add_to_target"] : true
excluded_pods = Set.new(user_options["exclude"])

sandbox = context.sandbox if defined? context.sandbox
Expand All @@ -68,7 +71,7 @@ def self.settings_bundle_in_project(project)
next unless metadata

plist_path = sandbox.root + "#{umbrella_target.cocoapods_target_label}-metadata.plist"
save_metadata(metadata, plist_path, project, sandbox, user_target_uuid)
save_metadata(metadata, plist_path, project, sandbox, user_target_uuid, true)

if should_include_settings
# Generate a plist in Settings format
Expand All @@ -77,13 +80,15 @@ def self.settings_bundle_in_project(project)
# We need to look for a Settings.bundle
# and add this to the root of the bundle

settings_bundle = settings_bundle_in_project(project)
# settings_bundle = settings_bundle_in_project(project)
settings_bundle = settings_bundle_in_project
Pod::UI.info "settings_bundle = #{settings_bundle}"
if settings_bundle == nil
Pod::UI.warn "Could not find a Settings.bundle to add the Pod Settings Plist to."
else
settings_plist_path = settings_bundle + "/#{umbrella_target.cocoapods_target_label}-settings-metadata.plist"
save_metadata(settings_metadata, settings_plist_path, project, sandbox, user_target_uuid)
Pod::UI.info "Added Pod info to Settings.bundle for target #{umbrella_target.cocoapods_target_label}"
save_metadata(settings_metadata, settings_plist_path, project, sandbox, user_target_uuid, should_add_to_target)
Pod::UI.info "Added Pod info to Settings.bundle for target #{umbrella_target.cocoapods_target_label} with should_add_to_target = #{should_add_to_target}"

# Support a callback for the key :settings_post_process
if user_options["settings_post_process"]
Expand All @@ -100,4 +105,4 @@ def self.settings_bundle_in_project(project)
end

end
end
end