class PodsOrz::PodsDetector

Attributes

kx_pods_path[RW]
orzconfig_parse[RW]

Public Class Methods

new(main_path) click to toggle source
# File lib/podsorz/core/PodsOrz/pods_detector.rb, line 8
def initialize(main_path)
                                
        @orzconfig_parse = PodsOrz::PodOrzconfigParse.new(main_path)
        @kx_pods_path = File.expand_path("../#{@orzconfig_parse.file_devpods_name}", main_path)
        detect_kx_pods(main_path)
end

Public Instance Methods

check_directory(main_path) click to toggle source
# File lib/podsorz/core/PodsOrz/pods_detector.rb, line 15
def check_directory(main_path)
        is_directory = File.directory?(main_path)
        Logger.error("Detect failure, it is not a directory path: #{main_path}") unless is_directory

        is_directory
end
clone_orz_pod(pod) click to toggle source
# File lib/podsorz/core/PodsOrz/pods_detector.rb, line 74
def clone_orz_pod(pod)
        is_clone_success = true
        pod_directory = File.expand_path(pod, @kx_pods_path)

        Logger.default("Start clone 【#{pod}】 Project...")
        git_clone_content = ""
        # 替换为config参数
        IO.popen("git clone #{@orzconfig_parse.remote_url_sourcecode}/#{pod}.git #{pod_directory}", :err=>[:child, :out]) {|io|
                git_clone_content = io.read
                puts(git_clone_content)
                is_clone_success = false if git_clone_content.to_s.include? "fatal"
        }

        if is_clone_success
                Logger.highlight("Clone 【#{pod}】 success!")
        else
                Logger.error("Clone 【#{pod}】 failure!")
        end

        is_clone_success
end
detect_kx_pods(main_path) click to toggle source
# File lib/podsorz/core/PodsOrz/pods_detector.rb, line 22
def detect_kx_pods(main_path)

        result = check_directory(main_path)

        if result
                pods_result = File.directory?(@kx_pods_path)
                unless pods_result
                        Logger.warning("#{@orzconfig_parse.file_devpods_name} directory not exist, generate default directory")    
                        FileUtils.mkdir_p(@kx_pods_path, :mode => 0777)
                end
        end
end
detect_pod(pod) click to toggle source
# File lib/podsorz/core/PodsOrz/pods_detector.rb, line 58
def detect_pod(pod)
        pod_path = File.expand_path(pod, @kx_pods_path)
        result = File.directory?(pod_path)
        if result
                file_entries = Dir.entries(pod_path)
                result = false if file_entries.empty?
                result = false unless file_entries.include?(".git")

                Logger.error("【#{pod}】 at #{pod_path} exist, but .git not work success, please manual check.") unless result
        else
                result = clone_orz_pod(pod)
        end

        result
end
ensure_kxpods_exist() click to toggle source
# File lib/podsorz/core/PodsOrz/pods_detector.rb, line 43
def ensure_kxpods_exist()
        pods_list = @orzconfig_parse.fix_pod_list
        is_clone_success = true
        pods_list.each {|pod|
                command = Thread.new do 
                        each_result = detect_pod(pod)
                        is_clone_success = false unless each_result
                end

                command.join
        }

        exit() unless is_clone_success
end
start_detector() click to toggle source
# File lib/podsorz/core/PodsOrz/pods_detector.rb, line 35
def start_detector()
        if @orzconfig_parse.fix_pod_list.empty?
                Logger.warning("Fix pod list is empty, there is nothings to do, please setup 'FIX_POD_LIST' in \"PodsOrzConfig.rb\"")
        else
                ensure_kxpods_exist()
        end
end