Class: Trinidad::Extensions::DiagnosticsListener

Inherits:
Object
  • Object
show all
Includes:
Tomcat::LifecycleListener
Defined in:
lib/trinidad_diagnostics_extension.rb

Instance Method Summary collapse

Constructor Details

#initialize(debug) ⇒ DiagnosticsListener

Returns a new instance of DiagnosticsListener.



30
31
32
# File 'lib/trinidad_diagnostics_extension.rb', line 30

def initialize(debug)
  @debug = debug || false
end

Instance Method Details

#lifecycleEvent(event) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/trinidad_diagnostics_extension.rb', line 34

def lifecycleEvent(event)
  if event.type == Trinidad::Tomcat::Lifecycle::BEFORE_START_EVENT
    puts '-- Trinidad diagnostics on' if @debug
    app_context = event.lifecycle

    options = lint_options(app_context)

    run_diagnostics(options)
    puts '-- Trinidad diagnostics off' if @debug
  end
end

#lint_options(app_context) ⇒ Object



50
51
52
53
54
55
# File 'lib/trinidad_diagnostics_extension.rb', line 50

def lint_options(app_context)
  OpenStruct.new(
    :html => report_output(app_context),
    :chdir => app_context.doc_base,
    :text => @debug)
end

#report_output(app_context) ⇒ Object



57
58
59
60
# File 'lib/trinidad_diagnostics_extension.rb', line 57

def report_output(app_context)
  public_root = app_context.find_parameter('public.root') || 'public'
  File.join(public_root, 'diagnostics.html')
end

#run_diagnostics(options) ⇒ Object



46
47
48
# File 'lib/trinidad_diagnostics_extension.rb', line 46

def run_diagnostics(options)
  JRuby::Lint::Project.new(options).run
end