rubylet-tasks 0.1.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/VERSION +1 -0
- data/examples/Gemfile +4 -0
- data/examples/Gemfile.lock +28 -0
- data/examples/Gemfile~ +2 -0
- data/examples/Rakefile +11 -0
- data/examples/Rakefile~ +1 -0
- data/examples/config.ru +3 -0
- data/examples/pkg/test_app.war +0 -0
- data/examples/tmp/restart.txt +0 -0
- data/lib/rubylet-ee-0.1.0-SNAPSHOT.jar +0 -0
- data/lib/rubylet/builder_alias_tag.rb +9 -0
- data/lib/rubylet/builder_defaults.rb +8 -0
- data/lib/rubylet/glassfish_descriptor_builder.rb +29 -0
- data/lib/rubylet/jetty_descriptor_builder.rb +28 -0
- data/lib/rubylet/war_task.rb +398 -0
- data/lib/rubylet/webapp_descriptor_builder.rb +90 -0
- data/spec/rubylet/war_task_spec.rb +54 -0
- data/spec/spec_helper.rb +55 -0
- metadata +192 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Common Ground Publishing
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/examples/Gemfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
rubylet-tasks (0.1.0-java)
|
5
|
+
builder
|
6
|
+
rake
|
7
|
+
zip
|
8
|
+
|
9
|
+
PATH
|
10
|
+
remote: ../../rubylet
|
11
|
+
specs:
|
12
|
+
rubylet (0.1-java)
|
13
|
+
|
14
|
+
GEM
|
15
|
+
remote: http://rubygems.org/
|
16
|
+
specs:
|
17
|
+
builder (3.1.4)
|
18
|
+
rack (1.4.1)
|
19
|
+
rake (10.0.2)
|
20
|
+
zip (2.0.2)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
java
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
rack
|
27
|
+
rubylet!
|
28
|
+
rubylet-tasks!
|
data/examples/Gemfile~
ADDED
data/examples/Rakefile
ADDED
data/examples/Rakefile~
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rubylet/war_task'
|
data/examples/config.ru
ADDED
Binary file
|
File without changes
|
Binary file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'rubylet/builder_alias_tag'
|
3
|
+
require 'rubylet/builder_defaults'
|
4
|
+
|
5
|
+
module Rubylet
|
6
|
+
class GlassfishDescriptorBuilder < ::Builder::XmlMarkup
|
7
|
+
extend BuilderAliasTag
|
8
|
+
include BuilderDefaults
|
9
|
+
|
10
|
+
alias_tag 'glassfish-web-app'
|
11
|
+
alias_tag 'resource-ref'
|
12
|
+
alias_tag 'res-ref-name'
|
13
|
+
alias_tag 'jndi-name'
|
14
|
+
|
15
|
+
def initialize(opts = {})
|
16
|
+
super(opts)
|
17
|
+
@alt_root_count = 0
|
18
|
+
declare!(:DOCTYPE, :'glassfish-web-app', :PUBLIC,
|
19
|
+
'-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN',
|
20
|
+
'http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd')
|
21
|
+
end
|
22
|
+
|
23
|
+
def alternate_doc_root!(from, dir)
|
24
|
+
@alt_root_count += 1
|
25
|
+
property(:name => "alternatedocroot_#{@alt_root_count}",
|
26
|
+
:value => "from=#{from} dir=#{dir}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'rubylet/builder_alias_tag'
|
3
|
+
require 'rubylet/builder_defaults'
|
4
|
+
|
5
|
+
module Rubylet
|
6
|
+
class JettyDescriptorBuilder < ::Builder::XmlMarkup
|
7
|
+
extend BuilderAliasTag
|
8
|
+
include BuilderDefaults
|
9
|
+
|
10
|
+
alias_tag 'Configure'
|
11
|
+
alias_tag 'Set'
|
12
|
+
|
13
|
+
def initialize(opts = {})
|
14
|
+
super(opts)
|
15
|
+
declare!(:DOCTYPE, :Configure, :PUBLIC,
|
16
|
+
'-//Jetty//Configure//EN',
|
17
|
+
'http://www.eclipse.org/jetty/configure.dtd')
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure!(&block)
|
21
|
+
configure :class => 'org.eclipse.jetty.webapp.WebAppContext', &block
|
22
|
+
end
|
23
|
+
|
24
|
+
def set!(name, value)
|
25
|
+
set value, :name => name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,398 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'rake/tasklib'
|
3
|
+
require 'zip/zipfilesystem'
|
4
|
+
|
5
|
+
require 'rubylet/webapp_descriptor_builder'
|
6
|
+
require 'rubylet/glassfish_descriptor_builder'
|
7
|
+
require 'rubylet/jetty_descriptor_builder'
|
8
|
+
|
9
|
+
module ParamAccessor
|
10
|
+
# Define a 'param', like attr_accessor, but with an optional default
|
11
|
+
# value. If params are defined as objects that respond to +:call+
|
12
|
+
# (e.g. a +Proc+) or a block is given, the proc or block will be
|
13
|
+
# instance_eval'ed in the context of the instance once on first
|
14
|
+
# read, after which the value is cached and returned on subsequent
|
15
|
+
# reads.
|
16
|
+
def param_accessor(sym, default = nil, &block)
|
17
|
+
if !default.nil? && block_given?
|
18
|
+
raise ArgumentError, 'both default value and block may not be given'
|
19
|
+
end
|
20
|
+
|
21
|
+
iv = "@#{sym}"
|
22
|
+
define_method(sym) do
|
23
|
+
v = instance_variable_get(iv)
|
24
|
+
val = if !v.nil?
|
25
|
+
v
|
26
|
+
elsif !default.nil?
|
27
|
+
default
|
28
|
+
elsif block_given?
|
29
|
+
block
|
30
|
+
else
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
if val.respond_to?(:call)
|
35
|
+
newval = instance_eval(&val)
|
36
|
+
instance_variable_set(iv, newval)
|
37
|
+
newval
|
38
|
+
else
|
39
|
+
val
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
define_method("#{sym}=") do |val|
|
44
|
+
instance_variable_set(iv, val)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module CommonParams
|
50
|
+
extend ParamAccessor
|
51
|
+
|
52
|
+
param_accessor :jruby_home do
|
53
|
+
unless self.respond_to?(:webapp) && webapp.jruby_home
|
54
|
+
# default to the current JRuby
|
55
|
+
if defined? JRUBY_VERSION
|
56
|
+
regex = %r{/lib/ruby/site_ruby.*}
|
57
|
+
$:.find { |p| p =~ regex }.gsub(regex, '')
|
58
|
+
else
|
59
|
+
raise "Please set jruby_home for rake task #{self}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
param_accessor :env do
|
65
|
+
{}
|
66
|
+
end
|
67
|
+
|
68
|
+
param_accessor :gems do
|
69
|
+
[]
|
70
|
+
end
|
71
|
+
|
72
|
+
def gem(name, req = '>= 0')
|
73
|
+
gems << [name, req]
|
74
|
+
end
|
75
|
+
|
76
|
+
# If +bundle exec+ equivalent should be used when running the
|
77
|
+
# webapp. Defaults to true if +Gemfile+ exists, otherwise false.
|
78
|
+
param_accessor :bundle_exec, File.exists?('Gemfile')
|
79
|
+
|
80
|
+
param_accessor :boot
|
81
|
+
|
82
|
+
param_accessor :app_root, Dir.pwd
|
83
|
+
|
84
|
+
param_accessor :servlet_class
|
85
|
+
|
86
|
+
# Directory from which to serve static files. Defaults to
|
87
|
+
# "#{app_root}/public".
|
88
|
+
param_accessor :resource_base do
|
89
|
+
::File.join(app_root, 'public')
|
90
|
+
end
|
91
|
+
|
92
|
+
param_accessor :compile_mode
|
93
|
+
|
94
|
+
param_accessor :compat_version
|
95
|
+
|
96
|
+
# CONCURRENT and SINGLETON are classloader shared singletons!
|
97
|
+
# Probably not what you want when deploying multiple apps to one
|
98
|
+
# servlet container. So it's between THREADSAFE and SINGLETHREAD.
|
99
|
+
# Default: unspecified; uses rubylet default of THREADSAFE.
|
100
|
+
param_accessor :local_context_scope
|
101
|
+
|
102
|
+
def common_params
|
103
|
+
yield 'jrubyHome', jruby_home
|
104
|
+
env.each do |key, value|
|
105
|
+
yield "env.#{key}", value
|
106
|
+
end
|
107
|
+
gems.each do |(name, req)|
|
108
|
+
yield "gem.#{name}", req
|
109
|
+
end
|
110
|
+
yield 'bundleExec', bundle_exec
|
111
|
+
yield 'boot', boot
|
112
|
+
yield 'servletClass', servlet_class
|
113
|
+
yield 'appRoot', app_root
|
114
|
+
yield 'compileMode', compile_mode
|
115
|
+
yield 'compatVersion', compat_version
|
116
|
+
yield 'localContextScope', local_context_scope
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class StaticFileFilter
|
121
|
+
extend ParamAccessor
|
122
|
+
|
123
|
+
param_accessor :name, 'StaticFileFilter'
|
124
|
+
|
125
|
+
param_accessor :java_class, 'com.commongroundpublishing.rubylet.StaticFileFilter'
|
126
|
+
|
127
|
+
param_accessor :doc_base
|
128
|
+
|
129
|
+
param_accessor :async_supported, false
|
130
|
+
|
131
|
+
param_accessor :url_pattern, '/*'
|
132
|
+
|
133
|
+
# @param [WebappDescriptorBuilder] w
|
134
|
+
def call(w)
|
135
|
+
w.filter { |f|
|
136
|
+
f.filter_name name
|
137
|
+
f.filter_class java_class
|
138
|
+
f.init_param! 'docBase', doc_base
|
139
|
+
f.async_supported async_supported if async_supported
|
140
|
+
}
|
141
|
+
w.filter_mapping { |f|
|
142
|
+
f.filter_name name
|
143
|
+
f.url_pattern url_pattern
|
144
|
+
}
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
class RubyletDescriptor
|
149
|
+
extend ParamAccessor
|
150
|
+
include CommonParams
|
151
|
+
|
152
|
+
param_accessor :name do
|
153
|
+
"Rubylet - #{File.basename(app_root)}"
|
154
|
+
end
|
155
|
+
|
156
|
+
param_accessor :java_servlet_class, 'com.commongroundpublishing.rubylet.Servlet'
|
157
|
+
|
158
|
+
param_accessor :url_pattern, '/*'
|
159
|
+
|
160
|
+
param_accessor :servlet_path do
|
161
|
+
# if url_pattern is (alpha-numeric or slashes)/*
|
162
|
+
if url_pattern =~ /^([\w\/]+)\/\*$/
|
163
|
+
$1
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
param_accessor :async_supported, false
|
168
|
+
|
169
|
+
attr_reader :webapp
|
170
|
+
|
171
|
+
def initialize(webapp)
|
172
|
+
@webapp = webapp
|
173
|
+
end
|
174
|
+
|
175
|
+
# @param [WebappDescriptorBuilder] w
|
176
|
+
def call(w)
|
177
|
+
w.servlet { |s|
|
178
|
+
s.servlet_name name
|
179
|
+
s.servlet_class java_servlet_class
|
180
|
+
common_params do |key, value|
|
181
|
+
s.init_param! key, value
|
182
|
+
end
|
183
|
+
s.init_param! 'servletPath', servlet_path
|
184
|
+
s.load_on_startup 1
|
185
|
+
s.async_supported async_supported if async_supported
|
186
|
+
}
|
187
|
+
|
188
|
+
w.servlet_mapping { |s|
|
189
|
+
s.servlet_name name
|
190
|
+
s.url_pattern url_pattern
|
191
|
+
}
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
module Rubylet
|
196
|
+
class WarTask < Rake::TaskLib
|
197
|
+
extend ParamAccessor
|
198
|
+
include CommonParams
|
199
|
+
|
200
|
+
# The name of the web application. The WAR file output will be
|
201
|
+
# derived from this, +"#{name}.war"+.
|
202
|
+
param_accessor :name, 'webapp'
|
203
|
+
|
204
|
+
# The directory in which to create the WAR file. Defaults to +./pkg+.
|
205
|
+
param_accessor :output_directory, ::File.join(Dir.pwd, 'pkg')
|
206
|
+
|
207
|
+
param_accessor :java_servlets_version, '3.0'
|
208
|
+
|
209
|
+
param_accessor :display_name do
|
210
|
+
"#{name}"
|
211
|
+
end
|
212
|
+
|
213
|
+
param_accessor(:listeners) { [] }
|
214
|
+
|
215
|
+
param_accessor(:filters) { [] }
|
216
|
+
|
217
|
+
param_accessor(:servlets) { [] }
|
218
|
+
|
219
|
+
# TODO: currently does not work with Jetty
|
220
|
+
param_accessor(:resources) { [] }
|
221
|
+
|
222
|
+
def initialize
|
223
|
+
yield(self) if block_given?
|
224
|
+
define
|
225
|
+
end
|
226
|
+
|
227
|
+
def filter(&block)
|
228
|
+
filters << block
|
229
|
+
end
|
230
|
+
|
231
|
+
def external_jruby
|
232
|
+
listeners << proc do |w|
|
233
|
+
w.listener! 'com.commongroundpublishing.rubylet.ExternalJRubyLoader'
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def static_file_filter
|
238
|
+
f = StaticFileFilter.new
|
239
|
+
yield(f) if block_given?
|
240
|
+
filters << f
|
241
|
+
end
|
242
|
+
|
243
|
+
def servlet(&block)
|
244
|
+
servlets << block
|
245
|
+
end
|
246
|
+
|
247
|
+
def rubylet
|
248
|
+
s = RubyletDescriptor.new(self)
|
249
|
+
yield(s) if block_given?
|
250
|
+
servlets << s
|
251
|
+
end
|
252
|
+
|
253
|
+
def webapp_descriptor(opts = {})
|
254
|
+
builder = WebappDescriptorBuilder.new(opts)
|
255
|
+
builder.web_app!(java_servlets_version) { |w|
|
256
|
+
w.display_name display_name()
|
257
|
+
|
258
|
+
# If defined as context params, will apply to all Rubylet servlets
|
259
|
+
common_params do |key, value|
|
260
|
+
w.context_param! key, value
|
261
|
+
end
|
262
|
+
|
263
|
+
listeners.each do |block|
|
264
|
+
block.call(w)
|
265
|
+
end
|
266
|
+
|
267
|
+
filters.each do |block|
|
268
|
+
block.call(w)
|
269
|
+
end
|
270
|
+
|
271
|
+
servlets.each do |block|
|
272
|
+
block.call(w)
|
273
|
+
end
|
274
|
+
|
275
|
+
resources.each do |res|
|
276
|
+
w.resource_ref do |r|
|
277
|
+
r.description(res[:description]) if res[:description]
|
278
|
+
r.res_ref_name(res[:name])
|
279
|
+
r.res_type(res[:type] || 'javax.sql.DataSource')
|
280
|
+
r.res_auth(res[:auth] || 'Container')
|
281
|
+
end
|
282
|
+
end
|
283
|
+
}
|
284
|
+
end
|
285
|
+
|
286
|
+
def glassfish_descriptor(opts = {})
|
287
|
+
builder = GlassfishDescriptorBuilder.new(opts)
|
288
|
+
builder.glassfish_web_app { |w|
|
289
|
+
w.alternate_doc_root!('/*', resource_base)
|
290
|
+
resources.each do |res|
|
291
|
+
w.resource_ref do |r|
|
292
|
+
r.res_ref_name res[:name]
|
293
|
+
r.jndi_name res[:jndi_name] || res[:name]
|
294
|
+
end
|
295
|
+
end
|
296
|
+
}
|
297
|
+
end
|
298
|
+
|
299
|
+
def jetty_descriptor(opts = {})
|
300
|
+
builder = JettyDescriptorBuilder.new(opts)
|
301
|
+
builder.configure! { |c|
|
302
|
+
c.set!('resourceBase', resource_base)
|
303
|
+
}
|
304
|
+
end
|
305
|
+
|
306
|
+
def rubylet_jar
|
307
|
+
base = ::File.expand_path('../..', __FILE__)
|
308
|
+
jar = Dir[::File.join(base, 'rubylet-ee-*.jar')].first
|
309
|
+
unless jar
|
310
|
+
raise 'cannot find rubylet-ee-VERSION.jar; was this gem built correctly?'
|
311
|
+
end
|
312
|
+
jar
|
313
|
+
end
|
314
|
+
|
315
|
+
def war(warfile)
|
316
|
+
Zip::ZipFile.open(warfile, Zip::ZipFile::CREATE) do |z|
|
317
|
+
z.dir.mkdir('WEB-INF')
|
318
|
+
z.file.open('WEB-INF/web.xml', 'w') do |f|
|
319
|
+
webapp_descriptor(:target => f)
|
320
|
+
end
|
321
|
+
z.file.open('WEB-INF/jetty-web.xml', 'w') do |f|
|
322
|
+
jetty_descriptor(:target => f)
|
323
|
+
end
|
324
|
+
z.file.open('WEB-INF/glassfish-web.xml', 'w') do |f|
|
325
|
+
glassfish_descriptor(:target => f)
|
326
|
+
end
|
327
|
+
|
328
|
+
container = rubylet_jar
|
329
|
+
z.dir.mkdir('WEB-INF/lib')
|
330
|
+
z.file.open("WEB-INF/lib/#{::File.basename(container)}", 'w') do |f|
|
331
|
+
::File.open(container) do |input|
|
332
|
+
buf = ''
|
333
|
+
while input.read(4096, buf)
|
334
|
+
f.write(buf)
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
# Runs maven if we are a JRuby process. Currently not used.
|
342
|
+
#
|
343
|
+
# See http://watchitlater.com/blog/2011/08/jruby-rake-and-maven/
|
344
|
+
def mvn(*args)
|
345
|
+
mvn = catch(:mvn) do
|
346
|
+
ENV['PATH'].split(::File::PATH_SEPARATOR).each do |path|
|
347
|
+
Dir.glob(::File.join(path, 'mvn')).each do |file|
|
348
|
+
if ::File.executable?(file)
|
349
|
+
throw :mvn, if ::File.symlink?(file)
|
350
|
+
::File.readlink(file)
|
351
|
+
else
|
352
|
+
file
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
raise 'No maven found on $PATH' unless mvn
|
360
|
+
|
361
|
+
mvn_home = ::File.expand_path(::File.join(mvn, '..', '..'))
|
362
|
+
m2_conf = ::File.expand_path(::File.join(mvn_home, 'bin', 'm2.conf'))
|
363
|
+
|
364
|
+
java.lang.System.setProperty('maven.home', mvn_home)
|
365
|
+
java.lang.System.setProperty('classworlds.conf', m2_conf)
|
366
|
+
|
367
|
+
Dir[::File.join(mvn_home, 'boot', '*.jar')].each do |jar|
|
368
|
+
require jar
|
369
|
+
end
|
370
|
+
launcher = Java::org.codehaus.plexus.classworlds.launcher.Launcher
|
371
|
+
exit_code = launcher.mainWithExitCode(args.flatten.to_java(:string))
|
372
|
+
raise "Maven exited #{exit_code}" unless exit_code == 0
|
373
|
+
end
|
374
|
+
|
375
|
+
private
|
376
|
+
|
377
|
+
def define
|
378
|
+
rakefile = 'Rakefile'
|
379
|
+
file rakefile
|
380
|
+
|
381
|
+
warfile = "#{output_directory}/#{name}.war"
|
382
|
+
|
383
|
+
file warfile => Dir['**/*rb'] do
|
384
|
+
::File.delete(warfile) if ::File.exists?(warfile)
|
385
|
+
FileUtils.mkdir_p("#{output_directory}")
|
386
|
+
war(warfile)
|
387
|
+
end
|
388
|
+
|
389
|
+
desc 'Create a very-skinny WAR referencing an external Rack app'
|
390
|
+
task :war => [warfile, rakefile]
|
391
|
+
|
392
|
+
task :clean do
|
393
|
+
::File.delete warfile
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
end
|
398
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'rubylet/builder_alias_tag'
|
3
|
+
require 'rubylet/builder_defaults'
|
4
|
+
|
5
|
+
module Rubylet
|
6
|
+
class WebappDescriptorBuilder < ::Builder::XmlMarkup
|
7
|
+
extend BuilderAliasTag
|
8
|
+
include BuilderDefaults
|
9
|
+
|
10
|
+
# def self.alias_tag(tag_name, method_name = tag_name.downcase.gsub('-', '_'))
|
11
|
+
# define_method(method_name.to_sym) do |*args, &block|
|
12
|
+
# tag!(tag_name, *args, &block)
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
|
16
|
+
alias_tag 'web-app'
|
17
|
+
|
18
|
+
alias_tag 'display-name'
|
19
|
+
|
20
|
+
alias_tag 'listener'
|
21
|
+
alias_tag 'listener-class'
|
22
|
+
|
23
|
+
alias_tag 'filter-name'
|
24
|
+
alias_tag 'filter-class'
|
25
|
+
alias_tag 'filter-mapping'
|
26
|
+
|
27
|
+
alias_tag 'servlet-name'
|
28
|
+
alias_tag 'servlet-class'
|
29
|
+
alias_tag 'servlet-mapping'
|
30
|
+
alias_tag 'async-supported'
|
31
|
+
alias_tag 'load-on-startup'
|
32
|
+
|
33
|
+
alias_tag 'url-pattern'
|
34
|
+
alias_tag 'context-param'
|
35
|
+
alias_tag 'init-param'
|
36
|
+
alias_tag 'param-name'
|
37
|
+
alias_tag 'param-value'
|
38
|
+
|
39
|
+
alias_tag 'resource-ref'
|
40
|
+
alias_tag 'description'
|
41
|
+
alias_tag 'res-ref-tag'
|
42
|
+
alias_tag 'res-ref-name'
|
43
|
+
alias_tag 'res-type'
|
44
|
+
alias_tag 'res-auth'
|
45
|
+
|
46
|
+
# Write a context param tag unless value is nil.
|
47
|
+
def context_param!(name, value)
|
48
|
+
return unless value
|
49
|
+
context_param { |p|
|
50
|
+
p.param_name name
|
51
|
+
p.param_value value
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
# Write an init param tag unless value is nil.
|
56
|
+
def init_param!(name, value)
|
57
|
+
return unless value
|
58
|
+
init_param { |p|
|
59
|
+
p.param_name name
|
60
|
+
p.param_value value
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def listener!(klass)
|
65
|
+
listener { |w| w.listener_class(klass) }
|
66
|
+
end
|
67
|
+
|
68
|
+
def web_app!(version, metadata_complete = true, &block)
|
69
|
+
xmlns, schema_loc =
|
70
|
+
case version.to_s
|
71
|
+
when '2.5'
|
72
|
+
j2ee = 'http://java.sun.com/xml/ns/j2ee'
|
73
|
+
[j2ee, "#{j2ee}/web-app_2_5.xsd"]
|
74
|
+
when '3.0'
|
75
|
+
javaee = 'http://java.sun.com/xml/ns/javaee'
|
76
|
+
[javaee, "#{javaee} #{javaee}/web-app_3_0.xsd"]
|
77
|
+
else
|
78
|
+
raise ArgumentError, "unknown java servlet version #{version}"
|
79
|
+
end
|
80
|
+
|
81
|
+
web_app('xmlns' => xmlns,
|
82
|
+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
83
|
+
'xsi:schemaLocation' => schema_loc,
|
84
|
+
'version' => version.to_s,
|
85
|
+
'metadata-complete' => metadata_complete,
|
86
|
+
&block)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rubylet/war_task'
|
3
|
+
|
4
|
+
module Rubylet
|
5
|
+
JAVAEE_SCHEMA = 'http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd'
|
6
|
+
|
7
|
+
describe WarTask do
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@task = WarTask.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'generates web.xml' do
|
14
|
+
xml = @task.webapp_descriptor
|
15
|
+
xml.must_validate JAVAEE_SCHEMA
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'generates glassfish-web.xml' do
|
19
|
+
@task.glassfish_descriptor
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'generates jetty-web.xml' do
|
24
|
+
@task.jetty_descriptor
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'adds servlet descriptors' do
|
28
|
+
@task.compile_mode = 'JIT'
|
29
|
+
@task.static_file_filter
|
30
|
+
@task.rubylet do |s|
|
31
|
+
s.name = 'myname'
|
32
|
+
end
|
33
|
+
@task.rubylet do |s|
|
34
|
+
s.name = 'MyOtherServlet'
|
35
|
+
end
|
36
|
+
xml = @task.webapp_descriptor
|
37
|
+
|
38
|
+
xml.must_validate JAVAEE_SCHEMA
|
39
|
+
|
40
|
+
# puts xml
|
41
|
+
xml.must_match %r{<servlet-name>myname</servlet-name>}
|
42
|
+
xml.must_match %r{rubylet.Servlet</servlet-class>}
|
43
|
+
end
|
44
|
+
|
45
|
+
# it 'generate war' do
|
46
|
+
# Rake::Task['war'].invoke
|
47
|
+
# end
|
48
|
+
|
49
|
+
# it 'runs maven' do
|
50
|
+
# @task.mvn('--version')
|
51
|
+
# end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
if RUBY_VERSION =~ /^1.8/
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'minitest'
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'minitest/spec'
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'minitest/matchers'
|
9
|
+
|
10
|
+
# Validation matcher of XMl text against a schema. TODO: should fetch
|
11
|
+
# and report line number from underlying java exception.
|
12
|
+
#
|
13
|
+
# Requires Java.
|
14
|
+
class Validate
|
15
|
+
attr_reader :schema_url
|
16
|
+
|
17
|
+
attr_accessor :schema_url, :error
|
18
|
+
|
19
|
+
def initialize(schema_url)
|
20
|
+
@schema_url = schema_url
|
21
|
+
end
|
22
|
+
|
23
|
+
def failure_message
|
24
|
+
" expected no errors but got #{error}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def negative_failure_message
|
28
|
+
' expected errors but got none'
|
29
|
+
end
|
30
|
+
|
31
|
+
def description
|
32
|
+
"validate against XML schema #{schema_url}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def matches?(subject)
|
36
|
+
factory =
|
37
|
+
Java::JavaxXmlValidation::SchemaFactory.newInstance('http://www.w3.org/2001/XMLSchema')
|
38
|
+
|
39
|
+
url = Java::JavaNet::URL.new(schema_url)
|
40
|
+
schema = factory.newSchema(url)
|
41
|
+
validator = schema.newValidator
|
42
|
+
reader = Java::JavaIO::StringReader.new(subject.to_s)
|
43
|
+
source = Java::JavaxXmlTransformStream::StreamSource.new(reader)
|
44
|
+
|
45
|
+
begin
|
46
|
+
validator.validate(source)
|
47
|
+
true
|
48
|
+
rescue => e
|
49
|
+
self.error = e.message
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
MiniTest::Unit::TestCase.register_matcher Validate, :validate
|
metadata
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubylet-tasks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: java
|
7
|
+
authors:
|
8
|
+
- CG Labs
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: builder
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: !binary |-
|
21
|
+
MA==
|
22
|
+
none: false
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: !binary |-
|
28
|
+
MA==
|
29
|
+
none: false
|
30
|
+
prerelease: false
|
31
|
+
type: :runtime
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: rake
|
34
|
+
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: !binary |-
|
39
|
+
MA==
|
40
|
+
none: false
|
41
|
+
requirement: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: !binary |-
|
46
|
+
MA==
|
47
|
+
none: false
|
48
|
+
prerelease: false
|
49
|
+
type: :runtime
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: zip
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: !binary |-
|
57
|
+
MA==
|
58
|
+
none: false
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: !binary |-
|
64
|
+
MA==
|
65
|
+
none: false
|
66
|
+
prerelease: false
|
67
|
+
type: :runtime
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: mini_aether
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: !binary |-
|
75
|
+
MA==
|
76
|
+
none: false
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: !binary |-
|
82
|
+
MA==
|
83
|
+
none: false
|
84
|
+
prerelease: false
|
85
|
+
type: :development
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: minitest
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: !binary |-
|
93
|
+
MA==
|
94
|
+
none: false
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: !binary |-
|
100
|
+
MA==
|
101
|
+
none: false
|
102
|
+
prerelease: false
|
103
|
+
type: :development
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: minitest-matchers
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: !binary |-
|
111
|
+
MA==
|
112
|
+
none: false
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: !binary |-
|
118
|
+
MA==
|
119
|
+
none: false
|
120
|
+
prerelease: false
|
121
|
+
type: :development
|
122
|
+
- !ruby/object:Gem::Dependency
|
123
|
+
name: version
|
124
|
+
version_requirements: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: !binary |-
|
129
|
+
MA==
|
130
|
+
none: false
|
131
|
+
requirement: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: !binary |-
|
136
|
+
MA==
|
137
|
+
none: false
|
138
|
+
prerelease: false
|
139
|
+
type: :development
|
140
|
+
description: ''
|
141
|
+
email:
|
142
|
+
- eng@commongroundpublishing.com
|
143
|
+
executables: []
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- VERSION
|
148
|
+
- MIT-LICENSE
|
149
|
+
- lib/rubylet/builder_alias_tag.rb
|
150
|
+
- lib/rubylet/builder_defaults.rb
|
151
|
+
- lib/rubylet/war_task.rb
|
152
|
+
- lib/rubylet/webapp_descriptor_builder.rb
|
153
|
+
- lib/rubylet/jetty_descriptor_builder.rb
|
154
|
+
- lib/rubylet/glassfish_descriptor_builder.rb
|
155
|
+
- lib/rubylet-ee-0.1.0-SNAPSHOT.jar
|
156
|
+
- spec/spec_helper.rb
|
157
|
+
- spec/rubylet/war_task_spec.rb
|
158
|
+
- examples/Gemfile~
|
159
|
+
- examples/Gemfile
|
160
|
+
- examples/Rakefile~
|
161
|
+
- examples/Gemfile.lock
|
162
|
+
- examples/Rakefile
|
163
|
+
- examples/config.ru
|
164
|
+
- examples/pkg/test_app.war
|
165
|
+
- examples/tmp/restart.txt
|
166
|
+
homepage:
|
167
|
+
licenses: []
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ! '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: !binary |-
|
177
|
+
MA==
|
178
|
+
none: false
|
179
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ! '>='
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: !binary |-
|
184
|
+
MA==
|
185
|
+
none: false
|
186
|
+
requirements: []
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 1.8.24
|
189
|
+
signing_key:
|
190
|
+
specification_version: 3
|
191
|
+
summary: Rake tasks for rubylet, rubylet-ee, and Java servlets
|
192
|
+
test_files: []
|