Sha256: 37a6ff931df1b6c223c6560b30a44520809af8463acab9f9b3d301caa9835539

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require "json"

module LicenseFinder
  class CocoaPods < PackageManager
    def current_packages
      podfile = YAML.load_file(lockfile_path)

      acknowledgements = read_plist(acknowledgements_path)["PreferenceSpecifiers"]

      podfile["PODS"].map do |pod|
        pod = pod.keys.first if pod.is_a?(Hash)

        pod_name, pod_version = pod.scan(/(.*)\s\((.*)\)/).flatten
        pod_acknowledgment = acknowledgements.detect { |hash| hash["Title"] == pod_name } || {}
        CocoaPodsPackage.new(pod_name, pod_version, pod_acknowledgment["FooterText"])
      end
    end

    private

    def package_path
      Pathname.new("Podfile")
    end

    def lockfile_path
      Pathname.new("Podfile.lock")
    end

    def acknowledgements_path
      filename = 'Pods-acknowledgements.plist'
      directories = [
        'Pods',                          # cocoapods < 0.34
        'Pods/Target Support Files/Pods' # cocoapods >= 0.34
      ]

      directories.map { |dir| Pathname.new(File.join(dir, filename)) }.find(&:exist?)
    end

    def read_plist pathname
      JSON.parse(`plutil -convert json -o - '#{pathname.expand_path}'`)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
license_finder-1.2 lib/license_finder/package_managers/cocoa_pods.rb
license_finder-1.2-java lib/license_finder/package_managers/cocoa_pods.rb