warbler_updated 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +10 -0
  3. data/History.txt +411 -0
  4. data/LICENSE.txt +27 -0
  5. data/Mavenfile +32 -0
  6. data/README.rdoc +280 -0
  7. data/Rakefile +63 -0
  8. data/bin/warble +11 -0
  9. data/ext/JarMain.java +334 -0
  10. data/ext/WarMain.java +375 -0
  11. data/ext/WarblerJar.java +199 -0
  12. data/ext/WarblerJarService.java +18 -0
  13. data/lib/warbler/application.rb +104 -0
  14. data/lib/warbler/bundler_helper.rb +22 -0
  15. data/lib/warbler/config.rb +265 -0
  16. data/lib/warbler/executable_helper.rb +25 -0
  17. data/lib/warbler/gems.rb +77 -0
  18. data/lib/warbler/jar.rb +348 -0
  19. data/lib/warbler/pathmap_helper.rb +20 -0
  20. data/lib/warbler/platform_helper.rb +26 -0
  21. data/lib/warbler/rake_helper.rb +30 -0
  22. data/lib/warbler/scripts/rails.rb +5 -0
  23. data/lib/warbler/task.rb +185 -0
  24. data/lib/warbler/templates/bundler.erb +19 -0
  25. data/lib/warbler/templates/config.erb +1 -0
  26. data/lib/warbler/templates/jar.erb +11 -0
  27. data/lib/warbler/templates/jbundler.erb +2 -0
  28. data/lib/warbler/templates/rack.erb +5 -0
  29. data/lib/warbler/templates/rails.erb +1 -0
  30. data/lib/warbler/templates/war.erb +19 -0
  31. data/lib/warbler/traits/bundler.rb +157 -0
  32. data/lib/warbler/traits/gemspec.rb +79 -0
  33. data/lib/warbler/traits/jar.rb +58 -0
  34. data/lib/warbler/traits/jbundler.rb +48 -0
  35. data/lib/warbler/traits/nogemspec.rb +47 -0
  36. data/lib/warbler/traits/rack.rb +33 -0
  37. data/lib/warbler/traits/rails.rb +91 -0
  38. data/lib/warbler/traits/war.rb +260 -0
  39. data/lib/warbler/traits.rb +124 -0
  40. data/lib/warbler/version.rb +10 -0
  41. data/lib/warbler/war.rb +8 -0
  42. data/lib/warbler/web_server.rb +125 -0
  43. data/lib/warbler/zip_support.rb +13 -0
  44. data/lib/warbler.rb +40 -0
  45. data/lib/warbler_jar.jar +0 -0
  46. data/warble.rb +188 -0
  47. data/warbler.gemspec +37 -0
  48. data/web.xml.erb +57 -0
  49. metadata +188 -0
@@ -0,0 +1,22 @@
1
+ #--
2
+ # Copyright (c) 2014-2015 JRuby Team
3
+ # This source code is available under the MIT license.
4
+ # See the file LICENSE.txt for details.
5
+ #++
6
+
7
+ module Warbler
8
+ module BundlerHelper
9
+ def to_spec(spec)
10
+ # JRuby <= 1.7.20 does not handle respond_to? with method_missing right
11
+ # thus a `spec.respond_to?(:to_spec) ? spec.to_spec : spec` won't do :
12
+ if ::Bundler.const_defined?(:StubSpecification) # since Bundler 1.10.1
13
+ spec = spec.to_spec if spec.is_a?(::Bundler::StubSpecification)
14
+ else
15
+ spec = spec.to_spec if spec.respond_to?(:to_spec)
16
+ end
17
+ spec
18
+ end
19
+ module_function :to_spec
20
+ end
21
+ end
22
+
@@ -0,0 +1,265 @@
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 'set'
9
+ require 'warbler/gems'
10
+ require 'warbler/traits'
11
+
12
+ module Warbler
13
+ # Warbler archive assembly configuration class.
14
+ class Config
15
+ include RakeHelper
16
+
17
+ TOP_DIRS = %w(app db config lib log script vendor)
18
+ FILE = "config/warble.rb"
19
+ BUILD_GEMS = %w(warbler rake rcov)
20
+
21
+ include Traits
22
+
23
+ # Features: additional options controlling how the jar is built.
24
+ # Currently the following features are supported:
25
+ # - gemjar: package the gem repository in a jar file in WEB-INF/lib
26
+ # - executable: embed a web server and make the war executable
27
+ # - compiled: compile .rb files to .class files
28
+ attr_accessor :features
29
+
30
+ # Traits: an array of trait classes corresponding to
31
+ # characteristics of the project that are either auto-detected or
32
+ # configured.
33
+ attr_accessor :traits
34
+
35
+ # Deprecated: No longer has any effect.
36
+ attr_accessor :staging_dir
37
+
38
+ # Directory where the war file will be written. Can be used to direct
39
+ # Warbler to place your war file directly in your application server's
40
+ # autodeploy directory. Defaults to the root of the application directory.
41
+ attr_accessor :autodeploy_dir
42
+
43
+ # Top-level directories to be copied into WEB-INF. Defaults to
44
+ # names in TOP_DIRS
45
+ attr_accessor :dirs
46
+
47
+ # Additional files beyond the top-level directories to include in the
48
+ # WEB-INF directory
49
+ attr_accessor :includes
50
+
51
+ # Files to exclude from the WEB-INF directory
52
+ attr_accessor :excludes
53
+
54
+ # Java classes and other files to copy to WEB-INF/classes
55
+ attr_accessor :java_classes
56
+
57
+ # Java libraries to copy to WEB-INF/lib
58
+ attr_accessor :java_libs
59
+
60
+ # Rubygems to install into the webapp.
61
+ attr_accessor :gems
62
+
63
+ # Whether to include dependent gems (default true)
64
+ attr_accessor :gem_dependencies
65
+
66
+ # Array of regular expressions matching relative paths in gems to
67
+ # be excluded from the war. Default contains no exclusions.
68
+ attr_accessor :gem_excludes
69
+
70
+ # Whether to exclude **/*.log files (default is true)
71
+ attr_accessor :exclude_logs
72
+
73
+ # Public HTML directory file list, to be copied into the root of the war
74
+ attr_accessor :public_html
75
+
76
+ # Container of pathmaps used for specifying source-to-destination transformations
77
+ # under various situations (<tt>public_html</tt> and <tt>java_classes</tt> are two
78
+ # entries in this structure).
79
+ attr_accessor :pathmaps
80
+
81
+ # Executable of the jar
82
+ attr_accessor :executable
83
+
84
+ # parameters to pass to the executable
85
+ attr_accessor :executable_params
86
+
87
+ # Name of jar or war file (without the extension), defaults to the
88
+ # directory name containing the application.
89
+ attr_accessor :jar_name
90
+
91
+ # Extension of jar file. Defaults to <tt>jar</tt> or <tt>war</tt> depending on the project.
92
+ attr_accessor :jar_extension
93
+
94
+ # Name of a MANIFEST.MF template to use.
95
+ attr_accessor :manifest_file
96
+
97
+ # Files for WEB-INF directory (next to web.xml). Contains web.xml by default.
98
+ # If there are .erb files they will be processed with webxml config.
99
+ attr_accessor :webinf_files
100
+
101
+ # Use Bundler to locate gems if Gemfile is found. Default is true.
102
+ attr_accessor :bundler
103
+
104
+ # An array of Bundler groups to avoid including in the war file.
105
+ # Defaults to ["development", "test", "assets"].
106
+ attr_accessor :bundle_without
107
+
108
+ # Use JBundler to locate gems if Jarfile is found. Default is true.
109
+ attr_accessor :jbundler
110
+
111
+ # Path to the pre-bundled gem directory inside the war file. Default is '/WEB-INF/gems'.
112
+ # This also sets 'gem.path' inside web.xml.
113
+ attr_accessor :gem_path
114
+
115
+ # List of ruby files to compile to class files. Default is to
116
+ # compile all .rb files in the application.
117
+ attr_accessor :compiled_ruby_files
118
+
119
+ # Determines if ruby files in supporting gems will be compiled.
120
+ # Ignored unless compile feature is used.
121
+ attr_accessor :compile_gems
122
+
123
+ # Desired options passed to JRuby compiler if compiling to class files.
124
+ # Ignored unless compile feature is used.
125
+ attr_accessor :jrubyc_options
126
+
127
+ # Warbler writes an "init" file into the war at this location. JRuby-Rack and possibly other
128
+ # launchers may use this to initialize the Ruby environment.
129
+ attr_accessor :init_filename
130
+
131
+ # Array containing filenames or StringIO's to be concatenated together to form the init file.
132
+ # If the filename ends in .erb the file will be expanded the same way web.xml.erb is; see below.
133
+ attr_accessor :init_contents
134
+
135
+ # Override GEM_HOME environment variable at runtime. When false, gems in
136
+ # GEM_HOME will be loaded in preference to those packaged within the jar
137
+ # file. When true, only gems packaged in the jar file will be loaded.
138
+ # Defaults to true
139
+ attr_accessor :override_gem_home
140
+
141
+ # Explicit bytecode version for compiled ruby files. If given bytecode version is
142
+ # specified when ruby files are compiled using jrubyc
143
+ attr_accessor :bytecode_version
144
+
145
+ # Extra configuration for web.xml. Controls how the dynamically-generated web.xml
146
+ # file is generated.
147
+ #
148
+ # * <tt>webxml.jndi</tt> -- the name of one or more JNDI data sources name to be
149
+ # available to the application. Places appropriate &lt;resource-ref&gt; entries
150
+ # in the file.
151
+ # * <tt>webxml.ignored</tt> -- array of key names that will be not used to
152
+ # generate a context param. Defaults to ['jndi', 'booter']
153
+ #
154
+ # Any other key/value pair placed in the open structure will be dumped as a
155
+ # context parameter in the web.xml file. Some of the recognized values are:
156
+ #
157
+ # * <tt>webxml.rails.env</tt> -- the Rails environment to use for the
158
+ # running application, usually either development or production (the
159
+ # default).
160
+ # * <tt>webxml.gem.path</tt> -- the path to your bundled gem directory
161
+ # * <tt>webxml.jruby.min.runtimes</tt> -- minimum number of pooled runtimes to
162
+ # keep around during idle time
163
+ # * <tt>webxml.jruby.max.runtimes</tt> -- maximum number of pooled Rails
164
+ # application runtimes
165
+ #
166
+ # Note that if you attempt to access webxml configuration keys in a conditional,
167
+ # you might not obtain the result you want. For example:
168
+ # <%= webxml.maybe.present.key || 'default' %>
169
+ # doesn't yield the right result. Instead, you need to generate the context parameters:
170
+ # <%= webxml.context_params['maybe.present.key'] || 'default' %>
171
+ attr_accessor :webxml
172
+
173
+ # Embedded webserver to use. Currently supported webservers are:
174
+ # * <tt>jetty</tt> - Embedded Jetty from Eclipse
175
+ attr_accessor :webserver
176
+
177
+ # If set to true, Warbler will move jar files into the WEB-INF/lib directory of the
178
+ # created war file. This may be needed for some web servers. Defaults to false.
179
+ attr_accessor :move_jars_to_webinf_lib
180
+
181
+ # These file will be placed in the META-INF directory of the jar or war that warbler
182
+ # produces. They are primarily used as launchers by the runnable feature.
183
+ attr_accessor :script_files
184
+
185
+ attr_reader :warbler_templates
186
+ attr_reader :warbler_scripts
187
+
188
+ def initialize(warbler_home = WARBLER_HOME)
189
+ super()
190
+
191
+ @warbler_home = warbler_home
192
+ @warbler_templates = "#{WARBLER_HOME}/lib/warbler/templates"
193
+ @features = Set.new
194
+ @dirs = TOP_DIRS.select {|d| File.directory?(d)}
195
+ @includes = FileList['*file'] # [r/R]akefile gets included
196
+ @excludes = FileList[]
197
+ @java_libs = FileList[]
198
+ @java_classes = FileList[]
199
+ @gems = Warbler::Gems.new
200
+ @gem_dependencies = true
201
+ @gem_excludes = []
202
+ @exclude_logs = true
203
+ @public_html = FileList[]
204
+ @jar_name = File.basename(Dir.getwd)
205
+ @jar_extension = 'jar'
206
+ @webinf_files = FileList[]
207
+ @init_filename = 'META-INF/init.rb'
208
+ @init_contents = ["#{@warbler_templates}/config.erb"]
209
+ @override_gem_home = true
210
+ @script_files = []
211
+ @warbler_scripts = "#{WARBLER_HOME}/lib/warbler/scripts"
212
+ @move_jars_to_webinf_lib = false
213
+ @compile_gems = false
214
+
215
+ before_configure
216
+ yield self if block_given?
217
+ after_configure
218
+
219
+ @compiled_ruby_files ||= FileList[*@dirs.map {|d| "#{d}/**/*.rb"}]
220
+
221
+ @excludes += ["tmp/war", "tmp/war/**/*"] if File.directory?("tmp/war")
222
+ @excludes += ["tmp/cache/**/*"] if File.directory?("tmp/cache")
223
+ @excludes += warbler_vendor_excludes(warbler_home)
224
+ @excludes += FileList["**/*.log"] if @exclude_logs
225
+ end
226
+
227
+ def gems=(value)
228
+ @gems = Warbler::Gems.new(value)
229
+ end
230
+
231
+ def relative_gem_path
232
+ @gem_path[1..-1]
233
+ end
234
+
235
+ def define_tasks
236
+ task "gemjar" do
237
+ self.features << "gemjar"
238
+ end
239
+ task "executable" do
240
+ self.features << "executable"
241
+ end
242
+ task "runnable" do
243
+ self.features << "runnable"
244
+ end
245
+ end
246
+
247
+ alias_method :war_name, :jar_name
248
+ alias_method :war_name=, :jar_name=
249
+
250
+ private
251
+ def warbler_vendor_excludes(warbler_home)
252
+ warbler = File.expand_path(warbler_home)
253
+ if warbler =~ %r{^#{Dir.getwd}/(.*)}
254
+ FileList["#{$1}"]
255
+ else
256
+ []
257
+ end
258
+ end
259
+
260
+ def dump
261
+ YAML::dump(self.dup.tap{|c| c.dump_traits })
262
+ end
263
+ public :dump
264
+ end
265
+ end
@@ -0,0 +1,25 @@
1
+ #--
2
+ # Copyright (c) 2013 Michal Papis.
3
+ # This source code is available under the MIT license.
4
+ # See the file LICENSE.txt for details.
5
+ #++
6
+
7
+ module Warbler
8
+ module ExecutableHelper
9
+ def update_archive_add_executable(jar)
10
+ case executable
11
+ when Array
12
+ gem_name, executable_path = executable
13
+ gem_with_version = config.gems.full_name_for(gem_name, config.gem_dependencies)
14
+ bin_path = apply_pathmaps(config, File.join(gem_with_version, executable_path), :gems)
15
+ else
16
+ bin_path = apply_pathmaps(config, executable, :application)
17
+ end
18
+ add_main_rb(jar, bin_path, config.executable_params)
19
+ end
20
+
21
+ def executable
22
+ config.executable ||= default_executable
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,77 @@
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
+ # A set of gems. This only exists to allow expected operations
10
+ # to be used to add gems, and for backwards compatibility.
11
+ # It would be easier to just use a hash.
12
+ class Gems < Hash
13
+ ANY_VERSION = nil
14
+ private_constant :ANY_VERSION
15
+
16
+ def initialize(gems = nil)
17
+ if gems.is_a?(Hash)
18
+ self.merge!(gems)
19
+ elsif gems.is_a?(Array)
20
+ gems.each {|gem| self << gem }
21
+ end
22
+ end
23
+
24
+ def <<(gem)
25
+ @specs = nil
26
+ self[gem] ||= ANY_VERSION
27
+ end
28
+
29
+ def +(other)
30
+ @specs = nil
31
+ other.each {|g| self[g] ||= ANY_VERSION }
32
+ self
33
+ end
34
+
35
+ def -(other)
36
+ @specs = nil
37
+ other.each {|g| self.delete(g)}
38
+ self
39
+ end
40
+
41
+ def full_name_for(name, gem_dependencies)
42
+ gem_spec = specs(gem_dependencies).detect{ |spec| spec.name == name }
43
+ gem_spec.nil? ? name : gem_spec.full_name
44
+ end
45
+
46
+ def specs(gem_dependencies)
47
+ @specs ||= map { |gem, version| find_single_gem_files(gem_dependencies, gem, version) }.flatten.compact
48
+ end
49
+
50
+ private
51
+
52
+ # Add a single gem to WEB-INF/gems
53
+ def find_single_gem_files(gem_dependencies, gem_pattern, version = nil)
54
+ gem_spec_class = Gem::Specification
55
+ gem_spec_class = Gem::BasicSpecification if Gem.const_defined?(:BasicSpecification)
56
+ # Gem::Specification < Gem::BasicSpecification (since RGs 2.1)
57
+ case gem_pattern
58
+ when gem_spec_class
59
+ return BundlerHelper.to_spec(gem_pattern)
60
+ when Gem::Dependency
61
+ gem = gem_pattern
62
+ else
63
+ gem = Gem::Dependency.new(gem_pattern, Gem::Requirement.create(version))
64
+ end
65
+ # skip development dependencies
66
+ return nil if gem.respond_to?(:type) and gem.type != :runtime
67
+
68
+ # Deal with deprecated Gem.source_index and #search
69
+ matched = gem.respond_to?(:to_spec) ? [ gem.to_spec ] : Gem.source_index.search(gem)
70
+ fail "gem '#{gem}' not installed" if matched.empty?
71
+ spec = matched.last
72
+ return spec unless gem_dependencies
73
+ [spec] + spec.dependencies.map { |dependent_gem| find_single_gem_files(gem_dependencies, dependent_gem) }
74
+ end
75
+
76
+ end
77
+ end