2019-10-16 10:31:36 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2019-09-27 13:58:28 +01:00
|
|
|
module SeleniumRake
|
|
|
|
|
class CrazyFun
|
|
|
|
|
def initialize
|
|
|
|
|
@mappings = {}
|
2019-10-16 10:31:36 +01:00
|
|
|
add_mapping('java_binary')
|
|
|
|
|
add_mapping('java_library')
|
|
|
|
|
add_mapping('java_test')
|
2019-09-27 13:58:28 +01:00
|
|
|
end
|
|
|
|
|
|
2019-10-16 10:31:36 +01:00
|
|
|
def add_mapping(type_name, handler = detonating_handler)
|
2019-09-27 13:58:28 +01:00
|
|
|
@mappings[type_name] = [] unless @mappings.key?(type_name)
|
|
|
|
|
|
|
|
|
|
@mappings[type_name].push handler
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def prebuilt_roots
|
2019-10-16 10:31:36 +01:00
|
|
|
@prebuilt_roots ||= []
|
2019-09-27 13:58:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def find_prebuilt(of)
|
|
|
|
|
prebuilt_roots.each do |root|
|
|
|
|
|
root_parts = root.split('/')
|
2019-10-16 10:31:36 +01:00
|
|
|
src = generate_src(of, root_parts)
|
2019-09-27 13:58:28 +01:00
|
|
|
|
|
|
|
|
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|
|
2019-10-16 10:31:36 +01:00
|
|
|
crash_if_no_mapping_key(type)
|
2019-09-27 13:58:28 +01:00
|
|
|
|
|
|
|
|
mappings = @mappings[type.name]
|
|
|
|
|
mappings.each do |mapping|
|
|
|
|
|
mapping.handle(self, File.dirname(f), type.args)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-10-16 10:31:36 +01:00
|
|
|
|
|
|
|
|
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
|
2019-09-27 13:58:28 +01:00
|
|
|
end
|
|
|
|
|
end
|