Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/rake_tasks/selenium_rake/crazy_fun.rb
2884 views
1
# frozen_string_literal: true
2
3
module SeleniumRake
4
class CrazyFun
5
def initialize
6
@mappings = {}
7
add_mapping('java_binary')
8
add_mapping('java_library')
9
add_mapping('java_test')
10
end
11
12
def add_mapping(type_name, handler = detonating_handler)
13
@mappings[type_name] = [] unless @mappings.key?(type_name)
14
15
@mappings[type_name].push handler
16
end
17
18
def prebuilt_roots
19
@prebuilt_roots ||= []
20
end
21
22
def find_prebuilt(of)
23
prebuilt_roots.each do |root|
24
root_parts = root.split('/')
25
src = generate_src(of, root_parts)
26
27
return src if File.exist? src
28
end
29
30
nil
31
end
32
33
def create_tasks(files)
34
files.each do |f|
35
puts "Parsing #{f}" if $DEBUG
36
outputs = BuildFile.new.parse_file(f)
37
outputs.each do |type|
38
crash_if_no_mapping_key(type)
39
40
mappings = @mappings[type.name]
41
mappings.each do |mapping|
42
mapping.handle(self, File.dirname(f), type.args)
43
end
44
end
45
end
46
end
47
48
private
49
50
def detonating_handler
51
SeleniumRake::DetonatingHandler.new
52
end
53
54
def generate_src(of, root_parts)
55
if root_parts.first == of_parts(of).first
56
of_parts(of)[0] = root
57
of_parts(of).join('/')
58
else
59
"#{root}/#{of}"
60
end
61
end
62
63
def of_parts(of)
64
@of_parts ||=
65
if of =~ %r{build([/\\])}
66
of.split(Regexp.last_match(1))[1..-1]
67
else
68
of.split(Platform.dir_separator)
69
end
70
end
71
72
def crash_if_no_mapping_key(type)
73
raise "No mapping for type #{type.name}" unless @mappings.key?(type.name)
74
end
75
end
76
end
77
78