Sha256: bffccbea16f277498396fd2cef8b72355d51f6d79224d2f3cd8423ac577a3aa7

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cocoapods-gitlab_license_report-1.0.2 lib/cocoapods-gitlab_license_report.rb