Class: Warbler::Traits::Jar

Inherits:
Object
  • Object
show all
Includes:
Warbler::Trait
Defined in:
lib/warbler/traits/jar.rb

Overview

The Jar trait sets up the archive layout for an executable jar project, and adds the JRuby jar files and a JarMain class to the archive.

Instance Attribute Summary

Attributes included from Warbler::Trait

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Warbler::Trait

#add_init_load_path, #add_main_rb, included, #initialize, #update_gem_path

Class Method Details

.detect?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/warbler/traits/jar.rb', line 19

def self.detect?
  !War.detect?
end

Instance Method Details

#after_configureObject



31
32
33
# File 'lib/warbler/traits/jar.rb', line 31

def after_configure
  config.init_contents << StringIO.new("require 'rubygems'\n")
end

#before_configureObject



23
24
25
26
27
28
29
# File 'lib/warbler/traits/jar.rb', line 23

def before_configure
  config.gem_path      = '/'
  config.pathmaps      = default_pathmaps
  config.java_libs     = default_jar_files
  config.manifest_file = 'MANIFEST.MF' if File.exist?('MANIFEST.MF')
  config.init_contents << "#{config.warbler_templates}/jar.erb"
end

#default_jar_filesObject



50
51
52
53
# File 'lib/warbler/traits/jar.rb', line 50

def default_jar_files
  require 'jruby-jars'
  FileList[JRubyJars.core_jar_path, JRubyJars.stdlib_jar_path]
end

#default_pathmapsObject



40
41
42
43
44
45
46
47
48
# File 'lib/warbler/traits/jar.rb', line 40

def default_pathmaps
  p = OpenStruct.new
  p.java_libs    = ["META-INF/lib/%f"]
  p.java_classes = ["%p"]
  p.application  = ["#{config.jar_name}/%p"]
  p.gemspecs     = ["specifications/%f"]
  p.gems         = ["gems/%p"]
  p
end

#update_archive(jar) ⇒ Object



35
36
37
38
# File 'lib/warbler/traits/jar.rb', line 35

def update_archive(jar)
  jar.files['META-INF/MANIFEST.MF'] = StringIO.new(Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: JarMain\n") unless config.manifest_file
  jar.files['JarMain.class'] = jar.entry_in_jar("#{WARBLER_HOME}/lib/warbler_jar.jar", "JarMain.class")
end