Class: Warbler::Config
- Inherits:
-
Object
- Object
- Warbler::Config
- Includes:
- RakeHelper, Traits
- Defined in:
- lib/warbler/config.rb
Overview
Warbler archive assembly configuration class.
Constant Summary collapse
- TOP_DIRS =
%w(app db config lib log script vendor)
- CONFIG_DIR =
"config"- FILE =
"#{CONFIG_DIR}/warble.rb"
Instance Attribute Summary collapse
-
#autodeploy_dir ⇒ Object
Directory where the war file will be written.
-
#bundle_without ⇒ Object
An array of Bundler groups to avoid including in the war file.
-
#bundler ⇒ Object
Use Bundler to locate gems if Gemfile is found.
-
#bytecode_version ⇒ Object
Explicit bytecode version for compiled ruby files.
-
#compile_gems ⇒ Object
Determines if ruby files in supporting gems will be compiled.
-
#compiled_ruby_files ⇒ Object
List of ruby files to compile to class files.
-
#dirs ⇒ Object
Top-level directories to be copied into WEB-INF.
-
#exclude_logs ⇒ Object
Whether to exclude **/*.log files (default is true).
-
#excludes ⇒ Object
Files to exclude from the WEB-INF directory.
-
#executable ⇒ Object
Executable of the jar.
-
#executable_params ⇒ Object
parameters to pass to the executable.
-
#features ⇒ Object
Features: additional options controlling how the jar is built.
-
#gem_dependencies ⇒ Object
Whether to include dependent gems (default true).
-
#gem_excludes ⇒ Object
Array of regular expressions matching paths inside packed gems to be excluded from the archive.
-
#gem_path ⇒ Object
Path to the pre-bundled gem directory inside the war file.
-
#gems ⇒ Object
Rubygems to install into the webapp.
-
#includes ⇒ Object
Additional files beyond the top-level directories to include in the WEB-INF directory.
-
#init_contents ⇒ Object
Array containing filenames or StringIO's to be concatenated together to form the init file.
-
#init_filename ⇒ Object
Warbler writes an "init" file into the war at this location.
-
#jar_extension ⇒ Object
Extension of jar file.
-
#jar_name ⇒ Object
(also: #war_name)
Name of jar or war file (without the extension), defaults to the directory name containing the application.
-
#java_classes ⇒ Object
Java classes and other files to copy to WEB-INF/classes.
-
#java_libs ⇒ Object
Java libraries to copy to WEB-INF/lib.
-
#jbundler ⇒ Object
Use JBundler to locate gems if Jarfile is found.
-
#jrubyc_options ⇒ Object
Desired options passed to JRuby compiler if compiling to class files.
-
#manifest_file ⇒ Object
Name of a MANIFEST.MF template to use.
-
#move_jars_to_webinf_lib ⇒ Object
If set to true, Warbler will move jar files into the WEB-INF/lib directory of the created war file.
-
#override_gem_home ⇒ Object
Override GEM_HOME environment variable at runtime.
-
#pathmaps ⇒ Object
Container of pathmaps used for specifying source-to-destination transformations under various situations (public_html and java_classes are two entries in this structure).
-
#public_html ⇒ Object
Public HTML directory file list, to be copied into the root of the war.
-
#script_files ⇒ Object
These file will be placed in the META-INF directory of the jar or war that warbler produces.
-
#traits ⇒ Object
readonly
Traits: an array of trait classes corresponding to characteristics of the project that are either auto-detected or forced enabled during
Config.new(forced_traits: [...]) do |config|. -
#warbler_scripts ⇒ Object
readonly
Returns the value of attribute warbler_scripts.
-
#warbler_templates ⇒ Object
readonly
Returns the value of attribute warbler_templates.
-
#webinf_files ⇒ Object
Files for WEB-INF directory (next to web.xml).
-
#webserver ⇒ Object
Embedded webserver to use.
-
#webxml ⇒ Object
Extra configuration for web.xml.
Instance Method Summary collapse
- #define_tasks ⇒ Object
- #dump ⇒ Object
-
#initialize(warbler_home = WARBLER_HOME, forced_traits: nil) {|_self| ... } ⇒ Config
constructor
A new instance of Config.
- #relative_gem_path ⇒ Object
Methods included from Traits
#after_configure, #auto_detect_traits, #before_configure, #dump_traits, #trait_objects, #update_archive
Methods included from RakeHelper
Constructor Details
#initialize(warbler_home = WARBLER_HOME, forced_traits: nil) {|_self| ... } ⇒ Config
Returns a new instance of Config.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/warbler/config.rb', line 188 def initialize(warbler_home = WARBLER_HOME, forced_traits: nil) super(forced_traits) @warbler_home = warbler_home @warbler_templates = "#{WARBLER_HOME}/lib/warbler/templates" @features = Set.new @dirs = TOP_DIRS.select {|d| File.directory?(d)} @includes = FileList['*file'] # [r/R]akefile gets included @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"] @override_gem_home = true @script_files = [] @warbler_scripts = "#{WARBLER_HOME}/lib/warbler/scripts" @move_jars_to_webinf_lib = false @compile_gems = false before_configure yield self if block_given? after_configure @compiled_ruby_files ||= FileList[*@dirs.map {|d| "#{d}/**/*.rb"}] @excludes += ["tmp/war", "tmp/war/**/*"] if File.directory?("tmp/war") @excludes += ["tmp/cache/**/*"] if File.directory?("tmp/cache") @excludes += warbler_vendor_excludes(warbler_home) @excludes += FileList["**/*.log"] if @exclude_logs end |
Instance Attribute Details
#autodeploy_dir ⇒ Object
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.
38 39 40 |
# File 'lib/warbler/config.rb', line 38 def autodeploy_dir @autodeploy_dir end |
#bundle_without ⇒ Object
An array of Bundler groups to avoid including in the war file. Defaults to ["development", "test", "assets"].
105 106 107 |
# File 'lib/warbler/config.rb', line 105 def bundle_without @bundle_without end |
#bundler ⇒ Object
Use Bundler to locate gems if Gemfile is found. Default is true.
101 102 103 |
# File 'lib/warbler/config.rb', line 101 def bundler @bundler end |
#bytecode_version ⇒ Object
Explicit bytecode version for compiled ruby files. If given bytecode version is specified when ruby files are compiled using jrubyc
142 143 144 |
# File 'lib/warbler/config.rb', line 142 def bytecode_version @bytecode_version end |
#compile_gems ⇒ Object
Determines if ruby files in supporting gems will be compiled. Ignored unless compile feature is used.
120 121 122 |
# File 'lib/warbler/config.rb', line 120 def compile_gems @compile_gems end |
#compiled_ruby_files ⇒ Object
List of ruby files to compile to class files. Default is to compile all .rb files in the application.
116 117 118 |
# File 'lib/warbler/config.rb', line 116 def compiled_ruby_files @compiled_ruby_files end |
#dirs ⇒ Object
Top-level directories to be copied into WEB-INF. Defaults to names in TOP_DIRS
42 43 44 |
# File 'lib/warbler/config.rb', line 42 def dirs @dirs end |
#exclude_logs ⇒ Object
Whether to exclude **/*.log files (default is true)
70 71 72 |
# File 'lib/warbler/config.rb', line 70 def exclude_logs @exclude_logs end |
#excludes ⇒ Object
Files to exclude from the WEB-INF directory
49 50 51 |
# File 'lib/warbler/config.rb', line 49 def excludes @excludes end |
#executable ⇒ Object
Executable of the jar
81 82 83 |
# File 'lib/warbler/config.rb', line 81 def executable @executable end |
#executable_params ⇒ Object
parameters to pass to the executable
84 85 86 |
# File 'lib/warbler/config.rb', line 84 def executable_params @executable_params end |
#features ⇒ Object
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
28 29 30 |
# File 'lib/warbler/config.rb', line 28 def features @features end |
#gem_dependencies ⇒ Object
Whether to include dependent gems (default true)
61 62 63 |
# File 'lib/warbler/config.rb', line 61 def gem_dependencies @gem_dependencies end |
#gem_excludes ⇒ Object
Array of regular expressions matching paths inside packed gems to be excluded from the archive. Paths are matched relative to each gem's root (for git-sourced gems: the repository checkout root). Default contains no exclusions.
67 68 69 |
# File 'lib/warbler/config.rb', line 67 def gem_excludes @gem_excludes end |
#gem_path ⇒ Object
Path to the pre-bundled gem directory inside the war file. Default is '/WEB-INF/gems'. This also sets 'gem.path' inside web.xml.
112 113 114 |
# File 'lib/warbler/config.rb', line 112 def gem_path @gem_path end |
#gems ⇒ Object
Rubygems to install into the webapp.
58 59 60 |
# File 'lib/warbler/config.rb', line 58 def gems @gems end |
#includes ⇒ Object
Additional files beyond the top-level directories to include in the WEB-INF directory
46 47 48 |
# File 'lib/warbler/config.rb', line 46 def includes @includes end |
#init_contents ⇒ Object
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.
132 133 134 |
# File 'lib/warbler/config.rb', line 132 def init_contents @init_contents end |
#init_filename ⇒ Object
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.
128 129 130 |
# File 'lib/warbler/config.rb', line 128 def init_filename @init_filename end |
#jar_extension ⇒ Object
Extension of jar file. Defaults to jar or war depending on the project.
91 92 93 |
# File 'lib/warbler/config.rb', line 91 def jar_extension @jar_extension end |
#jar_name ⇒ Object Also known as: war_name
Name of jar or war file (without the extension), defaults to the directory name containing the application.
88 89 90 |
# File 'lib/warbler/config.rb', line 88 def jar_name @jar_name end |
#java_classes ⇒ Object
Java classes and other files to copy to WEB-INF/classes
52 53 54 |
# File 'lib/warbler/config.rb', line 52 def java_classes @java_classes end |
#java_libs ⇒ Object
Java libraries to copy to WEB-INF/lib
55 56 57 |
# File 'lib/warbler/config.rb', line 55 def java_libs @java_libs end |
#jbundler ⇒ Object
Use JBundler to locate gems if Jarfile is found. Default is true.
108 109 110 |
# File 'lib/warbler/config.rb', line 108 def jbundler @jbundler end |
#jrubyc_options ⇒ Object
Desired options passed to JRuby compiler if compiling to class files. Ignored unless compile feature is used.
124 125 126 |
# File 'lib/warbler/config.rb', line 124 def @jrubyc_options end |
#manifest_file ⇒ Object
Name of a MANIFEST.MF template to use.
94 95 96 |
# File 'lib/warbler/config.rb', line 94 def manifest_file @manifest_file end |
#move_jars_to_webinf_lib ⇒ Object
If set to true, Warbler will move jar files into the WEB-INF/lib directory of the created war file. This may be needed for some web servers. Defaults to false.
178 179 180 |
# File 'lib/warbler/config.rb', line 178 def move_jars_to_webinf_lib @move_jars_to_webinf_lib end |
#override_gem_home ⇒ Object
Override GEM_HOME environment variable at runtime. When false, gems in GEM_HOME will be loaded in preference to those packaged within the jar file. When true, only gems packaged in the jar file will be loaded. Defaults to true
138 139 140 |
# File 'lib/warbler/config.rb', line 138 def override_gem_home @override_gem_home end |
#pathmaps ⇒ Object
Container of pathmaps used for specifying source-to-destination transformations under various situations (public_html and java_classes are two entries in this structure).
78 79 80 |
# File 'lib/warbler/config.rb', line 78 def pathmaps @pathmaps end |
#public_html ⇒ Object
Public HTML directory file list, to be copied into the root of the war
73 74 75 |
# File 'lib/warbler/config.rb', line 73 def public_html @public_html end |
#script_files ⇒ Object
These file will be placed in the META-INF directory of the jar or war that warbler produces. They are primarily used as launchers by the runnable feature.
182 183 184 |
# File 'lib/warbler/config.rb', line 182 def script_files @script_files end |
#traits ⇒ Object (readonly)
Traits: an array of trait classes corresponding to
characteristics of the project that are either auto-detected or
forced enabled during Config.new(forced_traits: [...]) do |config|
33 34 35 |
# File 'lib/warbler/config.rb', line 33 def traits @traits end |
#warbler_scripts ⇒ Object (readonly)
Returns the value of attribute warbler_scripts.
185 186 187 |
# File 'lib/warbler/config.rb', line 185 def warbler_scripts @warbler_scripts end |
#warbler_templates ⇒ Object (readonly)
Returns the value of attribute warbler_templates.
184 185 186 |
# File 'lib/warbler/config.rb', line 184 def warbler_templates @warbler_templates end |
#webinf_files ⇒ Object
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.
98 99 100 |
# File 'lib/warbler/config.rb', line 98 def webinf_files @webinf_files end |
#webserver ⇒ Object
Embedded webserver to use. Currently supported webservers are:
- jetty - Embedded Jetty from Eclipse
174 175 176 |
# File 'lib/warbler/config.rb', line 174 def webserver @webserver end |
#webxml ⇒ Object
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 || 'default' %>
170 171 172 |
# File 'lib/warbler/config.rb', line 170 def webxml @webxml end |
Instance Method Details
#define_tasks ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/warbler/config.rb', line 235 def define_tasks task "gemjar" do self.features << "gemjar" end task "executable" do self.features << "executable" end task "runnable" do self.features << "runnable" end end |
#dump ⇒ Object
260 261 262 |
# File 'lib/warbler/config.rb', line 260 def dump YAML::dump(self.dup.tap{|c| c.dump_traits }) end |
#relative_gem_path ⇒ Object
231 232 233 |
# File 'lib/warbler/config.rb', line 231 def relative_gem_path @gem_path[1..-1] end |