Class: Warbler::Config

Inherits:
Object
  • Object
show all
Includes:
Traits
Defined in:
lib/warbler/config.rb

Overview

Warbler archive assembly configuration class.

Constant Summary collapse

TOP_DIRS =
%w(app config lib log vendor)
FILE =
"config/warble.rb"
BUILD_GEMS =
%w(warbler rake rcov)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Traits

#after_configure, #auto_detect_traits, #before_configure, #dump_traits, #trait_objects, #update_archive

Constructor Details

#initialize(warbler_home = WARBLER_HOME) {|_self| ... } ⇒ Config

Returns a new instance of Config.

Yields:

  • (_self)

Yield Parameters:



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/warbler/config.rb', line 146

def initialize(warbler_home = WARBLER_HOME)
  super()

  @warbler_home      = warbler_home
  @warbler_templates = "#{WARBLER_HOME}/lib/warbler/templates"
  @features          = Set.new
  @dirs              = TOP_DIRS.select {|d| File.directory?(d)}
  @includes          = FileList[]
  @excludes          = FileList[]
  @java_libs         = FileList[]
  @java_classes      = FileList[]
  @gems              = Warbler::Gems.new
  @gem_dependencies  = true
  @gem_excludes      = []
  @exclude_logs      = true
  @public_html       = FileList[]
  @jar_name          = File.basename(Dir.getwd)
  @jar_extension     = 'jar'
  @webinf_files      = FileList[]
  @init_filename     = 'META-INF/init.rb'
  @init_contents     = ["#{@warbler_templates}/config.erb"]

  before_configure
  yield self if block_given?
  after_configure

  @compiled_ruby_files ||= FileList[*@dirs.map {|d| "#{d}/**/*.rb"}]

  @excludes += ["tmp/war"] if File.directory?("tmp/war")
  @excludes += warbler_vendor_excludes(warbler_home)
  @excludes += FileList["**/*.log"] if @exclude_logs
end

Instance Attribute Details

#autodeploy_dirObject

Directory where the war file will be written. Can be used to direct Warbler to place your war file directly in your application server’s autodeploy directory. Defaults to the root of the application directory.



39
40
41
# File 'lib/warbler/config.rb', line 39

def autodeploy_dir
  @autodeploy_dir
end

#bundle_withoutObject

An array of Bundler groups to avoid including in the war file. Defaults to [“development”, “test”].



98
99
100
# File 'lib/warbler/config.rb', line 98

def bundle_without
  @bundle_without
end

#bundlerObject

Use Bundler to locate gems if Gemfile is found. Default is true.



94
95
96
# File 'lib/warbler/config.rb', line 94

def bundler
  @bundler
end

#compiled_ruby_filesObject

List of ruby files to compile to class files. Default is to compile all .rb files in the application.



106
107
108
# File 'lib/warbler/config.rb', line 106

def compiled_ruby_files
  @compiled_ruby_files
end

#dirsObject

Top-level directories to be copied into WEB-INF. Defaults to names in TOP_DIRS



43
44
45
# File 'lib/warbler/config.rb', line 43

def dirs
  @dirs
end

#exclude_logsObject

Whether to exclude */.log files (default is true)



69
70
71
# File 'lib/warbler/config.rb', line 69

def exclude_logs
  @exclude_logs
end

#excludesObject

Files to exclude from the WEB-INF directory



50
51
52
# File 'lib/warbler/config.rb', line 50

def excludes
  @excludes
end

#featuresObject

Features: additional options controlling how the jar is built. Currently the following features are supported:

  • gemjar: package the gem repository in a jar file in WEB-INF/lib

  • executable: embed a web server and make the war executable

  • compiled: compile .rb files to .class files



26
27
28
# File 'lib/warbler/config.rb', line 26

def features
  @features
end

#gem_dependenciesObject

Whether to include dependent gems (default true)



62
63
64
# File 'lib/warbler/config.rb', line 62

def gem_dependencies
  @gem_dependencies
end

#gem_excludesObject

Array of regular expressions matching relative paths in gems to be excluded from the war. Default contains no exclusions.



66
67
68
# File 'lib/warbler/config.rb', line 66

def gem_excludes
  @gem_excludes
end

#gem_pathObject

Path to the pre-bundled gem directory inside the war file. Default is ‘/WEB-INF/gems’. This also sets ‘gem.path’ inside web.xml.



102
103
104
# File 'lib/warbler/config.rb', line 102

def gem_path
  @gem_path
end

#gemsObject

Rubygems to install into the webapp.



59
60
61
# File 'lib/warbler/config.rb', line 59

def gems
  @gems
end

#includesObject

Additional files beyond the top-level directories to include in the WEB-INF directory



47
48
49
# File 'lib/warbler/config.rb', line 47

def includes
  @includes
end

#init_contentsObject

Array containing filenames or StringIO’s to be concatenated together to form the init file. If the filename ends in .erb the file will be expanded the same way web.xml.erb is; see below.



114
115
116
# File 'lib/warbler/config.rb', line 114

def init_contents
  @init_contents
end

#init_filenameObject

Warbler writes an “init” file into the war at this location. JRuby-Rack and possibly other launchers may use this to initialize the Ruby environment.



110
111
112
# File 'lib/warbler/config.rb', line 110

def init_filename
  @init_filename
end

#jar_extensionObject

Extension of jar file. Defaults to jar or war depending on the project.



84
85
86
# File 'lib/warbler/config.rb', line 84

def jar_extension
  @jar_extension
end

#jar_nameObject

Name of jar or war file (without the extension), defaults to the directory name containing the application.



81
82
83
# File 'lib/warbler/config.rb', line 81

def jar_name
  @jar_name
end

#java_classesObject

Java classes and other files to copy to WEB-INF/classes



53
54
55
# File 'lib/warbler/config.rb', line 53

def java_classes
  @java_classes
end

#java_libsObject

Java libraries to copy to WEB-INF/lib



56
57
58
# File 'lib/warbler/config.rb', line 56

def java_libs
  @java_libs
end

#manifest_fileObject

Name of a MANIFEST.MF template to use.



87
88
89
# File 'lib/warbler/config.rb', line 87

def manifest_file
  @manifest_file
end

#pathmapsObject

Container of pathmaps used for specifying source-to-destination transformations under various situations (public_html and java_classes are two entries in this structure).



77
78
79
# File 'lib/warbler/config.rb', line 77

def pathmaps
  @pathmaps
end

#public_htmlObject

Public HTML directory file list, to be copied into the root of the war



72
73
74
# File 'lib/warbler/config.rb', line 72

def public_html
  @public_html
end

#staging_dirObject

Deprecated: No longer has any effect.



34
35
36
# File 'lib/warbler/config.rb', line 34

def staging_dir
  @staging_dir
end

#traitsObject

Traits: an array of trait classes corresponding to characteristics of the project that are either auto-detected or configured.



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

def traits
  @traits
end

#warbler_templatesObject (readonly)

Returns the value of attribute warbler_templates.



144
145
146
# File 'lib/warbler/config.rb', line 144

def warbler_templates
  @warbler_templates
end

#webinf_filesObject

Files for WEB-INF directory (next to web.xml). Contains web.xml by default. If there are .erb files they will be processed with webxml config.



91
92
93
# File 'lib/warbler/config.rb', line 91

def webinf_files
  @webinf_files
end

#webxmlObject

Extra configuration for web.xml. Controls how the dynamically-generated web.xml file is generated.

  • webxml.jndi – the name of one or more JNDI data sources name to be available to the application. Places appropriate <resource-ref> entries in the file.

  • webxml.ignored – array of key names that will be not used to generate a context param. Defaults to [‘jndi’, ‘booter’]

Any other key/value pair placed in the open structure will be dumped as a context parameter in the web.xml file. Some of the recognized values are:

  • webxml.rails.env – the Rails environment to use for the running application, usually either development or production (the default).

  • webxml.gem.path – the path to your bundled gem directory

  • webxml.jruby.min.runtimes – minimum number of pooled runtimes to keep around during idle time

  • webxml.jruby.max.runtimes – maximum number of pooled Rails application runtimes

Note that if you attempt to access webxml configuration keys in a conditional, you might not obtain the result you want. For example:

<%= webxml.maybe.present.key || 'default' %>

doesn’t yield the right result. Instead, you need to generate the context parameters:

<%= webxml.context_params['maybe.present.key'] || 'default' %>


142
143
144
# File 'lib/warbler/config.rb', line 142

def webxml
  @webxml
end

Instance Method Details

#define_tasksObject



187
188
189
190
191
192
193
194
# File 'lib/warbler/config.rb', line 187

def define_tasks
  task "gemjar" do
    self.features << "gemjar"
  end
  task "executable" do
    self.features << "executable"
  end
end

#dumpObject



218
219
220
# File 'lib/warbler/config.rb', line 218

def dump
  YAML::dump(self.dup.tap{|c| c.dump_traits })
end

#relative_gem_pathObject



183
184
185
# File 'lib/warbler/config.rb', line 183

def relative_gem_path
  @gem_path[1..-1]
end

#war_nameObject

Deprecated



197
198
199
200
# File 'lib/warbler/config.rb', line 197

def war_name
  $stderr.puts "config.war_name deprecated; replace with config.jar_name" #:nocov:
  jar_name                  #:nocov:
end

#war_name=(w) ⇒ Object

Deprecated



203
204
205
206
# File 'lib/warbler/config.rb', line 203

def war_name=(w)
  $stderr.puts "config.war_name deprecated; replace with config.jar_name" #:nocov:
  self.jar_name = w         #:nocov:
end