lucidimagination-warbler 1.3.2.dev

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.
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,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,112 @@
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 'rubygems'
9
+ require 'spec'
10
+
11
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
12
+ require 'warbler'
13
+
14
+ raise %{Error: detected running Warbler specs in a Rails app;
15
+ Warbler specs are destructive to application directories.} if File.directory?("app")
16
+
17
+ def silence(io = nil)
18
+ require 'stringio'
19
+ old_stdout = $stdout
20
+ old_stderr = $stderr
21
+ $stdout = io || StringIO.new
22
+ $stderr = io || StringIO.new
23
+ yield
24
+ ensure
25
+ $stdout = old_stdout
26
+ $stderr = old_stderr
27
+ end
28
+
29
+ def capture(&block)
30
+ require 'stringio'
31
+ io = StringIO.new
32
+ silence(io, &block)
33
+ io.string
34
+ end
35
+
36
+ module Spec::Example::ExampleGroupMethods
37
+ def run_in_directory(dir)
38
+ before :each do
39
+ (@pwd ||= []) << Dir.getwd
40
+ Dir.chdir(@pwd.first) # let directory always be relative to project root
41
+ mkdir_p(dir, :verbose => false)
42
+ Dir.chdir(dir)
43
+ end
44
+
45
+ after :each do
46
+ Dir.chdir(@pwd.pop)
47
+ end
48
+ end
49
+
50
+ def use_fresh_rake_application
51
+ before :each do
52
+ @rake = Rake::Application.new
53
+ Rake.application = @rake
54
+ verbose(false)
55
+ end
56
+ end
57
+
58
+ def use_fresh_environment
59
+ before(:each) do
60
+ @env_save = {}
61
+ (ENV.keys.grep(/BUNDLE/) + ["RUBYOPT"]).each {|k| @env_save[k] = ENV[k]; ENV.delete(k)}
62
+ end
63
+
64
+ after(:each) do
65
+ @env_save.keys.each {|k| ENV[k] = @env_save[k]}
66
+ end
67
+ end
68
+
69
+ def cleanup_temp_files
70
+ after(:each) do
71
+ rm_rf FileList["log", ".bundle", "tmp/war"]
72
+ rm_f FileList["*.war", "*.foobar", "**/config.ru", "*web.xml*", "config/web.xml*", "config/warble.rb",
73
+ "file.txt", 'manifest', '*Gemfile*', 'MANIFEST.MF*', 'init.rb*', '**/*.class']
74
+ end
75
+ end
76
+
77
+ def run_out_of_process_with_drb
78
+ before :all do
79
+ require 'drb'
80
+ DRb.start_service
81
+ @orig_dir = Dir.pwd
82
+ end
83
+
84
+ let(:drbclient) do
85
+ drb
86
+ DRbObject.new(nil, 'druby://127.0.0.1:7890').tap do |drbclient|
87
+ loop { (drbclient.alive? && break) rescue nil }
88
+ end
89
+ end
90
+
91
+ let(:drb) do
92
+ Thread.new do
93
+ ruby "-I#{Warbler::WARBLER_HOME}/lib", File.join(@orig_dir, 'spec/drb_helper.rb')
94
+ end
95
+ end
96
+
97
+ after :each do
98
+ drbclient.stop
99
+ drb.join
100
+ end
101
+ end
102
+ end
103
+
104
+ Spec::Runner.configure do |config|
105
+ config.after(:each) do
106
+ class << Object
107
+ public :remove_const
108
+ end
109
+ Object.remove_const("Rails") rescue nil
110
+ rm_rf "vendor"
111
+ end
112
+ end
@@ -0,0 +1,95 @@
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 File.expand_path('../../spec_helper', __FILE__)
9
+
10
+ describe Warbler::Application do
11
+ run_in_directory "spec/sample_war"
12
+
13
+ before :each do
14
+ verbose(false)
15
+ @argv = ARGV.dup
16
+ ARGV.clear
17
+ @app = Rake.application
18
+ rm_f "config/warble.rb"
19
+ @detection = Warbler.framework_detection
20
+ Warbler.framework_detection = false
21
+ end
22
+
23
+ after :each do
24
+ Rake.application = @app
25
+ Warbler.project_application = nil
26
+ Warbler.application = nil
27
+ Warbler.framework_detection = @detection
28
+ @argv.reverse.each {|a| ARGV.unshift a}
29
+ rm_rf FileList['vendor/plugins/warbler']
30
+ end
31
+
32
+ it "should be able to list its tasks" do
33
+ ARGV.unshift "-T"
34
+ output = capture do
35
+ Warbler::Application.new.run
36
+ end
37
+ output.should =~ /warble war\s/
38
+ output.should =~ /warble war:clean/
39
+ output.should =~ /warble war:debug/
40
+ end
41
+
42
+ it "should display the version" do
43
+ ARGV.unshift "version"
44
+ capture { Warbler::Application.new.run }.should =~ /#{Warbler::VERSION}/
45
+ end
46
+
47
+ it "should copy a fresh config file into place" do
48
+ File.exists?("config/warble.rb").should_not be_true
49
+ ARGV.unshift "config"
50
+ silence { Warbler::Application.new.run }
51
+ File.exists?("config/warble.rb").should be_true
52
+ end
53
+
54
+ it "should refuse to copy over an existing config file" do
55
+ touch "config/warble.rb"
56
+ ARGV.unshift "config"
57
+ capture { Warbler::Application.new.run }.should =~ /already exists/
58
+ end
59
+
60
+ it "should complain if the config directory is missing" do
61
+ begin
62
+ mv "config", "config-tmp"
63
+ ARGV.unshift "config"
64
+ capture { Warbler::Application.new.run }.should =~ /missing/
65
+ ensure
66
+ mv "config-tmp", "config"
67
+ end
68
+ end
69
+
70
+ it "should refuse to pluginize if the vendor/plugins/warbler directory exists" do
71
+ mkdir_p "vendor/plugins/warbler"
72
+ ARGV.unshift "pluginize"
73
+ silence { Warbler::Application.new.run }
74
+ File.exist?("vendor/plugins/warbler/tasks/warbler.rake").should_not be_true
75
+ end
76
+
77
+ it "should define a pluginize task for adding the tasks to a Rails application" do
78
+ ARGV.unshift "pluginize"
79
+ Warbler::Application.new.run
80
+ File.exist?("vendor/plugins/warbler/tasks/warbler.rake").should be_true
81
+ end
82
+
83
+ it "should provide a means to load the project Rakefile" do
84
+ Warbler::Application.new.load_project_rakefile
85
+ end
86
+ end
87
+
88
+ describe Warbler::Application do
89
+ it "should report Warbler version with --version" do
90
+ ruby = File.join Config::CONFIG['bindir'], 'ruby'
91
+ output = `#{ruby} -rubygems -Ilib -S bin/warble --version`.chomp
92
+ output.should =~ /warbler/i
93
+ output.should =~ /#{Warbler::VERSION}/
94
+ end
95
+ end
@@ -0,0 +1,136 @@
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 File.expand_path('../../spec_helper', __FILE__)
9
+
10
+ describe Warbler::Jar, "with Bundler" do
11
+ use_fresh_rake_application
12
+ use_fresh_environment
13
+ run_out_of_process_with_drb
14
+
15
+ def file_list(regex)
16
+ jar.files.keys.select {|f| f =~ regex }
17
+ end
18
+
19
+ def use_config(&block)
20
+ @extra_config = block
21
+ end
22
+
23
+ let(:config) { drbclient.config(@extra_config) }
24
+ let(:jar) { drbclient.jar }
25
+
26
+ context "in a war project" do
27
+ run_in_directory "spec/sample_war"
28
+ cleanup_temp_files
29
+
30
+ before :each do
31
+ File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
32
+ end
33
+
34
+ it "detects a Bundler trait" do
35
+ config.traits.should include(Warbler::Traits::Bundler)
36
+ end
37
+
38
+ it "detects a Gemfile and process only its gems" do
39
+ use_config do |config|
40
+ config.gems << "rake"
41
+ end
42
+ jar.apply(config)
43
+ file_list(%r{WEB-INF/Gemfile}).should_not be_empty
44
+ file_list(%r{WEB-INF/gems/specifications/rspec}).should_not be_empty
45
+ file_list(%r{WEB-INF/gems/specifications/rake}).should be_empty
46
+ end
47
+
48
+ it "copies Gemfiles into the war" do
49
+ File.open("Gemfile.lock", "w") {|f| f << "GEM"}
50
+ jar.apply(config)
51
+ file_list(%r{WEB-INF/Gemfile}).should_not be_empty
52
+ file_list(%r{WEB-INF/Gemfile.lock}).should_not be_empty
53
+ end
54
+
55
+ it "allows overriding of the gem path when using Bundler" do
56
+ use_config do |config|
57
+ config.gem_path = '/WEB-INF/jewels'
58
+ end
59
+ jar.apply(config)
60
+ file_list(%r{WEB-INF/jewels/specifications/rspec}).should_not be_empty
61
+ end
62
+
63
+ it "works with :git entries in Gemfiles" do
64
+ File.open("Gemfile", "w") {|f| f << "gem 'warbler', :git => '#{Warbler::WARBLER_HOME}'\n"}
65
+ silence { ruby "-S", "bundle", "install", "--local" }
66
+ jar.apply(config)
67
+ file_list(%r{WEB-INF/gems/bundler/gems/warbler[^/]*/lib/warbler/version\.rb}).should_not be_empty
68
+ file_list(%r{WEB-INF/gems/bundler/gems/warbler[^/]*/warbler.gemspec}).should_not be_empty
69
+ end
70
+
71
+ it "does not work with :path entries in Gemfiles" do
72
+ File.open("Gemfile", "w") {|f| f << "gem 'warbler', :path => '#{Warbler::WARBLER_HOME}'\n"}
73
+ silence do
74
+ ruby "-S", "bundle", "install", "--local"
75
+ jar.apply(config)
76
+ end
77
+ file_list(%r{warbler}).should be_empty
78
+ end
79
+
80
+ it "does not bundle dependencies in the test group by default" do
81
+ File.open("Gemfile", "w") {|f| f << "gem 'rake'\ngroup :test do\ngem 'rspec'\nend\n"}
82
+ jar.apply(config)
83
+ file_list(%r{WEB-INF/gems/gems/rake[^/]*/}).should_not be_empty
84
+ file_list(%r{WEB-INF/gems/gems/rspec[^/]*/}).should be_empty
85
+ file_list(%r{WEB-INF/gems/specifications/rake}).should_not be_empty
86
+ file_list(%r{WEB-INF/gems/specifications/rspec}).should be_empty
87
+ end
88
+
89
+ it "adds BUNDLE_WITHOUT to init.rb" do
90
+ jar.add_init_file(config)
91
+ contents = jar.contents('META-INF/init.rb')
92
+ contents.should =~ /ENV\['BUNDLE_WITHOUT'\]/
93
+ contents.should =~ /'development:test'/
94
+ end
95
+
96
+ it "uses ENV['BUNDLE_GEMFILE'] if set" do
97
+ mv "Gemfile", "Special-Gemfile"
98
+ ENV['BUNDLE_GEMFILE'] = "Special-Gemfile"
99
+ config.traits.should include(Warbler::Traits::Bundler)
100
+ end
101
+ end
102
+
103
+ context "in a jar project" do
104
+ run_in_directory "spec/sample_jar"
105
+ cleanup_temp_files
106
+
107
+ it "works with :git entries in Gemfiles" do
108
+ File.open("Gemfile", "w") {|f| f << "gem 'warbler', :git => '#{Warbler::WARBLER_HOME}'\n"}
109
+ silence { ruby "-S", "bundle", "install", "--local" }
110
+ jar.apply(config)
111
+ file_list(%r{^bundler/gems/warbler[^/]*/lib/warbler/version\.rb}).should_not be_empty
112
+ file_list(%r{^bundler/gems/warbler[^/]*/warbler.gemspec}).should_not be_empty
113
+ end
114
+ end
115
+
116
+ context "when frozen" do
117
+ run_in_directory "spec/sample_bundler"
118
+
119
+ it "includes the bundler gem" do
120
+ jar.apply(config)
121
+ config.gems.detect{|k,v| k.name == 'bundler'}.should_not be_nil
122
+ file_list(/bundler-/).should_not be_empty
123
+ end
124
+
125
+ it "does not include the bundler cache directory" do
126
+ jar.apply(config)
127
+ file_list(%r{vendor/bundle}).should be_empty
128
+ end
129
+
130
+ it "includes ENV['BUNDLE_FROZEN'] in init.rb" do
131
+ jar.apply(config)
132
+ contents = jar.contents('META-INF/init.rb')
133
+ contents.split("\n").grep(/ENV\['BUNDLE_FROZEN'\] = '1'/).should_not be_empty
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,130 @@
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 File.expand_path('../../spec_helper', __FILE__)
9
+
10
+ describe Warbler::Config do
11
+ before :each do
12
+ verbose(false)
13
+ end
14
+
15
+ context "in an unknown application" do
16
+ run_in_directory 'spec/sample_war/tmp'
17
+
18
+ it "has suitable default values" do
19
+ config = Warbler::Config.new
20
+ config.includes.should be_empty
21
+ config.jar_name.size.should > 0
22
+ end
23
+ end
24
+
25
+ context "in a web application" do
26
+ run_in_directory 'spec/sample_war'
27
+
28
+ after :each do
29
+ rm_f "vendor/test.log"
30
+ end
31
+
32
+ it "should have suitable default values" do
33
+ config = Warbler::Config.new
34
+ config.dirs.should include(*Warbler::Config::TOP_DIRS.select{|d| File.directory?(d)})
35
+ config.includes.should be_empty
36
+ config.java_libs.should_not be_empty
37
+ config.jar_name.size.should > 0
38
+ config.webxml.should be_kind_of(OpenStruct)
39
+ config.pathmaps.should be_kind_of(OpenStruct)
40
+ config.pathmaps.public_html.should == ["%{public/,}p"]
41
+ end
42
+
43
+ it "should allow configuration through an initializer block" do
44
+ config = Warbler::Config.new do |c|
45
+ c.jar_name = "mywar"
46
+ end
47
+ config.jar_name.should == "mywar"
48
+ end
49
+
50
+ it "should allow gems to be added/changed with =, +=, -=, <<" do
51
+ config = Warbler::Config.new do |c|
52
+ c.gems += ["activerecord-jdbc-adapter"]
53
+ c.gems -= ["rails"]
54
+ c.gems << "tzinfo"
55
+ c.gems = ["camping"]
56
+ end
57
+ end
58
+
59
+ it "should exclude log files by default" do
60
+ mkdir_p "vendor"
61
+ touch "vendor/test.log"
62
+ config = Warbler::Config.new
63
+ config.exclude_logs.should == true
64
+ config.excludes.include?("vendor/test.log").should == true
65
+ end
66
+
67
+ it "should include log files if exclude_logs is false" do
68
+ mkdir_p "vendor"
69
+ touch "vendor/test.log"
70
+ config = Warbler::Config.new {|c| c.exclude_logs = false }
71
+ config.exclude_logs.should == false
72
+ config.excludes.include?("vendor/test.log").should == false
73
+ end
74
+
75
+ it "should exclude Warbler itself when run as a plugin" do
76
+ config = Warbler::Config.new
77
+ config.excludes.include?("vendor/plugins/warbler").should == false
78
+ config = Warbler::Config.new File.join(Dir.getwd, "vendor", "plugins", "warbler")
79
+ config.excludes.include?("vendor/plugins/warbler").should == true
80
+ end
81
+
82
+ it "should generate context parameters from the webxml openstruct" do
83
+ config = Warbler::Config.new
84
+ config.webxml.a.b.c = "123"
85
+ config.webxml.com.example.config = "blah"
86
+ config.webxml.rails.env = 'staging'
87
+ config.webxml.jruby.min.runtimes = 2
88
+ config.webxml.jruby.max.runtimes = 4
89
+ config.webxml['org']['jruby']['rack'] = "rails"
90
+ params = config.webxml.context_params
91
+ params.should have_key('a.b.c')
92
+ params.should have_key('rails.env')
93
+ params.should have_key('jruby.min.runtimes')
94
+ params.should have_key('jruby.max.runtimes')
95
+ params['a.b.c'].should == "123"
96
+ params['com.example.config'].should == "blah"
97
+ params['rails.env'].should == "staging"
98
+ params['jruby.min.runtimes'].should == "2"
99
+ params['jruby.max.runtimes'].should == "4"
100
+ params['org.jruby.rack'].should == "rails"
101
+ end
102
+
103
+ it "should determine the context listener from the webxml.booter parameter" do
104
+ config = Warbler::Config.new
105
+ config.webxml.booter = :rack
106
+ config.webxml.servlet_context_listener.should == "org.jruby.rack.RackServletContextListener"
107
+ config = Warbler::Config.new
108
+ config.webxml.booter = :merb
109
+ config.webxml.servlet_context_listener.should == "org.jruby.rack.merb.MerbServletContextListener"
110
+ config = Warbler::Config.new
111
+ config.webxml.servlet_context_listener.should == "org.jruby.rack.rails.RailsServletContextListener"
112
+ end
113
+
114
+ it "should not include ignored webxml keys in the context params hash" do
115
+ Warbler::Config.new.webxml.context_params.should_not have_key('ignored')
116
+ Warbler::Config.new.webxml.context_params.should_not have_key('jndi')
117
+ Warbler::Config.new.webxml.context_params.should_not have_key('booter')
118
+ end
119
+
120
+ it "should have a helpful string representation for an empty key" do
121
+ Warbler::Config.new.webxml.missing_key.to_s.should =~ /No value for 'missing_key' found/
122
+ end
123
+
124
+ it "should HTML-escape all webxml keys and values" do
125
+ config = Warbler::Config.new
126
+ config.webxml.a["b&"].c = "123<hi>456"
127
+ config.webxml.context_params['a.b&amp;.c'].should == "123&lt;hi&gt;456"
128
+ end
129
+ end
130
+ end