torquebox-core 3.2.0-java → 4.0.0.alpha1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/bin/torquebox +20 -0
  3. data/lib/resources/logback-cli.xml +12 -0
  4. data/lib/torquebox-core.jar +0 -0
  5. data/lib/torquebox-core.rb +51 -10
  6. data/lib/torquebox/cli.rb +129 -0
  7. data/lib/torquebox/cli/jar.rb +336 -0
  8. data/lib/torquebox/cli/war.rb +140 -0
  9. data/lib/torquebox/codecs.rb +35 -36
  10. data/lib/torquebox/codecs/edn.rb +39 -24
  11. data/lib/torquebox/codecs/json.rb +45 -44
  12. data/lib/torquebox/codecs/marshal.rb +25 -25
  13. data/lib/torquebox/codecs/marshal_base64.rb +26 -25
  14. data/lib/torquebox/codecs/marshal_smart.rb +34 -33
  15. data/lib/torquebox/codecs/text.rb +35 -0
  16. data/lib/torquebox/logger.rb +19 -129
  17. data/lib/torquebox/option_utils.rb +72 -0
  18. data/lib/torquebox/spec_helpers.rb +48 -0
  19. data/lib/torquebox/version.rb +20 -0
  20. data/lib/wunderboss-jars/jboss-logging-3.1.4.GA.jar +0 -0
  21. data/lib/wunderboss-jars/logback-classic-1.1.2.jar +0 -0
  22. data/lib/wunderboss-jars/logback-core-1.1.2.jar +0 -0
  23. data/lib/wunderboss-jars/slf4j-api-1.7.5.jar +0 -0
  24. data/lib/wunderboss-jars/wunderboss-core-1.x.incremental.174.jar +0 -0
  25. data/lib/wunderboss-jars/wunderboss-ruby-1.x.incremental.174.jar +0 -0
  26. data/lib/wunderboss-jars/wunderboss-wildfly-1.x.incremental.174.jar +0 -0
  27. metadata +71 -61
  28. data/lib/gem_hook.rb +0 -18
  29. data/lib/torquebox/component_manager.rb +0 -32
  30. data/lib/torquebox/core.rb +0 -29
  31. data/lib/torquebox/injectors.rb +0 -81
  32. data/lib/torquebox/kernel.rb +0 -47
  33. data/lib/torquebox/msc.rb +0 -98
  34. data/lib/torquebox/registry.rb +0 -52
  35. data/lib/torquebox/scheduled_job.rb +0 -245
  36. data/lib/torquebox/service.rb +0 -77
  37. data/lib/torquebox/service_registry.rb +0 -68
  38. data/licenses/cc0-1.0.txt +0 -121
  39. data/spec/codecs_spec.rb +0 -87
  40. data/spec/injectors_spec.rb +0 -28
  41. data/spec/kernel_spec.rb +0 -47
  42. data/spec/logger_spec.rb +0 -103
  43. data/spec/scheduled_job_spec.rb +0 -57
  44. data/spec/service_registry_spec.rb +0 -52
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da4f0ba096b358f19a5bc5761a10236f7a60f2fd
4
- data.tar.gz: 316aea8fd629d6ddf05e3b2a531a8f3424c68702
3
+ metadata.gz: e8cf11a23000d1db2bbf771b2d4a8ae8c177cc2d
4
+ data.tar.gz: b8875fb8ee9f5d3d144ecad52976ae5aa1e69f05
5
5
  SHA512:
6
- metadata.gz: f4d6ab43537ebfb98c7b5d4610982d50dce27fee9389a2c6fe582ab41b1f8a32fcbaf762b30e2bd578f04dfc396be3eb5adf4ffcbc8d41c80370a3c16794f1ea
7
- data.tar.gz: 35e33b27a2fd5db90e200a050fca8bcd6ce2d04f24d47b2005ca671ddf6c3c221454690c6adacd3ec77b72a810f2d961087ca84842b5ea0dbf97b6899c7344d0
6
+ metadata.gz: 7f867844665d4c0f451b6de698c9b9f3d08ec046a65d0a3992e36c1040c9541990683d02d8373ccdbf22cc00690cf106e72dbb0179084d68054cf026eb449bfe
7
+ data.tar.gz: d57604b36264857fa2ce6d19db91b962f9450503255ab1c2a90635470a8a04736aeb02143460b654fd19133629e7b5a3aeaf6b6355502b5d90d427febb16e273
data/bin/torquebox ADDED
@@ -0,0 +1,20 @@
1
+ # Copyright 2014 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ java.lang.System.set_property('logback.configurationFile',
16
+ File.join(File.dirname(__FILE__), '..', 'lib', 'resources', 'logback-cli.xml'))
17
+
18
+ require 'torquebox-core'
19
+
20
+ cli = TorqueBox::CLI.new(ARGV)
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <configuration>
4
+ <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
5
+ <encoder>
6
+ <pattern>%date{HH:mm:ss.SSS} %-5level %message%n</pattern>
7
+ </encoder>
8
+ </appender>
9
+ <root level="INFO">
10
+ <appender-ref ref="Console"/>
11
+ </root>
12
+ </configuration>
Binary file
@@ -1,13 +1,54 @@
1
- module TorqueboxCore
2
- VERSION = '3.2.0'
3
- MAVEN_VERSION = '3.2.0'
1
+ # Copyright 2014 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "pathname"
16
+
17
+ module TorqueBox
18
+
19
+ # @api private
20
+ JAR_MARKER = "torquebox_jar_marker"
21
+
22
+ # @api private
23
+ EXPLODED_JAR = !JRuby.classloader_resources(JAR_MARKER).empty?
24
+
25
+ class Jars
26
+ class << self
27
+ def register_and_require(jar)
28
+ path = Pathname.new(jar)
29
+ raise 'Jars must be registered using absolute paths' unless path.absolute?
30
+ jar = path.expand_path.to_s
31
+ @jars ||= []
32
+ @jars << jar
33
+ require jar unless EXPLODED_JAR
34
+ end
35
+
36
+ def list
37
+ @jars
38
+ end
39
+ end
40
+ end
4
41
  end
5
- begin
6
- require 'java'
7
- require File.dirname(__FILE__) + '/torquebox-core.jar'
8
- rescue LoadError
9
- puts 'JAR-based gems require JRuby to load. Please visit www.jruby.org.'
10
- raise
42
+
43
+ Dir.glob("#{File.dirname(__FILE__)}/wunderboss-jars/*.jar") do |jar|
44
+ TorqueBox::Jars.register_and_require(jar)
11
45
  end
12
46
 
13
- load File.dirname(__FILE__) + '/gem_hook.rb' if File.exists?( File.dirname(__FILE__) + '/gem_hook.rb')
47
+ TorqueBox::Jars.register_and_require("#{File.dirname(__FILE__)}/torquebox-core.jar")
48
+ require 'torquebox/cli'
49
+ require 'torquebox/cli/jar'
50
+ require 'torquebox/cli/war'
51
+ require 'torquebox/logger'
52
+ require 'torquebox/option_utils'
53
+ require 'torquebox/version'
54
+ require 'torquebox/codecs'
@@ -0,0 +1,129 @@
1
+ # Copyright 2014 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'optparse'
16
+
17
+ module TorqueBox
18
+ class CLI
19
+
20
+ class << self
21
+ def extensions
22
+ @extensions ||= {}
23
+ end
24
+
25
+ def extension_descriptions
26
+ @extension_descriptions ||= {}
27
+ end
28
+
29
+ def register_extension(command, extension, description)
30
+ extensions[command] = extension
31
+ extension_descriptions[command] = description
32
+ end
33
+ end
34
+
35
+ def initialize(argv)
36
+ require_torquebox_gems
37
+ options = {}
38
+ extension = TorqueBox::CLI.extensions[argv.first]
39
+ parser = OptionParser.new
40
+ if extension
41
+ setup_extension_parser(extension, argv.shift, parser, options)
42
+ else
43
+ setup_usage_parser(parser)
44
+ end
45
+
46
+ setup_common_parser(parser, options)
47
+ begin
48
+ parser.parse!(argv)
49
+ rescue OptionParser::InvalidOption => e
50
+ puts e.message
51
+ puts
52
+ puts parser
53
+ exit 1
54
+ end
55
+
56
+
57
+ if extension
58
+ log_level = case options.delete(:verbosity)
59
+ when :quiet then 'ERROR'
60
+ when :verbose then 'DEBUG'
61
+ when :really_verbose then 'TRACE'
62
+ else 'INFO'
63
+ end
64
+ TorqueBox::Logger.log_level = log_level
65
+ extension.run(argv, options)
66
+ else
67
+ puts parser
68
+ exit 1
69
+ end
70
+ end
71
+
72
+ def setup_extension_parser(extension, command, parser, options)
73
+ parser.banner = "Usage: torquebox #{command} #{extension.usage_parameters}"
74
+ parser.separator TorqueBox::CLI.extension_descriptions[command]
75
+ parser.separator ""
76
+ parser.separator "#{command} options:"
77
+ extension.setup_parser(parser, options)
78
+ end
79
+
80
+ def setup_usage_parser(parser)
81
+ parser.banner = "Usage: torquebox [command] [options]"
82
+ parser.separator ""
83
+ parser.separator "Commands:"
84
+ TorqueBox::CLI.extensions.keys.each do |command|
85
+ description = TorqueBox::CLI.extension_descriptions[command]
86
+ command = "#{command}:".ljust(8)
87
+ parser.separator " #{command} #{description}"
88
+ end
89
+ parser.separator ""
90
+ parser.separator "Installing additional torquebox gems may provide additional commands."
91
+ parser.separator "'torquebox [command] -h' for additional help on each command"
92
+ end
93
+
94
+ def setup_common_parser(parser, options)
95
+ parser.separator ""
96
+ parser.separator "Common options:"
97
+ parser.on '-q', '--quiet', 'Log only errors' do
98
+ options[:verbosity] = :quiet
99
+ end
100
+ parser.on '-v', '--verbose', 'Log more - use twice for even more' do
101
+ if options[:verbosity] == :verbose
102
+ options[:verbosity] = :really_verbose
103
+ else
104
+ options[:verbosity] = :verbose
105
+ end
106
+ end
107
+ parser.on_tail('-h', '--help', 'Show this message') do
108
+ puts parser
109
+ exit 1
110
+ end
111
+ parser.on_tail('--version', 'Show version') do
112
+ puts "TorqueBox #{TorqueBox::VERSION}"
113
+ exit 1
114
+ end
115
+ end
116
+
117
+ def require_torquebox_gems
118
+ # Ensure all other known TorqueBox gems are loaded so we can see their
119
+ # CLI extensions and jars
120
+ %W(torquebox-web torquebox-messaging torquebox-scheduling torquebox-caching).each do |gem|
121
+ begin
122
+ require gem
123
+ rescue LoadError
124
+ end
125
+ end
126
+ end
127
+
128
+ end
129
+ end
@@ -0,0 +1,336 @@
1
+ # Copyright 2014 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'fileutils'
16
+ require 'pathname'
17
+ require 'rbconfig'
18
+ require 'tmpdir'
19
+ require 'torquebox-core'
20
+
21
+ module TorqueBox
22
+ class CLI
23
+ class Jar
24
+
25
+ DEFAULT_INIT = "require 'torquebox-web'; \
26
+ if org.projectodd.wunderboss.WunderBoss.options.get('wildfly-service').nil?; \
27
+ begin; \
28
+ TorqueBox::CLI.new(ARGV.unshift('run')); \
29
+ rescue SystemExit => e; \
30
+ status = e.respond_to?(:status) ? e.status : 0; \
31
+ java.lang.System.exit(status); \
32
+ end; \
33
+ else; \
34
+ TorqueBox::Web.run(:rackup => '$$rackup$$'); \
35
+ end;"
36
+
37
+ def initialize
38
+ @logger = org.projectodd.wunderboss.WunderBoss.logger('TorqueBox')
39
+ @classpath = []
40
+ end
41
+
42
+ def usage_parameters
43
+ "[options]"
44
+ end
45
+
46
+ def option_defaults
47
+ {
48
+ :destination => '.',
49
+ :jar_name => "#{File.basename(Dir.pwd)}.jar",
50
+ :include_jruby => true,
51
+ :bundle_gems => true,
52
+ :bundle_without => %W(development test assets),
53
+ :rackup => 'config.ru'
54
+ }
55
+ end
56
+
57
+ def available_options
58
+ defaults = option_defaults
59
+ [{
60
+ :name => :destination,
61
+ :switch => '--destination PATH',
62
+ :description => "Destination directory for the jar file (default: #{defaults[:destination]})"
63
+ },
64
+ {
65
+ :name => :jar_name,
66
+ :switch => '--name NAME',
67
+ :description => "Name of the jar file (default: #{defaults[:jar_name]})"
68
+ },
69
+ {
70
+ :name => :include_jruby,
71
+ :switch => '--[no-]include-jruby',
72
+ :description => "Include JRuby in the jar (default: #{defaults[:include_jruby]})"
73
+ },
74
+ {
75
+ :name => :bundle_gems,
76
+ :switch => '--[no-]bundle-gems',
77
+ :description => "Bundle gem dependencies in the jar (default: #{defaults[:bundle_gems]})"
78
+ },
79
+ {
80
+ :name => :bundle_without,
81
+ :switch => '--bundle-without GROUPS',
82
+ :description => "Bundler groups to skip (default: #{defaults[:bundle_without]})",
83
+ :type => Array
84
+ },
85
+ {
86
+ :name => :main,
87
+ :switch => '--main MAIN',
88
+ :description => 'File to require to bootstrap the application (if not given, assumes a web app)'
89
+ }]
90
+ end
91
+
92
+ def setup_parser(parser, options)
93
+ available_options.each do |opt|
94
+ parser.on(*(opt.values_at(:short, :switch, :type, :description).compact)) do |arg|
95
+ options[opt[:name]] = arg
96
+ end
97
+ end
98
+ parser.on('--envvar KEY=VALUE',
99
+ 'Specify an environment variable to set before running the app') do |arg|
100
+ key, value = arg.split('=')
101
+ if key.nil? || value.nil?
102
+ $stderr.puts "Error: Environment variables must be separated by '='"
103
+ exit 1
104
+ end
105
+ options[:envvar] ||= {}
106
+ options[:envvar][key] = value
107
+ end
108
+ end
109
+
110
+ def run(_argv, options)
111
+ options = option_defaults.merge(options)
112
+ jar_path = File.join(options[:destination], options[:jar_name])
113
+ @logger.debug("Creating jar with options {}", options.inspect)
114
+
115
+ if options[:main]
116
+ init = "require '#{options[:main]}'"
117
+ else
118
+ init = DEFAULT_INIT.sub('$$rackup$$', options[:rackup])
119
+ end
120
+
121
+ jar_builder = org.torquebox.core.JarBuilder.new
122
+ jar_builder.add_manifest_attribute("Main-Class", "org.torquebox.core.TorqueBoxMain")
123
+ jar_builder.add_string(TorqueBox::JAR_MARKER, "")
124
+
125
+ add_torquebox_files(jar_builder)
126
+
127
+ if options[:include_jruby]
128
+ add_jruby_files(jar_builder)
129
+ end
130
+
131
+ add_app_files(jar_builder)
132
+
133
+ if options[:bundle_gems]
134
+ tmpdir = Dir.mktmpdir("tmptorqueboxjar", ".")
135
+ add_bundler_files(jar_builder, tmpdir, options[:bundle_without])
136
+ end
137
+
138
+ jar_builder.add_string("META-INF/app.properties",
139
+ app_properties(options[:envvar] || {}, init))
140
+
141
+ if File.exist?(jar_path)
142
+ @logger.info("Removing {}", jar_path)
143
+ FileUtils.rm_f(jar_path)
144
+ end
145
+ @logger.info("Writing {}", jar_path)
146
+ jar_builder.create(jar_path)
147
+ jar_path
148
+ ensure
149
+ FileUtils.rm_rf(tmpdir) if tmpdir
150
+ end
151
+
152
+ def add_jruby_files(jar_builder)
153
+ @logger.trace("Adding JRuby files to jar...")
154
+ rb_config = RbConfig::CONFIG
155
+ add_files(jar_builder,
156
+ :file_prefix => rb_config["prefix"],
157
+ :pattern => "/*",
158
+ :jar_prefix => "jruby")
159
+ add_files(jar_builder,
160
+ :file_prefix => rb_config["libdir"],
161
+ :pattern => "/**/*",
162
+ :jar_prefix => "jruby/lib",
163
+ :exclude => ["jruby.jar", "ruby/gems/shared"])
164
+ add_files(jar_builder,
165
+ :file_prefix => rb_config["bindir"],
166
+ :pattern => "/*",
167
+ :jar_prefix => "jruby/bin")
168
+ add_jar(jar_builder, "#{rb_config['libdir']}/jruby.jar")
169
+ end
170
+
171
+ def add_app_files(jar_builder)
172
+ @logger.trace("Adding application files to jar...")
173
+ add_files(jar_builder,
174
+ :file_prefix => Dir.pwd,
175
+ :pattern => "/**/*",
176
+ :jar_prefix => "app",
177
+ :exclude => [%r{^/[^/]*\.(jar|war)}])
178
+ end
179
+
180
+ def add_bundler_files(jar_builder, tmpdir, bundle_without)
181
+ @logger.trace("Adding bundler files to jar...")
182
+ unless File.exist?(ENV['BUNDLE_GEMFILE'] || 'Gemfile')
183
+ @logger.info("No Gemfile found - skipping gem dependencies")
184
+ return {}
185
+ end
186
+ @logger.info("Bundling gem dependencies")
187
+ require 'bundler'
188
+
189
+ copy_bundle_config(tmpdir)
190
+
191
+ vendor_dir_exists = File.exist?('vendor')
192
+ cache_dir_exists = File.exist?('vendor/cache')
193
+ bundle_dir_exists = File.exist?('vendor/bundle')
194
+ already_cached = Dir.glob('vendor/cache/*.gem').count > 0
195
+ already_bundled = Pathname.new(Bundler.settings.path).relative?
196
+
197
+ lockfile = Bundler.default_lockfile
198
+ original_lockfile = File.exist?(lockfile) ? File.read(lockfile) : nil
199
+
200
+ cache_gems(tmpdir) unless already_cached
201
+ bundle_gems(tmpdir, bundle_without) unless already_bundled
202
+ copy_cached_gems(tmpdir) unless already_cached
203
+ copy_and_restore_lockfile(tmpdir, lockfile, original_lockfile)
204
+
205
+ add_files(jar_builder,
206
+ :file_prefix => tmpdir,
207
+ :pattern => "/{**/*,.bundle/**/*}",
208
+ :jar_prefix => "app",
209
+ :exclude => TorqueBox::Jars.list.map { |j| File.basename(j) })
210
+ Gem.default_path.each do |prefix|
211
+ add_files(jar_builder,
212
+ :file_prefix => prefix,
213
+ :pattern => "/**/bundler-#{Bundler::VERSION}{*,/**/*}",
214
+ :jar_prefix => "jruby/lib/ruby/gems/shared")
215
+ end
216
+ ensure
217
+ FileUtils.rm_rf('vendor/bundle') unless bundle_dir_exists
218
+ FileUtils.rm_rf('vendor/cache') unless cache_dir_exists
219
+ FileUtils.rm_rf('vendor') unless vendor_dir_exists
220
+ end
221
+
222
+ def copy_bundle_config(tmpdir)
223
+ if File.exist?('.bundle/config')
224
+ FileUtils.mkdir_p("#{tmpdir}/.bundle")
225
+ FileUtils.cp('.bundle/config', "#{tmpdir}/.bundle")
226
+ end
227
+ end
228
+
229
+ def cache_gems(tmpdir)
230
+ eval_in_new_ruby <<-EOS
231
+ ENV['BUNDLE_APP_CONFIG'] = "#{tmpdir}/.bundle"
232
+ require 'bundler/cli'
233
+ Bundler::CLI.start(['cache', '--all'])
234
+ EOS
235
+ end
236
+
237
+ def bundle_gems(tmpdir, bundle_without)
238
+ install_options = %W(--local --path vendor/bundle --no-cache)
239
+ unless bundle_without.empty?
240
+ install_options += %W(--without #{bundle_without.join(' ')})
241
+ end
242
+ eval_in_new_ruby <<-EOS
243
+ ENV['BUNDLE_APP_CONFIG'] = "#{tmpdir}/.bundle"
244
+ require 'bundler/cli'
245
+ Bundler::CLI.start(['install'] + #{install_options.inspect})
246
+ EOS
247
+ FileUtils.mkdir_p("#{tmpdir}/vendor/bundle/jruby")
248
+ FileUtils.cp_r('vendor/bundle/jruby', "#{tmpdir}/vendor/bundle/")
249
+ end
250
+
251
+ def copy_cached_gems(tmpdir)
252
+ FileUtils.mkdir_p("#{tmpdir}/vendor/cache")
253
+ FileUtils.cp_r('vendor/cache', "#{tmpdir}/vendor/")
254
+ end
255
+
256
+ def copy_and_restore_lockfile(tmpdir, lockfile, original_lockfile)
257
+ new_lockfile = File.exist?(lockfile) ? File.read(lockfile) : nil
258
+ FileUtils.cp(lockfile, "#{tmpdir}/Gemfile.lock") if new_lockfile
259
+ if original_lockfile.nil? && !new_lockfile.nil?
260
+ FileUtils.rm_f(lockfile)
261
+ elsif original_lockfile != new_lockfile
262
+ File.open(lockfile, 'w') { |f| f.write(original_lockfile) }
263
+ end
264
+ end
265
+
266
+ def add_jar(jar_builder, jar)
267
+ @logger.debug("Adding jar {}", jar)
268
+ jar_name = "jars/#{File.basename(jar)}"
269
+ @classpath << "${extract_root}/#{jar_name}"
270
+ jar_builder.add_file(jar_name, jar)
271
+ end
272
+
273
+ def add_torquebox_files(jar_builder)
274
+ TorqueBox::Jars.list.each do |jar|
275
+ if File.basename(jar) =~ /^wunderboss-(rack|ruby).*?\.jar$/
276
+ add_jar(jar_builder, jar)
277
+ else
278
+ @logger.debug("Shading jar {}", jar)
279
+ jar_builder.shade_jar(jar)
280
+ end
281
+ end
282
+ end
283
+
284
+ def add_files(jar_builder, options)
285
+ prefix = options[:file_prefix]
286
+ prefix += '/' unless prefix.end_with?('/')
287
+ Dir.glob("#{prefix}#{options[:pattern]}").each do |file|
288
+ suffix = file.sub(prefix, '')
289
+ excludes = [options[:exclude]].compact.flatten
290
+ next if excludes.any? do |exclude|
291
+ if exclude.is_a?(Regexp)
292
+ exclude =~ suffix
293
+ else
294
+ suffix.include?(exclude)
295
+ end
296
+ end
297
+ next if suffix.include?("tmptorqueboxjar")
298
+ in_jar_name = options[:jar_prefix] ? File.join(options[:jar_prefix], suffix) : suffix
299
+ jar_builder.add_file(in_jar_name, file)
300
+ end
301
+ end
302
+
303
+ def eval_in_new_ruby(script)
304
+ ruby = org.jruby.Ruby.new_instance
305
+ unless %W(DEBUG TRACE).include?(TorqueBox::Logger.log_level)
306
+ dev_null = PLATFORM =~ /mswin/ ? 'NUL' : '/dev/null'
307
+ ruby.evalScriptlet("$stdout = File.open('#{dev_null}', 'w')")
308
+ end
309
+ ruby.evalScriptlet(script)
310
+ end
311
+
312
+ def app_properties(env, init)
313
+ env_str = env.map do |key, value|
314
+ "ENV['#{key}']||='#{value}';"
315
+ end.join(' ')
316
+ classpath_str = @classpath.join(':')
317
+
318
+ <<-EOS
319
+ language=ruby
320
+ extract_paths=app/:jruby/:jars/
321
+ root=${extract_root}/app
322
+ classpath=#{classpath_str}
323
+ init=ENV['BUNDLE_GEMFILE'] = nil; \
324
+ #{env_str} \
325
+ require "bundler/setup"; \
326
+ #{init}; \
327
+ require "torquebox/spec_helpers"; \
328
+ TorqueBox::SpecHelpers.booted
329
+ EOS
330
+ end
331
+ end
332
+ end
333
+ end
334
+
335
+ TorqueBox::CLI.register_extension('jar', TorqueBox::CLI::Jar.new,
336
+ 'Create an executable jar from an application')