warbler 0.9.14 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -0
- data/History.txt +16 -0
- data/{LICENSES.txt → LICENSE.txt} +2 -13
- data/Manifest.txt +21 -9
- data/README.txt +38 -53
- data/Rakefile +48 -16
- data/bin/warble +5 -62
- data/ext/WarblerWar.java +113 -0
- data/ext/WarblerWarService.java +17 -0
- data/lib/warbler.rb +20 -4
- data/lib/warbler/application.rb +63 -0
- data/lib/warbler/config.rb +100 -13
- data/lib/warbler/gems.rb +4 -3
- data/lib/warbler/runtime.rb +43 -0
- data/lib/warbler/task.rb +55 -288
- data/lib/warbler/version.rb +5 -4
- data/lib/warbler/war.rb +169 -0
- data/lib/warbler_war.jar +0 -0
- data/spec/sample/config/database.yml +19 -0
- data/spec/sample/lib/tasks/utils.rake +0 -0
- data/spec/sample/public/404.html +30 -0
- data/spec/sample/public/422.html +30 -0
- data/spec/sample/public/500.html +30 -0
- data/spec/sample/public/favicon.ico +0 -0
- data/spec/sample/public/index.html +274 -0
- data/spec/sample/public/robots.txt +5 -0
- data/spec/spec_helper.rb +5 -4
- data/spec/warbler/application_spec.rb +73 -0
- data/spec/warbler/config_spec.rb +8 -6
- data/spec/warbler/gems_spec.rb +4 -3
- data/spec/warbler/task_spec.rb +24 -428
- data/spec/warbler/war_spec.rb +425 -0
- data/{generators/warble/templates/warble.rb → warble.rb} +29 -9
- metadata +94 -26
- data/generators/warble/warble_generator.rb +0 -19
- data/lib/jruby-rack-0.9.5.jar +0 -0
- data/tasks/warbler.rake +0 -18
@@ -0,0 +1,17 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2010 Engine Yard, Inc.
|
3
|
+
* This source code is available under the MIT license.
|
4
|
+
* See the file LICENSE.txt for details.
|
5
|
+
*/
|
6
|
+
|
7
|
+
import java.io.IOException;
|
8
|
+
import org.jruby.Ruby;
|
9
|
+
import org.jruby.runtime.load.BasicLibraryService;
|
10
|
+
|
11
|
+
public class WarblerWarService implements BasicLibraryService {
|
12
|
+
public boolean basicLoad(final Ruby runtime) throws IOException {
|
13
|
+
WarblerWar.create(runtime);
|
14
|
+
return true;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
data/lib/warbler.rb
CHANGED
@@ -1,16 +1,32 @@
|
|
1
1
|
#--
|
2
|
-
# (c)
|
3
|
-
#
|
4
|
-
#
|
2
|
+
# Copyright (c) 2010 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.
|
5
6
|
#++
|
6
7
|
|
7
8
|
# Warbler is a lightweight, flexible, Rake-based system for packaging your Rails apps
|
8
9
|
# into .war files.
|
9
10
|
module Warbler
|
10
11
|
WARBLER_HOME = File.expand_path(File.dirname(__FILE__) + '/..') unless defined?(WARBLER_HOME)
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :application
|
15
|
+
attr_accessor :framework_detection
|
16
|
+
attr_writer :project_application
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.project_application
|
20
|
+
application.load_project_rakefile if application
|
21
|
+
@project_application || Rake.application
|
22
|
+
end
|
23
|
+
self.framework_detection = true
|
11
24
|
end
|
12
25
|
|
13
26
|
require 'warbler/gems'
|
14
27
|
require 'warbler/config'
|
28
|
+
require 'warbler/war'
|
15
29
|
require 'warbler/task'
|
16
|
-
require 'warbler/
|
30
|
+
require 'warbler/application'
|
31
|
+
require 'warbler/runtime'
|
32
|
+
require 'warbler/version'
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010 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
|
+
|
10
|
+
class Warbler::Application < Rake::Application
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
Warbler.application = self
|
14
|
+
@project_loaded = false
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_rakefile
|
18
|
+
@name = 'warble'
|
19
|
+
|
20
|
+
# Load the main warbler tasks
|
21
|
+
Warbler::Task.new
|
22
|
+
|
23
|
+
task :default => :war
|
24
|
+
|
25
|
+
desc "Generate a configuration file to customize your war assembly"
|
26
|
+
task :config do
|
27
|
+
if File.exists?(Warbler::Config::FILE) && ENV["FORCE"].nil?
|
28
|
+
puts "There's another bird sitting on my favorite branch"
|
29
|
+
puts "(file '#{Warbler::Config::FILE}' already exists. Pass argument FORCE=1 to override)"
|
30
|
+
elsif !File.directory?("config")
|
31
|
+
puts "I'm confused; my favorite branch is missing"
|
32
|
+
puts "(directory 'config' is missing)"
|
33
|
+
else
|
34
|
+
cp "#{Warbler::WARBLER_HOME}/warble.rb", Warbler::Config::FILE
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Display version of warbler"
|
39
|
+
task :version do
|
40
|
+
puts "Warbler version #{Warbler::VERSION}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_project_rakefile
|
45
|
+
return if @project_loaded
|
46
|
+
# Load any application rakefiles to aid in autodetecting applications
|
47
|
+
app = Warbler.project_application = Rake::Application.new
|
48
|
+
Rake.application = app
|
49
|
+
Rake::Application::DEFAULT_RAKEFILES.each do |rf|
|
50
|
+
if File.exist?(rf)
|
51
|
+
load rf
|
52
|
+
break
|
53
|
+
end
|
54
|
+
end
|
55
|
+
Rake.application = self
|
56
|
+
@project_loaded = true
|
57
|
+
end
|
58
|
+
|
59
|
+
def run
|
60
|
+
Rake.application = self
|
61
|
+
super
|
62
|
+
end
|
63
|
+
end
|
data/lib/warbler/config.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#--
|
2
|
-
# (c)
|
3
|
-
#
|
4
|
-
#
|
2
|
+
# Copyright (c) 2010 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.
|
5
6
|
#++
|
6
7
|
|
7
8
|
require 'ostruct'
|
@@ -11,11 +12,20 @@ module Warbler
|
|
11
12
|
class Config
|
12
13
|
TOP_DIRS = %w(app config lib log vendor)
|
13
14
|
FILE = "config/warble.rb"
|
15
|
+
DEFAULT_GEM_PATH = '/WEB-INF/gems'
|
14
16
|
BUILD_GEMS = %w(warbler rake rcov)
|
15
17
|
|
16
|
-
#
|
18
|
+
# Deprecated: No longer has any effect.
|
17
19
|
attr_accessor :staging_dir
|
18
20
|
|
21
|
+
# A hash of files that Warbler will build into the .war file. Keys
|
22
|
+
# to the hash are filenames in the .war, values are either nil
|
23
|
+
# (for a directory entry), the source filenames or IO objects for
|
24
|
+
# temporary file contents. This will be filled with files by the
|
25
|
+
# various Warbler tasks as they run. You can add arbitrary
|
26
|
+
# filenames to this hash if you wish.
|
27
|
+
attr_accessor :files
|
28
|
+
|
19
29
|
# Directory where the war file will be written. Can be used to direct
|
20
30
|
# Warbler to place your war file directly in your application server's
|
21
31
|
# autodeploy directory. Defaults to the root of the Rails directory.
|
@@ -38,7 +48,7 @@ module Warbler
|
|
38
48
|
# Java libraries to copy to WEB-INF/lib
|
39
49
|
attr_accessor :java_libs
|
40
50
|
|
41
|
-
# Rubygems to install into the webapp
|
51
|
+
# Rubygems to install into the webapp.
|
42
52
|
attr_accessor :gems
|
43
53
|
|
44
54
|
# Whether to include dependent gems (default true)
|
@@ -63,6 +73,17 @@ module Warbler
|
|
63
73
|
# by jar -cf....
|
64
74
|
attr_accessor :manifest_file
|
65
75
|
|
76
|
+
# Files for WEB-INF directory (next to web.xml). Contains web.xml by default.
|
77
|
+
# If there are .erb files they will be processed with webxml config.
|
78
|
+
attr_accessor :webinf_files
|
79
|
+
|
80
|
+
# Use Bundler to locate gems if Gemfile is found. Default is true.
|
81
|
+
attr_accessor :bundler
|
82
|
+
|
83
|
+
# Path to the pre-bundled gem directory inside the war file. Default is '/WEB-INF/gems'.
|
84
|
+
# This also sets 'gem.path' inside web.xml.
|
85
|
+
attr_accessor :gem_path
|
86
|
+
|
66
87
|
# Extra configuration for web.xml. Controls how the dynamically-generated web.xml
|
67
88
|
# file is generated.
|
68
89
|
#
|
@@ -78,6 +99,7 @@ module Warbler
|
|
78
99
|
# * <tt>webxml.rails.env</tt> -- the Rails environment to use for the
|
79
100
|
# running application, usually either development or production (the
|
80
101
|
# default).
|
102
|
+
# * <tt>webxml.gem.path</tt> -- the path to your bundled gem directory
|
81
103
|
# * <tt>webxml.jruby.min.runtimes</tt> -- minimum number of pooled runtimes to
|
82
104
|
# keep around during idle time
|
83
105
|
# * <tt>webxml.jruby.max.runtimes</tt> -- maximum number of pooled Rails
|
@@ -92,13 +114,13 @@ module Warbler
|
|
92
114
|
|
93
115
|
def initialize(warbler_home = WARBLER_HOME)
|
94
116
|
@warbler_home = warbler_home
|
95
|
-
@staging_dir = File.join("tmp", "war")
|
96
117
|
@dirs = TOP_DIRS.select {|d| File.directory?(d)}
|
97
118
|
@includes = FileList[]
|
98
119
|
@excludes = FileList[]
|
99
120
|
@java_libs = default_jar_files
|
100
121
|
@java_classes = FileList[]
|
101
122
|
@gems = Warbler::Gems.new
|
123
|
+
@gem_path = DEFAULT_GEM_PATH
|
102
124
|
@gem_dependencies = true
|
103
125
|
@exclude_logs = true
|
104
126
|
@public_html = FileList["public/**/*"]
|
@@ -106,17 +128,24 @@ module Warbler
|
|
106
128
|
@webxml = default_webxml_config
|
107
129
|
@rails_root = File.expand_path(defined?(RAILS_ROOT) ? RAILS_ROOT : Dir.getwd)
|
108
130
|
@war_name = File.basename(@rails_root)
|
131
|
+
@bundler = true
|
132
|
+
@webinf_files = default_webinf_files
|
109
133
|
auto_detect_frameworks
|
110
134
|
yield self if block_given?
|
135
|
+
update_gem_path
|
136
|
+
detect_bundler_gems
|
111
137
|
@excludes += warbler_vendor_excludes(warbler_home)
|
112
138
|
@excludes += FileList["**/*.log"] if @exclude_logs
|
113
|
-
@excludes << @staging_dir
|
114
139
|
end
|
115
140
|
|
116
141
|
def gems=(value)
|
117
142
|
@gems = Warbler::Gems.new(value)
|
118
143
|
end
|
119
144
|
|
145
|
+
def relative_gem_path
|
146
|
+
@gem_path[1..-1]
|
147
|
+
end
|
148
|
+
|
120
149
|
private
|
121
150
|
def warbler_vendor_excludes(warbler_home)
|
122
151
|
warbler = File.expand_path(warbler_home)
|
@@ -133,8 +162,9 @@ module Warbler
|
|
133
162
|
p.java_libs = ["WEB-INF/lib/%f"]
|
134
163
|
p.java_classes = ["WEB-INF/classes/%p"]
|
135
164
|
p.application = ["WEB-INF/%p"]
|
136
|
-
p.
|
137
|
-
p.
|
165
|
+
p.webinf = ["WEB-INF/%{.erb$,}f"]
|
166
|
+
p.gemspecs = ["#{relative_gem_path}/specifications/%f"]
|
167
|
+
p.gems = ["#{relative_gem_path}/gems/%p"]
|
138
168
|
p
|
139
169
|
end
|
140
170
|
|
@@ -147,13 +177,61 @@ module Warbler
|
|
147
177
|
c
|
148
178
|
end
|
149
179
|
|
180
|
+
def default_webinf_files
|
181
|
+
webxml = if File.exist?("config/web.xml")
|
182
|
+
"config/web.xml"
|
183
|
+
elsif File.exist?("config/web.xml.erb")
|
184
|
+
"config/web.xml.erb"
|
185
|
+
else
|
186
|
+
"#{WARBLER_HOME}/web.xml.erb"
|
187
|
+
end
|
188
|
+
FileList[webxml]
|
189
|
+
end
|
190
|
+
|
191
|
+
def update_gem_path
|
192
|
+
if @gem_path != DEFAULT_GEM_PATH
|
193
|
+
@gem_path = "/#{@gem_path}" unless @gem_path =~ %r{^/}
|
194
|
+
sub_gem_path = @gem_path[1..-1]
|
195
|
+
@pathmaps.gemspecs.each {|p| p.sub!(DEFAULT_GEM_PATH[1..-1], sub_gem_path)}
|
196
|
+
@pathmaps.gems.each {|p| p.sub!(DEFAULT_GEM_PATH[1..-1], sub_gem_path)}
|
197
|
+
@webxml["gem"]["path"] = @gem_path
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def detect_bundler_gems
|
202
|
+
if @bundler && File.exist?("Gemfile")
|
203
|
+
@gems.clear
|
204
|
+
@gem_dependencies = false # Bundler takes care of these
|
205
|
+
require 'bundler'
|
206
|
+
env = Bundler.respond_to?(:runtime) ? Bundler.runtime : Bundler.load
|
207
|
+
def Bundler.env_file; root.join(::Warbler::Runtime::WAR_ENV); end
|
208
|
+
env.extend Warbler::Runtime
|
209
|
+
env.gem_path = @gem_path
|
210
|
+
env.write_war_environment
|
211
|
+
env.war_specs.each {|spec| @gems << spec }
|
212
|
+
else
|
213
|
+
@bundler = false
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
150
217
|
def default_jar_files
|
151
218
|
require 'jruby-jars'
|
152
|
-
|
219
|
+
require 'jruby-rack'
|
220
|
+
FileList[JRubyJars.core_jar_path, JRubyJars.stdlib_jar_path, JRubyJars.jruby_rack_jar_path]
|
153
221
|
end
|
154
222
|
|
155
223
|
def auto_detect_frameworks
|
156
|
-
|
224
|
+
return unless Warbler.framework_detection
|
225
|
+
if File.exist?(".bundle/environment.rb")
|
226
|
+
begin # Don't want Bundler to load from .bundle/environment
|
227
|
+
mv(".bundle/environment.rb",".bundle/environment-save.rb", :verbose => false)
|
228
|
+
auto_detect_rails || auto_detect_merb || auto_detect_rackup
|
229
|
+
ensure
|
230
|
+
mv(".bundle/environment-save.rb",".bundle/environment.rb", :verbose => false)
|
231
|
+
end
|
232
|
+
else
|
233
|
+
auto_detect_rails || auto_detect_merb || auto_detect_rackup
|
234
|
+
end
|
157
235
|
end
|
158
236
|
|
159
237
|
def auto_detect_rails
|
@@ -166,9 +244,17 @@ module Warbler
|
|
166
244
|
@gems["rails"] = Rails::VERSION::STRING
|
167
245
|
end
|
168
246
|
if defined?(Rails.configuration.gems)
|
169
|
-
Rails.configuration.gems.each
|
247
|
+
Rails.configuration.gems.each do |g|
|
248
|
+
@gems << Gem::Dependency.new(g.name, g.requirement) if Dir["vendor/gems/#{g.name}*"].empty?
|
249
|
+
end
|
250
|
+
end
|
251
|
+
if defined?(Rails.configuration.threadsafe!) &&
|
252
|
+
(defined?(Rails.configuration.allow_concurrency) && # Rails 3
|
253
|
+
Rails.configuration.allow_concurrency && Rails.configuration.preload_frameworks) ||
|
254
|
+
(defined?(Rails.configuration.action_controller.allow_concurrency) && # Rails 2
|
255
|
+
Rails.configuration.action_controller.allow_concurrency && Rails.configuration.action_controller.preload_frameworks)
|
256
|
+
@webxml.jruby.max.runtimes = 1
|
170
257
|
end
|
171
|
-
@webxml.jruby.max.runtimes = 1 if defined?(Rails.configuration.threadsafe!)
|
172
258
|
true
|
173
259
|
end
|
174
260
|
|
@@ -189,6 +275,7 @@ module Warbler
|
|
189
275
|
return false unless File.exist?("config.ru")
|
190
276
|
@webxml.booter = :rack
|
191
277
|
@webxml.rackup = File.read("config.ru")
|
278
|
+
true
|
192
279
|
end
|
193
280
|
end
|
194
281
|
|
data/lib/warbler/gems.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#--
|
2
|
-
# (c)
|
3
|
-
#
|
4
|
-
#
|
2
|
+
# Copyright (c) 2010 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.
|
5
6
|
#++
|
6
7
|
|
7
8
|
module Warbler
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Warbler
|
2
|
+
# Extension module for a Bundler::Runtime instance, to add methods
|
3
|
+
# to create a Bundler environment file specific to war packaging.
|
4
|
+
module Runtime
|
5
|
+
WAR_ENV = ".bundle/war-environment.rb"
|
6
|
+
|
7
|
+
attr_writer :gem_path
|
8
|
+
def gem_path
|
9
|
+
@gem_path || Config::DEFAULT_GEM_PATH
|
10
|
+
end
|
11
|
+
|
12
|
+
class Spec
|
13
|
+
def initialize(spec, gem_path)
|
14
|
+
location = spec[:loaded_from][%r{(.*)/specifications}, 1]
|
15
|
+
spec = spec.dup
|
16
|
+
spec[:loaded_from] = spec[:loaded_from].sub(location, gem_path)
|
17
|
+
spec[:load_paths] = spec[:load_paths].map {|p| p.sub(location, gem_path)}
|
18
|
+
@spec = spec
|
19
|
+
end
|
20
|
+
|
21
|
+
def inspect
|
22
|
+
str = @spec.inspect
|
23
|
+
str.gsub(%r'"/WEB-INF(/[^"]*)"', 'File.expand_path("../..\1", __FILE__)')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def rb_lock_file
|
28
|
+
root.join(WAR_ENV)
|
29
|
+
end
|
30
|
+
|
31
|
+
def specs_for_lock_file
|
32
|
+
super.map {|s| Spec.new(s, gem_path)}
|
33
|
+
end
|
34
|
+
|
35
|
+
def write_war_environment
|
36
|
+
write_rb_lock
|
37
|
+
end
|
38
|
+
|
39
|
+
def war_specs
|
40
|
+
respond_to?(:requested_specs) ? requested_specs : specs_for
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/warbler/task.rb
CHANGED
@@ -1,39 +1,29 @@
|
|
1
1
|
#--
|
2
|
-
# (c)
|
3
|
-
#
|
4
|
-
#
|
2
|
+
# Copyright (c) 2010 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.
|
5
6
|
#++
|
6
7
|
|
7
8
|
require 'rake'
|
8
9
|
require 'rake/tasklib'
|
10
|
+
require 'stringio'
|
11
|
+
require 'zip/zip'
|
9
12
|
|
10
13
|
module Warbler
|
11
|
-
class << self
|
12
|
-
attr_writer :project_application
|
13
|
-
def project_application
|
14
|
-
@project_application || Rake.application
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_accessor :framework_detection
|
18
|
-
end
|
19
|
-
self.framework_detection = true
|
20
|
-
|
21
14
|
# Warbler Rake task. Allows defining multiple configurations inside the same
|
22
15
|
# Rakefile by using different task names.
|
23
16
|
class Task < Rake::TaskLib
|
24
|
-
COPY_PROC = proc {|t| cp t.prerequisites.last, t.name }
|
25
|
-
|
26
17
|
# Task name
|
27
18
|
attr_accessor :name
|
28
19
|
|
29
20
|
# Warbler::Config
|
30
21
|
attr_accessor :config
|
31
22
|
|
32
|
-
#
|
33
|
-
|
34
|
-
attr_accessor :verbose
|
23
|
+
# Warbler::War
|
24
|
+
attr_accessor :war
|
35
25
|
|
36
|
-
def initialize(name = :war, config = nil
|
26
|
+
def initialize(name = :war, config = nil)
|
37
27
|
@name = name
|
38
28
|
@config = config
|
39
29
|
if @config.nil? && File.exists?(Config::FILE)
|
@@ -41,310 +31,87 @@ module Warbler
|
|
41
31
|
end
|
42
32
|
@config ||= Config.new
|
43
33
|
unless @config.kind_of? Config
|
44
|
-
warn "
|
34
|
+
warn "Warbler::Config not provided by override in initializer or #{Config::FILE}; using defaults"
|
45
35
|
@config = Config.new
|
46
36
|
end
|
37
|
+
@war = Warbler::War.new
|
47
38
|
yield self if block_given?
|
48
|
-
|
39
|
+
define_tasks
|
49
40
|
end
|
50
41
|
|
51
42
|
private
|
52
43
|
def define_tasks
|
53
44
|
define_main_task
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
define_exploded_task
|
61
|
-
define_debug_task
|
62
|
-
end
|
63
|
-
|
64
|
-
def define_main_task
|
65
|
-
desc "Create #{@config.war_name}.war"
|
66
|
-
task @name => ["#{@name}:app", "#{@name}:public", "#{@name}:webxml", "#{@name}:jar"]
|
67
|
-
end
|
68
|
-
|
69
|
-
def define_clean_task
|
70
|
-
with_namespace_and_config do |name, config|
|
71
|
-
desc "Clean up the .war file and the staging area"
|
72
|
-
task "clean" do
|
73
|
-
rm_rf config.staging_dir
|
74
|
-
rm_f "#{config.war_name}.war"
|
75
|
-
end
|
76
|
-
task "clear" => "#{name}:clean"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def define_public_task
|
81
|
-
public_target_files = define_public_file_tasks
|
82
|
-
with_namespace_and_config do
|
83
|
-
desc "Copy all public HTML files to the root of the .war"
|
84
|
-
task "public" => public_target_files
|
85
|
-
task "debug:public" do
|
86
|
-
puts "", "public files:"
|
87
|
-
puts *public_target_files
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def define_gems_task
|
93
|
-
directory "#{config.staging_dir}/#{apply_pathmaps("sources-0.0.1.gem", :gems).pathmap("%d")}"
|
94
|
-
targets = define_copy_gems_task
|
95
|
-
with_namespace_and_config do
|
96
|
-
desc "Unpack all gems into WEB-INF/gems"
|
97
|
-
task "gems" => targets
|
98
|
-
task "debug:gems" do
|
99
|
-
puts "", "gems files:"
|
100
|
-
puts *targets
|
101
|
-
end
|
45
|
+
namespace name do
|
46
|
+
define_clean_task
|
47
|
+
define_files_task
|
48
|
+
define_gemjar_task
|
49
|
+
define_jar_task
|
50
|
+
define_debug_task
|
102
51
|
end
|
103
52
|
end
|
104
53
|
|
105
|
-
def
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
else
|
113
|
-
erb = if File.exist?("config/web.xml.erb")
|
114
|
-
"config/web.xml.erb"
|
115
|
-
else
|
116
|
-
"#{WARBLER_HOME}/web.xml.erb"
|
117
|
-
end
|
118
|
-
require 'erb'
|
119
|
-
erb = ERB.new(File.open(erb) {|f| f.read })
|
120
|
-
File.open("#{config.staging_dir}/WEB-INF/web.xml", "w") do |f|
|
121
|
-
f << erb.result(erb_binding(config.webxml))
|
122
|
-
end
|
123
|
-
end
|
54
|
+
def define_main_task
|
55
|
+
desc "Create the project .war file"
|
56
|
+
task @name do
|
57
|
+
# Invoke this way so custom dependencies can be defined before
|
58
|
+
# the file find routine is run
|
59
|
+
["#{@name}:files", "#{@name}:jar"].each do |t|
|
60
|
+
Rake::Task[t].invoke
|
124
61
|
end
|
125
62
|
end
|
126
63
|
end
|
127
64
|
|
128
|
-
def
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
end
|
133
|
-
with_namespace_and_config do |name, config|
|
134
|
-
desc "Copy all java libraries into the .war"
|
135
|
-
task "java_libs" => target_files
|
136
|
-
task "debug:java_libs" do
|
137
|
-
puts "", "java_libs files:"
|
138
|
-
puts *target_files
|
139
|
-
end
|
65
|
+
def define_clean_task
|
66
|
+
desc "Remove the .war file"
|
67
|
+
task "clean" do
|
68
|
+
rm_f "#{config.war_name}.war"
|
140
69
|
end
|
141
|
-
|
70
|
+
task "clear" => "#{name}:clean"
|
142
71
|
end
|
143
72
|
|
144
|
-
def
|
145
|
-
|
146
|
-
|
147
|
-
"#{@config.staging_dir}/#{apply_pathmaps(f, :java_classes)}")
|
148
|
-
end
|
149
|
-
with_namespace_and_config do |name, config|
|
150
|
-
desc "Copy java classes into the .war"
|
151
|
-
task "java_classes" => target_files
|
152
|
-
task "debug:java_classes" do
|
153
|
-
puts "", "java_classes files:"
|
154
|
-
puts *target_files
|
155
|
-
end
|
73
|
+
def define_files_task
|
74
|
+
task "files" do
|
75
|
+
war.apply(config)
|
156
76
|
end
|
157
|
-
target_files
|
158
77
|
end
|
159
78
|
|
160
|
-
def
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
puts *webinf_target_files
|
79
|
+
def define_gemjar_task
|
80
|
+
gem_jar = Warbler::War.new
|
81
|
+
task "gemjar" => "files" do
|
82
|
+
gem_path = Regexp::quote(config.relative_gem_path)
|
83
|
+
gems = war.files.select{|k,v| k =~ %r{#{gem_path}/} }
|
84
|
+
gems.each do |k,v|
|
85
|
+
gem_jar.files[k.sub(%r{#{gem_path}/}, '')] = v
|
168
86
|
end
|
87
|
+
war.files["WEB-INF/lib/gems.jar"] = "tmp/gems.jar"
|
88
|
+
war.files.reject!{|k,v| k =~ /#{gem_path}/ }
|
89
|
+
mkdir_p "tmp"
|
90
|
+
gem_jar.create("tmp/gems.jar")
|
169
91
|
end
|
170
92
|
end
|
171
93
|
|
172
94
|
def define_jar_task
|
173
|
-
|
174
|
-
|
175
|
-
task "jar" do
|
176
|
-
war_path = "#{config.war_name}.war"
|
177
|
-
war_path = File.join(config.autodeploy_dir, war_path) if config.autodeploy_dir
|
178
|
-
flags, manifest = config.manifest_file ? ["cfm", config.manifest_file] : ["cf", ""]
|
179
|
-
sh "jar #{flags} #{war_path} #{manifest} -C #{config.staging_dir} ."
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def define_exploded_task
|
185
|
-
with_namespace_and_config do |name,config|
|
186
|
-
libs = define_java_libs_task
|
187
|
-
desc "Create an exploded war in the app's public directory"
|
188
|
-
task "exploded" => ["webxml", "java_classes", "gems", *libs] do
|
189
|
-
cp "#{@config.staging_dir}/WEB-INF/web.xml", "."
|
190
|
-
cp File.join(WARBLER_HOME, "sun-web.xml"), "." unless File.exists?("sun-web.xml")
|
191
|
-
ln_sf "#{@config.staging_dir}/WEB-INF/gems", "."
|
192
|
-
if File.directory?("#{@config.staging_dir}/WEB-INF/classes")
|
193
|
-
ln_sf "#{@config.staging_dir}/WEB-INF/classes", "."
|
194
|
-
end
|
195
|
-
mkdir_p "lib"
|
196
|
-
libs.each {|l| ln_sf l, "lib/#{File.basename(l)}"}
|
197
|
-
ln_sf "..", "public/WEB-INF"
|
198
|
-
end
|
199
|
-
|
200
|
-
task "clean:exploded" do
|
201
|
-
(libs.map {|l| "lib/#{File.basename(l)}" } +
|
202
|
-
["gems", "public/WEB-INF", "classes"]).each do |l|
|
203
|
-
rm_f l if File.exist?(l) && File.symlink?(l)
|
204
|
-
end
|
205
|
-
rm_f "*web.xml"
|
206
|
-
end
|
95
|
+
task "jar" do
|
96
|
+
war.create(config)
|
207
97
|
end
|
208
98
|
end
|
209
99
|
|
210
100
|
def define_debug_task
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
all_debug_tasks = %w(: app java_libs java_classes gems public includes excludes).map do |n|
|
217
|
-
n.sub(/^:?/, "#{name}:debug:").sub(/:$/, '')
|
218
|
-
end
|
219
|
-
task "debug:all" => all_debug_tasks
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
def define_public_file_tasks
|
224
|
-
@config.public_html.map do |f|
|
225
|
-
define_file_task(f, "#{@config.staging_dir}/#{apply_pathmaps(f, :public_html)}")
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
def define_webinf_file_tasks
|
230
|
-
target_files = @config.dirs.select do |d|
|
231
|
-
exists = File.directory?(d)
|
232
|
-
warn "warning: application directory `#{d}' does not exist or is not a directory; skipping" unless exists
|
233
|
-
exists
|
234
|
-
end.map do |d|
|
235
|
-
define_file_task(d, "#{@config.staging_dir}/#{apply_pathmaps(d, :application)}")
|
236
|
-
end
|
237
|
-
files = FileList[*(@config.dirs.map{|d| "#{d}/**/*"})]
|
238
|
-
files.include *(@config.includes.to_a)
|
239
|
-
files.exclude *(@config.excludes.to_a)
|
240
|
-
target_files += files.map do |f|
|
241
|
-
define_file_task(f,
|
242
|
-
"#{@config.staging_dir}/#{apply_pathmaps(f, :application)}")
|
101
|
+
desc "Dump diagnostic information"
|
102
|
+
task "debug" => "files" do
|
103
|
+
require 'yaml'
|
104
|
+
puts YAML::dump(config)
|
105
|
+
war.files.each {|k,v| puts "#{k} -> #{String === v ? v : '<blob>'}"}
|
243
106
|
end
|
244
|
-
|
245
|
-
target_files += define_java_classes_task
|
246
|
-
task "#@name:debug:includes" do
|
107
|
+
task "debug:includes" => "files" do
|
247
108
|
puts "", "included files:"
|
248
|
-
puts *
|
109
|
+
puts *war.webinf_filelist.include
|
249
110
|
end
|
250
|
-
task "
|
111
|
+
task "debug:excludes" => "files" do
|
251
112
|
puts "", "excluded files:"
|
252
|
-
puts *
|
253
|
-
end
|
254
|
-
target_files
|
255
|
-
end
|
256
|
-
|
257
|
-
def define_file_task(source, target)
|
258
|
-
if File.directory?(source)
|
259
|
-
directory target
|
260
|
-
puts %{directory "#{target}"} if verbose
|
261
|
-
else
|
262
|
-
directory File.dirname(target)
|
263
|
-
file(target => [File.dirname(target), source], ©_PROC)
|
264
|
-
puts %{file "#{target}" => "#{source}"} if verbose
|
265
|
-
end
|
266
|
-
target
|
267
|
-
end
|
268
|
-
|
269
|
-
def with_namespace_and_config
|
270
|
-
name, config = @name, @config
|
271
|
-
namespace name do
|
272
|
-
yield name, config
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
def define_copy_gems_task
|
277
|
-
targets = []
|
278
|
-
@config.gems.each do |gem, version|
|
279
|
-
define_single_gem_tasks(gem, targets, version)
|
280
|
-
end
|
281
|
-
targets
|
282
|
-
end
|
283
|
-
|
284
|
-
def define_single_gem_tasks(gem_pattern, targets, version = nil)
|
285
|
-
gem = case gem_pattern
|
286
|
-
when Gem::Dependency
|
287
|
-
gem_pattern
|
288
|
-
else
|
289
|
-
Gem::Dependency.new(gem_pattern, Gem::Requirement.create(version))
|
290
|
-
end
|
291
|
-
|
292
|
-
# skip development dependencies
|
293
|
-
return if gem.respond_to?(:type) and gem.type != :runtime
|
294
|
-
|
295
|
-
matched = Gem.source_index.search(gem)
|
296
|
-
fail "gem '#{gem}' not installed" if matched.empty?
|
297
|
-
spec = matched.last
|
298
|
-
|
299
|
-
# skip gems with no load path
|
300
|
-
return if spec.loaded_from == ""
|
301
|
-
|
302
|
-
gem_name = "#{spec.name}-#{spec.version}"
|
303
|
-
unless spec.platform.nil? || spec.platform == Gem::Platform::RUBY
|
304
|
-
[spec.platform, spec.original_platform].each do |p|
|
305
|
-
name = "#{gem_name}-#{p}"
|
306
|
-
if File.exist?(File.join(Gem.dir, 'cache', "#{name}.gem"))
|
307
|
-
gem_name = name
|
308
|
-
break
|
309
|
-
end
|
310
|
-
end
|
113
|
+
puts *war.webinf_filelist.exclude
|
311
114
|
end
|
312
|
-
|
313
|
-
gem_unpack_task_name = "gem:#{gem_name}"
|
314
|
-
return if Rake::Task.task_defined?(gem_unpack_task_name)
|
315
|
-
|
316
|
-
targets << define_file_task(spec.loaded_from,
|
317
|
-
"#{@config.staging_dir}/#{apply_pathmaps(spec.loaded_from, :gemspecs)}")
|
318
|
-
|
319
|
-
task targets.last do
|
320
|
-
Rake::Task[gem_unpack_task_name].invoke
|
321
|
-
end
|
322
|
-
|
323
|
-
src = File.join(Gem.dir, 'cache', "#{gem_name}.gem")
|
324
|
-
dest = "#{config.staging_dir}/#{apply_pathmaps(src, :gems)}"
|
325
|
-
|
326
|
-
task gem_unpack_task_name => [dest.pathmap("%d")] do |t|
|
327
|
-
require 'rubygems/installer'
|
328
|
-
Gem::Installer.new(src, :unpack => true).unpack(dest)
|
329
|
-
end
|
330
|
-
|
331
|
-
if @config.gem_dependencies
|
332
|
-
spec.dependencies.each do |dep|
|
333
|
-
define_single_gem_tasks(dep, targets)
|
334
|
-
end
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
def erb_binding(webxml)
|
339
|
-
binding
|
340
|
-
end
|
341
|
-
|
342
|
-
def apply_pathmaps(file, pathmaps)
|
343
|
-
pathmaps = @config.pathmaps.send(pathmaps)
|
344
|
-
pathmaps.each do |p|
|
345
|
-
file = file.pathmap(p)
|
346
|
-
end if pathmaps
|
347
|
-
file
|
348
115
|
end
|
349
116
|
end
|
350
117
|
end
|