Class: U3d::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/u3d/installer.rb

Instance Method Summary collapse

Instance Method Details

#find_arg_in_args(arg_to_find, args) ⇒ Object



212
213
214
215
216
217
218
# File 'lib/u3d/installer.rb', line 212

def find_arg_in_args(arg_to_find, args)
  raise 'Only arguments of type array supported right now' unless args.is_a?(Array)
  args.each_with_index do |arg, index|
    return args[index + 1] if arg == arg_to_find && index < args.count - 1
  end
  nil
end

#find_logFile_in_args(args) ⇒ Object



204
205
206
# File 'lib/u3d/installer.rb', line 204

def find_logFile_in_args(args)
  find_arg_in_args('-logFile', args)
end

#find_projectpath_in_args(args) ⇒ Object



208
209
210
# File 'lib/u3d/installer.rb', line 208

def find_projectpath_in_args(args)
  find_arg_in_args('-projectpath', args)
end

#run(installation, args, raw_logs: false) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/u3d/installer.rb', line 163

def run(installation, args, raw_logs: false)
  require 'fileutils'

  log_file = find_logFile_in_args(args)

  if log_file # we wouldn't want to do that for the default log file.
    File.delete(log_file) if File.exist?(log_file)
  else
    log_file = installation.default_log_file
  end

  FileUtils.touch(log_file)

  tail_thread = Thread.new do
    begin
      if raw_logs
        pipe(log_file) { |l| UI.message l.rstrip }
      else
        analyzer = LogAnalyzer.new
        pipe(log_file) { |l| analyzer.parse_line l }
      end
    rescue => e
      UI.error "Failure while trying to pipe #{log_file}: #{e.message}"
      e.backtrace.each { |l| UI.error "  #{l}" }
    end
  end

  begin
    args.unshift(installation.exe_path)
    if Helper.windows?
      args.map! { |a| a =~ / / ? "\"#{a}\"" : a }
    else
      args.map!(&:shellescape)
    end
    U3dCore::CommandExecutor.execute(command: args)
  ensure
    sleep 0.5
    Thread.kill(tail_thread)
  end
end