Module: RokuBuilder

Defined in:
lib/roku_builder/util.rb,
lib/roku_builder.rb,
lib/roku_builder/config.rb,
lib/roku_builder/errors.rb,
lib/roku_builder/logger.rb,
lib/roku_builder/plugin.rb,
lib/roku_builder/stager.rb,
lib/roku_builder/options.rb,
lib/roku_builder/version.rb,
lib/roku_builder/manifest.rb,
lib/roku_builder/plugins/core.rb,
lib/roku_builder/config_parser.rb,
lib/roku_builder/device_manager.rb,
lib/roku_builder/plugins/linker.rb,
lib/roku_builder/plugins/loader.rb,
lib/roku_builder/plugins/tester.rb,
lib/roku_builder/plugins/monitor.rb,
lib/roku_builder/config_validator.rb,
lib/roku_builder/plugins/analyzer.rb,
lib/roku_builder/plugins/packager.rb,
lib/roku_builder/plugins/profiler.rb,
lib/roku_builder/plugins/scripter.rb,
lib/roku_builder/plugins/inspector.rb,
lib/roku_builder/plugins/navigator.rb,
lib/roku_builder/plugins/line_inspector.rb,
lib/roku_builder/plugins/indentation_inspector.rb

Overview

********** Copyright Viacom, Inc. Apache 2.0 **********

Defined Under Namespace

Modules: Plugin Classes: Analyzer, Config, ConfigParser, ConfigValidator, Core, Device, DeviceError, DeviceManager, ExecutionError, ImplementationError, IndentationInspector, Inspector, InvalidConfig, InvalidOptions, LineInspector, Linker, Loader, Logger, Manifest, ManifestError, Monitor, Navigator, Options, Packager, ParseError, Profiler, Scripter, Stager, Tester, Util

Constant Summary collapse

VERSION =

Version of the RokuBuilder Gem

"4.26.0"

Class Method Summary collapse

Class Method Details

.device_managerObject



174
175
176
# File 'lib/roku_builder.rb', line 174

def self.device_manager
  @@device_manager ||= DeviceManager.new(config: @@config, options: @@options)
end

.executeObject



70
71
72
73
# File 'lib/roku_builder.rb', line 70

def self.execute
  load_config
  execute_command
end

.execute_commandObject



178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/roku_builder.rb', line 178

def self.execute_command
  @@plugins.each do |plugin|
    if plugin.commands.keys.include?(@@options.command)
      stager = nil
      if plugin.commands[@@options.command][:stage]
        stager = Stager.new(config: @@config, options: @@options)
        stager.stage
      end
      instance = plugin.new(config: @@config)
      instance.send(@@options.command, **{options: @@options})
      stager.unstage if stager
    end
  end
end

.initialize_loggerObject



154
155
156
157
158
159
160
161
162
# File 'lib/roku_builder.rb', line 154

def self.initialize_logger
  if @@options[:debug]
    Logger.set_debug
  elsif @@options[:verbose]
    Logger.set_info
  else
    Logger.set_warn
  end
end

.load_configObject



164
165
166
167
168
169
170
171
172
# File 'lib/roku_builder.rb', line 164

def self.load_config
  @@config = Config.new(options: @@options)
  @@config.configure
  unless @@options[:configure] and not @@options[:edit_params]
    @@config.load
    @@config.validate
    @@config.parse
  end
end

.load_dev_pluginObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/roku_builder.rb', line 110

def self.load_dev_plugin
  dev_path = nil
  ARGV.each_index do |i|
    if ARGV[i] == "--dev-plugin"
      dev_path = ARGV[i+1]
      2.times {ARGV.delete_at(i)}
      break
    end
  end
  if dev_path
    @@dev = true
    Dir.glob(File.join(dev_path, "lib", "*.rb")).each do |path|
      require path
    end
    Dir.glob(File.join(dev_path, "lib", "roku_builder", "plugins", "*")).each do |path|
      require path
    end
    @@dev = false
  end
end

.load_pluginsObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/roku_builder.rb', line 92

def self.load_plugins
  Dir.glob(File.join(File.dirname(__FILE__), "roku_builder", "plugins", "*.rb")).each do |path|
    file = "roku_builder/plugins/"+File.basename(path, ".rb")
    require file
  end
  gem_versions = Gem::Specification.sort_by {|g| [g.name.downcase, g.version]}.group_by {|g| g.name}
  gems = []
  gem_versions.each {|v| gems.push(v.last.last)}
  gems.each do |gem|
    unless gem.name == "roku_builder"
      Dir.glob(File.join(gem.full_gem_path, "lib", "roku_builder", "plugins", "*")).each do |path|
        require path
      end
    end
  end
  load_dev_plugin
end

.options_parse(options:) ⇒ Hash

Parses a string into and options hash

Parameters:

  • options (String)

    string of options in the format “a:b, c:d”

Returns:

  • (Hash)

    Options hash generated



196
197
198
199
200
201
202
203
204
205
206
# File 'lib/roku_builder.rb', line 196

def self.options_parse(options:)
  parsed = {}
  opts = options.split(/,\s*/)
  opts.each do |opt|
    opt = opt.split(":")
    key = opt.shift.strip.to_sym
    value = opt.join(":").strip
    parsed[key] = value
  end
  parsed
end

.pluginsObject



75
76
77
# File 'lib/roku_builder.rb', line 75

def self.plugins
  @@plugins ||= []
end

.process_hook(hook:, params:) ⇒ Object



208
209
210
211
212
213
214
# File 'lib/roku_builder.rb', line 208

def self.process_hook(hook:, params:)
  @@plugins.each do |plugin|
    if plugin.respond_to?("#{hook}_hook".to_sym)
      plugin.send("#{hook}_hook", **params)
    end
  end
end

.process_pluginsObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/roku_builder.rb', line 131

def self.process_plugins
  @@plugins ||= []
  @@plugins.sort! {|a,b| a.to_s <=> b.to_s}
  unless @@plugins.count == @@plugins.uniq.count
    duplicates = @@plugins.select{ |e| @@plugins.count(e) > 1  }.uniq
    raise ImplementationError, "Duplicate plugins: #{duplicates.join(", ")}"
  end
  @@plugins.each do |plugin|
    plugin.dependencies.each do |dependency|
      raise ImplementationError, "Missing dependency: #{dependency}" unless @@plugins.include?(dependency)
    end
    plugin.commands.keys.each do |command|
      raise ImplementationError, "Missing command method '#{command}' in #{plugin}" unless  plugin.instance_methods.include?(command)
    end
  end
end

.register_plugin(plugin) ⇒ Object



79
80
81
82
83
84
# File 'lib/roku_builder.rb', line 79

def self.register_plugin(plugin)
  @@dev ||= false
  @@plugins ||= []
  @@plugins.delete(plugin) if @@dev
  @@plugins << plugin
end

.run(options: nil) ⇒ Object

Run the builder

Parameters:

  • options (Hash) (defaults to: nil)

    The options hash



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/roku_builder.rb', line 40

def self.run(options: nil)
  @@options = nil
  @@testing ||= false
  setup_plugins
  setup_options(options: options)
  return unless @@options
  initialize_logger
  if @@options[:debug]
    execute
  else
    begin
      execute
    rescue StandardError => e
      Logger.instance.fatal "#{e.class}: #{e.message}"
      exit false unless @@testing
    end
  end
end

.set_testingObject



223
224
225
226
# File 'lib/roku_builder.rb', line 223

def self.set_testing
  @@testing = true
  Logger.set_testing
end

.setup_options(options:) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/roku_builder.rb', line 59

def self.setup_options(options:)
  begin
    @@options = Options.new(options: options)
    @@options.validate
  rescue InvalidOptions => e
    Logger.instance.fatal "#{e.class}: #{e.message}"
    @@options = nil
    return
  end
end

.setup_pluginsObject



86
87
88
89
90
# File 'lib/roku_builder.rb', line 86

def self.setup_plugins
  load_plugins
  process_plugins
  validate_plugins
end

.system(command:) ⇒ String

Run a system command

Parameters:

  • command (String)

    The command to be run

Returns:

  • (String)

    The output of the command



219
220
221
# File 'lib/roku_builder.rb', line 219

def self.system(command:)
  `#{command}`.chomp
end

.validate_pluginsObject



148
149
150
151
152
# File 'lib/roku_builder.rb', line 148

def self.validate_plugins
  @@plugins.each do |plugin|
    plugin.validate
  end
end