module Pod::ExternalSources

Public Class Methods

clone_binary(params,podfile_path,podname) click to toggle source
# File lib/cocoapods-xzdevelop/xz_external_sources.rb, line 174
def self.clone_binary(params,podfile_path,podname)
    devpod_path = File.dirname(podfile_path)
    if Dir.exist?("#{devpod_path}/DevPods")
      itselfpath = findposepec("#{devpod_path}/DevPods",podname)
      if !itselfpath.empty?
        `rm -rf #{itselfpath}`
      end
    end
    if params[:binary] == true
      gitv = params[:tag]
      binary_url = "http://10.0.2.77/staticpods/#{podname}/#{podname}-#{gitv}.zip"
      #生成二进制url下载
      params.clear()
      params[:http] = binary_url
      return params
    else
      params.delete(:dev)
      params.delete(:binary)
      return params
    end
end
clone_dev(params,podfile_path,podname) click to toggle source
# File lib/cocoapods-xzdevelop/xz_external_sources.rb, line 73
def self.clone_dev(params,podfile_path,podname)
    if !params.key?(:git)
      puts "dev model need git source"
      exit
    end
    devpod_path = File.dirname(podfile_path)
    unless Dir.exist?("#{devpod_path}/DevPods")
      FileUtils.mkdir "#{devpod_path}/DevPods"
    end
    if params[:binary] == true
      hasframework = false
      itselfpath = findposepec("#{devpod_path}/DevPods",podname)
      if !itselfpath.empty?
        Find.find(itselfpath) do |path|
          if path.end_with?('.framework')
            hasframework = true
          end
        end
      end
      if !itselfpath.empty? && !hasframework
        `rm -rf #{itselfpath}`
      elsif !itselfpath.empty? && hasframework
        params.clear()
        params[:path] = itselfpath
        return params
      end
      itselfpath = findposepec("#{devpod_path}/DevPods",podname)
      if itselfpath.empty?
        # 下载二进制包 然后更改path
        gitv = params[:tag]
        binary_url = "http://10.0.2.77/staticpods/#{podname}/#{podname}-#{gitv}.zip"
        downloadpath = "#{devpod_path}/DevPods"
        downloadermanager = Pod::Downloader::Http.new(downloadpath,binary_url,{})
        full_path = "#{downloadpath}/#{podname}-#{gitv}.zip"
        downloadermanager.download_file(full_path)
        downloadermanager.verify_checksum(full_path)
        `unzip -d #{downloadpath}/#{podname}-#{gitv} #{full_path}`
        `rm -rf #{full_path}`
        # 使用 Downloader 下载并自动解压
        params.clear
        # 注意一下路径问题
        params[:path] = "#{downloadpath}/#{podname}-#{gitv}"
        return params
      end 
    else
      hasframework = false
      itselfpath = findposepec("#{devpod_path}/DevPods",podname)
      if !itselfpath.empty?
        Find.find(itselfpath) do |path|
          if path.end_with?('.framework')
            hasframework = true
          end
        end
      end
      if !itselfpath.empty? && hasframework
        `rm -rf #{itselfpath}`
      elsif !itselfpath.empty? && !hasframework
        params.clear()
        params[:path] = itselfpath
        return params
      end
      gitsource = params[:git]
      itselfpath = findposepec("#{devpod_path}/DevPods",podname)
      if itselfpath.empty?
        devpods_path = "#{devpod_path}/DevPods"
        puts "start clone source code"
        `git -C #{devpods_path} clone --quiet #{gitsource}`
        if $?.exitstatus == 0
          itselfpath = findposepec("#{devpod_path}/DevPods",podname)
          if params.key?(:tag) || params.key?(:commit) || params.key?(:branch)
            # Dir.chdir(itselfpath)
            gittag = params[:tag]
            gitcomm = params[:commit]
            gitbranch = params[:branch]
            if gittag
              `git -C #{itselfpath} checkout #{gittag}`
            elsif gitcomm
              `git -C #{itselfpath} checkout #{gitcomm}`
            elsif gitbranch
                `git -C #{itselfpath} checkout #{gitbranch}`
            end
            
          end
        end
      else
        `echo start`
      end
      
      if $?.exitstatus != 0
        puts("git soure maybe error please check #{podname} --> #{gitsource}")
        exit
      else
        itselfpath = findposepec("#{devpod_path}/DevPods",podname)
        params.clear()
        params[:path] = itselfpath
        puts "dev process params #{params}"
        return params
      end
    end
end
concrete_class_from_params(params,podfile_path,podname) click to toggle source
# File lib/cocoapods-xzdevelop/xz_external_sources.rb, line 16
def self.concrete_class_from_params(params,podfile_path,podname)
    puts "concrete_class_from_params xzdevelop plugin--> #{params}"
    if podfile_path
      process_custome_parameters(params,podfile_path,podname)
    end
    if params.key?(:podspec)
      PodspecSource
    elsif params.key?(:path)
      PathSource
    elsif Downloader.strategy_from_options(params)
      DownloaderSource
    end
end
findposepec(podpath,podname) click to toggle source
# File lib/cocoapods-xzdevelop/xz_external_sources.rb, line 196
def self.findposepec(podpath,podname)
    itselfpath = ''
    Find.find(podpath) do |path|
      if !File.directory?(path)
        if path.end_with?('.podspec')
          specname = File.basename(path)
          specarr = specname.split('.')
          specname = specarr[0]
          if specname == podname
            itselfpath = File.dirname(path)
          end
        end
      end
    end
    itselfpath
end
from_params(params, dependency, podfile_path, can_cache) click to toggle source
# File lib/cocoapods-xzdevelop/xz_external_sources.rb, line 6
def self.from_params(params, dependency, podfile_path, can_cache)
  name = dependency.root_name
  if klass = concrete_class_from_params(params,podfile_path,name)
      klass.new(name, params, podfile_path, can_cache)
  else
      msg = "Unknown external source parameters for `#{name}`: `#{params}`"
      raise Informative, msg
  end
end
process_custome_parameters(params,podfile_path,podname) click to toggle source
# File lib/cocoapods-xzdevelop/xz_external_sources.rb, line 30
def self.process_custome_parameters(params,podfile_path,podname)
    devpod_path = File.dirname(podfile_path)
    if params.key?(:dev) && params.key?(:binary)
      if params[:dev] == true && params[:binary] == true
        params = clone_dev(params,podfile_path,podname)
      elsif params[:dev] == true && params[:binary] == false
        params = clone_dev(params,podfile_path,podname)
      elsif params[:dev] == false && params[:binary] == true
        params = clone_binary(params,podfile_path,podname)
      elsif params[:dev] == false && params[:binary] == false
        params = clone_binary(params,podfile_path,podname)
      end
    elsif params.key?(:dev)
      if params[:dev] == true 
        params = clone_dev(params,podfile_path,podname)
      else
        params.delete(:dev)
        if Dir.exist?("#{devpod_path}/DevPods")
          itselfpath = findposepec("#{devpod_path}/DevPods",podname)
          if !itselfpath.empty?
            `rm -rf #{itselfpath}`
          end
        end
      end
    elsif params.key?(:binary)
      if params[:binary] == true
        params = clone_binary(params,podfile_path,podname)
      else
        params.delete(:binary)
        if Dir.exist?("#{devpod_path}/DevPods")
          itselfpath = findposepec("#{devpod_path}/DevPods",podname)
          if !itselfpath.empty?
            `rm -rf #{itselfpath}`
          end
        end
      end
    else
      # params = clone_binary(params,podfile_path,podname)
      params = params
    end
    params
end