class Pod::Command::Jyanalyzer::Recursion

Public Class Methods

new(argv) click to toggle source
Calls superclass method
# File lib/cocoapods-jyanalyzer/command/jyanalyzer/recursion.rb, line 17
def initialize(argv)
  @pods = argv.arguments!

  super
end

Public Instance Methods

recursion_dependencies(pod_target) click to toggle source
# File lib/cocoapods-jyanalyzer/command/jyanalyzer/recursion.rb, line 124
def recursion_dependencies(pod_target)
  
  names = Array.new
  pod_targets = pod_target.dependent_targets

  pod_targets.each do |item|
    map = Hash["name" => item.pod_name,"version" => item.version]
    names.push(map)

    if item.dependent_targets.empty?
      # puts ""
    else
      news = recursion_dependencies(item)
      names = names + news
    end
  end
  return names
end
run() click to toggle source
# File lib/cocoapods-jyanalyzer/command/jyanalyzer/recursion.rb, line 22
def run

  appId=""
  branch=""
  packageId=""
  api_url="https://sunflower.hellobike.cn:20000/plugin/setDependInfo"

  @pods.each do |item|
    map = item.split("=")
    if map[0] == "appId"
      appId = map[1]
    elsif map[0] == "branch"
      branch=map[1]
    elsif map[0] == "packageId"
      packageId = map[1]
    elsif map[0] == "api_url"
      api_url = map[1]
    else
      # Pod::UI.puts " "
    end
  end
  
  if appId.empty? 
    UI.puts 'appId 不可为空'
    exit 2
  end

  if branch.empty? 
    UI.puts 'branch 不可为空'
    exit 2
  end

  if packageId.empty? 
    UI.puts 'packageId 不可为空'
    exit 2
  end


  verify_podfile_exists!

  installer = installer_for_config
  installer.repo_update = repo_update?(:default => true)
  # installer.clean_install = @clean_install
  UI.puts 'Update all pods'.yellow
  installer.update = true
  installer.prepare
  installer.resolve_dependencies
  pod_targets = installer.pod_targets;

  Pod::UI.puts "获取pod递归依赖,pod jyanalyzer recursion"

  names = Array.new
  pod_targets.each do |item|

    depends = recursion_dependencies(item)

    depends.each do | info |
      array = [] 
      array << info          
      depends = depends - array
      depends << info
    end

    dependent_pods = recursion_dependencies(item)
    map = Hash["name" => item.pod_name,"version" => item.version,"depend" => depends]
    names.push(map)
  end

  body = Hash["appId" => appId,
  "branch" => branch,
  "packageId" => packageId,
  "libraryDependList" => names]
  # Pod::UI.puts JSON.pretty_generate(body).yellow
  
  url = URI.parse(api_url)
  http = Net::HTTP.new(url.host, url.port)
  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
  
end