Class: PodsOrz::PodsDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/podsorz/core/PodsOrz/pods_detector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(main_path) ⇒ PodsDetector

Returns a new instance of PodsDetector.



8
9
10
11
12
13
# 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

Instance Attribute Details

#kx_pods_pathObject

Returns the value of attribute kx_pods_path.



6
7
8
# File 'lib/podsorz/core/PodsOrz/pods_detector.rb', line 6

def kx_pods_path
  @kx_pods_path
end

#orzconfig_parseObject

Returns the value of attribute orzconfig_parse.



6
7
8
# File 'lib/podsorz/core/PodsOrz/pods_detector.rb', line 6

def orzconfig_parse
  @orzconfig_parse
end

Instance Method Details

#check_directory(main_path) ⇒ Object



15
16
17
18
19
20
# 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) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# 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) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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_existObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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_detectorObject



35
36
37
38
39
40
41
# 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