forked from jruby/warbler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.rb
225 lines (182 loc) · 7.65 KB
/
config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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
178
179
180
181
182
183
184
185
186
187
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
#--
# Copyright (c) 2010-2011 Engine Yard, Inc.
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
# This source code is available under the MIT license.
# See the file LICENSE.txt for details.
#++
require 'set'
require 'warbler/gems'
require 'warbler/traits'
module Warbler
# Warbler archive assembly configuration class.
class Config
include RakeHelper
TOP_DIRS = %w(app config lib log vendor)
FILE = "config/warble.rb"
BUILD_GEMS = %w(warbler rake rcov)
include Traits
# 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
attr_accessor :features
# Traits: an array of trait classes corresponding to
# characteristics of the project that are either auto-detected or
# configured.
attr_accessor :traits
# Deprecated: No longer has any effect.
attr_accessor :staging_dir
# 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.
attr_accessor :autodeploy_dir
# Top-level directories to be copied into WEB-INF. Defaults to
# names in TOP_DIRS
attr_accessor :dirs
# Additional files beyond the top-level directories to include in the
# WEB-INF directory
attr_accessor :includes
# Files to exclude from the WEB-INF directory
attr_accessor :excludes
# Java classes and other files to copy to WEB-INF/classes
attr_accessor :java_classes
# Java libraries to copy to WEB-INF/lib
attr_accessor :java_libs
# Rubygems to install into the webapp.
attr_accessor :gems
# Whether to include dependent gems (default true)
attr_accessor :gem_dependencies
# Array of regular expressions matching relative paths in gems to
# be excluded from the war. Default contains no exclusions.
attr_accessor :gem_excludes
# Whether to exclude **/*.log files (default is true)
attr_accessor :exclude_logs
# Public HTML directory file list, to be copied into the root of the war
attr_accessor :public_html
# Container of pathmaps used for specifying source-to-destination transformations
# under various situations (<tt>public_html</tt> and <tt>java_classes</tt> are two
# entries in this structure).
attr_accessor :pathmaps
# Name of jar or war file (without the extension), defaults to the
# directory name containing the application.
attr_accessor :jar_name
# Extension of jar file. Defaults to <tt>jar</tt> or <tt>war</tt> depending on the project.
attr_accessor :jar_extension
# Name of a MANIFEST.MF template to use.
attr_accessor :manifest_file
# 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.
attr_accessor :webinf_files
# Use Bundler to locate gems if Gemfile is found. Default is true.
attr_accessor :bundler
# An array of Bundler groups to avoid including in the war file.
# Defaults to ["development", "test"].
attr_accessor :bundle_without
# Path to the pre-bundled gem directory inside the war file. Default is '/WEB-INF/gems'.
# This also sets 'gem.path' inside web.xml.
attr_accessor :gem_path
# List of ruby files to compile to class files. Default is to
# compile all .rb files in the application.
attr_accessor :compiled_ruby_files
# 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.
attr_accessor :init_filename
# 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.
attr_accessor :init_contents
# Extra configuration for web.xml. Controls how the dynamically-generated web.xml
# file is generated.
#
# * <tt>webxml.jndi</tt> -- the name of one or more JNDI data sources name to be
# available to the application. Places appropriate <resource-ref> entries
# in the file.
# * <tt>webxml.ignored</tt> -- 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:
#
# * <tt>webxml.rails.env</tt> -- the Rails environment to use for the
# running application, usually either development or production (the
# default).
# * <tt>webxml.gem.path</tt> -- the path to your bundled gem directory
# * <tt>webxml.jruby.min.runtimes</tt> -- minimum number of pooled runtimes to
# keep around during idle time
# * <tt>webxml.jruby.max.runtimes</tt> -- 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' %>
attr_accessor :webxml
attr_reader :warbler_templates
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", "tmp/war/**/*"] if File.directory?("tmp/war")
@excludes += warbler_vendor_excludes(warbler_home)
@excludes += FileList["**/*.log"] if @exclude_logs
end
def gems=(value)
@gems = Warbler::Gems.new(value)
end
def relative_gem_path
@gem_path[1..-1]
end
def define_tasks
task "gemjar" do
self.features << "gemjar"
end
task "executable" do
self.features << "executable"
end
end
# Deprecated
def war_name
$stderr.puts "config.war_name deprecated; replace with config.jar_name" #:nocov:
jar_name #:nocov:
end
# Deprecated
def war_name=(w)
$stderr.puts "config.war_name deprecated; replace with config.jar_name" #:nocov:
self.jar_name = w #:nocov:
end
private
def warbler_vendor_excludes(warbler_home)
warbler = File.expand_path(warbler_home)
if warbler =~ %r{^#{Dir.getwd}/(.*)}
FileList["#{$1}"]
else
[]
end
end
def dump
YAML::dump(self.dup.tap{|c| c.dump_traits })
end
public :dump
end
end