class Pod::Command::Jyanalyzer::Component
Public Class Methods
new(argv)
click to toggle source
Calls superclass method
# File lib/cocoapods-jyanalyzer/command/jyanalyzer/component.rb, line 18 def initialize(argv) @pods = argv.arguments! @podHash = Hash.new super end
Public Instance Methods
dependencies_tmp(pods,podsPath)
click to toggle source
# File lib/cocoapods-jyanalyzer/command/jyanalyzer/component.rb, line 139 def dependencies_tmp(pods,podsPath) names = Array.new pods.each do |item| childNodes = Array.new recursive_pods = item.recursive_dependent_targets recursive_pods.each do |recursive_item| recursive_size = size_lib(podsPath,recursive_item.pod_name) recursive_type = type_lib(podsPath,recursive_item.pod_name) recursive_map = Hash["name" => recursive_item.pod_name,"version" => recursive_item.version,"size" => recursive_size,"system" => "ios","type" => recursive_type,"childNodes" => Array.new] childNodes.push(recursive_map) end size = size_lib(podsPath,item.pod_name) type = type_lib(podsPath,item.pod_name) map = Hash["name" => item.pod_name,"version" => item.version,"size" => size,"system" => "ios","type" => type,"childNodes" => childNodes] names.push(map) end return names end
run()
click to toggle source
# File lib/cocoapods-jyanalyzer/command/jyanalyzer/component.rb, line 25 def run planId = "" api_url = "https://sunflower.hellobike.cn:20000/plugin/setComponentInfo" @pods.each do |item| map = item.split("=") if map[0] == "planId" planId = map[1] elsif map[0] == "api_url" api_url = map[1] else end end if planId.empty? UI.puts 'planId 不可为空' exit 2 end verify_podfile_exists! installer = installer_for_config installer.repo_update = repo_update?(:default => true) UI.puts 'Update all pods'.yellow installer.update = true installer.prepare installer.resolve_dependencies pod_targets = installer.pod_targets; Pod::UI.puts "组件库依赖关系树、包大小, 使用: pod jyanalyzer component" podfile_path = "#{Config.instance.podfile_path}" Pod::UI.puts "#{podfile_path}" tmp_ary = podfile_path.split("/") tmp_ary.pop currentPath = tmp_ary.join("/") podsPath = "#{currentPath}/Pods" Pod::UI.puts currentPath if File.directory?(podsPath) == false Pod::UI.puts "#{podsPath} 不存在" exit 2 end body = Hash["planId" => planId, "treePackageNodeList" => dependencies_tmp(pod_targets,podsPath)] # Pod::UI.puts JSON.pretty_generate(body).yellow f=File.new("component.lock","w+") f.puts(JSON.pretty_generate(body)) f.close # return url = URI.parse(api_url) http = Net::HTTP.new(url.host, url.port) http.read_timeout = 9999 http.use_ssl = true if url.scheme == "https" # enable SSL/TLS http.verify_mode = OpenSSL::SSL::VERIFY_NONE #这个也很重要 # 设置请求参数 data = body.to_json # 设置请求头 header = {'content-type':'application/json'} response = http.post(url, data, header) puts response.body puts response.code if "#{response.code}" == "200" result = JSON.parse(response.body) if result["status"] == 0 puts "请求成功" else puts "返回结果一异常" exit 2 end else puts "请求服务器失败" exit 2 end puts planId end
size_lib(podsPath,pod_name)
click to toggle source
# File lib/cocoapods-jyanalyzer/command/jyanalyzer/component.rb, line 129 def size_lib(podsPath,pod_name) size=0 IO.popen("du -sk #{podsPath}/#{pod_name}"){ |f| text = f.gets.split(" ") size = text[0] } size=size.to_i*1024 return size end
type_lib(podsPath,pod_name)
click to toggle source
# File lib/cocoapods-jyanalyzer/command/jyanalyzer/component.rb, line 118 def type_lib(podsPath,pod_name) type = 1 IO.popen("find #{podsPath}/#{pod_name} -name \"*.m\""){ |f| text = f.gets if text.nil? type = 0 end } return type end