realityforge-buildr 1.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.md +3 -0
  6. data/Rakefile +50 -0
  7. data/addon/buildr/checkstyle-report.xsl +104 -0
  8. data/addon/buildr/checkstyle.rb +254 -0
  9. data/addon/buildr/git_auto_version.rb +36 -0
  10. data/addon/buildr/gpg.rb +90 -0
  11. data/addon/buildr/gwt.rb +413 -0
  12. data/addon/buildr/jacoco.rb +161 -0
  13. data/addon/buildr/pmd.rb +185 -0
  14. data/addon/buildr/single_intermediate_layout.rb +71 -0
  15. data/addon/buildr/spotbugs.rb +265 -0
  16. data/addon/buildr/top_level_generate_dir.rb +37 -0
  17. data/addon/buildr/wsgen.rb +192 -0
  18. data/bin/buildr +20 -0
  19. data/buildr.gemspec +61 -0
  20. data/lib/buildr.rb +86 -0
  21. data/lib/buildr/core/application.rb +705 -0
  22. data/lib/buildr/core/assets.rb +96 -0
  23. data/lib/buildr/core/build.rb +587 -0
  24. data/lib/buildr/core/common.rb +167 -0
  25. data/lib/buildr/core/compile.rb +599 -0
  26. data/lib/buildr/core/console.rb +124 -0
  27. data/lib/buildr/core/doc.rb +275 -0
  28. data/lib/buildr/core/environment.rb +128 -0
  29. data/lib/buildr/core/filter.rb +405 -0
  30. data/lib/buildr/core/help.rb +114 -0
  31. data/lib/buildr/core/progressbar.rb +161 -0
  32. data/lib/buildr/core/project.rb +994 -0
  33. data/lib/buildr/core/test.rb +776 -0
  34. data/lib/buildr/core/transports.rb +456 -0
  35. data/lib/buildr/core/util.rb +77 -0
  36. data/lib/buildr/ide/idea.rb +1664 -0
  37. data/lib/buildr/java/commands.rb +230 -0
  38. data/lib/buildr/java/compiler.rb +85 -0
  39. data/lib/buildr/java/custom_pom.rb +300 -0
  40. data/lib/buildr/java/doc.rb +62 -0
  41. data/lib/buildr/java/packaging.rb +393 -0
  42. data/lib/buildr/java/pom.rb +191 -0
  43. data/lib/buildr/java/test_result.rb +54 -0
  44. data/lib/buildr/java/tests.rb +111 -0
  45. data/lib/buildr/packaging/archive.rb +586 -0
  46. data/lib/buildr/packaging/artifact.rb +1113 -0
  47. data/lib/buildr/packaging/artifact_namespace.rb +1010 -0
  48. data/lib/buildr/packaging/artifact_search.rb +138 -0
  49. data/lib/buildr/packaging/package.rb +237 -0
  50. data/lib/buildr/packaging/version_requirement.rb +189 -0
  51. data/lib/buildr/packaging/zip.rb +189 -0
  52. data/lib/buildr/packaging/ziptask.rb +387 -0
  53. data/lib/buildr/version.rb +18 -0
  54. data/rakelib/release.rake +99 -0
  55. data/spec/addon/checkstyle_spec.rb +58 -0
  56. data/spec/core/application_spec.rb +576 -0
  57. data/spec/core/build_spec.rb +922 -0
  58. data/spec/core/common_spec.rb +670 -0
  59. data/spec/core/compile_spec.rb +656 -0
  60. data/spec/core/console_spec.rb +65 -0
  61. data/spec/core/doc_spec.rb +194 -0
  62. data/spec/core/extension_spec.rb +200 -0
  63. data/spec/core/project_spec.rb +736 -0
  64. data/spec/core/test_spec.rb +1131 -0
  65. data/spec/core/transport_spec.rb +452 -0
  66. data/spec/core/util_spec.rb +154 -0
  67. data/spec/ide/idea_spec.rb +1952 -0
  68. data/spec/java/commands_spec.rb +79 -0
  69. data/spec/java/compiler_spec.rb +274 -0
  70. data/spec/java/custom_pom_spec.rb +165 -0
  71. data/spec/java/doc_spec.rb +55 -0
  72. data/spec/java/packaging_spec.rb +786 -0
  73. data/spec/java/pom_spec.rb +162 -0
  74. data/spec/java/test_coverage_helper.rb +257 -0
  75. data/spec/java/tests_spec.rb +224 -0
  76. data/spec/packaging/archive_spec.rb +686 -0
  77. data/spec/packaging/artifact_namespace_spec.rb +757 -0
  78. data/spec/packaging/artifact_spec.rb +1351 -0
  79. data/spec/packaging/packaging_helper.rb +63 -0
  80. data/spec/packaging/packaging_spec.rb +690 -0
  81. data/spec/sandbox.rb +166 -0
  82. data/spec/spec_helpers.rb +420 -0
  83. data/spec/version_requirement_spec.rb +145 -0
  84. data/spec/xpath_matchers.rb +123 -0
  85. metadata +295 -0
@@ -0,0 +1,18 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ module Buildr #:nodoc:
17
+ VERSION = '1.5.9'.freeze
18
+ end
@@ -0,0 +1,99 @@
1
+ WORKSPACE_DIR = File.expand_path(File.dirname(__FILE__) + '/..')
2
+
3
+ ENV['PREVIOUS_PRODUCT_VERSION'] = nil if ENV['PREVIOUS_PRODUCT_VERSION'].to_s == ''
4
+ ENV['PRODUCT_VERSION'] = nil if ENV['PRODUCT_VERSION'].to_s == ''
5
+
6
+ def in_dir(dir)
7
+ current = Dir.pwd
8
+ begin
9
+ Dir.chdir(dir)
10
+ yield
11
+ ensure
12
+ Dir.chdir(current)
13
+ end
14
+ end
15
+
16
+ def stage(stage_name, description, options = {})
17
+ if ENV['STAGE'].nil? || ENV['STAGE'] == stage_name || options[:always_run]
18
+ puts "🚀 Release Stage: #{stage_name} - #{description}"
19
+ begin
20
+ yield
21
+ rescue Exception => e
22
+ puts '💣 Error completing stage.'
23
+ puts "Fix the error and re-run release process passing: STAGE=#{stage_name}#{ ENV['PREVIOUS_PRODUCT_VERSION'] ? " PREVIOUS_PRODUCT_VERSION=#{ENV['PREVIOUS_PRODUCT_VERSION']}" : ''}#{ ENV['PREVIOUS_PRODUCT_VERSION'] ? " PRODUCT_VERSION=#{ENV['PRODUCT_VERSION']}" : ''}"
24
+ raise e
25
+ end
26
+ ENV['STAGE'] = nil unless options[:always_run]
27
+ elsif !ENV['STAGE'].nil?
28
+ puts "Skipping Stage: #{stage_name} - #{description}"
29
+ end
30
+ end
31
+
32
+ desc 'Perform a release'
33
+ task 'perform_release' do
34
+
35
+ in_dir(WORKSPACE_DIR) do
36
+ stage('ExtractVersion', 'Extract the version from the version constant', :always_run => true) do
37
+ ENV['PRODUCT_VERSION'] ||= IO.read('lib/buildr/version.rb')[/VERSION = '(\d+\.\d+\.\d+)(\.dev)?'\.freeze/, 1]
38
+ raise "Unable to extract version from lib/buildr/version.rb" unless ENV['PRODUCT_VERSION']
39
+ end
40
+
41
+ stage('PreReleaseUpdateVersion', 'Update the version to the non-dev version') do
42
+ filename = 'lib/buildr/version.rb'
43
+ content = IO.read(filename).sub(/VERSION = '(.*)'\.freeze/, "VERSION = '#{ENV['PRODUCT_VERSION']}'.freeze")
44
+ IO.write(filename, content)
45
+ unless `git status #{filename}`.strip.empty?
46
+ sh "git add #{filename}"
47
+ sh 'git commit -m "Update version in preparation for release"'
48
+ end
49
+ end
50
+
51
+ stage('ZapWhite', 'Ensure that zapwhite produces no changes') do
52
+ sh 'bundle exec zapwhite'
53
+ end
54
+
55
+ stage('GitClean', 'Ensure there is nothing to commit and the working tree is clean') do
56
+ status_output = `git status -s 2>&1`.strip
57
+ raise 'Uncommitted changes in git repository. Please commit them prior to release.' if 0 != status_output.size
58
+ end
59
+
60
+ stage('AddonExtensionsCheck', 'Ensure that files in addon directory do not have the .rake suffix.') do
61
+ bad_files = FileList['addon/**/*.rake']
62
+ raise "#{bad_files.join(', ')} named with .rake extension but should be .rb, fix them before making a release!" unless bad_files.empty?
63
+ end
64
+
65
+ stage('Build', 'Build the project to ensure that the tests pass') do
66
+ sh "bundle exec rake clobber"
67
+ sh "bundle exec rake package"
68
+ end
69
+
70
+ stage('TagProject', 'Tag the project') do
71
+ sh "git tag v#{ENV['PRODUCT_VERSION']}"
72
+ end
73
+
74
+ stage('RubyGemsPublish', 'Publish artifacts to RubyGems.org') do
75
+ FileList["pkg/*.gem"].each do |f|
76
+ sh "bundle exec gem push #{f}"
77
+ end
78
+ end
79
+
80
+ stage('PostReleaseUpdateVersion', 'Update the version to the non-dev version') do
81
+ filename = 'lib/buildr/version.rb'
82
+ parts = ENV['PRODUCT_VERSION'].split
83
+ next_version = "#{parts[0]}.#{parts[1]}.#{parts[2].to_i + 1}"
84
+ content = IO.read(filename).sub(/VERSION = '(.*)'\.freeze/, "VERSION = '#{next_version}.dev'.freeze")
85
+ IO.write(filename, content)
86
+ sh "git add #{filename}"
87
+ sh 'git commit -m "Update version in preparation for development"'
88
+ end
89
+
90
+ stage('PushChanges', 'Push changes to git repository') do
91
+ sh 'git push'
92
+ sh 'git push --tags'
93
+ end
94
+ end
95
+
96
+ if ENV['STAGE']
97
+ raise "Invalid STAGE specified '#{ENV['STAGE']}' that did not match any stage"
98
+ end
99
+ end
@@ -0,0 +1,58 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ require File.expand_path('../spec_helpers', File.dirname(__FILE__))
17
+
18
+ Sandbox.require_optional_extension 'buildr/checkstyle'
19
+ artifacts(Buildr::Checkstyle::dependencies).map(&:invoke)
20
+
21
+ CHECKS_CONTENT = <<CHECKS
22
+ <?xml version="1.0"?>
23
+ <!DOCTYPE module PUBLIC
24
+ "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
25
+ "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
26
+ <module name="Checker">
27
+ </module>
28
+ CHECKS
29
+ GOOD_CONTENT = <<GOOD
30
+ public final class SomeClass {
31
+ }
32
+ GOOD
33
+
34
+ describe Buildr::Checkstyle do
35
+
36
+ before do
37
+ # Reloading the extension because the sandbox removes all its actions
38
+ Buildr.module_eval { remove_const :Checkstyle }
39
+ load File.expand_path('../../addon/buildr/checkstyle.rb', File.dirname(__FILE__))
40
+ @tool_module = Buildr::Checkstyle
41
+
42
+ write 'src/main/java/SomeClass.java', GOOD_CONTENT
43
+ write 'src/main/etc/checkstyle/checks.xml', CHECKS_CONTENT
44
+ end
45
+
46
+ it 'should generate an XML report' do
47
+ define 'foo'
48
+ task('foo:checkstyle:xml').invoke
49
+ file(project('foo')._('reports/checkstyle/checkstyle.xml')).should exist
50
+ end
51
+
52
+ it 'should generate an HTML report' do
53
+ define 'foo'
54
+ task('foo:checkstyle:html').invoke
55
+ file(project('foo')._('reports/checkstyle/checkstyle.html')).should exist
56
+ end
57
+
58
+ end
@@ -0,0 +1,576 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18
+
19
+
20
+ describe Buildr::Application do
21
+
22
+ describe 'home_dir' do
23
+ it 'should point to ~/.buildr' do
24
+ Buildr.application.home_dir.should eql(File.expand_path('.buildr', ENV['HOME']))
25
+ end
26
+
27
+ it 'should point to existing directory' do
28
+ File.directory?(Buildr.application.home_dir).should be_true
29
+ end
30
+ end
31
+
32
+ describe '#run' do
33
+ before(:each) do
34
+ FileUtils.touch 'Buildfile'
35
+ end
36
+
37
+ it 'should execute *_load methods in order' do
38
+ order = [:load_gems, :load_artifact_ns, :load_tasks, :raw_load_buildfile]
39
+ order.each { |method| Buildr.application.should_receive(method).ordered }
40
+ Buildr.application.stub(:exit) # With this, shows the correct error instead of SystemExit.
41
+ Buildr.application.run
42
+ end
43
+
44
+ it 'should load imports after loading buildfile' do
45
+ method = Buildr.application.method(:raw_load_buildfile)
46
+ Buildr.application.should_receive(:raw_load_buildfile) do
47
+ Buildr.application.should_receive(:load_imports)
48
+ method.call
49
+ end
50
+ Buildr.application.stub(:exit) # With this, shows the correct error instead of SystemExit.
51
+ Buildr.application.run
52
+ end
53
+
54
+ it 'should evaluate all projects after loading buildfile' do
55
+ Buildr.application.should_receive(:load_imports) do
56
+ Buildr.should_receive(:projects)
57
+ end
58
+ Buildr.application.stub(:exit) # With this, shows the correct error instead of SystemExit.
59
+ Buildr.application.run
60
+ end
61
+ end
62
+
63
+ describe 'environment' do
64
+ it 'should return value of BUILDR_ENV' do
65
+ ENV['BUILDR_ENV'] = 'qa'
66
+ Buildr.application.environment.should eql('qa')
67
+ end
68
+
69
+ it 'should default to development' do
70
+ Buildr.application.environment.should eql('development')
71
+ end
72
+
73
+ it 'should set environment name from -e argument' do
74
+ ARGV.push('-e', 'test')
75
+ Buildr.application.send(:handle_options)
76
+ Buildr.application.environment.should eql('test')
77
+ ENV['BUILDR_ENV'].should eql('test')
78
+ end
79
+
80
+ it 'should be echoed to user' do
81
+ write 'buildfile'
82
+ ENV['BUILDR_ENV'] = 'spec'
83
+ Buildr.application.send(:handle_options)
84
+ lambda { Buildr.application.send :load_buildfile }.should show(%r{(in .*, spec)})
85
+ end
86
+ end
87
+
88
+ describe 'options' do
89
+ it "should have 'tasks' as the sole default rakelib" do
90
+ Buildr.application.send(:handle_options)
91
+ Buildr.application.options.rakelib.should == ['tasks']
92
+ end
93
+
94
+ it 'should show the version when prompted with -V' do
95
+ ARGV.push('-V')
96
+ test_exit(0) { Buildr.application.send(:handle_options) }.should show(/Buildr #{Buildr::VERSION}.*/)
97
+ end
98
+
99
+ it 'should show the version when prompted with --version' do
100
+ ARGV.push('--version')
101
+ test_exit(0) { Buildr.application.send(:handle_options) }.should show(/Buildr #{Buildr::VERSION}.*/)
102
+ end
103
+
104
+ it 'should enable tracing with --trace' do
105
+ ARGV.push('--trace')
106
+ Buildr.application.send(:handle_options)
107
+ Buildr.application.options.trace.should == true
108
+ end
109
+
110
+ it 'should enable tracing of [:foo, :bar] categories with --trace=foo,bar' do
111
+ ARGV.push('--trace=foo,bar')
112
+ Buildr.application.send(:handle_options)
113
+ Buildr.application.options.trace.should == true
114
+ Buildr.application.options.trace_categories.should == [:foo, :bar]
115
+ trace?(:foo).should == true
116
+ trace?(:not).should == false
117
+ end
118
+
119
+ it 'should enable tracing for all categories with --trace=all' do
120
+ ARGV.push('--trace=all')
121
+ Buildr.application.send(:handle_options)
122
+ Buildr.application.options.trace.should == true
123
+ Buildr.application.options.trace_all.should == true
124
+ trace?(:foo).should == true
125
+ end
126
+
127
+ end
128
+
129
+ describe 'gems' do
130
+ before do
131
+ class << Buildr.application
132
+ public :load_gems
133
+ end
134
+ end
135
+
136
+ def load_with_yaml
137
+ write 'build.yaml', <<-YAML
138
+ gems:
139
+ - rake
140
+ - rspec ~> 2.9.0
141
+ YAML
142
+ Buildr.application.should_receive(:listed_gems).and_return([[Gem.loaded_specs['rspec'],Gem.loaded_specs['rake']],[]])
143
+ Buildr.application.load_gems
144
+ end
145
+
146
+ it 'should return empty array if no gems specified' do
147
+ Buildr.application.load_gems
148
+ Buildr.application.gems.should be_empty
149
+ end
150
+
151
+ it 'should return one entry for each gem specified in buildr.yaml' do
152
+ load_with_yaml
153
+ Buildr.application.gems.size.should be(2)
154
+ end
155
+
156
+ it 'should parse Gem name correctly' do
157
+ load_with_yaml
158
+ Buildr.application.gems.map(&:name).should include('rspec', 'rake')
159
+ end
160
+
161
+ it 'should find installed version of Gem' do
162
+ load_with_yaml
163
+ Buildr.application.gems.each { |gem| gem.version.should eql(Gem.loaded_specs[gem.name].version) }
164
+ end
165
+ end
166
+
167
+ describe 'load_gems' do
168
+ before do
169
+ class << Buildr.application
170
+ public :load_gems
171
+ end
172
+ @spec = Gem::Specification.new do |spec|
173
+ spec.name = 'buildr-foo'
174
+ spec.version = '1.2'
175
+ end
176
+ $stdout.stub(:isatty).and_return(true)
177
+ end
178
+
179
+ it 'should do nothing if no gems specified' do
180
+ lambda { Buildr.application.load_gems }.should_not raise_error
181
+ end
182
+
183
+ it 'should install nothing if specified gems already installed' do
184
+ Buildr.application.should_receive(:listed_gems).and_return([[Gem.loaded_specs['rspec']],[]])
185
+ Util.should_not_receive(:ruby)
186
+ lambda { Buildr.application.load_gems }.should_not raise_error
187
+ end
188
+
189
+ it 'should fail if required gem not installed' do
190
+ Buildr.application.should_receive(:listed_gems).and_return([[],[Gem::Dependency.new('buildr-foo', '>=1.1')]])
191
+ lambda { Buildr.application.load_gems }.should raise_error(LoadError, /cannot be found/i)
192
+ end
193
+
194
+ it 'should load previously installed gems' do
195
+ Gem.loaded_specs['rspec'].should_receive(:activate)
196
+ Buildr.application.should_receive(:listed_gems).and_return([[Gem.loaded_specs['rspec']],[]])
197
+ #Buildr.application.should_receive(:gem).with('rspec', Gem.loaded_specs['rspec'].version.to_s)
198
+ Buildr.application.load_gems
199
+ end
200
+
201
+ it 'should default to >=0 version requirement if not specified' do
202
+ write 'build.yaml', 'gems: buildr-foo'
203
+ should_attempt_to_load_dependency(Gem::Dependency.new('buildr-foo', '>= 0'))
204
+ end
205
+
206
+ it 'should parse exact version requirement' do
207
+ write 'build.yaml', 'gems: buildr-foo 2.5'
208
+ should_attempt_to_load_dependency(Gem::Dependency.new('buildr-foo', '=2.5'))
209
+ end
210
+
211
+ it 'should parse range version requirement' do
212
+ write 'build.yaml', 'gems: buildr-foo ~>2.3'
213
+ should_attempt_to_load_dependency(Gem::Dependency.new('buildr-foo', '~>2.3'))
214
+ end
215
+
216
+ it 'should parse multiple version requirements' do
217
+ write 'build.yaml', 'gems: buildr-foo >=2.0 !=2.1'
218
+ should_attempt_to_load_dependency(Gem::Dependency.new('buildr-foo', %w[>=2.0 !=2.1]))
219
+ end
220
+
221
+ def should_attempt_to_load_dependency(dep)
222
+ missing_gems = Buildr.application.send(:listed_gems)[1]
223
+ missing_gems.size.should eql(1)
224
+ missing_gems[0].eql?(dep)
225
+ end
226
+ end
227
+
228
+ describe 'load_tasks' do
229
+ before do
230
+ class << Buildr.application
231
+ public :load_tasks
232
+ end
233
+ @original_loaded_features = $LOADED_FEATURES.dup
234
+ Buildr.application.options.rakelib = ["tasks"]
235
+ end
236
+
237
+ after do
238
+ $taskfiles = nil
239
+ ($LOADED_FEATURES - @original_loaded_features).each do |new_load|
240
+ $LOADED_FEATURES.delete(new_load)
241
+ end
242
+ end
243
+
244
+ def write_task(filename)
245
+ write filename, <<-RUBY
246
+ $taskfiles ||= []
247
+ $taskfiles << __FILE__
248
+ RUBY
249
+ end
250
+
251
+ def loaded_tasks
252
+ @loaded ||= Buildr.application.load_tasks
253
+ $taskfiles
254
+ end
255
+
256
+ it "should load {options.rakelib}/foo.rake" do
257
+ write_task 'tasks/foo.rake'
258
+ loaded_tasks.should have(1).task
259
+ loaded_tasks.first.should =~ %r{tasks/foo\.rake$}
260
+ end
261
+
262
+ it 'should load all *.rake files from the rakelib' do
263
+ write_task 'tasks/bar.rake'
264
+ write_task 'tasks/quux.rake'
265
+ loaded_tasks.should have(2).tasks
266
+ end
267
+
268
+ it 'should not load files which do not have the .rake extension' do
269
+ write_task 'tasks/foo.rb'
270
+ write_task 'tasks/bar.rake'
271
+ loaded_tasks.should have(1).task
272
+ loaded_tasks.first.should =~ %r{tasks/bar\.rake$}
273
+ end
274
+
275
+ it 'should load files only from the directory specified in the rakelib option' do
276
+ Buildr.application.options.rakelib = ['extensions']
277
+ write_task 'extensions/amp.rake'
278
+ write_task 'tasks/bar.rake'
279
+ write_task 'extensions/foo.rake'
280
+ loaded_tasks.should have(2).tasks
281
+ %w[amp foo].each do |filename|
282
+ loaded_tasks.select{|x| x =~ %r{extensions/#{filename}\.rake}}.should have(1).entry
283
+ end
284
+ end
285
+
286
+ it 'should load files from all the directories specified in the rakelib option' do
287
+ Buildr.application.options.rakelib = %w[ext more tasks]
288
+ write_task 'ext/foo.rake'
289
+ write_task 'tasks/bar.rake'
290
+ write_task 'tasks/zeb.rake'
291
+ write_task 'more/baz.rake'
292
+ loaded_tasks.should have(4).tasks
293
+ end
294
+
295
+ it 'should not load files from the rakelib more than once' do
296
+ write_task 'tasks/new_one.rake'
297
+ write_task 'tasks/already.rake'
298
+ $LOADED_FEATURES << File.expand_path('tasks/already.rake')
299
+
300
+ loaded_tasks.should have(1).task
301
+ loaded_tasks.first.should =~ %r{tasks/new_one\.rake$}
302
+ end
303
+ end
304
+
305
+ describe 'exception handling' do
306
+
307
+ it 'should exit when given a SystemExit exception' do
308
+ test_exit(3) { Buildr.application.standard_exception_handling { raise SystemExit.new(3) } }
309
+ end
310
+
311
+ it 'should exit with status 1 when given an OptionParser::ParseError exception' do
312
+ test_exit(1) { Buildr.application.standard_exception_handling { raise OptionParser::ParseError.new() } }
313
+ end
314
+
315
+ it 'should exit with status 1 when given any other type of exception exception' do
316
+ test_exit(1) { Buildr.application.standard_exception_handling { raise Exception.new() } }
317
+ end
318
+
319
+ it 'should print the class name and the message when receiving an exception (except when the exception is named Exception)' do
320
+
321
+ # Our fake $stderr for the exercise. We could start it with a matcher instead
322
+ class FakeStdErr
323
+
324
+ attr_accessor :messages
325
+
326
+ def puts(*args)
327
+ @messages ||= []
328
+ @messages += args
329
+ end
330
+
331
+ alias :write :puts
332
+ end
333
+
334
+ # Save the old $stderr and make sure to restore it in the end.
335
+ old_stderr = $stderr
336
+ begin
337
+
338
+ $stderr = FakeStdErr.new
339
+ test_exit(1) {
340
+ Buildr.application.send :standard_exception_handling do
341
+ class MyOwnNicelyNamedException < Exception
342
+ end
343
+ raise MyOwnNicelyNamedException.new('My message')
344
+ end
345
+ }.call
346
+ $stderr.messages.select {|msg| msg =~ /.*MyOwnNicelyNamedException : My message.*/}.size.should == 1
347
+ $stderr.messages.clear
348
+ test_exit(1) {
349
+ Buildr.application.send :standard_exception_handling do
350
+ raise Exception.new('My message')
351
+ end
352
+ }.call
353
+ $stderr.messages.select {|msg| msg =~ /.*My message.*/ && !(msg =~ /Exception/)}.size.should == 1
354
+ end
355
+ $stderr = old_stderr
356
+ end
357
+ end
358
+
359
+ end
360
+
361
+
362
+ describe Buildr, 'settings' do
363
+
364
+ describe 'user' do
365
+
366
+ it 'should be empty hash if no settings.yaml file' do
367
+ Buildr.settings.user.should == {}
368
+ end
369
+
370
+ it 'should return loaded settings.yaml file' do
371
+ write 'home/.buildr/settings.yaml', 'foo: bar'
372
+ Buildr.settings.user.should == { 'foo'=>'bar' }
373
+ end
374
+
375
+ it 'should return loaded settings.yml file' do
376
+ write 'home/.buildr/settings.yml', 'foo: bar'
377
+ Buildr.settings.user.should == { 'foo'=>'bar' }
378
+ end
379
+
380
+ it 'should fail if settings.yaml file is not a hash' do
381
+ write 'home/.buildr/settings.yaml', 'foo bar'
382
+ lambda { Buildr.settings.user }.should raise_error(RuntimeError, /expecting.*settings.yaml/i)
383
+ end
384
+
385
+ it 'should be empty hash if settings.yaml file is empty' do
386
+ write 'home/.buildr/settings.yaml'
387
+ Buildr.settings.user.should == {}
388
+ end
389
+ end
390
+
391
+ describe 'configuration' do
392
+ it 'should be empty hash if no build.yaml file' do
393
+ Buildr.settings.build.should == {}
394
+ end
395
+
396
+ it 'should return loaded build.yaml file' do
397
+ write 'build.yaml', 'foo: bar'
398
+ Buildr.settings.build.should == { 'foo'=>'bar' }
399
+ end
400
+
401
+ it 'should return loaded build.yml file' do
402
+ write 'build.yml', 'foo: bar'
403
+ Buildr.settings.build.should == { 'foo'=>'bar' }
404
+ end
405
+
406
+ it 'should fail if build.yaml file is not a hash' do
407
+ write 'build.yaml', 'foo bar'
408
+ lambda { Buildr.settings.build }.should raise_error(RuntimeError, /expecting.*build.yaml/i)
409
+ end
410
+
411
+ it 'should be empty hash if build.yaml file is empty' do
412
+ write 'build.yaml'
413
+ Buildr.settings.build.should == {}
414
+ end
415
+ end
416
+
417
+ describe 'profiles' do
418
+ it 'should be empty hash if no profiles.yaml file' do
419
+ Buildr.settings.profiles.should == {}
420
+ end
421
+
422
+ it 'should return loaded profiles.yaml file' do
423
+ write 'profiles.yaml', <<-YAML
424
+ development:
425
+ foo: bar
426
+ YAML
427
+ Buildr.settings.profiles.should == { 'development'=> { 'foo'=>'bar' } }
428
+ end
429
+
430
+ it 'should return loaded profiles.yml file' do
431
+ write 'profiles.yml', <<-YAML
432
+ development:
433
+ foo: bar
434
+ YAML
435
+ Buildr.settings.profiles.should == { 'development'=> { 'foo'=>'bar' } }
436
+ end
437
+
438
+ it 'should fail if profiles.yaml file is not a hash' do
439
+ write 'profiles.yaml', 'foo bar'
440
+ lambda { Buildr.settings.profiles }.should raise_error(RuntimeError, /expecting.*profiles.yaml/i)
441
+ end
442
+
443
+ it 'should be empty hash if profiles.yaml file is empty' do
444
+ write 'profiles.yaml'
445
+ Buildr.settings.profiles.should == {}
446
+ end
447
+ end
448
+
449
+ describe 'profile' do
450
+ before do
451
+ end
452
+
453
+ it 'should be empty hash if no profiles.yaml' do
454
+ Buildr.settings.profile.should == {}
455
+ end
456
+
457
+ it 'should be empty hash if no matching profile' do
458
+ write 'profiles.yaml', <<-YAML
459
+ test:
460
+ foo: bar
461
+ YAML
462
+ Buildr.settings.profile.should == {}
463
+ end
464
+
465
+ it 'should return profile matching environment name' do
466
+ write 'profiles.yaml', <<-YAML
467
+ development:
468
+ foo: bar
469
+ test:
470
+ foo: baz
471
+ YAML
472
+ Buildr.settings.profile.should == { 'foo'=>'bar' }
473
+ end
474
+ end
475
+
476
+ describe 'buildfile task' do
477
+ before do
478
+ @buildfile_time = Time.now - 10
479
+ write 'buildfile'; File.utime(@buildfile_time, @buildfile_time, 'buildfile')
480
+ end
481
+
482
+ it 'should point to the buildfile' do
483
+ Buildr.application.buildfile.should point_to_path('buildfile')
484
+ end
485
+
486
+ it 'should be a defined task' do
487
+ Buildr.application.buildfile.should == file(File.expand_path('buildfile'))
488
+ end
489
+
490
+ it 'should ignore any rake namespace' do
491
+ namespace 'dummy_ns' do
492
+ Buildr.application.buildfile.should point_to_path('buildfile')
493
+ end
494
+ end
495
+
496
+ it 'should have the same timestamp as the buildfile' do
497
+ Buildr.application.buildfile.timestamp.should be_within(1).of(@buildfile_time)
498
+ end
499
+
500
+ it 'should have the same timestamp as build.yaml if the latter is newer' do
501
+ write 'build.yaml'; File.utime(@buildfile_time + 5, @buildfile_time + 5, 'build.yaml')
502
+ Buildr.application.run
503
+ Buildr.application.buildfile.timestamp.should be_within(1).of(@buildfile_time + 5)
504
+ end
505
+
506
+ it 'should have the same timestamp as the buildfile if build.yaml is older' do
507
+ write 'build.yaml'; File.utime(@buildfile_time - 5, @buildfile_time - 5, 'build.yaml')
508
+ Buildr.application.run
509
+ Buildr.application.buildfile.timestamp.should be_within(1).of(@buildfile_time)
510
+ end
511
+
512
+ it 'should have the same timestamp as build.rb in home dir if the latter is newer (until version 1.6)' do
513
+ Buildr::VERSION.should < '1.6'
514
+ buildfile_should_have_same_timestamp_as 'home/buildr.rb'
515
+ end
516
+
517
+ it 'should have the same timestamp as build.rb in home dir if the latter is newer' do
518
+ buildfile_should_have_same_timestamp_as 'home/.buildr/buildr.rb'
519
+ end
520
+
521
+ it 'should have the same timestamp as .buildr.rb in buildfile dir if the latter is newer' do
522
+ buildfile_should_have_same_timestamp_as '.buildr.rb'
523
+ end
524
+
525
+ it 'should have the same timestamp as _buildr.rb in buildfile dir if the latter is newer' do
526
+ buildfile_should_have_same_timestamp_as '_buildr.rb'
527
+ end
528
+
529
+ def buildfile_should_have_same_timestamp_as(file)
530
+ write file; File.utime(@buildfile_time + 5, @buildfile_time + 5, file)
531
+ Buildr.application.send :load_tasks
532
+ Buildr.application.buildfile.timestamp.should be_within(1).of(@buildfile_time + 5)
533
+ end
534
+ end
535
+ end
536
+
537
+
538
+ describe Buildr do
539
+
540
+ describe 'environment' do
541
+ it 'should be same as Buildr.application.environment' do
542
+ Buildr.environment.should eql(Buildr.application.environment)
543
+ end
544
+ end
545
+
546
+ describe 'application' do
547
+ it 'should be same as Rake.application' do
548
+ Buildr.application.should == Rake.application
549
+ end
550
+ end
551
+
552
+ describe 'settings' do
553
+ it 'should be same as Buildr.application.settings' do
554
+ Buildr.settings.should == Buildr.application.settings
555
+ end
556
+ end
557
+
558
+ end
559
+
560
+ describe Rake do
561
+ describe 'define_task' do
562
+ it 'should restore call chain when invoke is called' do
563
+ task1 = Rake::Task.define_task('task1') do
564
+ end
565
+
566
+ task2 = Rake::Task.define_task('task2') do
567
+ chain1 = Thread.current[:rake_chain]
568
+ task1.invoke
569
+ chain2 = Thread.current[:rake_chain]
570
+ chain2.should == chain1
571
+ end
572
+
573
+ task2.invoke
574
+ end
575
+ end
576
+ end