Class: YJCocoa::PodDependency
- Defined in:
- lib/yjcocoa/pod/pod_dependency.rb
Overview
Usage
Constant Summary
Constants inherited from Command
Instance Attribute Summary collapse
-
#dir_array ⇒ Object
目录.
-
#ignore_frameworks ⇒ Object
忽略的外部库.
-
#output ⇒ Object
输出地址.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ PodDependency
constructor
A new instance of PodDependency.
- #parsing_class(products) ⇒ Object
- #parsing_content(file, all_frameworks, products) ⇒ Object
- #parsing_files(files) ⇒ Object
- #run ⇒ Object
- #search_files ⇒ Object
- #validate! ⇒ Object
Methods inherited from Command
Constructor Details
#initialize(argv) ⇒ PodDependency
Returns a new instance of PodDependency.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/yjcocoa/pod/pod_dependency.rb', line 36 def initialize(argv) super self.dir_array = argv.option('dir') self.output = argv.option('output') if self.dir_array self.dir_array = self.dir_array.split(",").reject {|i| i.empty? || !Dir.exist?(i) } end self.output = Dir.pwd unless self.output self.output << "/YJCocoa.log" self.ignore_frameworks = ["AppKit", "Foundation", "UIKit", "WatchKit"] end |
Instance Attribute Details
#dir_array ⇒ Object
目录
32 33 34 |
# File 'lib/yjcocoa/pod/pod_dependency.rb', line 32 def dir_array @dir_array end |
#ignore_frameworks ⇒ Object
忽略的外部库
34 35 36 |
# File 'lib/yjcocoa/pod/pod_dependency.rb', line 34 def ignore_frameworks @ignore_frameworks end |
#output ⇒ Object
输出地址
33 34 35 |
# File 'lib/yjcocoa/pod/pod_dependency.rb', line 33 def output @output end |
Class Method Details
.options ⇒ Object
27 28 29 30 |
# File 'lib/yjcocoa/pod/pod_dependency.rb', line 27 def self. [['--dir', '库路径,多个库用’,‘号分割'], ['--output', '日志存放路径,默认当前路径']] + super end |
Instance Method Details
#parsing_class(products) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/yjcocoa/pod/pod_dependency.rb', line 108 def parsing_class(products) puts "\n分析文件内容...".green log = "" all_frameworks = [] for project in products.values puts project.name templog = "" hlog = self.parsing_content(project.h_path, all_frameworks, products) if project.h_path templog << hlog if hlog mlog = self.parsing_content(project.m_path, all_frameworks, products) if project.m_path templog << mlog if mlog mmlog = self.parsing_content(project.mm_path, all_frameworks, products) if project.mm_path templog << mmlog if mmlog log << "\n#{project.name}\n#{templog}" unless templog.empty? end all_frameworks.uniq! all_frameworks.sort! return "外部依赖汇总:#{all_frameworks.size} #{all_frameworks.to_s}\n\n" + log end |
#parsing_content(file, all_frameworks, products) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/yjcocoa/pod/pod_dependency.rb', line 128 def parsing_content(file, all_frameworks, products) frameworks = [] warning = [] error = [] File.open(file, "r") { |file| while line = file.gets if line.include?("#import") if line.include?("<") import = line[/<.*>/][/<.*\//] if import import[0] = "" import[-1] = "" frameworks << import unless self.ignore_frameworks.include?(import) else error << line.chomp end elsif line.include?(".h\"") import = line[/".*.h"/] import[0] = "" import[-1] = "" warning << import unless products[import[0..import.size-3]] end elsif line.include?("@protocol") || line.include?("@interface") || line.include?("@implementation") break end end } all_frameworks.concat(frameworks) frameworks.uniq! frameworks.sort! if !frameworks.empty? || !warning.empty? || !error.empty? log = "#{file}\n" log << "外部依赖:#{frameworks.to_s}\n" unless frameworks.empty? log << "错误依赖:#{error.to_s}\n" unless error.empty? log << "不合理依赖:#{warning.to_s}\n" unless warning.empty? return log end return nil end |
#parsing_files(files) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/yjcocoa/pod/pod_dependency.rb', line 85 def parsing_files(files) puts "\n分析文件...".green hash = {} for file in files puts file fileName = File.basename(file).split(".").first product_class = hash[fileName] unless product_class product_class = ProductClass.new(fileName) hash[fileName] = product_class end case File.extname(file) when ".h" product_class.h_path = file when ".m" product_class.m_path = file when ".mm" product_class.mm_path = file end end return hash end |
#run ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/yjcocoa/pod/pod_dependency.rb', line 58 def run log = "YJCocoa 代码依赖分析\n" files = self.search_files log << "文件数:#{files.size}\n" products = self.parsing_files(files) log << "class数:#{products.size}\n" log << self.parsing_class(products) puts "\n分析完毕,打开日志:#{self.output}".green File.write(self.output, log) `open #{self.output}` end |
#search_files ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/yjcocoa/pod/pod_dependency.rb', line 70 def search_files puts "\n搜索文件...".green files = [] for dir in self.dir_array do Dir.chdir(dir) { puts dir for path in Dir["**/*.{h,m,mm}"] do files << "#{dir}/#{path}" end } end files.uniq! files.sort! end |
#validate! ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/yjcocoa/pod/pod_dependency.rb', line 50 def validate! super unless self.dir_array && !self.dir_array.empty? puts "库路径为空或不存在".red self. end end |