warbler 1.3.6 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/warbler/task.rb CHANGED
@@ -43,7 +43,7 @@ module Warbler
43
43
  def initialize(name = nil, config = nil)
44
44
  @config = config
45
45
  if @config.nil? && File.exists?(Config::FILE)
46
- @config = eval(File.open(Config::FILE) {|f| f.read})
46
+ @config = eval(File.read(Config::FILE), binding, Config::FILE, 0)
47
47
  end
48
48
  @config ||= Config.new
49
49
  unless @config.kind_of? Config
@@ -162,13 +162,13 @@ module Warbler
162
162
 
163
163
  def define_pluginize_task
164
164
  task "pluginize" do
165
- if !Dir["vendor/plugins/warbler*"].empty? && ENV["FORCE"].nil?
166
- puts "I found an old nest in vendor/plugins; please trash it so I can make a new one"
167
- puts "(directory vendor/plugins/warbler* exists)"
165
+ if !Dir["lib/tasks/warbler*"].empty? && ENV["FORCE"].nil?
166
+ puts "I found an old nest in lib/tasks; please trash it so I can make a new one"
167
+ puts "(directory lib/tasks/warbler* exists)"
168
168
  else
169
- rm_rf FileList["vendor/plugins/warbler*"], :verbose => false
170
- mkdir_p "vendor/plugins/warbler/tasks"
171
- File.open("vendor/plugins/warbler/tasks/warbler.rake", "w") do |f|
169
+ rm_rf FileList["lib/tasks/warbler*"], :verbose => false
170
+ mkdir_p "lib/tasks/warbler"
171
+ File.open("lib/tasks/warbler/warbler.rake", "w") do |f|
172
172
  f.puts "require 'warbler'"
173
173
  f.puts "Warbler::Task.new"
174
174
  end
@@ -1,7 +1,8 @@
1
+ <% assignment_operator = config.override_gem_home ? "=" : "||=" %>
1
2
  <% if config.relative_gem_path.empty? %>
2
- ENV['GEM_HOME'] ||= File.expand_path('../..', __FILE__)
3
+ ENV['GEM_HOME'] <%= assignment_operator %> File.expand_path('../..', __FILE__)
3
4
  <% else %>
4
- ENV['GEM_HOME'] ||= File.expand_path('../../<%= config.relative_gem_path %>', __FILE__)
5
+ ENV['GEM_HOME'] <%= assignment_operator %> File.expand_path('../../<%= config.relative_gem_path %>', __FILE__)
5
6
  <% end %>
6
7
  <% if config.bundler && config.bundler[:gemfile_path] %>
7
8
  ENV['BUNDLE_GEMFILE'] = File.expand_path('../../<%= config.bundler[:gemfile_path] %>', __FILE__)
@@ -1,6 +1,4 @@
1
1
  ENV['GEM_HOME'] ||= $servlet_context.getRealPath('<%= config.gem_path %>')
2
2
  <% if config.bundler && config.bundler[:gemfile_path] %>
3
- ENV['BUNDLE_GEMFILE'] = $servlet_context.getRealPath('/<%= config.bundler[:gemfile_path] %>')
3
+ ENV['BUNDLE_GEMFILE'] ||= $servlet_context.getRealPath('/<%= config.bundler[:gemfile_path] %>')
4
4
  <% end %>
5
-
6
-
@@ -23,7 +23,7 @@ module Warbler
23
23
 
24
24
  def before_configure
25
25
  config.bundler = true
26
- config.bundle_without = ["development", "test"]
26
+ config.bundle_without = ["development", "test", "assets"]
27
27
  end
28
28
 
29
29
  def after_configure
@@ -41,8 +41,16 @@ module Warbler
41
41
  # bundler gemspec from bundler/source.rb
42
42
  if spec.name == "bundler"
43
43
  full_gem_path = Pathname.new(spec.full_gem_path)
44
- tries = 2
45
- (full_gem_path = full_gem_path.dirname; tries -= 1) while tries > 0 && !full_gem_path.join('bundler.gemspec').exist?
44
+
45
+ while !full_gem_path.join('bundler.gemspec').exist?
46
+ full_gem_path = full_gem_path.dirname
47
+ # if at top of the path, meaning we cannot find bundler.gemspec, abort.
48
+ if full_gem_path.to_s=~/^[\.\/]$/
49
+ $stderr.puts("warning: Unable to detect bundler spec under '#{spec.full_gem_path}'' and is sub-dirs")
50
+ exit
51
+ end
52
+ end
53
+
46
54
  spec.loaded_from = full_gem_path.join('bundler.gemspec').to_s
47
55
  # RubyGems 1.8.x: @full_gem_path is cached, so we have to set it
48
56
  def spec.full_gem_path=(p); @full_gem_path = p; end
@@ -49,7 +49,7 @@ module Warbler
49
49
  if !@spec.executables.empty?
50
50
  "bin/#{@spec.executables.first}"
51
51
  else
52
- exe = Dir['bin/*'].first
52
+ exe = Dir['bin/*'].sort.first
53
53
  raise "No executable script found" unless exe
54
54
  warn "No default executable found in #{@spec_file}, using #{exe}"
55
55
  exe
@@ -33,8 +33,11 @@ module Warbler
33
33
  end
34
34
 
35
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")
36
+ unless config.manifest_file
37
+ manifest = Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: JarMain\n"
38
+ jar.files['META-INF/MANIFEST.MF'] = StringIO.new(manifest)
39
+ end
40
+ jar.files['JarMain.class'] = jar.entry_in_jar(WARBLER_JAR, "JarMain.class")
38
41
  end
39
42
 
40
43
  def default_pathmaps
@@ -33,8 +33,13 @@ module Warbler
33
33
  end
34
34
 
35
35
  def default_executable
36
- exes = Dir['bin/*']
37
- exe = exes.grep(/#{config.jar_name}/).first || exes.first
36
+ exes = Dir['bin/*'].sort
37
+ unless(exe = exes.grep(/#{config.jar_name}/).first)
38
+ exe = exes.first
39
+ if exe
40
+ warn "No executable matching config.jar_name found, using #{exe}"
41
+ end
42
+ end
38
43
  raise "No executable script found" unless exe
39
44
  exe
40
45
  end
@@ -77,6 +77,7 @@ module Warbler
77
77
  add_public_files(jar)
78
78
  add_webxml(jar)
79
79
  move_jars_to_webinf_lib(jar)
80
+ add_runnables(jar) if config.features.include?("runnable")
80
81
  add_executables(jar) if config.features.include?("executable")
81
82
  add_gemjar(jar) if config.features.include?("gemjar")
82
83
  end
@@ -99,11 +100,21 @@ module Warbler
99
100
  end
100
101
  end
101
102
 
103
+ def add_runnables(jar, main_class = 'WarMain')
104
+ main_class = main_class.sub('.class', '') # handles WarMain.class
105
+ unless config.manifest_file
106
+ manifest = Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: #{main_class}\n"
107
+ jar.files['META-INF/MANIFEST.MF'] = StringIO.new(manifest)
108
+ end
109
+ [ 'JarMain', 'WarMain', main_class ].uniq.each do |klass|
110
+ jar.files["#{klass}.class"] = jar.entry_in_jar(WARBLER_JAR, "#{klass}.class")
111
+ end
112
+ end
113
+
102
114
  def add_executables(jar)
103
115
  webserver = WEB_SERVERS[config.webserver.to_s]
104
116
  webserver.add(jar)
105
- jar.files['META-INF/MANIFEST.MF'] = StringIO.new(Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: WarMain\n")
106
- jar.files['WarMain.class'] = jar.entry_in_jar("#{WARBLER_HOME}/lib/warbler_jar.jar", webserver.main_class)
117
+ add_runnables jar, webserver.main_class || 'WarMain'
107
118
  end
108
119
 
109
120
  def add_gemjar(jar)
@@ -6,5 +6,5 @@
6
6
  #++
7
7
 
8
8
  module Warbler
9
- VERSION = "1.3.6"
9
+ VERSION = "1.3.7"
10
10
  end
@@ -65,9 +65,9 @@ PROPS
65
65
 
66
66
  class JenkinsWinstoneServer < WinstoneServer
67
67
  def initialize
68
- @artifact = Artifact.new("http://maven.jenkins-ci.org/content/repositories/releases",
68
+ @artifact = Artifact.new("http://repo.jenkins-ci.org/public",
69
69
  "org.jenkins-ci", "winstone",
70
- ENV["WEBSERVER_VERSION"] || "0.9.10-jenkins-35")
70
+ ENV["WEBSERVER_VERSION"] || "0.9.10-jenkins-43")
71
71
  end
72
72
  end
73
73
 
data/lib/warbler_jar.jar CHANGED
Binary file
@@ -6,6 +6,10 @@
6
6
 
7
7
  require 'rake'
8
8
  require 'rake/testtask'
9
- require 'rake/rdoctask'
9
+ begin
10
+ require 'rdoc/task'
11
+ rescue LoadError
12
+ require 'rake/rdoctask'
13
+ end
10
14
 
11
15
  #require 'tasks/rails'
@@ -0,0 +1,8 @@
1
+ class RubyOneNine
2
+
3
+ RUBY_ONE_NINE_HASH = {
4
+ test: 'some ruby 1.9 syntax',
5
+ another: -> { puts 'foo' },
6
+ }
7
+
8
+ end
data/spec/spec_helper.rb CHANGED
@@ -15,7 +15,7 @@ raise %{Error: detected running Warbler specs in a Rails app;
15
15
  Warbler specs are destructive to application directories.} if File.directory?("app")
16
16
 
17
17
  require 'rbconfig'
18
- RUBY_EXE = File.join Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']
18
+ RUBY_EXE = File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']
19
19
 
20
20
  require 'fileutils'
21
21
  require 'stringio'
@@ -26,7 +26,7 @@ describe Warbler::Application do
26
26
  Warbler.application = nil
27
27
  Warbler.framework_detection = @detection
28
28
  @argv.reverse.each {|a| ARGV.unshift a}
29
- rm_rf FileList['vendor/plugins/warbler']
29
+ rm_rf FileList['lib/tasks/warbler']
30
30
  end
31
31
 
32
32
  it "should be able to list its tasks" do
@@ -67,17 +67,17 @@ describe Warbler::Application do
67
67
  end
68
68
  end
69
69
 
70
- it "should refuse to pluginize if the vendor/plugins/warbler directory exists" do
71
- mkdir_p "vendor/plugins/warbler"
70
+ it "should refuse to pluginize if the lib/tasks/warbler directory exists" do
71
+ mkdir_p "lib/tasks/warbler"
72
72
  ARGV.unshift "pluginize"
73
73
  silence { Warbler::Application.new.run }
74
- File.exist?("vendor/plugins/warbler/tasks/warbler.rake").should_not be_true
74
+ File.exist?("lib/tasks/warbler/warbler.rake").should_not be_true
75
75
  end
76
76
 
77
77
  it "should define a pluginize task for adding the tasks to a Rails application" do
78
78
  ARGV.unshift "pluginize"
79
79
  silence { Warbler::Application.new.run }
80
- File.exist?("vendor/plugins/warbler/tasks/warbler.rake").should be_true
80
+ File.exist?("lib/tasks/warbler/warbler.rake").should be_true
81
81
  end
82
82
 
83
83
  it "should provide a means to load the project Rakefile" do
@@ -20,6 +20,15 @@ describe Warbler::Jar, "with Bundler" do
20
20
  @extra_config = block
21
21
  end
22
22
 
23
+ def hide_shallow_git_clone
24
+ git_shallow_marker = File.join(Warbler::WARBLER_HOME, ".git/shallow")
25
+ tmp_marker = File.join(Warbler::WARBLER_HOME, ".git/shallow.tmp")
26
+ File.rename(git_shallow_marker, tmp_marker) if File.exists?(git_shallow_marker)
27
+ yield
28
+ ensure
29
+ File.rename(tmp_marker, git_shallow_marker) if File.exist?(tmp_marker)
30
+ end
31
+
23
32
  let(:config) { drbclient.config(@extra_config) }
24
33
  let(:jar) { drbclient.jar }
25
34
 
@@ -61,19 +70,23 @@ describe Warbler::Jar, "with Bundler" do
61
70
  end
62
71
 
63
72
  it "works with :git entries in Gemfiles" do
64
- File.open("Gemfile", "w") {|f| f << "gem 'warbler', :git => '#{Warbler::WARBLER_HOME}'\n"}
65
- `#{RUBY_EXE} -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
73
+ hide_shallow_git_clone do
74
+ File.open("Gemfile", "w") {|f| f << "gem 'warbler', :git => '#{Warbler::WARBLER_HOME}'\n"}
75
+ `#{RUBY_EXE} -S bundle install --local`
76
+ jar.apply(config)
77
+ file_list(%r{WEB-INF/gems/bundler/gems/warbler[^/]*/lib/warbler/version\.rb}).should_not be_empty
78
+ file_list(%r{WEB-INF/gems/bundler/gems/warbler[^/]*/warbler.gemspec}).should_not be_empty
79
+ end
69
80
  end
70
81
 
71
82
  it "bundles only the gemspec for :git entries that are excluded" do
72
- File.open("Gemfile", "w") {|f| f << "gem 'rake'\ngroup :test do\ngem 'warbler', :git => '#{Warbler::WARBLER_HOME}'\nend\n"}
73
- `#{RUBY_EXE} -S bundle install --local`
74
- jar.apply(config)
75
- file_list(%r{WEB-INF/gems/bundler/gems/warbler[^/]*/lib/warbler/version\.rb}).should be_empty
76
- file_list(%r{WEB-INF/gems/bundler/gems/warbler[^/]*/warbler.gemspec}).should_not be_empty
83
+ hide_shallow_git_clone do
84
+ File.open("Gemfile", "w") {|f| f << "gem 'rake'\ngroup :test do\ngem 'warbler', :git => '#{Warbler::WARBLER_HOME}'\nend\n"}
85
+ `#{RUBY_EXE} -S bundle install --local`
86
+ jar.apply(config)
87
+ file_list(%r{WEB-INF/gems/bundler/gems/warbler[^/]*/lib/warbler/version\.rb}).should be_empty
88
+ file_list(%r{WEB-INF/gems/bundler/gems/warbler[^/]*/warbler.gemspec}).should_not be_empty
89
+ end
77
90
  end
78
91
 
79
92
  it "does not work with :path entries in Gemfiles" do
@@ -96,13 +109,13 @@ describe Warbler::Jar, "with Bundler" do
96
109
  jar.add_init_file(config)
97
110
  contents = jar.contents('META-INF/init.rb')
98
111
  contents.should =~ /ENV\['BUNDLE_WITHOUT'\]/
99
- contents.should =~ /'development:test'/
112
+ contents.should =~ /'development:test:assets'/
100
113
  end
101
114
 
102
115
  it "adds BUNDLE_GEMFILE to init.rb" do
103
116
  jar.add_init_file(config)
104
117
  contents = jar.contents('META-INF/init.rb')
105
- contents.should =~ Regexp.new(Regexp.quote("ENV['BUNDLE_GEMFILE'] = $servlet_context.getRealPath('/WEB-INF/Gemfile')"))
118
+ contents.should =~ Regexp.new(Regexp.quote("ENV['BUNDLE_GEMFILE'] ||= $servlet_context.getRealPath('/WEB-INF/Gemfile')"))
106
119
  end
107
120
 
108
121
  it "uses ENV['BUNDLE_GEMFILE'] if set" do
@@ -117,14 +130,16 @@ describe Warbler::Jar, "with Bundler" do
117
130
  cleanup_temp_files
118
131
 
119
132
  it "works with :git entries in Gemfiles" do
120
- File.open("Gemfile", "w") {|f| f << "gem 'warbler', :git => '#{Warbler::WARBLER_HOME}'\n"}
121
- `#{RUBY_EXE} -S bundle install --local`
122
- jar.apply(config)
123
- file_list(%r{^bundler/gems/warbler[^/]*/lib/warbler/version\.rb}).should_not be_empty
124
- file_list(%r{^bundler/gems/warbler[^/]*/warbler.gemspec}).should_not be_empty
125
- jar.add_init_file(config)
126
- contents = jar.contents('META-INF/init.rb')
127
- contents.should =~ /ENV\['BUNDLE_GEMFILE'\] = File.expand_path(.*, __FILE__)/
133
+ hide_shallow_git_clone do
134
+ File.open("Gemfile", "w") {|f| f << "gem 'warbler', :git => '#{Warbler::WARBLER_HOME}'\n"}
135
+ `#{RUBY_EXE} -S bundle install --local`
136
+ jar.apply(config)
137
+ file_list(%r{^bundler/gems/warbler[^/]*/lib/warbler/version\.rb}).should_not be_empty
138
+ file_list(%r{^bundler/gems/warbler[^/]*/warbler.gemspec}).should_not be_empty
139
+ jar.add_init_file(config)
140
+ contents = jar.contents('META-INF/init.rb')
141
+ contents.should =~ /ENV\['BUNDLE_GEMFILE'\] = File.expand_path(.*, __FILE__)/
142
+ end
128
143
  end
129
144
 
130
145
  it "adds BUNDLE_GEMFILE to init.rb" do
@@ -155,4 +170,16 @@ describe Warbler::Jar, "with Bundler" do
155
170
  contents.split("\n").grep(/ENV\['BUNDLE_FROZEN'\] = '1'/).should_not be_empty
156
171
  end
157
172
  end
173
+
174
+ context "when deployment" do
175
+ run_in_directory "spec/sample_bundler"
176
+
177
+ it "includes the bundler gem" do
178
+ `#{RUBY_EXE} -S bundle install --deployment`
179
+ jar.apply(config)
180
+ file_list(%r{gems/rake-0.8.7/lib}).should_not be_empty
181
+ file_list(%r{gems/bundler-}).should_not be_empty
182
+ file_list(%r{gems/bundler-.*/lib}).should_not be_empty
183
+ end
184
+ end
158
185
  end
@@ -19,6 +19,7 @@ describe Warbler::Config do
19
19
  config = Warbler::Config.new
20
20
  config.includes.should be_empty
21
21
  config.jar_name.size.should > 0
22
+ config.override_gem_home.should be_false
22
23
  end
23
24
  end
24
25
 
@@ -32,12 +33,13 @@ describe Warbler::Config do
32
33
  it "should have suitable default values" do
33
34
  config = Warbler::Config.new
34
35
  config.dirs.should include(*Warbler::Config::TOP_DIRS.select{|d| File.directory?(d)})
35
- config.includes.should be_empty
36
+ config.excludes.should be_empty
36
37
  config.java_libs.should_not be_empty
37
38
  config.jar_name.size.should > 0
38
39
  config.webxml.should be_kind_of(OpenStruct)
39
40
  config.pathmaps.should be_kind_of(OpenStruct)
40
41
  config.pathmaps.public_html.should == ["%{public/,}p"]
42
+ config.override_gem_home.should be_false
41
43
  end
42
44
 
43
45
  it "should allow configuration through an initializer block" do
@@ -55,10 +55,17 @@ describe Warbler::Jar do
55
55
  contents.split("\n").grep(/require 'rubygems'/).should_not be_empty
56
56
  end
57
57
 
58
- it "adds ENV['GEM_HOME'] to init.rb" do
58
+ it "does not override ENV['GEM_HOME'] by default" do
59
59
  jar.add_init_file(config)
60
60
  contents = jar.contents('META-INF/init.rb')
61
- contents.should =~ /ENV\['GEM_HOME'\]/
61
+ contents.should =~ %r{ENV['GEM_HOME'] ||=}
62
+ end
63
+
64
+ it "overrides ENV['GEM_HOME'] when override_gem_home is set" do
65
+ config.override_gem_home = true
66
+ jar.add_init_file(config)
67
+ contents = jar.contents('META-INF/init.rb')
68
+ contents.should =~ /ENV\['GEM_HOME'\] =/
62
69
  end
63
70
 
64
71
  it "adds a main.rb" do
@@ -137,7 +144,7 @@ describe Warbler::Jar do
137
144
  jar.compile(config)
138
145
  jar.apply(config)
139
146
  file_list(%r{^sample_jar/lib/sample_jar\.class$}).should_not be_empty
140
- jar.contents('sample_jar/lib/sample_jar.rb').should =~ /require __FILE__\.sub/
147
+ jar.contents('sample_jar/lib/sample_jar.rb').should =~ /load __FILE__\.sub/
141
148
  end
142
149
  end
143
150
 
@@ -475,16 +482,30 @@ describe Warbler::Jar do
475
482
  context "with the executable feature" do
476
483
  use_test_webserver
477
484
 
478
- it "adds a WarMain class" do
485
+ it "adds WarMain (and JarMain) class" do
479
486
  use_config do |config|
480
487
  config.webserver = "test"
481
488
  config.features << "executable"
482
489
  end
483
490
  jar.apply(config)
484
491
  file_list(%r{^WarMain\.class$}).should_not be_empty
492
+ file_list(%r{^JarMain\.class$}).should_not be_empty
485
493
  end
486
494
  end
487
495
 
496
+ context "with the runnable feature" do
497
+
498
+ it "adds WarMain (and JarMain) class" do
499
+ use_config do |config|
500
+ config.features << "runnable"
501
+ end
502
+ jar.apply(config)
503
+ file_list(%r{^WarMain\.class$}).should_not be_empty
504
+ file_list(%r{^JarMain\.class$}).should_not be_empty
505
+ end
506
+
507
+ end
508
+
488
509
  context "in a Rails application" do
489
510
  before :each do
490
511
  @rails = nil
@@ -105,7 +105,23 @@ describe Warbler::Task do
105
105
  ruby_class_definition = zf.get_input_stream('WEB-INF/app/helpers/application_helper.rb') {|io| io.read }
106
106
 
107
107
  java_class_header.should == java_class_magic_number
108
- ruby_class_definition.should == %{require __FILE__.sub(/.rb$/, '.class')}
108
+ ruby_class_definition.should == %{load __FILE__.sub(/.rb$/, '.class')}
109
+ end
110
+ end
111
+
112
+ it "should compile ruby 1.9 mode" do
113
+ config.features << "compiled"
114
+ config.webxml.jruby.compat.version = '1.9'
115
+ silence { run_task "warble" }
116
+
117
+ java_class_magic_number = [0xCA,0xFE,0xBA,0xBE].map { |magic_char| magic_char.chr }.join
118
+
119
+ Zip::ZipFile.open("#{config.jar_name}.war") do |zf|
120
+ java_class_header = zf.get_input_stream('WEB-INF/lib/ruby_one_nine.class') {|io| io.read }[0..3]
121
+ ruby_class_definition = zf.get_input_stream('WEB-INF/lib/ruby_one_nine.rb') {|io| io.read }
122
+
123
+ java_class_header.should == java_class_magic_number
124
+ ruby_class_definition.should == %{load __FILE__.sub(/.rb$/, '.class')}
109
125
  end
110
126
  end
111
127