lucidimagination-warbler 1.3.2.dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/Gemfile +16 -0
  2. data/History.txt +217 -0
  3. data/LICENSE.txt +26 -0
  4. data/Manifest.txt +92 -0
  5. data/README.txt +255 -0
  6. data/Rakefile +103 -0
  7. data/bin/warble +11 -0
  8. data/ext/JarMain.java +148 -0
  9. data/ext/WarMain.java +112 -0
  10. data/ext/WarblerJar.java +182 -0
  11. data/ext/WarblerJarService.java +18 -0
  12. data/lib/warbler.rb +33 -0
  13. data/lib/warbler/application.rb +86 -0
  14. data/lib/warbler/config.rb +223 -0
  15. data/lib/warbler/gems.rb +37 -0
  16. data/lib/warbler/jar.rb +253 -0
  17. data/lib/warbler/task.rb +183 -0
  18. data/lib/warbler/templates/bundler.erb +3 -0
  19. data/lib/warbler/templates/config.erb +1 -0
  20. data/lib/warbler/templates/jar.erb +5 -0
  21. data/lib/warbler/templates/rack.erb +1 -0
  22. data/lib/warbler/templates/rails.erb +1 -0
  23. data/lib/warbler/templates/war.erb +1 -0
  24. data/lib/warbler/traits.rb +107 -0
  25. data/lib/warbler/traits/bundler.rb +104 -0
  26. data/lib/warbler/traits/gemspec.rb +59 -0
  27. data/lib/warbler/traits/jar.rb +56 -0
  28. data/lib/warbler/traits/merb.rb +35 -0
  29. data/lib/warbler/traits/nogemspec.rb +42 -0
  30. data/lib/warbler/traits/rack.rb +33 -0
  31. data/lib/warbler/traits/rails.rb +62 -0
  32. data/lib/warbler/traits/war.rb +197 -0
  33. data/lib/warbler/version.rb +10 -0
  34. data/lib/warbler/war.rb +8 -0
  35. data/lib/warbler_jar.jar +0 -0
  36. data/spec/drb_helper.rb +41 -0
  37. data/spec/sample_bundler/Gemfile.lock +10 -0
  38. data/spec/sample_bundler/config.ru +0 -0
  39. data/spec/sample_jar/History.txt +6 -0
  40. data/spec/sample_jar/Manifest.txt +8 -0
  41. data/spec/sample_jar/README.txt +30 -0
  42. data/spec/sample_jar/lib/sample_jar.rb +6 -0
  43. data/spec/sample_jar/sample_jar.gemspec +40 -0
  44. data/spec/sample_jar/test/test_sample_jar.rb +8 -0
  45. data/spec/sample_war/app/controllers/application.rb +15 -0
  46. data/spec/sample_war/app/helpers/application_helper.rb +3 -0
  47. data/spec/sample_war/config/boot.rb +109 -0
  48. data/spec/sample_war/config/database.yml +19 -0
  49. data/spec/sample_war/config/environment.rb +67 -0
  50. data/spec/sample_war/config/environments/development.rb +17 -0
  51. data/spec/sample_war/config/environments/production.rb +25 -0
  52. data/spec/sample_war/config/environments/test.rb +22 -0
  53. data/spec/sample_war/config/initializers/inflections.rb +10 -0
  54. data/spec/sample_war/config/initializers/mime_types.rb +5 -0
  55. data/spec/sample_war/config/initializers/new_rails_defaults.rb +15 -0
  56. data/spec/sample_war/config/routes.rb +41 -0
  57. data/spec/sample_war/lib/tasks/utils.rake +0 -0
  58. data/spec/sample_war/public/404.html +30 -0
  59. data/spec/sample_war/public/422.html +30 -0
  60. data/spec/sample_war/public/500.html +30 -0
  61. data/spec/sample_war/public/favicon.ico +0 -0
  62. data/spec/sample_war/public/index.html +274 -0
  63. data/spec/sample_war/public/robots.txt +5 -0
  64. data/spec/spec_helper.rb +112 -0
  65. data/spec/warbler/application_spec.rb +95 -0
  66. data/spec/warbler/bundler_spec.rb +136 -0
  67. data/spec/warbler/config_spec.rb +130 -0
  68. data/spec/warbler/gems_spec.rb +40 -0
  69. data/spec/warbler/jar_spec.rb +718 -0
  70. data/spec/warbler/task_spec.rb +170 -0
  71. data/spec/warbler/traits_spec.rb +17 -0
  72. data/spec/warbler/war_spec.rb +14 -0
  73. data/warble.rb +142 -0
  74. data/web.xml.erb +32 -0
  75. metadata +198 -0
@@ -0,0 +1,56 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 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 'stringio'
9
+ require 'ostruct'
10
+
11
+ module Warbler
12
+ module Traits
13
+ # The Jar trait sets up the archive layout for an executable jar
14
+ # project, and adds the JRuby jar files and a JarMain class to the
15
+ # archive.
16
+ class Jar
17
+ include Trait
18
+
19
+ def self.detect?
20
+ !War.detect?
21
+ end
22
+
23
+ def before_configure
24
+ config.gem_path = '/'
25
+ config.pathmaps = default_pathmaps
26
+ config.java_libs = default_jar_files
27
+ config.manifest_file = 'MANIFEST.MF' if File.exist?('MANIFEST.MF')
28
+ config.init_contents << "#{config.warbler_templates}/jar.erb"
29
+ end
30
+
31
+ def after_configure
32
+ config.init_contents << StringIO.new("require 'rubygems'\n")
33
+ end
34
+
35
+ def update_archive(jar)
36
+ jar.files['META-INF/MANIFEST.MF'] = StringIO.new(Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: JarMain\n") unless config.manifest_file
37
+ jar.files['JarMain.class'] = jar.entry_in_jar("#{WARBLER_HOME}/lib/warbler_jar.jar", "JarMain.class")
38
+ end
39
+
40
+ def default_pathmaps
41
+ p = OpenStruct.new
42
+ p.java_libs = ["META-INF/lib/%f"]
43
+ p.java_classes = ["%p"]
44
+ p.application = ["#{config.jar_name}/%p"]
45
+ p.gemspecs = ["specifications/%f"]
46
+ p.gems = ["gems/%p"]
47
+ p
48
+ end
49
+
50
+ def default_jar_files
51
+ require 'jruby-jars'
52
+ FileList[JRubyJars.core_jar_path, JRubyJars.stdlib_jar_path]
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,35 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 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
+ module Traits
10
+ # The Merb trait adds Merb::BootLoader gem dependencies to the project.
11
+ class Merb
12
+ include Trait
13
+
14
+ def self.detect?
15
+ File.exist?("config/init.rb")
16
+ end
17
+
18
+ def self.requires?(trait)
19
+ trait == Traits::War
20
+ end
21
+
22
+ def before_configure
23
+ return false unless task = Warbler.project_application.lookup("merb_env")
24
+ task.invoke rescue nil
25
+ return false unless defined?(::Merb)
26
+ config.webxml.booter = :merb
27
+ if defined?(::Merb::BootLoader::Dependencies.dependencies)
28
+ ::Merb::BootLoader::Dependencies.dependencies.each {|g| config.gems << g }
29
+ else
30
+ warn "unable to auto-detect Merb dependencies; upgrade to Merb 1.0 or greater"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,42 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 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
+ module Traits
10
+ # The NoGemspec trait is used when no gemspec file is found for a
11
+ # jar project. It assumes a standard layout including +bin+ and
12
+ # +lib+ directories.
13
+ class NoGemspec
14
+ include Trait
15
+
16
+ def self.detect?
17
+ Jar.detect? && !Gemspec.detect?
18
+ end
19
+
20
+ def before_configure
21
+ config.dirs = ['.']
22
+ end
23
+
24
+ def after_configure
25
+ if File.directory?("lib")
26
+ add_init_load_path(config.pathmaps.application.inject("lib") {|pm,x| pm.pathmap(x)})
27
+ end
28
+ end
29
+
30
+ def update_archive(jar)
31
+ add_main_rb(jar, jar.apply_pathmaps(config, default_executable, :application))
32
+ end
33
+
34
+ def default_executable
35
+ exes = Dir['bin/*']
36
+ exe = exes.grep(/#{config.jar_name}/).first || exes.first
37
+ raise "No executable script found" unless exe
38
+ exe
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,33 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 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
+ module Traits
10
+ # The Rack trait adds config.ru to a Rack-based war project.
11
+ class Rack
12
+ include Trait
13
+
14
+ def self.detect?
15
+ !Rails.detect? && (File.exist?("config.ru") || !Dir['*/config.ru'].empty?)
16
+ end
17
+
18
+ def self.requires?(trait)
19
+ trait == Traits::War
20
+ end
21
+
22
+ def before_configure
23
+ config.webxml.booter = :rack
24
+ config.webinf_files += [FileList['config.ru', '*/config.ru'].detect {|f| File.exist?(f)}]
25
+ config.webxml.rack.env = ENV['RACK_ENV'] || 'production'
26
+ end
27
+
28
+ def after_configure
29
+ config.init_contents << "#{config.warbler_templates}/rack.erb"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,62 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 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
+ module Traits
10
+ # The Rails trait invokes the Rake environment task and sets up Rails for a war-based project.
11
+ class Rails
12
+ include Trait
13
+
14
+ def self.detect?
15
+ File.exist?("config/environment.rb")
16
+ end
17
+
18
+ def self.requires?(trait)
19
+ trait == Traits::War
20
+ end
21
+
22
+ def before_configure
23
+ config.jar_name = default_app_name
24
+ config.webxml.rails.env = ENV['RAILS_ENV'] || 'production'
25
+
26
+ return unless Warbler.framework_detection
27
+ return false unless task = Warbler.project_application.lookup("environment")
28
+
29
+ task.invoke rescue nil
30
+ return false unless defined?(::Rails)
31
+
32
+ config.dirs << "tmp" if File.directory?("tmp")
33
+ config.webxml.booter = :rails
34
+ unless (defined?(::Rails.vendor_rails?) && ::Rails.vendor_rails?) || File.directory?("vendor/rails")
35
+ config.gems["rails"] = ::Rails::VERSION::STRING
36
+ end
37
+ if defined?(::Rails.configuration.gems)
38
+ ::Rails.configuration.gems.each do |g|
39
+ config.gems << Gem::Dependency.new(g.name, g.requirement) if Dir["vendor/gems/#{g.name}*"].empty?
40
+ end
41
+ end
42
+ end
43
+
44
+ def after_configure
45
+ config.init_contents << "#{config.warbler_templates}/rails.erb"
46
+ begin
47
+ rails_env = config.webxml.rails.env
48
+ unless IO.readlines("config/environments/#{rails_env}.rb").grep(/^\s*config\.threadsafe!/).empty?
49
+ config.webxml.jruby.min.runtimes = 1 unless Integer === config.webxml.jruby.min.runtimes
50
+ config.webxml.jruby.max.runtimes = 1 unless Integer === config.webxml.jruby.max.runtimes
51
+ end
52
+ rescue
53
+ end
54
+ end
55
+
56
+
57
+ def default_app_name
58
+ File.basename(File.expand_path(defined?(::Rails.root) ? ::Rails.root : (defined?(RAILS_ROOT) ? RAILS_ROOT : Dir.getwd)))
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,197 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 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 'ostruct'
9
+
10
+ module Warbler
11
+ module Traits
12
+ # The War trait sets up the layout and generates web.xml for the war project.
13
+ class War
14
+ include Trait
15
+
16
+ DEFAULT_GEM_PATH = '/WEB-INF/gems'
17
+
18
+ def self.detect?
19
+ Traits::Rails.detect? || Traits::Merb.detect? || Traits::Rack.detect?
20
+ end
21
+
22
+ def before_configure
23
+ config.gem_path = DEFAULT_GEM_PATH
24
+ config.pathmaps = default_pathmaps
25
+ config.webxml = default_webxml_config
26
+ config.webinf_files = default_webinf_files
27
+ config.java_libs = default_jar_files
28
+ config.public_html = FileList["public/**/*"]
29
+ config.jar_extension = 'war'
30
+ config.init_contents << "#{config.warbler_templates}/war.erb"
31
+ end
32
+
33
+ def after_configure
34
+ update_gem_path(DEFAULT_GEM_PATH)
35
+ end
36
+
37
+ def default_pathmaps
38
+ p = OpenStruct.new
39
+ p.public_html = ["%{public/,}p"]
40
+ p.java_libs = ["WEB-INF/lib/%f"]
41
+ p.java_classes = ["WEB-INF/classes/%p"]
42
+ p.application = ["WEB-INF/%p"]
43
+ p.webinf = ["WEB-INF/%{.erb$,}f"]
44
+ p.gemspecs = ["#{config.relative_gem_path}/specifications/%f"]
45
+ p.gems = ["#{config.relative_gem_path}/gems/%p"]
46
+ p
47
+ end
48
+
49
+ def default_webxml_config
50
+ c = WebxmlOpenStruct.new
51
+ c.public.root = '/'
52
+ c.jndi = nil
53
+ c.ignored = %w(jndi booter)
54
+ c
55
+ end
56
+
57
+ def default_webinf_files
58
+ webxml = if File.exist?("config/web.xml")
59
+ "config/web.xml"
60
+ elsif File.exist?("config/web.xml.erb")
61
+ "config/web.xml.erb"
62
+ else
63
+ "#{WARBLER_HOME}/web.xml.erb"
64
+ end
65
+ FileList[webxml]
66
+ end
67
+
68
+ def default_jar_files
69
+ require 'jruby-jars'
70
+ require 'jruby-rack'
71
+ FileList[JRubyJars.core_jar_path, JRubyJars.stdlib_jar_path, JRubyJars.jruby_rack_jar_path]
72
+ end
73
+
74
+ def update_archive(jar)
75
+ add_public_files(jar)
76
+ add_webxml(jar)
77
+ add_executables(jar) if config.features.include?("executable")
78
+ add_gemjar(jar) if config.features.include?("gemjar")
79
+ end
80
+
81
+ # Add public/static assets to the root of the war file.
82
+ def add_public_files(jar)
83
+ config.public_html.exclude *(config.excludes.to_a)
84
+ config.public_html.map {|f| jar.add_with_pathmaps(config, f, :public_html) }
85
+ end
86
+
87
+ # Add web.xml and other WEB-INF configuration files from
88
+ # config.webinf_files to the war file.
89
+ def add_webxml(jar)
90
+ config.webinf_files.each do |wf|
91
+ if wf =~ /\.erb$/
92
+ jar.files[jar.apply_pathmaps(config, wf, :webinf)] = jar.expand_erb(wf, config)
93
+ else
94
+ jar.files[jar.apply_pathmaps(config, wf, :webinf)] = wf
95
+ end
96
+ end
97
+ end
98
+
99
+ def add_executables(jar)
100
+ winstone_type = ENV["WINSTONE"] || "winstone-lite"
101
+ winstone_version = ENV["WINSTONE_VERSION"] || "0.9.10"
102
+ winstone_path = "net/sourceforge/winstone/#{winstone_type}/#{winstone_version}/#{winstone_type}-#{winstone_version}.jar"
103
+ winstone_jar = File.expand_path("~/.m2/repository/#{winstone_path}")
104
+ unless File.exist?(winstone_jar)
105
+ # Not always covered in tests as these lines may not get
106
+ # executed every time if the jar is cached.
107
+ puts "Downloading #{winstone_type}.jar" #:nocov:
108
+ mkdir_p File.dirname(winstone_jar) #:nocov:
109
+ require 'open-uri' #:nocov:
110
+ maven_repo = ENV["MAVEN_REPO"] || "http://repo2.maven.org/maven2" #:nocov:
111
+ open("#{maven_repo}/#{winstone_path}") do |stream| #:nocov:
112
+ File.open(winstone_jar, "wb") do |f| #:nocov:
113
+ while buf = stream.read(4096) #:nocov:
114
+ f << buf #:nocov:
115
+ end #:nocov:
116
+ end #:nocov:
117
+ end #:nocov:
118
+ end
119
+
120
+ jar.files['META-INF/MANIFEST.MF'] = StringIO.new(Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: WarMain\n")
121
+ jar.files['WarMain.class'] = jar.entry_in_jar("#{WARBLER_HOME}/lib/warbler_jar.jar", 'WarMain.class')
122
+ jar.files['WEB-INF/winstone.jar'] = winstone_jar
123
+ end
124
+
125
+ def add_gemjar(jar)
126
+ gem_jar = Warbler::Jar.new
127
+ gem_path = Regexp::quote(config.relative_gem_path)
128
+ gems = jar.files.select{|k,v| k =~ %r{#{gem_path}/} }
129
+ gems.each do |k,v|
130
+ gem_jar.files[k.sub(%r{#{gem_path}/}, '')] = v
131
+ end
132
+ jar.files["WEB-INF/lib/gems.jar"] = "tmp/gems.jar"
133
+ jar.files.reject!{|k,v| k =~ /#{gem_path}/ || k == "WEB-INF/tmp/gems.jar"}
134
+ mkdir_p "tmp"
135
+ gem_jar.add_manifest
136
+ gem_jar.create("tmp/gems.jar")
137
+ end
138
+
139
+ # Helper class for holding arbitrary config.webxml values for injecting into +web.xml+.
140
+ class WebxmlOpenStruct < OpenStruct
141
+ %w(java com org javax gem).each do |name|
142
+ undef_method name if Object.methods.include?(name)
143
+ undef_method name.to_sym if Object.methods.include?(name.to_sym)
144
+ end
145
+
146
+ def initialize(key = 'webxml')
147
+ @key = key
148
+ @table = Hash.new {|h,k| h[k] = WebxmlOpenStruct.new(k) }
149
+ end
150
+
151
+ def servlet_context_listener
152
+ case self.booter
153
+ when :rack
154
+ "org.jruby.rack.RackServletContextListener"
155
+ when :merb
156
+ "org.jruby.rack.merb.MerbServletContextListener"
157
+ else # :rails, default
158
+ "org.jruby.rack.rails.RailsServletContextListener"
159
+ end
160
+ end
161
+
162
+ def [](key)
163
+ new_ostruct_member(key)
164
+ send(key)
165
+ end
166
+
167
+ def []=(key, value)
168
+ new_ostruct_member(key)
169
+ send("#{key}=", value)
170
+ end
171
+
172
+ def context_params(escape = true)
173
+ require 'cgi'
174
+ params = {}
175
+ @table.each do |k,v|
176
+ case v
177
+ when WebxmlOpenStruct
178
+ nested_params = v.context_params
179
+ nested_params.each do |nk,nv|
180
+ params["#{escape ? CGI::escapeHTML(k.to_s) : k.to_s}.#{nk}"] = nv
181
+ end
182
+ else
183
+ params[escape ? CGI::escapeHTML(k.to_s) : k.to_s] = escape ? CGI::escapeHTML(v.to_s) : v.to_s
184
+ end
185
+ end
186
+ extra_ignored = Array === ignored ? ignored : []
187
+ params.delete_if {|k,v| ['ignored', *extra_ignored].include?(k.to_s) }
188
+ params
189
+ end
190
+
191
+ def to_s
192
+ "No value for '#@key' found"
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,10 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 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
+ VERSION = "1.3.2.dev"
10
+ end
@@ -0,0 +1,8 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 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 'warbler/jar'