Class: Trinidad::Lifecycle::War

Inherits:
Base
  • Object
show all
Defined in:
lib/trinidad/lifecycle/lifecycle_listener_war.rb

Instance Attribute Summary

Attributes inherited from Base

#webapp

Instance Method Summary collapse

Methods inherited from Base

#configure_logging, #initialize, #remove_defaults

Constructor Details

This class inherits a constructor from Trinidad::Lifecycle::Base

Instance Method Details

#configure_class_loader(context) ⇒ Object



20
21
22
23
24
# File 'lib/trinidad/lifecycle/lifecycle_listener_war.rb', line 20

def configure_class_loader(context)
  loader = Trinidad::Tomcat::WebappLoader.new(@webapp.class_loader)
  loader.container = context
  context.loader = loader
end

#configure_defaults(context) ⇒ Object



15
16
17
18
# File 'lib/trinidad/lifecycle/lifecycle_listener_war.rb', line 15

def configure_defaults(context)
  super
  configure_class_loader(context)
end

#destroy_expanded_appObject



26
27
28
29
# File 'lib/trinidad/lifecycle/lifecycle_listener_war.rb', line 26

def destroy_expanded_app
  require 'fileutils'
  FileUtils.rm_rf @webapp.web_app_dir.gsub(/\.war$/, '')
end

#expand_app(context) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/trinidad/lifecycle/lifecycle_listener_war.rb', line 31

def expand_app(context)
  if !File.exist?(context.doc_base)
    host = context.parent
    war_file = java.io.File.new(@webapp.web_app_dir)
    war = java.net.URL.new("jar:" + war_file.toURI.toURL.to_s + "!/")
    path_name = File.basename(context.doc_base)

    Trinidad::Tomcat::ExpandWar.expand(host, war, path_name)
  end
end

#lifecycleEvent(event) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/trinidad/lifecycle/lifecycle_listener_war.rb', line 4

def lifecycleEvent(event)
  case event.type
  when Trinidad::Tomcat::Lifecycle::AFTER_STOP_EVENT
    destroy_expanded_app
  when Trinidad::Tomcat::Lifecycle::BEFORE_START_EVENT
    expand_app(event.lifecycle)
  end

  super
end