module CocoaPodsGitlabLicenseReport require 'cocoapods-gitlab_license_report/report_generator' require 'cocoapods' require 'set' class PostInstallHookHandler def initialize(context, options, generator = nil) @context = context @options = options sandbox = @context.sandbox if defined? @context.sandbox sandbox ||= Pod::Sandbox.new(@context.sandbox_root) @generator = generator || ReportGenerator.new(sandbox) end def handle! Pod::UI.section 'Generating Gitlab licenses report' do report_path = @options["report_path"] || 'reports/licenses.json' excluded_pods = Set.new(@options["exclude"]) installed_specs = @context.umbrella_targets.flat_map(&:specs).map(&:root).uniq licenses_report = @generator.generate(installed_specs, excluded_pods) puts "fef" Dir.mkdir File.dirname(report_path) unless File.exist? File.dirname(report_path) File.write(report_path, licenses_report.to_json) end end end Pod::HooksManager.register('cocoapods-gitlab_license_report', :post_install) do |context, user_options| # Until CocoaPods provides a HashWithIndifferentAccess, normalize the hash keys here. # See https://github.com/CocoaPods/CocoaPods/issues/3354 user_options.inject({}) do |normalized_hash, (key, value)| normalized_hash[key.to_s] = value normalized_hash end handler = PostInstallHookHandler.new(context, user_options) handler.handle! end end