warbler 0.9.14 → 1.0
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/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
data/Gemfile
ADDED
data/History.txt
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
== 1.0
|
2
|
+
|
3
|
+
* Warbler hits 1.0! There are enough structural changes in Warbler
|
4
|
+
that I feel it's time to roll the major version over to 1.0.
|
5
|
+
* Add support for Bundler. Detect Gemfiles, make sure gems are
|
6
|
+
included in the war file and rewrite .bundle/environment.rb inside
|
7
|
+
the war file.
|
8
|
+
* Warbler now uses RubyZip to create the war file in-place, without
|
9
|
+
copying files to a tmp/war staging area. When run in JRuby it uses a
|
10
|
+
Java ZipOutputStream for a modest performance boost.
|
11
|
+
* Add config option to allow override of gem_home (Daniel Harrington).
|
12
|
+
* Stop bundling jruby-rack, as promised.
|
13
|
+
* WARBLER-3: don't add from Rails config.gems if they are frozen
|
14
|
+
* WARBLER-7: Add config.webinf_files option with more support for
|
15
|
+
custom web.xml files
|
16
|
+
|
1
17
|
== 0.9.14
|
2
18
|
|
3
19
|
* So, jruby-rack is bundled for one more release. 1.0 will not contain
|
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
Warbler is provided under the terms of the MIT license.
|
4
4
|
|
5
|
-
(c)
|
5
|
+
Warbler (c) 2010 Engine Yard, Inc.
|
6
|
+
Warbler (c) 2007-2009 Sun Microsystems, Inc.
|
6
7
|
|
7
8
|
Permission is hereby granted, free of charge, to any person
|
8
9
|
obtaining a copy of this software and associated documentation files
|
@@ -23,15 +24,3 @@ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
23
24
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
24
25
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
25
26
|
SOFTWARE.
|
26
|
-
|
27
|
-
= Additional Bundled Software
|
28
|
-
|
29
|
-
JRuby-Rack (jruby-rack-*.jar) is distributed under the terms of the MIT license.
|
30
|
-
See http://svn.codehaus.org/jruby-contrib/trunk/rack/LICENSE.txt
|
31
|
-
for details.
|
32
|
-
|
33
|
-
JRuby (jruby-complete-*.jar) is distrubuted under the terms of the Common
|
34
|
-
Public License. See http://www.eclipse.org/legal/cpl-v10.html for details. At
|
35
|
-
your option, JRuby is also available under the GPL or LGPL licenses. See the
|
36
|
-
file COPYING in the JRuby distribution for details
|
37
|
-
(http://svn.codehaus.org/jruby/trunk/jruby/COPYING).
|
data/Manifest.txt
CHANGED
@@ -1,24 +1,26 @@
|
|
1
|
+
Gemfile
|
1
2
|
History.txt
|
3
|
+
LICENSE.txt
|
2
4
|
Manifest.txt
|
3
5
|
README.txt
|
4
|
-
LICENSES.txt
|
5
6
|
Rakefile
|
6
|
-
web.xml.erb
|
7
7
|
bin/warble
|
8
|
-
|
9
|
-
|
10
|
-
generators/warble/templates/warble.rb
|
11
|
-
generators/warble/warble_generator.rb
|
12
|
-
lib/jruby-rack-0.9.5.jar
|
8
|
+
ext/WarblerWar.java
|
9
|
+
ext/WarblerWarService.java
|
13
10
|
lib/warbler
|
11
|
+
lib/warbler.rb
|
12
|
+
lib/warbler/application.rb
|
14
13
|
lib/warbler/config.rb
|
15
14
|
lib/warbler/gems.rb
|
15
|
+
lib/warbler/runtime.rb
|
16
16
|
lib/warbler/task.rb
|
17
17
|
lib/warbler/version.rb
|
18
|
-
lib/warbler.rb
|
18
|
+
lib/warbler/war.rb
|
19
|
+
lib/warbler_war.jar
|
19
20
|
spec/sample/app/controllers/application.rb
|
20
21
|
spec/sample/app/helpers/application_helper.rb
|
21
22
|
spec/sample/config/boot.rb
|
23
|
+
spec/sample/config/database.yml
|
22
24
|
spec/sample/config/environment.rb
|
23
25
|
spec/sample/config/environments/development.rb
|
24
26
|
spec/sample/config/environments/production.rb
|
@@ -27,8 +29,18 @@ spec/sample/config/initializers/inflections.rb
|
|
27
29
|
spec/sample/config/initializers/mime_types.rb
|
28
30
|
spec/sample/config/initializers/new_rails_defaults.rb
|
29
31
|
spec/sample/config/routes.rb
|
32
|
+
spec/sample/lib/tasks/utils.rake
|
33
|
+
spec/sample/public/404.html
|
34
|
+
spec/sample/public/422.html
|
35
|
+
spec/sample/public/500.html
|
36
|
+
spec/sample/public/favicon.ico
|
37
|
+
spec/sample/public/index.html
|
38
|
+
spec/sample/public/robots.txt
|
30
39
|
spec/spec_helper.rb
|
40
|
+
spec/warbler/application_spec.rb
|
31
41
|
spec/warbler/config_spec.rb
|
32
42
|
spec/warbler/gems_spec.rb
|
33
43
|
spec/warbler/task_spec.rb
|
34
|
-
|
44
|
+
spec/warbler/war_spec.rb
|
45
|
+
warble.rb
|
46
|
+
web.xml.erb
|
data/README.txt
CHANGED
@@ -9,11 +9,6 @@ Warbler provides a sane set of out-of-the box defaults that should allow most
|
|
9
9
|
Rails applications without external gem dependencies (aside from Rails itself)
|
10
10
|
to assemble and Just Work.
|
11
11
|
|
12
|
-
Warbler bundles JRuby and the JRuby-Rack servlet adapter for dispatching
|
13
|
-
requests to your application inside the java application server, and assembles
|
14
|
-
all jar files in WARBLER_HOME/lib/*.jar into your application. No external
|
15
|
-
dependencies are downloaded.
|
16
|
-
|
17
12
|
== Getting Started
|
18
13
|
|
19
14
|
1. Install the gem: <tt>gem install warbler</tt>.
|
@@ -23,26 +18,32 @@ dependencies are downloaded.
|
|
23
18
|
== Usage
|
24
19
|
|
25
20
|
Warbler's +warble+ command is just a small wrapper around Rake with internally
|
26
|
-
defined tasks.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
updated files will be copied, making repeated assemblies much faster.
|
21
|
+
defined tasks.
|
22
|
+
|
23
|
+
$ warble -T
|
24
|
+
warble config # Generate a configuration file to customize your war assembly
|
25
|
+
warble version # Display version of warbler
|
26
|
+
warble war # Create the project .war file
|
27
|
+
warble war:clean # Remove the .war file
|
28
|
+
warble war:debug # Dump diagnostic information
|
29
|
+
|
30
|
+
If you'd like to control Warbler from your own project's Rakefile,
|
31
|
+
simply add the following code somewhere in the Rakefile:
|
32
|
+
|
33
|
+
require 'warbler'
|
34
|
+
Warbler::Task.new
|
35
|
+
|
36
|
+
Now you should be able to invoke "rake war" to create your war file.
|
43
37
|
|
44
38
|
== Configuration
|
45
39
|
|
40
|
+
=== Bundler
|
41
|
+
|
42
|
+
Applications that use Bundler (http://gembundler.com/), detected via
|
43
|
+
presence of a +Gemfile+, will have the gems packaged up into the war
|
44
|
+
file. The .bundle/environment.rb file will be included for you, and
|
45
|
+
rewritten to use the paths to the gems inside the war.
|
46
|
+
|
46
47
|
=== Rails applications
|
47
48
|
|
48
49
|
Rails applications are detected automatically and configured appropriately.
|
@@ -50,7 +51,7 @@ The following items are set up for you:
|
|
50
51
|
|
51
52
|
* The Rails gem is packaged if you haven't vendored Rails.
|
52
53
|
* Other gems configured in Rails.configuration.gems are packaged
|
53
|
-
(Rails 2.1
|
54
|
+
(Rails 2.1 - 2.3)
|
54
55
|
* Multi-thread-safe execution (as introduced in Rails 2.2) is detected
|
55
56
|
and runtime pooling is disabled.
|
56
57
|
|
@@ -98,25 +99,9 @@ doing this. With the gem, simply run
|
|
98
99
|
|
99
100
|
warble config
|
100
101
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
Finally, edit the config/warble.rb to your taste. If you install the gem but
|
106
|
-
later decide you'd like to have it as a plugin, use the +pluginize+ command:
|
107
|
-
|
108
|
-
warble pluginize
|
109
|
-
|
110
|
-
If you wish to upgrade or switch one or more java libraries from what's
|
111
|
-
bundled in the Warbler gem, simply change the jars in WARBLER_HOME/lib, or
|
112
|
-
modify the +java_libs+ attribute of Warbler::Config to include the files you
|
113
|
-
need.
|
114
|
-
|
115
|
-
Once Warbler is installed as a plugin, you can use +rake+ to build the war
|
116
|
-
(with the same set of tasks as above).
|
117
|
-
|
118
|
-
The generated config/warble.rb file is fully-documented with the available
|
119
|
-
options and default values.
|
102
|
+
Finally, edit the config/warble.rb to your taste. The generated
|
103
|
+
config/warble.rb file is fully-documented with the available options
|
104
|
+
and default values.
|
120
105
|
|
121
106
|
=== Web.xml
|
122
107
|
|
@@ -140,13 +125,8 @@ For more information on configuration, see Warbler::Config.
|
|
140
125
|
|
141
126
|
=== Troubleshooting
|
142
127
|
|
143
|
-
If Warbler isn't packaging the files you were expecting,
|
144
|
-
debug
|
145
|
-
|
146
|
-
* <tt>war:debug</tt> prints a YAML dump of the current configuration
|
147
|
-
* <tt>war:debug:X</tt> prints a list of files that Warbler will
|
148
|
-
include during that stage of assembly. Valid values of <tt>X</tt>
|
149
|
-
are <tt>app, java_libs, gems, public, includes, excludes</tt>.
|
128
|
+
If Warbler isn't packaging the files you were expecting, use the
|
129
|
+
war:debug task to give you more insight into what's going on.
|
150
130
|
|
151
131
|
== Source
|
152
132
|
|
@@ -159,12 +139,17 @@ You can get the Warbler source using Git, in any of the following ways:
|
|
159
139
|
You can also download a tarball of Warbler source at
|
160
140
|
http://github.com/nicksieger/warbler/tree/master.
|
161
141
|
|
142
|
+
== Development
|
143
|
+
|
144
|
+
You can develop Warbler with any implementation of Ruby. To write
|
145
|
+
Warbler code and run specs, you need to have Bundler installed
|
146
|
+
and run "bundle install" once.
|
147
|
+
|
148
|
+
After that, simply run "rake".
|
149
|
+
|
162
150
|
== License
|
163
151
|
|
164
152
|
Warbler is provided under the terms of the MIT license.
|
165
153
|
|
154
|
+
Warbler (c) 2010 Engine Yard, Inc.
|
166
155
|
Warbler (c) 2007-2009 Sun Microsystems, Inc.
|
167
|
-
|
168
|
-
Warbler also bundles several other pieces of software for convenience.
|
169
|
-
Please read the file LICENSES.txt to ensure that you agree with the
|
170
|
-
terms of all the components.
|
data/Rakefile
CHANGED
@@ -1,8 +1,24 @@
|
|
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
|
+
begin
|
9
|
+
require 'bundler'
|
10
|
+
Bundler.setup
|
11
|
+
rescue LoadError
|
12
|
+
puts "Please install Bundler and run 'bundle install' to ensure you have all dependencies"
|
13
|
+
end
|
14
|
+
|
1
15
|
require 'spec/rake/spectask'
|
2
16
|
require 'spec/rake/verify_rcov'
|
3
17
|
|
4
|
-
MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt", "
|
5
|
-
|
18
|
+
MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt", "Gemfile",
|
19
|
+
"LICENSE.txt", "Rakefile", "*.erb", "*.rb", "bin/*",
|
20
|
+
"ext/**/*", "lib/**/*", "spec/**/*.rb", "spec/sample/**/*.*"
|
21
|
+
].to_a.reject{|f| f=~%r{spec/sample/(MANIFEST|web.xml)}}.sort.uniq
|
6
22
|
|
7
23
|
begin
|
8
24
|
File.open("Manifest.txt", "w") {|f| MANIFEST.each {|n| f << "#{n}\n"} }
|
@@ -17,8 +33,8 @@ begin
|
|
17
33
|
p.summary = "Warbler chirpily constructs .war files of your Rails applications."
|
18
34
|
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
19
35
|
p.description = p.paragraphs_of('README.txt', 1...2).join("\n\n")
|
20
|
-
p.extra_deps += [['rake', '>= 0.7
|
21
|
-
p.
|
36
|
+
p.extra_deps += [['rake', '>= 0.8.7'], ['jruby-jars', '>= 1.4.0'], ['jruby-rack', '>= 0.9.7'], ['rubyzip', '>= 0.9.4']]
|
37
|
+
p.clean_globs += ['spec/sample/MANIFEST*', 'spec/sample/web.xml*']
|
22
38
|
end
|
23
39
|
hoe.spec.files = MANIFEST
|
24
40
|
hoe.spec.dependencies.delete_if { |dep| dep.name == "hoe" }
|
@@ -31,15 +47,10 @@ rescue LoadError
|
|
31
47
|
puts "You really need Hoe installed to be able to package this gem"
|
32
48
|
end
|
33
49
|
|
34
|
-
#
|
35
|
-
|
36
|
-
Rake::Task[
|
37
|
-
Rake::Task[
|
38
|
-
|
39
|
-
if defined?(JRUBY_VERSION)
|
40
|
-
task :default => :spec
|
41
|
-
else
|
42
|
-
task :default => :rcov_verify
|
50
|
+
# Leave my tasks alone, Hoe
|
51
|
+
%w(default spec rcov).each do |task|
|
52
|
+
Rake::Task[task].prerequisites.clear
|
53
|
+
Rake::Task[task].actions.clear
|
43
54
|
end
|
44
55
|
|
45
56
|
Spec::Rake::SpecTask.new do |t|
|
@@ -48,12 +59,33 @@ Spec::Rake::SpecTask.new do |t|
|
|
48
59
|
end
|
49
60
|
|
50
61
|
Spec::Rake::SpecTask.new("spec:rcov") do |t|
|
62
|
+
t.spec_opts ||= []
|
63
|
+
t.spec_opts << "--options" << "spec/spec.opts"
|
51
64
|
t.rcov = true
|
52
65
|
end
|
53
66
|
|
54
|
-
|
55
|
-
RCov::VerifyTask.new(:rcov_verify) do |t|
|
67
|
+
RCov::VerifyTask.new(:rcov => "spec:rcov") do |t|
|
56
68
|
t.threshold = 100
|
57
69
|
end
|
58
70
|
|
59
|
-
task :
|
71
|
+
task :default => :spec
|
72
|
+
|
73
|
+
begin
|
74
|
+
require 'ant'
|
75
|
+
directory "pkg/classes"
|
76
|
+
task :compile => "pkg/classes" do |t|
|
77
|
+
ant.javac :srcdir => "ext", :destdir => t.prerequisites.first,
|
78
|
+
:source => "1.5", :target => "1.5", :debug => true,
|
79
|
+
:classpath => "${java.class.path}:${sun.boot.class.path}"
|
80
|
+
end
|
81
|
+
|
82
|
+
task :jar => :compile do
|
83
|
+
ant.jar :basedir => "pkg/classes", :destfile => "lib/warbler_war.jar", :includes => "*.class"
|
84
|
+
end
|
85
|
+
rescue LoadError
|
86
|
+
task :jar do
|
87
|
+
puts "Run 'jar' with JRuby >= 1.5 to re-compile the java war booster"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
task :package => :jar
|
data/bin/warble
CHANGED
@@ -1,68 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
3
|
#--
|
4
|
-
# (c)
|
5
|
-
#
|
6
|
-
#
|
4
|
+
# Copyright (c) 2010 Engine Yard, Inc.
|
5
|
+
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
|
6
|
+
# This source code is available under the MIT license.
|
7
|
+
# See the file LICENSE.txt for details.
|
7
8
|
#++
|
8
9
|
|
9
|
-
require 'rubygems'
|
10
|
-
require 'rake'
|
11
10
|
require 'warbler'
|
12
|
-
|
13
|
-
application = Rake.application
|
14
|
-
|
15
|
-
# Load any application rakefiles to aid in autodetecting applications
|
16
|
-
Warbler.project_application = Rake::Application.new
|
17
|
-
Rake.application = Warbler.project_application
|
18
|
-
Rake::Application::DEFAULT_RAKEFILES.each do |rf|
|
19
|
-
if File.exist?(rf)
|
20
|
-
load rf
|
21
|
-
break
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
Rake.application = application
|
26
|
-
application.standard_exception_handling do
|
27
|
-
application.init
|
28
|
-
|
29
|
-
# Load the main warbler tasks
|
30
|
-
Warbler::Task.new
|
31
|
-
|
32
|
-
task :default => :war
|
33
|
-
|
34
|
-
desc "Generate a configuration file to customize your war assembly"
|
35
|
-
task :config do
|
36
|
-
if File.exists?(Warbler::Config::FILE) && ENV["FORCE"].nil?
|
37
|
-
puts "There's another bird sitting on my favorite branch"
|
38
|
-
puts "(file '#{Warbler::Config::FILE}' already exists. Pass argument FORCE=1 to override)"
|
39
|
-
elsif !File.directory?("config")
|
40
|
-
puts "I'm confused; my favorite branch is missing"
|
41
|
-
puts "(directory 'config' is missing)"
|
42
|
-
else
|
43
|
-
cp "#{Warbler::WARBLER_HOME}/generators/warble/templates/warble.rb", Warbler::Config::FILE
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
desc "Unpack warbler as a plugin in your Rails application"
|
48
|
-
task :pluginize do
|
49
|
-
if !Dir["vendor/plugins/warbler*"].empty?
|
50
|
-
puts "I found an old nest in vendor/plugins; please trash it so I can make a new one"
|
51
|
-
puts "(directory vendor/plugins/warbler* exists)"
|
52
|
-
elsif !File.directory?("vendor/plugins")
|
53
|
-
puts "I can't find a place to build my nest"
|
54
|
-
puts "(directory 'vendor/plugins' is missing)"
|
55
|
-
else
|
56
|
-
Dir.chdir("vendor/plugins") do
|
57
|
-
ruby "-S", "gem", "unpack", "warbler"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
desc "Display version of warbler"
|
63
|
-
task :version do
|
64
|
-
puts "Warbler version #{Warbler::VERSION}"
|
65
|
-
end
|
66
|
-
|
67
|
-
application.top_level
|
68
|
-
end
|
11
|
+
Warbler::Application.new.run
|
data/ext/WarblerWar.java
ADDED
@@ -0,0 +1,113 @@
|
|
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.Closeable;
|
8
|
+
import java.io.File;
|
9
|
+
import java.io.FileInputStream;
|
10
|
+
import java.io.FileOutputStream;
|
11
|
+
import java.io.IOException;
|
12
|
+
import java.util.zip.ZipEntry;
|
13
|
+
import java.util.zip.ZipOutputStream;
|
14
|
+
|
15
|
+
import org.jruby.Ruby;
|
16
|
+
import org.jruby.RubyArray;
|
17
|
+
import org.jruby.RubyHash;
|
18
|
+
import org.jruby.RubyModule;
|
19
|
+
import org.jruby.RubyString;
|
20
|
+
import org.jruby.anno.JRubyMethod;
|
21
|
+
import org.jruby.runtime.Block;
|
22
|
+
import org.jruby.runtime.ThreadContext;
|
23
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
24
|
+
import org.jruby.util.JRubyFile;
|
25
|
+
|
26
|
+
public class WarblerWar {
|
27
|
+
public static void create(Ruby runtime) {
|
28
|
+
RubyModule task = runtime.getClassFromPath("Warbler::War");
|
29
|
+
task.defineAnnotatedMethods(WarblerWar.class);
|
30
|
+
}
|
31
|
+
|
32
|
+
@JRubyMethod
|
33
|
+
public static IRubyObject create_war(ThreadContext context, IRubyObject recv, IRubyObject war_path, IRubyObject entries) {
|
34
|
+
final Ruby runtime = recv.getRuntime();
|
35
|
+
|
36
|
+
if (!(entries instanceof RubyHash)) {
|
37
|
+
throw runtime.newArgumentError("expected a hash for the second argument");
|
38
|
+
}
|
39
|
+
|
40
|
+
RubyHash hash = (RubyHash) entries;
|
41
|
+
try {
|
42
|
+
FileOutputStream file = newFile(war_path);
|
43
|
+
try {
|
44
|
+
ZipOutputStream zip = new ZipOutputStream(file);
|
45
|
+
addEntries(context, zip, hash);
|
46
|
+
zip.finish();
|
47
|
+
} finally {
|
48
|
+
close(file);
|
49
|
+
}
|
50
|
+
} catch (IOException e) {
|
51
|
+
e.printStackTrace();
|
52
|
+
throw runtime.newIOErrorFromException(e);
|
53
|
+
}
|
54
|
+
|
55
|
+
return runtime.getNil();
|
56
|
+
}
|
57
|
+
|
58
|
+
private static void addEntries(ThreadContext context, ZipOutputStream zip, RubyHash entries) throws IOException {
|
59
|
+
RubyArray keys = entries.keys().sort(context, Block.NULL_BLOCK);
|
60
|
+
for (int i = 0; i < keys.getLength(); i++) {
|
61
|
+
IRubyObject key = keys.entry(i);
|
62
|
+
IRubyObject value = entries.op_aref(context, key);
|
63
|
+
addEntry(context, zip, key.convertToString().getUnicodeValue(), value);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
private static void addEntry(ThreadContext context, ZipOutputStream zip, String entryName, IRubyObject value) throws IOException {
|
68
|
+
if (value.respondsTo("read")) {
|
69
|
+
RubyString str = (RubyString) value.callMethod(context, "read").checkStringType();
|
70
|
+
byte[] contents = str.getByteList().getUnsafeBytes();
|
71
|
+
zip.putNextEntry(new ZipEntry(entryName));
|
72
|
+
zip.write(contents);
|
73
|
+
} else {
|
74
|
+
File f;
|
75
|
+
if (value.isNil() || (f = getFile(value)).isDirectory()) {
|
76
|
+
zip.putNextEntry(new ZipEntry(entryName + "/"));
|
77
|
+
} else {
|
78
|
+
FileInputStream inFile = openFile(f);
|
79
|
+
try {
|
80
|
+
zip.putNextEntry(new ZipEntry(entryName));
|
81
|
+
byte[] buf = new byte[16384];
|
82
|
+
int bytesRead = -1;
|
83
|
+
while ((bytesRead = inFile.read(buf)) != -1) {
|
84
|
+
zip.write(buf, 0, bytesRead);
|
85
|
+
}
|
86
|
+
} finally {
|
87
|
+
close(inFile);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
private static FileOutputStream newFile(IRubyObject war_path) throws IOException {
|
94
|
+
return new FileOutputStream(getFile(war_path));
|
95
|
+
}
|
96
|
+
|
97
|
+
private static FileInputStream openFile(File file) throws IOException {
|
98
|
+
return new FileInputStream(file);
|
99
|
+
}
|
100
|
+
|
101
|
+
private static File getFile(IRubyObject path) {
|
102
|
+
return JRubyFile.create(path.getRuntime().getCurrentDirectory(),
|
103
|
+
path.convertToString().getUnicodeValue());
|
104
|
+
}
|
105
|
+
|
106
|
+
private static void close(Closeable c) {
|
107
|
+
try {
|
108
|
+
c.close();
|
109
|
+
} catch (IOException e) {
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
}
|