warbler_updated 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +10 -0
- data/History.txt +411 -0
- data/LICENSE.txt +27 -0
- data/Mavenfile +32 -0
- data/README.rdoc +280 -0
- data/Rakefile +63 -0
- data/bin/warble +11 -0
- data/ext/JarMain.java +334 -0
- data/ext/WarMain.java +375 -0
- data/ext/WarblerJar.java +199 -0
- data/ext/WarblerJarService.java +18 -0
- data/lib/warbler/application.rb +104 -0
- data/lib/warbler/bundler_helper.rb +22 -0
- data/lib/warbler/config.rb +265 -0
- data/lib/warbler/executable_helper.rb +25 -0
- data/lib/warbler/gems.rb +77 -0
- data/lib/warbler/jar.rb +348 -0
- data/lib/warbler/pathmap_helper.rb +20 -0
- data/lib/warbler/platform_helper.rb +26 -0
- data/lib/warbler/rake_helper.rb +30 -0
- data/lib/warbler/scripts/rails.rb +5 -0
- data/lib/warbler/task.rb +185 -0
- data/lib/warbler/templates/bundler.erb +19 -0
- data/lib/warbler/templates/config.erb +1 -0
- data/lib/warbler/templates/jar.erb +11 -0
- data/lib/warbler/templates/jbundler.erb +2 -0
- data/lib/warbler/templates/rack.erb +5 -0
- data/lib/warbler/templates/rails.erb +1 -0
- data/lib/warbler/templates/war.erb +19 -0
- data/lib/warbler/traits/bundler.rb +157 -0
- data/lib/warbler/traits/gemspec.rb +79 -0
- data/lib/warbler/traits/jar.rb +58 -0
- data/lib/warbler/traits/jbundler.rb +48 -0
- data/lib/warbler/traits/nogemspec.rb +47 -0
- data/lib/warbler/traits/rack.rb +33 -0
- data/lib/warbler/traits/rails.rb +91 -0
- data/lib/warbler/traits/war.rb +260 -0
- data/lib/warbler/traits.rb +124 -0
- data/lib/warbler/version.rb +10 -0
- data/lib/warbler/war.rb +8 -0
- data/lib/warbler/web_server.rb +125 -0
- data/lib/warbler/zip_support.rb +13 -0
- data/lib/warbler.rb +40 -0
- data/lib/warbler_jar.jar +0 -0
- data/warble.rb +188 -0
- data/warbler.gemspec +37 -0
- data/web.xml.erb +57 -0
- metadata +188 -0
data/lib/warbler/jar.rb
ADDED
@@ -0,0 +1,348 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2012 Engine Yard, Inc.
|
3
|
+
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
|
4
|
+
# This source code is available under the MIT license.
|
5
|
+
# See the file LICENSE.txt for details.
|
6
|
+
#++
|
7
|
+
|
8
|
+
require 'warbler/zip_support'
|
9
|
+
require 'stringio'
|
10
|
+
require 'pathname'
|
11
|
+
|
12
|
+
module Warbler
|
13
|
+
# Class that holds the files that will be stored in the jar file.
|
14
|
+
# The #files attribute contains a hash of pathnames inside the jar
|
15
|
+
# file to their contents. Contents can be one of:
|
16
|
+
# * +nil+ representing a directory entry
|
17
|
+
# * Any object responding to +read+ representing an in-memory blob
|
18
|
+
# * A String filename pointing to a file on disk
|
19
|
+
class Jar
|
20
|
+
include PathmapHelper
|
21
|
+
include RakeHelper
|
22
|
+
include PlatformHelper
|
23
|
+
|
24
|
+
DEFAULT_MANIFEST = %{Manifest-Version: 1.0\nCreated-By: Warbler #{Warbler::VERSION}\n\n}
|
25
|
+
|
26
|
+
attr_reader :files
|
27
|
+
attr_reader :app_filelist
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@files = {}
|
31
|
+
end
|
32
|
+
|
33
|
+
def contents(entry)
|
34
|
+
file = files[entry]
|
35
|
+
file.respond_to?(:read) ? file.read : File.read(file)
|
36
|
+
end
|
37
|
+
|
38
|
+
def compile(config)
|
39
|
+
find_gems_files(config)
|
40
|
+
# Compiling all Ruby files we can find -- do we need to allow an
|
41
|
+
# option to configure what gets compiled?
|
42
|
+
return if (config.compiled_ruby_files.nil? || config.compiled_ruby_files.empty?) && files.empty?
|
43
|
+
|
44
|
+
if config.compile_gems
|
45
|
+
ruby_files = gather_all_rb_files(config)
|
46
|
+
run_jrubyc(config, ruby_files.values)
|
47
|
+
replace_compiled_ruby_files_and_gems(config, ruby_files)
|
48
|
+
else
|
49
|
+
compiled_ruby_files = config.compiled_ruby_files - config.excludes.to_a
|
50
|
+
run_jrubyc(config, compiled_ruby_files)
|
51
|
+
replace_compiled_ruby_files(config, compiled_ruby_files)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
DEFAULT_COMPILED_FILES_SLICE = 2500
|
56
|
+
|
57
|
+
def run_jrubyc(config, compiled_ruby_files)
|
58
|
+
slice_size = (ENV['WARBLER_COMPILED_FILES_SLICE'] || 0).to_i
|
59
|
+
slice_size = DEFAULT_COMPILED_FILES_SLICE if slice_size <= 0
|
60
|
+
compiled_ruby_files.each_slice(slice_size) do |files|
|
61
|
+
files = "\"#{files.join('" "')}\""
|
62
|
+
classpath = config.java_libs.map { |lib| "\"#{lib.gsub('"', '\\"')}\"" }.join(File::PATH_SEPARATOR)
|
63
|
+
# Need to use the version of JRuby in the application to compile it
|
64
|
+
javac_cmd = %Q{java -classpath #{classpath} #{java_version(config)} org.jruby.Main -S jrubyc #{jrubyc_options(config)} #{files}}
|
65
|
+
if which('java').nil? && which('env')
|
66
|
+
sh_jrubyc %Q{env -i #{javac_cmd}}
|
67
|
+
else
|
68
|
+
sh_jrubyc javac_cmd
|
69
|
+
end
|
70
|
+
end
|
71
|
+
@compiled = true
|
72
|
+
end
|
73
|
+
# @deprecated only due compatibility
|
74
|
+
alias_method :run_javac, :run_jrubyc
|
75
|
+
|
76
|
+
def sh_jrubyc(cmd)
|
77
|
+
sh(cmd) do |ok, res|
|
78
|
+
raise "Compilation of .rb files failed (#{res})" unless ok
|
79
|
+
end
|
80
|
+
end
|
81
|
+
private :sh_jrubyc
|
82
|
+
|
83
|
+
def jrubyc_options(config)
|
84
|
+
options = ENV['WARBLER_JRUBYC_OPTIONS'] || config.jrubyc_options
|
85
|
+
options = options.join(' ') if options.is_a?(Array)
|
86
|
+
options || ''
|
87
|
+
end
|
88
|
+
private :jrubyc_options
|
89
|
+
|
90
|
+
def java_version(config)
|
91
|
+
config.bytecode_version ? "-Djava.specification.version=#{config.bytecode_version}" : ''
|
92
|
+
end
|
93
|
+
|
94
|
+
def replace_compiled_ruby_files(config, compiled_ruby_files)
|
95
|
+
# Exclude the rb files and recreate them. This
|
96
|
+
# prevents the original contents being used.
|
97
|
+
config.excludes += compiled_ruby_files
|
98
|
+
|
99
|
+
compiled_ruby_files.each do |ruby_source|
|
100
|
+
files[apply_pathmaps(config, ruby_source, :application)] = StringIO.new("load __FILE__.sub(/\.rb$/, '.class')")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def replace_compiled_ruby_files_and_gems(config, compiled_ruby_files)
|
105
|
+
# Exclude the rb files and recreate them. This
|
106
|
+
# prevents the original contents being used.
|
107
|
+
config.excludes += compiled_ruby_files.keys
|
108
|
+
|
109
|
+
compiled_ruby_files.each do |inside_jar, file_system_location|
|
110
|
+
# The gems are already inside the gems folder inside the jar, however when using the :gems pathmap, they will
|
111
|
+
# get put into the gems/gems folder, to prevent this we chop off the first gems folder directory
|
112
|
+
inside_jar = inside_jar.dup
|
113
|
+
if inside_jar.split(File::SEPARATOR).first == 'gems'
|
114
|
+
inside_jar = inside_jar.split(File::SEPARATOR)[1..-1].join(File::SEPARATOR)
|
115
|
+
pathmap = :gems
|
116
|
+
else
|
117
|
+
pathmap = :application
|
118
|
+
end
|
119
|
+
files[apply_pathmaps(config, inside_jar, pathmap)] = StringIO.new("load __FILE__.sub(/\.rb$/, '.class')")
|
120
|
+
files[apply_pathmaps(config, inside_jar.sub(/\.rb$/, '.class'), pathmap)] = file_system_location.sub(/\.rb$/, '.class')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
def gather_all_rb_files(config)
|
126
|
+
FileUtils.mkdir_p('tmp')
|
127
|
+
# Gather all the files in the files list and copy them to the tmp directory
|
128
|
+
files_to_compile = files.select { |_, f| !f.is_a?(StringIO) && f.end_with?('.rb') }
|
129
|
+
files_to_compile.each do |jar_file, rb|
|
130
|
+
FileUtils.mkdir_p(File.dirname(File.join('tmp', jar_file)))
|
131
|
+
new_rb = File.join('tmp', jar_file)
|
132
|
+
FileUtils.copy(rb, new_rb)
|
133
|
+
files_to_compile[jar_file] = new_rb
|
134
|
+
end
|
135
|
+
# Gather all the application files which the user wrote (not dependencies)
|
136
|
+
main_files_to_compile = config.compiled_ruby_files - config.excludes.to_a
|
137
|
+
main_files_to_compile.each do |f|
|
138
|
+
FileUtils.mkdir_p(File.dirname(File.join('tmp', f)))
|
139
|
+
FileUtils.copy(f, File.join('tmp', f))
|
140
|
+
end
|
141
|
+
main_files_to_compile = main_files_to_compile.inject({}) {|h,f| h.merge!(f => f) }
|
142
|
+
files.keys.each do |k|
|
143
|
+
# Update files list to point to the temporary file
|
144
|
+
files[k] = files_to_compile[k] || main_files_to_compile[k] || files[k]
|
145
|
+
end
|
146
|
+
main_files_to_compile.merge(files_to_compile)
|
147
|
+
end
|
148
|
+
|
149
|
+
# Apply the information in a Warbler::Config object in order to
|
150
|
+
# look for files to put into this war file.
|
151
|
+
def apply(config)
|
152
|
+
find_application_files(config)
|
153
|
+
find_java_libs(config)
|
154
|
+
find_java_classes(config)
|
155
|
+
find_gems_files(config)
|
156
|
+
add_manifest(config)
|
157
|
+
add_init_file(config)
|
158
|
+
add_script_files(config)
|
159
|
+
apply_traits(config)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Create the jar or war file. The single argument can either be a
|
163
|
+
# Warbler::Config or a filename of the file to create.
|
164
|
+
def create(config_or_path)
|
165
|
+
path = config_or_path
|
166
|
+
if Warbler::Config === config_or_path
|
167
|
+
path = "#{config_or_path.jar_name}.#{config_or_path.jar_extension}"
|
168
|
+
path = File.join(config_or_path.autodeploy_dir, path) if config_or_path.autodeploy_dir
|
169
|
+
end
|
170
|
+
rm_f path
|
171
|
+
ensure_directory_entries
|
172
|
+
if Warbler::Config === config_or_path
|
173
|
+
@files.delete("#{config_or_path.jar_name}/#{path}")
|
174
|
+
end
|
175
|
+
puts "Creating #{path}" unless silent?
|
176
|
+
create_jar path, @files
|
177
|
+
end
|
178
|
+
|
179
|
+
# Invoke a hook to allow the project traits to add or modify the archive contents.
|
180
|
+
def apply_traits(config)
|
181
|
+
config.update_archive(self)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Add a manifest file either from config or by making a default manifest.
|
185
|
+
def add_manifest(config = nil)
|
186
|
+
unless @files.keys.detect{ |k| k =~ /^META-INF\/MANIFEST\.MF$/i }
|
187
|
+
if config && config.manifest_file
|
188
|
+
@files['META-INF/MANIFEST.MF'] = config.manifest_file
|
189
|
+
else
|
190
|
+
@files['META-INF/MANIFEST.MF'] = StringIO.new(DEFAULT_MANIFEST)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# Add java libraries to WEB-INF/lib.
|
196
|
+
def find_java_libs(config)
|
197
|
+
config.java_libs.map { |lib| add_with_pathmaps(config, lib, :java_libs) }
|
198
|
+
end
|
199
|
+
|
200
|
+
# Add java classes to WEB-INF/classes.
|
201
|
+
def find_java_classes(config)
|
202
|
+
config.java_classes.map { |f| add_with_pathmaps(config, f, :java_classes) }
|
203
|
+
end
|
204
|
+
|
205
|
+
# Add gems to WEB-INF/gems
|
206
|
+
def find_gems_files(config)
|
207
|
+
unless @compiled && config.compile_gems
|
208
|
+
config.gems.specs(config.gem_dependencies).each {|spec| find_single_gem_files(config, spec) }
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
# Add a single gem to WEB-INF/gems
|
213
|
+
def find_single_gem_files(config, spec)
|
214
|
+
full_gem_path = Pathname.new(spec.full_gem_path)
|
215
|
+
|
216
|
+
# skip gems whose full_gem_path does not exist
|
217
|
+
unless full_gem_path.exist?
|
218
|
+
# its very likely that its a default gem e.g. json/jruby-openssl :
|
219
|
+
if (Gem.default_dir rescue nil) && full_gem_path.to_s.start_with?(Gem.default_dir)
|
220
|
+
# OK if the gem does not exists as its un-packed on the "shared" path
|
221
|
+
# ... at least gem spec.spec_file should exists although not crucial
|
222
|
+
if JRUBY_VERSION != JRubyJars::VERSION
|
223
|
+
warn "skipping #{spec.name} default gem (assuming its part of jruby-jars #{JRubyJars::VERSION})" unless silent?
|
224
|
+
end
|
225
|
+
else
|
226
|
+
warn "skipping #{spec.name} gem (#{full_gem_path.to_s} does not exist)"
|
227
|
+
end
|
228
|
+
return
|
229
|
+
end
|
230
|
+
|
231
|
+
@files[apply_pathmaps(config, "#{spec.full_name}.gemspec", :gemspecs)] = StringIO.new(spec.to_ruby)
|
232
|
+
FileList["#{full_gem_path.to_s}/**/*"].each do |src|
|
233
|
+
f = Pathname.new(src).relative_path_from(full_gem_path).to_s
|
234
|
+
next if config.gem_excludes && config.gem_excludes.any? {|rx| f =~ rx }
|
235
|
+
@files[apply_pathmaps(config, File.join(spec.full_name, f), :gems)] = src
|
236
|
+
end
|
237
|
+
if File.exist?(spec.gem_build_complete_path)
|
238
|
+
base_dir = Pathname.new(spec.base_dir)
|
239
|
+
gem_build_complete_path = Pathname.new(spec.gem_build_complete_path)
|
240
|
+
@files[File.join(config.relative_gem_path, gem_build_complete_path.relative_path_from(base_dir))] = spec.gem_build_complete_path
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
# Add all application directories and files to the archive.
|
245
|
+
def find_application_files(config)
|
246
|
+
config.dirs.select do |d|
|
247
|
+
exists = File.directory?(d)
|
248
|
+
warn "application directory `#{d}' does not exist or is not a directory; skipping" unless exists
|
249
|
+
exists
|
250
|
+
end.each do |d|
|
251
|
+
@files[apply_pathmaps(config, d, :application)] = nil
|
252
|
+
end
|
253
|
+
@app_filelist = FileList[*(config.dirs.map{|d| %W{#{d}/**/*/**/* #{d}/*}}.flatten)]
|
254
|
+
@app_filelist.include( *(config.includes.to_a) )
|
255
|
+
@app_filelist.exclude( *(config.excludes.to_a) )
|
256
|
+
@app_filelist.map {|f| add_with_pathmaps(config, f, :application) }
|
257
|
+
end
|
258
|
+
|
259
|
+
# Add init.rb file to the war file.
|
260
|
+
def add_init_file(config)
|
261
|
+
if config.init_contents
|
262
|
+
contents = ''
|
263
|
+
config.init_contents.each do |file|
|
264
|
+
if file.respond_to?(:read)
|
265
|
+
contents << file.read
|
266
|
+
elsif File.extname(file) == '.erb'
|
267
|
+
contents << expand_erb(file, config).read
|
268
|
+
else
|
269
|
+
contents << File.read(file)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
@files[config.init_filename] = StringIO.new(contents)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
def add_script_files(config)
|
277
|
+
config.script_files.each do |file|
|
278
|
+
@files["META-INF/#{File.basename(file)}"] = StringIO.new(File.read(file))
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
def add_with_pathmaps(config, f, map_type)
|
283
|
+
@files[apply_pathmaps(config, f, map_type)] = f
|
284
|
+
end
|
285
|
+
|
286
|
+
def expand_erb(file, config)
|
287
|
+
require 'erb'
|
288
|
+
erb = ERB.new(File.read(file), nil, '-')
|
289
|
+
StringIO.new(erb.result(erb_binding(config)))
|
290
|
+
end
|
291
|
+
|
292
|
+
def erb_binding(config)
|
293
|
+
webxml = config.webxml
|
294
|
+
binding
|
295
|
+
end
|
296
|
+
|
297
|
+
def ensure_directory_entries
|
298
|
+
files.select {|k,v| !v.nil? }.each do |k,v|
|
299
|
+
dir = File.dirname(k)
|
300
|
+
while dir != "." && !files.has_key?(dir)
|
301
|
+
files[dir] = nil
|
302
|
+
dir = File.dirname(dir)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
def create_jar(jar_path, entries)
|
308
|
+
ZipSupport.create(jar_path) do |zipfile|
|
309
|
+
entries.keys.sort.each do |entry|
|
310
|
+
src = entries[entry]
|
311
|
+
if src.respond_to?(:read)
|
312
|
+
zipfile.get_output_stream(entry) { |f| f << src.read }
|
313
|
+
elsif src.nil? || File.directory?(src)
|
314
|
+
if File.symlink?(entry) && ! defined?(JRUBY_VERSION)
|
315
|
+
warn "directory symlinks are not followed unless using JRuby; " +
|
316
|
+
"#{entry.inspect} contents not in archive"
|
317
|
+
end
|
318
|
+
zipfile.mkdir(entry.dup) # in case it's frozen rubyzip 0.9.6.1 workaround
|
319
|
+
elsif File.symlink?(src)
|
320
|
+
zipfile.get_output_stream(entry) { |f| f << File.read(src) }
|
321
|
+
elsif File.exist?(src)
|
322
|
+
zipfile.add(entry, src)
|
323
|
+
else
|
324
|
+
warn "file not found; #{entry.inspect} not in archive"
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
def entry_in_jar(jar, entry)
|
331
|
+
ZipSupport.open(jar) do |zf|
|
332
|
+
zf.get_input_stream(entry) {|io| StringIO.new(io.read) }
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
# Java-boosted jar creation for JRuby; replaces #create_jar and
|
337
|
+
# #entry_in_jar with Java version
|
338
|
+
require 'warbler_jar' if defined?(JRUBY_VERSION) && JRUBY_VERSION >= "1.5"
|
339
|
+
end
|
340
|
+
|
341
|
+
# Warbler::War is Deprecated. Please use Warbler::Jar.
|
342
|
+
class War < Jar
|
343
|
+
def initialize(*)
|
344
|
+
super
|
345
|
+
warn "Warbler::War is deprecated. Please replace all occurrences with Warbler::Jar."
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2012 Engine Yard, Inc.
|
3
|
+
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
|
4
|
+
# This source code is available under the MIT license.
|
5
|
+
# See the file LICENSE.txt for details.
|
6
|
+
#++
|
7
|
+
|
8
|
+
module Warbler
|
9
|
+
module PathmapHelper
|
10
|
+
def apply_pathmaps(config, file, pathmaps)
|
11
|
+
file = file.to_s
|
12
|
+
file = file[2..-1] if file =~ /^\.\//
|
13
|
+
pathmaps = config.pathmaps.send(pathmaps)
|
14
|
+
pathmaps.each do |p|
|
15
|
+
file = file.pathmap(p)
|
16
|
+
end if pathmaps
|
17
|
+
file
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2012 Engine Yard, Inc.
|
3
|
+
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
|
4
|
+
# This source code is available under the MIT license.
|
5
|
+
# See the file LICENSE.txt for details.
|
6
|
+
#++
|
7
|
+
|
8
|
+
module Warbler
|
9
|
+
module PlatformHelper
|
10
|
+
# Cross-platform way of finding an executable in the $PATH.
|
11
|
+
# Thanks to @mislav
|
12
|
+
#
|
13
|
+
# which('ruby') #=> /usr/bin/ruby
|
14
|
+
def which(cmd)
|
15
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
16
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
17
|
+
exts.each { |ext|
|
18
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
19
|
+
return exe if File.executable? exe
|
20
|
+
}
|
21
|
+
end
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2012 Engine Yard, Inc.
|
3
|
+
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
|
4
|
+
# This source code is available under the MIT license.
|
5
|
+
# See the file LICENSE.txt for details.
|
6
|
+
#++
|
7
|
+
|
8
|
+
module Warbler
|
9
|
+
module RakeHelper
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.class_eval do
|
13
|
+
include Rake::DSL if defined?(Rake::DSL)
|
14
|
+
include Rake::FileUtilsExt # includes FileUtils
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.extended(base)
|
19
|
+
base.extend Rake::DSL if defined?(Rake::DSL)
|
20
|
+
base.extend Rake::FileUtilsExt
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def silent?
|
26
|
+
Rake.application.options.silent rescue nil
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/warbler/task.rb
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2012 Engine Yard, Inc.
|
3
|
+
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
|
4
|
+
# This source code is available under the MIT license.
|
5
|
+
# See the file LICENSE.txt for details.
|
6
|
+
#++
|
7
|
+
|
8
|
+
require 'rake'
|
9
|
+
require 'rake/tasklib'
|
10
|
+
require 'warbler/config'
|
11
|
+
require 'warbler/jar'
|
12
|
+
|
13
|
+
module Warbler
|
14
|
+
# Warbler Rake task. Allows defining multiple configurations inside the same
|
15
|
+
# Rakefile by using different task names.
|
16
|
+
#
|
17
|
+
# To define multiple Warbler configurations in a single project, use
|
18
|
+
# code like the following in a Rakefile:
|
19
|
+
#
|
20
|
+
# Warbler::Task.new("war1", Warbler::Config.new do |config|
|
21
|
+
# config.jar_name = "war1"
|
22
|
+
# # ...
|
23
|
+
# end
|
24
|
+
# Warbler::Task.new("war2", Warbler::Config.new do |config|
|
25
|
+
# config.jar_name = "war2"
|
26
|
+
# # ...
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# With this setup, you can create two separate war files two
|
30
|
+
# different configurations by running <tt>rake war1 war2</tt>.
|
31
|
+
class Task < Rake::TaskLib
|
32
|
+
include RakeHelper
|
33
|
+
|
34
|
+
# Task name
|
35
|
+
attr_accessor :name
|
36
|
+
|
37
|
+
# Warbler::Config
|
38
|
+
attr_accessor :config
|
39
|
+
|
40
|
+
# Warbler::Jar
|
41
|
+
attr_accessor :jar
|
42
|
+
|
43
|
+
def initialize(name = nil, config = nil)
|
44
|
+
@config = config
|
45
|
+
if @config.nil? && File.exists?(Config::FILE)
|
46
|
+
@config = eval(File.read(Config::FILE), binding, Config::FILE, 0)
|
47
|
+
end
|
48
|
+
@config ||= Config.new
|
49
|
+
unless @config.kind_of? Config
|
50
|
+
warn "Warbler::Config not provided by override in initializer or #{Config::FILE}; using defaults"
|
51
|
+
@config = Config.new
|
52
|
+
end
|
53
|
+
@name = name || @config.jar_extension
|
54
|
+
@jar = Warbler::Jar.new
|
55
|
+
yield self if block_given?
|
56
|
+
define_tasks
|
57
|
+
end
|
58
|
+
|
59
|
+
# Deprecated: attr_accessor :war
|
60
|
+
alias war jar
|
61
|
+
|
62
|
+
private
|
63
|
+
def define_tasks
|
64
|
+
define_main_task
|
65
|
+
namespace name do
|
66
|
+
define_clean_task
|
67
|
+
define_compiled_task
|
68
|
+
define_files_task
|
69
|
+
define_jar_task
|
70
|
+
define_debug_task
|
71
|
+
define_config_task
|
72
|
+
define_pluginize_task
|
73
|
+
define_version_task
|
74
|
+
define_extra_tasks
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def define_main_task
|
79
|
+
desc "Create the project #{config.jar_extension} file"
|
80
|
+
task @name do
|
81
|
+
unless @config.features.empty?
|
82
|
+
@config.features.each do |feature|
|
83
|
+
t = "#@name:#{feature}"
|
84
|
+
unless Rake.application.lookup(t)
|
85
|
+
warn "unknown feature `#{feature}', ignoring"
|
86
|
+
next
|
87
|
+
end
|
88
|
+
Rake::Task[t].invoke
|
89
|
+
end
|
90
|
+
end
|
91
|
+
# Invoke this way so custom dependencies can be defined before
|
92
|
+
# the file find routine is run
|
93
|
+
["#{@name}:files", "#{@name}:jar"].each do |t|
|
94
|
+
Rake::Task[t].invoke
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def define_clean_task
|
100
|
+
desc "Remove the project #{config.jar_extension} file"
|
101
|
+
task "clean" do
|
102
|
+
rm_f "#{config.jar_name}.#{config.jar_extension}"
|
103
|
+
end
|
104
|
+
task "clear" => "#{name}:clean"
|
105
|
+
end
|
106
|
+
|
107
|
+
def define_compiled_task
|
108
|
+
task "compiled" do
|
109
|
+
jar.compile(config)
|
110
|
+
task @name do
|
111
|
+
rm_f config.compiled_ruby_files.map {|f| f.sub(/\.rb$/, '.class') }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def define_files_task
|
117
|
+
task "files" do
|
118
|
+
jar.apply(config)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def define_jar_task
|
123
|
+
task "jar" do
|
124
|
+
jar.create(config)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def define_debug_task
|
129
|
+
desc "Dump diagnostic information"
|
130
|
+
task "debug" => "files" do
|
131
|
+
require 'yaml'
|
132
|
+
puts config.dump
|
133
|
+
jar.files.each {|k,v| puts "#{k} -> #{String === v ? v : '<blob>'}"}
|
134
|
+
end
|
135
|
+
task "debug:includes" => "files" do
|
136
|
+
puts "", "included files:"
|
137
|
+
puts( *war.app_filelist.include )
|
138
|
+
end
|
139
|
+
task "debug:excludes" => "files" do
|
140
|
+
puts "", "excluded files:"
|
141
|
+
puts( *war.app_filelist.exclude )
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def define_extra_tasks
|
146
|
+
@config.define_tasks
|
147
|
+
end
|
148
|
+
|
149
|
+
def define_config_task
|
150
|
+
task "config" do
|
151
|
+
if File.exists?(Warbler::Config::FILE) && ENV["FORCE"].nil?
|
152
|
+
puts "There's another bird sitting on my favorite branch"
|
153
|
+
puts "(file '#{Warbler::Config::FILE}' already exists. Pass argument FORCE=1 to override)"
|
154
|
+
elsif !File.directory?("config")
|
155
|
+
puts "I'm confused; my favorite branch is missing"
|
156
|
+
puts "(directory 'config' is missing)"
|
157
|
+
else
|
158
|
+
cp "#{Warbler::WARBLER_HOME}/warble.rb", Warbler::Config::FILE
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def define_pluginize_task
|
164
|
+
task "pluginize" do
|
165
|
+
if !Dir["lib/tasks/warbler*"].empty? && ENV["FORCE"].nil?
|
166
|
+
puts "I found an old nest in lib/tasks; please trash it so I can make a new one"
|
167
|
+
puts "(directory lib/tasks/warbler* exists)"
|
168
|
+
else
|
169
|
+
rm_rf FileList["lib/tasks/warbler*"], :verbose => false
|
170
|
+
mkdir_p "lib/tasks/warbler"
|
171
|
+
File.open("lib/tasks/warbler/warbler.rake", "w") do |f|
|
172
|
+
f.puts "require 'warbler'"
|
173
|
+
f.puts "Warbler::Task.new"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def define_version_task
|
180
|
+
task "version" do
|
181
|
+
puts "Warbler version #{Warbler::VERSION}"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
ENV['BUNDLE_WITHOUT'] = '<%= config.bundle_without.join(':') %>'
|
2
|
+
<% if config.bundler[:frozen] -%>
|
3
|
+
ENV['BUNDLE_FROZEN'] = '1'
|
4
|
+
<% end -%>
|
5
|
+
|
6
|
+
module Bundler
|
7
|
+
module Patch
|
8
|
+
def clean_load_path
|
9
|
+
# nothing to be done for embedded JRuby
|
10
|
+
end
|
11
|
+
end
|
12
|
+
module SharedHelpers
|
13
|
+
def included(bundler)
|
14
|
+
bundler.send :include, Patch
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'bundler/shared_helpers'
|
@@ -0,0 +1 @@
|
|
1
|
+
WARBLER_CONFIG = <%= config.webxml ? config.webxml.context_params(false).inspect : '{}' %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<% if config.relative_gem_path.empty? -%>
|
2
|
+
ENV['GEM_HOME'] <%= config.override_gem_home ? '=' : '||=' %> File.expand_path(File.join('..', '..', '<%= config.gem_path %>'), __FILE__)
|
3
|
+
<% else -%>
|
4
|
+
ENV['GEM_HOME'] <%= config.override_gem_home ? '=' : '||=' %> File.expand_path(File.join('..', '..', '<%= config.relative_gem_path %>'), __FILE__)
|
5
|
+
<% end -%>
|
6
|
+
<% if config.override_gem_home -%>
|
7
|
+
ENV['GEM_PATH'] = nil # RGs sets Gem.paths.path = Gem.default_path + [ GEM_HOME ]
|
8
|
+
<% end -%>
|
9
|
+
<% if config.bundler && config.bundler[:gemfile_path] -%>
|
10
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path(File.join('..', '..', '<%= config.bundler[:gemfile_path] %>'), __FILE__)
|
11
|
+
<% end -%>
|
@@ -0,0 +1 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= ENV_JAVA[ 'RAILS_ENV' ] || '<%= config.webxml.rails.env %>'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
if $servlet_context.nil?
|
2
|
+
ENV['GEM_HOME'] <%= config.override_gem_home ? '=' : '||=' %> File.expand_path(File.join('..', '..', '<%= config.gem_path %>'), __FILE__)
|
3
|
+
<% if config.override_gem_home -%>
|
4
|
+
<% # GEM_HOME/GEM_PATH are set as .war gets extracted (on java -jar ...)
|
5
|
+
# ... thus setting `ENV['GEM_PATH'] = nil` would cause a boot failure
|
6
|
+
-%>
|
7
|
+
<% end -%>
|
8
|
+
<% if config.bundler && config.bundler[:gemfile_path] -%>
|
9
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path(File.join('..', '..', '<%= config.bundler[:gemfile_path] %>'), __FILE__)
|
10
|
+
<% end -%>
|
11
|
+
else
|
12
|
+
ENV['GEM_HOME'] <%= config.override_gem_home ? '=' : '||=' %> $servlet_context.getRealPath('<%= config.gem_path %>')
|
13
|
+
<% if config.override_gem_home -%>
|
14
|
+
ENV['GEM_PATH'] = nil
|
15
|
+
<% end -%>
|
16
|
+
<% if config.bundler && config.bundler[:gemfile_path] -%>
|
17
|
+
ENV['BUNDLE_GEMFILE'] ||= $servlet_context.getRealPath('/<%= config.bundler[:gemfile_path] %>')
|
18
|
+
<% end -%>
|
19
|
+
end
|