Class: Pod::PodAnalysis
- Inherits:
-
Object
- Object
- Pod::PodAnalysis
- Defined in:
- lib/cocoapods-util/command/cocoapods-extend/install/analysis.rb
Instance Method Summary collapse
- #all_installed_pods! ⇒ Object
- #all_pod_analysis! ⇒ Object
- #analysis!(pod_name) ⇒ Object
- #check_podinfo(name, index = 1) ⇒ Object
-
#initialize(name, showmore) ⇒ PodAnalysis
constructor
A new instance of PodAnalysis.
- #pod_spec_repos! ⇒ Object
- #pods_tag! ⇒ Object
-
#recursion_dependent_targets(target) ⇒ Object
递归查找依赖.
- #run ⇒ Object
- #show_moreinfo(name) ⇒ Object
Constructor Details
#initialize(name, showmore) ⇒ PodAnalysis
Returns a new instance of PodAnalysis.
3 4 5 6 7 |
# File 'lib/cocoapods-util/command/cocoapods-extend/install/analysis.rb', line 3 def initialize(name, showmore) @name = name @showmore = showmore @lockfile = Pod::Config.instance.lockfile end |
Instance Method Details
#all_installed_pods! ⇒ Object
112 113 114 |
# File 'lib/cocoapods-util/command/cocoapods-extend/install/analysis.rb', line 112 def all_installed_pods! @installed_pods ||= @lockfile.internal_data["SPEC CHECKSUMS"].flat_map { |k, _| k } end |
#all_pod_analysis! ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/cocoapods-util/command/cocoapods-extend/install/analysis.rb', line 76 def all_pod_analysis! config = Pod::Config.instance @installer = Pod::Installer.new(config.sandbox, config.podfile, config.lockfile) @installer.sandbox.prepare # sandbox prepare @installer.resolve_dependencies # 解析依赖 # 递归查找依赖 def recursion_dependent_targets(target) target.dependent_targets.flat_map {|t| targets = [t] targets += recursion_dependent_targets(t) if target.dependent_targets.size > 0 targets }.reject(&:nil?) end def analysis!(pod_name) # 获取依赖 targets = [] dependent_targets = @installer.pod_targets.flat_map {|target| match_pod = target.pod_name.to_s == pod_name targets << target if match_pod recursion_dependent_targets(target) if match_pod }.reject(&:nil?).uniq [targets, dependent_targets] end @targets_hash = {} @dependencies_hash = {} all_installed_pods!.each do |pod_name| analysis = analysis!(pod_name) @targets_hash[pod_name] = analysis[0] @dependencies_hash[pod_name] = analysis[1] end end |
#analysis!(pod_name) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cocoapods-util/command/cocoapods-extend/install/analysis.rb', line 91 def analysis!(pod_name) # 获取依赖 targets = [] dependent_targets = @installer.pod_targets.flat_map {|target| match_pod = target.pod_name.to_s == pod_name targets << target if match_pod recursion_dependent_targets(target) if match_pod }.reject(&:nil?).uniq [targets, dependent_targets] end |
#check_podinfo(name, index = 1) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cocoapods-util/command/cocoapods-extend/install/analysis.rb', line 27 def check_podinfo(name, index=1) UI.puts "#{index}).".red " #{name} ".green "#{pods_tag![name]}".yellow # repo spec repo_name = pod_spec_repos![name] UI.puts " - SPEC REPO: ".yellow "#{repo_name}".green unless repo_name.nil? # external sources external_sources = @lockfile.internal_data['EXTERNAL SOURCES'] unless external_sources.nil? external_dict = external_sources[name] UI.puts " - EXTERNAL SOURCES: ".yellow unless external_dict.nil? external_dict.each { |key, value| UI.puts " - #{key}: ".yellow "#{value}".green } unless external_dict.nil? end show_moreinfo(name) if @showmore end |
#pod_spec_repos! ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/cocoapods-util/command/cocoapods-extend/install/analysis.rb', line 130 def pod_spec_repos! @repos ||= begin repos = {} @lockfile.internal_data["SPEC REPOS"].each do |key, value| value.each {|item| repos[item] = key } if value.is_a?(Array) end repos end end |
#pods_tag! ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cocoapods-util/command/cocoapods-extend/install/analysis.rb', line 116 def pods_tag! @tags ||= begin = {} @lockfile.internal_data["PODS"].each do |item| pod_info = item.keys.first if item.is_a?(Hash) && item.count == 1 pod_info = item if item.is_a?(String) name = pod_info.match(/^[^\/\s]*/).to_s tag = pod_info.match(/\(.*\)/).to_s [name] = tag unless .keys.include?(name) end end end |
#recursion_dependent_targets(target) ⇒ Object
递归查找依赖
83 84 85 86 87 88 89 |
# File 'lib/cocoapods-util/command/cocoapods-extend/install/analysis.rb', line 83 def recursion_dependent_targets(target) target.dependent_targets.flat_map {|t| targets = [t] targets += recursion_dependent_targets(t) if target.dependent_targets.size > 0 targets }.reject(&:nil?) end |
#run ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cocoapods-util/command/cocoapods-extend/install/analysis.rb', line 9 def run all_pods = all_installed_pods! # 忽略大小写检查name match_pods = all_pods.select { |pod_name| @name && pod_name.downcase == @name.downcase } @name = match_pods.first if match_pods.size == 1 # 解析所有依赖 all_pod_analysis! if @showmore if @name && all_pods.include?(@name) check_podinfo(@name) else all_pods.each_index do |index| check_podinfo(all_pods[index], index+1) end end end |
#show_moreinfo(name) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cocoapods-util/command/cocoapods-extend/install/analysis.rb', line 45 def show_moreinfo(name) # checkout options = @lockfile.internal_data['CHECKOUT OPTIONS'] unless .nil? checkout_dict = [name] UI.puts " - CHECKOUT OPTIONS: ".yellow unless checkout_dict.nil? checkout_dict.each { |key, value| UI.puts " - #{key}: ".yellow "#{value}".green } unless checkout_dict.nil? end targets = @targets_hash[name] dependent_targets = @dependencies_hash[name] # subspecs subspecs = targets.flat_map do |target| target.specs.reject { |spec| spec == spec.root }.map(&:name) end.uniq # dependencies dependencies = dependent_targets.map(&:pod_name).uniq # parents parents = @dependencies_hash.map do |pod_name, dependent_targets| next if pod_name == name pod_name if dependent_targets.map(&:pod_name).uniq.include?(name) end.reject(&:nil?) UI.puts " - SUBSPECS: ".yellow "#{subspecs.uniq.join('、')}".green unless subspecs.empty? UI.puts " - DEPENDENCIES: ".yellow "#{dependencies.uniq.join('、')}".green unless dependencies.empty? UI.puts " - DEPENDS ON IT: ".yellow "#{parents.uniq.join('、')}".green unless parents.empty? end |