Parent

Warbler::Traits::War

The War trait sets up the layout and generates web.xml for the war project.

Constants

DEFAULT_GEM_PATH

Public Class Methods

detect?() click to toggle source
# File lib/warbler/traits/war.rb, line 20
def self.detect?
  Traits::Rails.detect? || Traits::Merb.detect? || Traits::Rack.detect?
end

Public Instance Methods

add_executables(jar) click to toggle source
# File lib/warbler/traits/war.rb, line 102
def add_executables(jar)
  webserver = WEB_SERVERS[config.webserver.to_s]
  webserver.add(jar)
  jar.files['META-INF/MANIFEST.MF'] = StringIO.new(Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: WarMain\n")
  jar.files['WarMain.class'] = jar.entry_in_jar("#{WARBLER_HOME}/lib/warbler_jar.jar", webserver.main_class)
end
add_gemjar(jar) click to toggle source
# File lib/warbler/traits/war.rb, line 109
def add_gemjar(jar)
  gem_jar = Warbler::Jar.new
  gem_path = Regexp::quote(config.relative_gem_path)
  gems = jar.files.select{|k,v| k =~ %{#{gem_path}/} }
  gems.each do |k,v|
    gem_jar.files[k.sub(%{#{gem_path}/}, '')] = v
  end
  jar.files["WEB-INF/lib/gems.jar"] = "tmp/gems.jar"
  jar.files.reject!{|k,v| k =~ /#{gem_path}/ || k == "WEB-INF/tmp/gems.jar"}
  mkdir_p "tmp"
  gem_jar.add_manifest
  gem_jar.create("tmp/gems.jar")
end
add_public_files(jar) click to toggle source

Add public/static assets to the root of the war file.

# File lib/warbler/traits/war.rb, line 85
def add_public_files(jar)
  config.public_html.exclude *(config.excludes.to_a)
  config.public_html.map {|f| jar.add_with_pathmaps(config, f, :public_html) }
end
add_webxml(jar) click to toggle source

Add web.xml and other WEB-INF configuration files from config.webinf_files to the war file.

# File lib/warbler/traits/war.rb, line 92
def add_webxml(jar)
  config.webinf_files.each do |wf|
    if wf =~ /\.erb$/
      jar.files[apply_pathmaps(config, wf, :webinf)] = jar.expand_erb(wf, config)
    else
      jar.files[apply_pathmaps(config, wf, :webinf)] = wf
    end
  end
end
after_configure() click to toggle source
# File lib/warbler/traits/war.rb, line 35
def after_configure
  update_gem_path(DEFAULT_GEM_PATH)
end
before_configure() click to toggle source
# File lib/warbler/traits/war.rb, line 24
def before_configure
  config.gem_path      = DEFAULT_GEM_PATH
  config.pathmaps      = default_pathmaps
  config.webxml        = default_webxml_config
  config.webinf_files  = default_webinf_files
  config.java_libs     = default_jar_files
  config.public_html   = FileList["public/**/*"]
  config.jar_extension = 'war'
  config.init_contents << "#{config.warbler_templates}/war.erb"
end
default_jar_files() click to toggle source
# File lib/warbler/traits/war.rb, line 70
def default_jar_files
  require 'jruby-jars'
  require 'jruby-rack'
  FileList[JRubyJars.core_jar_path, JRubyJars.stdlib_jar_path, JRubyJars.jruby_rack_jar_path]
end
default_pathmaps() click to toggle source
# File lib/warbler/traits/war.rb, line 39
def default_pathmaps
  p = OpenStruct.new
  p.public_html  = ["%{public/,}p"]
  p.java_libs    = ["WEB-INF/lib/%f"]
  p.java_classes = ["WEB-INF/classes/%p"]
  p.application  = ["WEB-INF/%p"]
  p.webinf       = ["WEB-INF/%{.erb$,}f"]
  p.gemspecs     = ["#{config.relative_gem_path}/specifications/%f"]
  p.gems         = ["#{config.relative_gem_path}/gems/%p"]
  p
end
default_webinf_files() click to toggle source
# File lib/warbler/traits/war.rb, line 59
def default_webinf_files
  webxml = if File.exist?("config/web.xml")
    "config/web.xml"
  elsif File.exist?("config/web.xml.erb")
    "config/web.xml.erb"
  else
    "#{WARBLER_HOME}/web.xml.erb"
  end
  FileList[webxml]
end
default_webxml_config() click to toggle source
# File lib/warbler/traits/war.rb, line 51
def default_webxml_config
  c = WebxmlOpenStruct.new
  c.public.root = '/'
  c.jndi = nil
  c.ignored = %(jndi booter)
  c
end
empty_jar() click to toggle source
# File lib/warbler/traits/war.rb, line 131
def empty_jar
  @empty_jar ||= begin
    t = Tempfile.new(["empty", "jar"])
    path = t.path
    t.close!
    Zip::ZipFile.open(path, Zip::ZipFile::CREATE) do |zipfile|
      zipfile.mkdir("META-INF")
      zipfile.get_output_stream("META-INF/MANIFEST.MF") {|f| f << ::Warbler::Jar::DEFAULT_MANIFEST }
    end
    at_exit { File.delete(path) }
    path
  end
end
move_jars_to_webinf_lib(jar) click to toggle source
# File lib/warbler/traits/war.rb, line 123
def move_jars_to_webinf_lib(jar)
  jar.files.keys.select {|k| k =~ /^WEB-INF\/.*\.jar$/ }.each do |k|
    next if k =~ /^WEB-INF\/lib\/([^\/]+)\.jar$/ # skip jars already in WEB-INF/lib
    jar.files["WEB-INF/lib/#{k.sub('WEB-INF','')[1..-1].gsub(/[\/\\]/,'-')}"] = jar.files[k]
    jar.files[k] = empty_jar
  end
end
update_archive(jar) click to toggle source
# File lib/warbler/traits/war.rb, line 76
def update_archive(jar)
  add_public_files(jar)
  add_webxml(jar)
  move_jars_to_webinf_lib(jar)
  add_executables(jar) if config.features.include?("executable")
  add_gemjar(jar) if config.features.include?("gemjar")
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.