forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrazy_fun.rb
76 lines (62 loc) · 1.64 KB
/
crazy_fun.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# frozen_string_literal: true
module SeleniumRake
class CrazyFun
def initialize
@mappings = {}
add_mapping('java_binary')
add_mapping('java_library')
add_mapping('java_test')
end
def add_mapping(type_name, handler = detonating_handler)
@mappings[type_name] = [] unless @mappings.key?(type_name)
@mappings[type_name].push handler
end
def prebuilt_roots
@prebuilt_roots ||= []
end
def find_prebuilt(of)
prebuilt_roots.each do |root|
root_parts = root.split('/')
src = generate_src(of, root_parts)
return src if File.exist? src
end
nil
end
def create_tasks(files)
files.each do |f|
puts "Parsing #{f}" if $DEBUG
outputs = BuildFile.new.parse_file(f)
outputs.each do |type|
crash_if_no_mapping_key(type)
mappings = @mappings[type.name]
mappings.each do |mapping|
mapping.handle(self, File.dirname(f), type.args)
end
end
end
end
private
def detonating_handler
SeleniumRake::DetonatingHandler.new
end
def generate_src(of, root_parts)
if root_parts.first == of_parts(of).first
of_parts(of)[0] = root
of_parts(of).join('/')
else
"#{root}/#{of}"
end
end
def of_parts(of)
@of_parts ||=
if of =~ %r{build([/\\])}
of.split(Regexp.last_match(1))[1..-1]
else
of.split(Platform.dir_separator)
end
end
def crash_if_no_mapping_key(type)
raise "No mapping for type #{type.name}" unless @mappings.key?(type.name)
end
end
end