mguymon-buildr 1.4.5-java

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 (220) hide show
  1. data/CHANGELOG +1291 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +44 -0
  6. data/_buildr +35 -0
  7. data/_jbuildr +35 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/bnd.rb +147 -0
  10. data/addon/buildr/cobertura.rb +22 -0
  11. data/addon/buildr/drb.rb +281 -0
  12. data/addon/buildr/emma.rb +22 -0
  13. data/addon/buildr/hibernate.rb +149 -0
  14. data/addon/buildr/javacc.rb +85 -0
  15. data/addon/buildr/jaxb_xjc.rb +72 -0
  16. data/addon/buildr/jdepend.rb +60 -0
  17. data/addon/buildr/jetty.rb +248 -0
  18. data/addon/buildr/jibx.rb +86 -0
  19. data/addon/buildr/nailgun.rb +221 -0
  20. data/addon/buildr/openjpa.rb +88 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  22. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  23. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  26. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  27. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  28. data/addon/buildr/protobuf.rb +88 -0
  29. data/addon/buildr/xmlbeans.rb +93 -0
  30. data/bin/buildr +19 -0
  31. data/buildr.buildfile +58 -0
  32. data/buildr.gemspec +78 -0
  33. data/doc/_config.yml +1 -0
  34. data/doc/_layouts/default.html +90 -0
  35. data/doc/_layouts/preface.html +22 -0
  36. data/doc/artifacts.textile +217 -0
  37. data/doc/building.textile +276 -0
  38. data/doc/contributing.textile +268 -0
  39. data/doc/css/default.css +236 -0
  40. data/doc/css/print.css +101 -0
  41. data/doc/css/syntax.css +23 -0
  42. data/doc/download.textile +151 -0
  43. data/doc/extending.textile +212 -0
  44. data/doc/images/1442160941-frontcover.jpg +0 -0
  45. data/doc/images/asf-logo.gif +0 -0
  46. data/doc/images/asf-logo.png +0 -0
  47. data/doc/images/buildr-hires.png +0 -0
  48. data/doc/images/buildr.png +0 -0
  49. data/doc/images/favicon.png +0 -0
  50. data/doc/images/growl-icon.tiff +0 -0
  51. data/doc/images/note.png +0 -0
  52. data/doc/images/project-structure.png +0 -0
  53. data/doc/images/tip.png +0 -0
  54. data/doc/images/zbuildr.png +0 -0
  55. data/doc/images/zbuildr.tif +0 -0
  56. data/doc/index.textile +109 -0
  57. data/doc/installing.textile +284 -0
  58. data/doc/languages.textile +599 -0
  59. data/doc/mailing_lists.textile +29 -0
  60. data/doc/more_stuff.textile +845 -0
  61. data/doc/packaging.textile +618 -0
  62. data/doc/preface.textile +54 -0
  63. data/doc/projects.textile +276 -0
  64. data/doc/quick_start.textile +210 -0
  65. data/doc/releasing.textile +117 -0
  66. data/doc/scripts/buildr-git.rb +512 -0
  67. data/doc/scripts/gitflow.rb +296 -0
  68. data/doc/scripts/install-jruby.sh +44 -0
  69. data/doc/scripts/install-linux.sh +73 -0
  70. data/doc/scripts/install-osx.sh +52 -0
  71. data/doc/settings_profiles.textile +287 -0
  72. data/doc/testing.textile +247 -0
  73. data/etc/KEYS +189 -0
  74. data/lib/buildr.rb +44 -0
  75. data/lib/buildr/clojure.rb +34 -0
  76. data/lib/buildr/clojure/shell.rb +52 -0
  77. data/lib/buildr/core.rb +34 -0
  78. data/lib/buildr/core/application.rb +700 -0
  79. data/lib/buildr/core/build.rb +516 -0
  80. data/lib/buildr/core/cc.rb +166 -0
  81. data/lib/buildr/core/checks.rb +253 -0
  82. data/lib/buildr/core/common.rb +151 -0
  83. data/lib/buildr/core/compile.rb +622 -0
  84. data/lib/buildr/core/doc.rb +276 -0
  85. data/lib/buildr/core/environment.rb +129 -0
  86. data/lib/buildr/core/filter.rb +404 -0
  87. data/lib/buildr/core/generate.rb +197 -0
  88. data/lib/buildr/core/help.rb +119 -0
  89. data/lib/buildr/core/jrebel.rb +42 -0
  90. data/lib/buildr/core/linux.rb +30 -0
  91. data/lib/buildr/core/osx.rb +46 -0
  92. data/lib/buildr/core/progressbar.rb +161 -0
  93. data/lib/buildr/core/project.rb +975 -0
  94. data/lib/buildr/core/run.rb +43 -0
  95. data/lib/buildr/core/shell.rb +137 -0
  96. data/lib/buildr/core/test.rb +843 -0
  97. data/lib/buildr/core/transports.rb +575 -0
  98. data/lib/buildr/core/util.rb +537 -0
  99. data/lib/buildr/groovy.rb +20 -0
  100. data/lib/buildr/groovy/bdd.rb +106 -0
  101. data/lib/buildr/groovy/compiler.rb +153 -0
  102. data/lib/buildr/groovy/doc.rb +76 -0
  103. data/lib/buildr/groovy/shell.rb +57 -0
  104. data/lib/buildr/ide.rb +19 -0
  105. data/lib/buildr/ide/eclipse.rb +427 -0
  106. data/lib/buildr/ide/eclipse/java.rb +53 -0
  107. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  108. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  109. data/lib/buildr/ide/idea.rb +576 -0
  110. data/lib/buildr/java.rb +25 -0
  111. data/lib/buildr/java/ant.rb +94 -0
  112. data/lib/buildr/java/bdd.rb +460 -0
  113. data/lib/buildr/java/cobertura.rb +297 -0
  114. data/lib/buildr/java/commands.rb +223 -0
  115. data/lib/buildr/java/compiler.rb +135 -0
  116. data/lib/buildr/java/deprecated.rb +141 -0
  117. data/lib/buildr/java/doc.rb +86 -0
  118. data/lib/buildr/java/ecj.rb +69 -0
  119. data/lib/buildr/java/emma.rb +244 -0
  120. data/lib/buildr/java/external.rb +73 -0
  121. data/lib/buildr/java/jruby.rb +122 -0
  122. data/lib/buildr/java/jtestr_result.rb +295 -0
  123. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  124. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  125. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  126. data/lib/buildr/java/packaging.rb +734 -0
  127. data/lib/buildr/java/pom.rb +178 -0
  128. data/lib/buildr/java/rjb.rb +154 -0
  129. data/lib/buildr/java/test_result.rb +101 -0
  130. data/lib/buildr/java/tests.rb +362 -0
  131. data/lib/buildr/java/version_requirement.rb +172 -0
  132. data/lib/buildr/packaging.rb +25 -0
  133. data/lib/buildr/packaging/archive.rb +535 -0
  134. data/lib/buildr/packaging/artifact.rb +904 -0
  135. data/lib/buildr/packaging/artifact_namespace.rb +984 -0
  136. data/lib/buildr/packaging/artifact_search.rb +140 -0
  137. data/lib/buildr/packaging/gems.rb +105 -0
  138. data/lib/buildr/packaging/package.rb +249 -0
  139. data/lib/buildr/packaging/repository_array.rb +108 -0
  140. data/lib/buildr/packaging/tar.rb +189 -0
  141. data/lib/buildr/packaging/version_requirement.rb +192 -0
  142. data/lib/buildr/packaging/zip.rb +178 -0
  143. data/lib/buildr/packaging/ziptask.rb +356 -0
  144. data/lib/buildr/resources/buildr.icns +0 -0
  145. data/lib/buildr/resources/completed.png +0 -0
  146. data/lib/buildr/resources/failed.png +0 -0
  147. data/lib/buildr/resources/icons-license.txt +17 -0
  148. data/lib/buildr/run.rb +195 -0
  149. data/lib/buildr/scala.rb +26 -0
  150. data/lib/buildr/scala/bdd.rb +118 -0
  151. data/lib/buildr/scala/compiler.rb +242 -0
  152. data/lib/buildr/scala/doc.rb +142 -0
  153. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  154. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  155. data/lib/buildr/scala/shell.rb +52 -0
  156. data/lib/buildr/scala/tests.rb +171 -0
  157. data/lib/buildr/shell.rb +185 -0
  158. data/lib/buildr/version.rb +18 -0
  159. data/rakelib/all-in-one.rake +113 -0
  160. data/rakelib/checks.rake +57 -0
  161. data/rakelib/doc.rake +137 -0
  162. data/rakelib/metrics.rake +39 -0
  163. data/rakelib/package.rake +73 -0
  164. data/rakelib/release.rake +160 -0
  165. data/rakelib/rspec.rake +91 -0
  166. data/rakelib/setup.rake +66 -0
  167. data/rakelib/stage.rake +220 -0
  168. data/spec/addon/bnd_spec.rb +330 -0
  169. data/spec/addon/drb_spec.rb +328 -0
  170. data/spec/addon/jaxb_xjc_spec.rb +125 -0
  171. data/spec/core/application_spec.rb +631 -0
  172. data/spec/core/build_spec.rb +837 -0
  173. data/spec/core/cc_spec.rb +224 -0
  174. data/spec/core/checks_spec.rb +519 -0
  175. data/spec/core/common_spec.rb +725 -0
  176. data/spec/core/compile_spec.rb +658 -0
  177. data/spec/core/doc_spec.rb +195 -0
  178. data/spec/core/extension_spec.rb +201 -0
  179. data/spec/core/generate_spec.rb +33 -0
  180. data/spec/core/project_spec.rb +772 -0
  181. data/spec/core/run_spec.rb +93 -0
  182. data/spec/core/shell_spec.rb +146 -0
  183. data/spec/core/test_spec.rb +1320 -0
  184. data/spec/core/transport_spec.rb +544 -0
  185. data/spec/core/util_spec.rb +141 -0
  186. data/spec/groovy/bdd_spec.rb +80 -0
  187. data/spec/groovy/compiler_spec.rb +251 -0
  188. data/spec/groovy/doc_spec.rb +65 -0
  189. data/spec/ide/eclipse_spec.rb +739 -0
  190. data/spec/ide/idea_spec.rb +1145 -0
  191. data/spec/java/ant_spec.rb +37 -0
  192. data/spec/java/bdd_spec.rb +374 -0
  193. data/spec/java/cobertura_spec.rb +112 -0
  194. data/spec/java/commands_spec.rb +93 -0
  195. data/spec/java/compiler_spec.rb +252 -0
  196. data/spec/java/doc_spec.rb +56 -0
  197. data/spec/java/ecj_spec.rb +115 -0
  198. data/spec/java/emma_spec.rb +121 -0
  199. data/spec/java/external_spec.rb +56 -0
  200. data/spec/java/java_spec.rb +132 -0
  201. data/spec/java/packaging_spec.rb +1266 -0
  202. data/spec/java/run_spec.rb +78 -0
  203. data/spec/java/test_coverage_helper.rb +257 -0
  204. data/spec/java/tests_spec.rb +497 -0
  205. data/spec/packaging/archive_spec.rb +775 -0
  206. data/spec/packaging/artifact_namespace_spec.rb +743 -0
  207. data/spec/packaging/artifact_spec.rb +1074 -0
  208. data/spec/packaging/packaging_helper.rb +63 -0
  209. data/spec/packaging/packaging_spec.rb +719 -0
  210. data/spec/packaging/repository_array_spec.rb +109 -0
  211. data/spec/sandbox.rb +165 -0
  212. data/spec/scala/bdd_spec.rb +124 -0
  213. data/spec/scala/compiler_spec.rb +289 -0
  214. data/spec/scala/doc_spec.rb +88 -0
  215. data/spec/scala/scala.rb +38 -0
  216. data/spec/scala/tests_spec.rb +283 -0
  217. data/spec/spec_helpers.rb +369 -0
  218. data/spec/version_requirement_spec.rb +143 -0
  219. data/spec/xpath_matchers.rb +121 -0
  220. metadata +600 -0
@@ -0,0 +1,631 @@
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
+ it 'should execute *_load methods in order' do
34
+ order = [:load_gems, :load_artifact_ns, :load_tasks, :raw_load_buildfile]
35
+ order.each { |method| Buildr.application.should_receive(method).ordered }
36
+ Buildr.application.stub!(:exit) # With this, shows the correct error instead of SystemExit.
37
+ Buildr.application.run
38
+ end
39
+
40
+ it 'should load imports after loading buildfile' do
41
+ method = Buildr.application.method(:raw_load_buildfile)
42
+ Buildr.application.should_receive(:raw_load_buildfile) do
43
+ Buildr.application.should_receive(:load_imports)
44
+ method.call
45
+ end
46
+ Buildr.application.stub!(:exit) # With this, shows the correct error instead of SystemExit.
47
+ Buildr.application.run
48
+ end
49
+
50
+ it 'should evaluate all projects after loading buildfile' do
51
+ Buildr.application.should_receive(:load_imports) do
52
+ Buildr.should_receive(:projects)
53
+ end
54
+ Buildr.application.stub!(:exit) # With this, shows the correct error instead of SystemExit.
55
+ Buildr.application.run
56
+ end
57
+ end
58
+
59
+ describe 'environment' do
60
+ it 'should return value of BUILDR_ENV' do
61
+ ENV['BUILDR_ENV'] = 'qa'
62
+ Buildr.application.environment.should eql('qa')
63
+ end
64
+
65
+ it 'should default to development' do
66
+ Buildr.application.environment.should eql('development')
67
+ end
68
+
69
+ it 'should set environment name from -e argument' do
70
+ ARGV.push('-e', 'test')
71
+ Buildr.application.send(:handle_options)
72
+ Buildr.application.environment.should eql('test')
73
+ ENV['BUILDR_ENV'].should eql('test')
74
+ end
75
+
76
+ it 'should be echoed to user' do
77
+ write 'buildfile'
78
+ ENV['BUILDR_ENV'] = 'spec'
79
+ Buildr.application.send(:handle_options)
80
+ lambda { Buildr.application.send :load_buildfile }.should show(%r{(in .*, spec)})
81
+ end
82
+ end
83
+
84
+ describe 'options' do
85
+ it "should have 'tasks' as the sole default rakelib" do
86
+ Buildr.application.send(:handle_options)
87
+ Buildr.application.options.rakelib.should == ['tasks']
88
+ end
89
+
90
+ it 'should show the version when prompted with -V' do
91
+ ARGV.push('-V')
92
+ test_exit(0) { Buildr.application.send(:handle_options) }.should show(/Buildr #{Buildr::VERSION}.*/)
93
+ end
94
+
95
+ it 'should show the version when prompted with --version' do
96
+ ARGV.push('--version')
97
+ test_exit(0) { Buildr.application.send(:handle_options) }.should show(/Buildr #{Buildr::VERSION}.*/)
98
+ end
99
+
100
+ it 'should enable tracing with --trace' do
101
+ ARGV.push('--trace')
102
+ Buildr.application.send(:handle_options)
103
+ Buildr.application.options.trace.should == true
104
+ end
105
+
106
+ it 'should enable tracing of [:foo, :bar] categories with --trace=foo,bar' do
107
+ ARGV.push('--trace=foo,bar')
108
+ Buildr.application.send(:handle_options)
109
+ Buildr.application.options.trace.should == true
110
+ Buildr.application.options.trace_categories.should == [:foo, :bar]
111
+ trace?(:foo).should == true
112
+ trace?(:not).should == false
113
+ end
114
+
115
+ it 'should enable tracing for all categories with --trace=all' do
116
+ ARGV.push('--trace=all')
117
+ Buildr.application.send(:handle_options)
118
+ Buildr.application.options.trace.should == true
119
+ Buildr.application.options.trace_all.should == true
120
+ trace?(:foo).should == true
121
+ end
122
+
123
+ end
124
+
125
+ describe 'gems' do
126
+ before do
127
+ class << Buildr.application
128
+ public :load_gems
129
+ end
130
+ end
131
+
132
+ def load_with_yaml
133
+ write 'build.yaml', <<-YAML
134
+ gems:
135
+ - rake
136
+ - rspec ~> 2.1.0
137
+ YAML
138
+ Buildr.application.load_gems
139
+ end
140
+
141
+ it 'should return empty array if no gems specified' do
142
+ Buildr.application.load_gems
143
+ Buildr.application.gems.should be_empty
144
+ end
145
+
146
+ it 'should return one entry for each gem specified in buildr.yaml' do
147
+ load_with_yaml
148
+ Buildr.application.gems.size.should be(2)
149
+ end
150
+
151
+ it 'should return a Gem::Specification for each installed gem' do
152
+ load_with_yaml
153
+ Buildr.application.gems.each { |gem| gem.should be_kind_of(Gem::Specification) }
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 found in remote repository' do
190
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
191
+ Gem.source_index.should_receive(:search).at_least(:once).and_return([])
192
+ lambda { Buildr.application.load_gems }.should raise_error(LoadError, /cannot be found/i)
193
+ end
194
+
195
+ it 'should fail if need to install gem and not running in interactive mode' do
196
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
197
+ Gem.source_index.should_receive(:search).and_return([@spec])
198
+ $stdout.should_receive(:isatty).and_return(false)
199
+ lambda { Buildr.application.load_gems }.should raise_error(LoadError, /this build requires the gems/i)
200
+ end
201
+
202
+ it 'should ask permission before installing required gems' do
203
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
204
+ Gem.source_index.should_receive(:search).and_return([@spec])
205
+ $terminal.should_receive(:agree).with(/install/, true)
206
+ lambda { Buildr.application.load_gems }.should raise_error
207
+ end
208
+
209
+ it 'should fail if permission not granted to install gem' do
210
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
211
+ Gem.source_index.should_receive(:search).and_return([@spec])
212
+ $terminal.should_receive(:agree).and_return(false)
213
+ lambda { Buildr.application.load_gems }.should raise_error(LoadError, /cannot build without/i)
214
+ end
215
+
216
+ it 'should install gem if permission granted' do
217
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
218
+ Gem.source_index.should_receive(:search).and_return([@spec])
219
+ $terminal.should_receive(:agree).and_return(true)
220
+ Util.should_receive(:ruby) do |*args|
221
+ args.should include('install', 'buildr-foo', '-v', '1.2')
222
+ end
223
+ Buildr.application.should_receive(:gem).and_return(false)
224
+ Buildr.application.load_gems
225
+ end
226
+
227
+ it 'should reload gem cache after installing required gems' do
228
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
229
+ Gem.source_index.should_receive(:search).and_return([@spec])
230
+ $terminal.should_receive(:agree).and_return(true)
231
+ Util.should_receive(:ruby)
232
+ Gem.source_index.should_receive(:load_gems_in).with(Gem::SourceIndex.installed_spec_directories)
233
+ Buildr.application.should_receive(:gem).and_return(false)
234
+ Buildr.application.load_gems
235
+ end
236
+
237
+ it 'should load previously installed gems' do
238
+ Buildr.application.should_receive(:listed_gems).and_return([Gem.loaded_specs['rspec']])
239
+ Buildr.application.should_receive(:gem).with('rspec', Gem.loaded_specs['rspec'].version.to_s)
240
+ Buildr.application.load_gems
241
+ end
242
+
243
+ it 'should load newly installed gems' do
244
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
245
+ Gem.source_index.should_receive(:search).and_return([@spec])
246
+ $terminal.should_receive(:agree).and_return(true)
247
+ Util.should_receive(:ruby)
248
+ Buildr.application.should_receive(:gem).with('buildr-foo', @spec.version.to_s)
249
+ Buildr.application.load_gems
250
+ end
251
+
252
+ it 'should default to >=0 version requirement if not specified' do
253
+ write 'build.yaml', 'gems: buildr-foo'
254
+ should_attempt_to_load_dependency(Gem::Dependency.new('buildr-foo', '>= 0'))
255
+ end
256
+
257
+ it 'should parse exact version requirement' do
258
+ write 'build.yaml', 'gems: buildr-foo 2.5'
259
+ should_attempt_to_load_dependency(Gem::Dependency.new('buildr-foo', '=2.5'))
260
+ end
261
+
262
+ it 'should parse range version requirement' do
263
+ write 'build.yaml', 'gems: buildr-foo ~>2.3'
264
+ should_attempt_to_load_dependency(Gem::Dependency.new('buildr-foo', '~>2.3'))
265
+ end
266
+
267
+ it 'should parse multiple version requirements' do
268
+ write 'build.yaml', 'gems: buildr-foo >=2.0 !=2.1'
269
+ should_attempt_to_load_dependency(Gem::Dependency.new('buildr-foo', ['>=2.0', '!=2.1']))
270
+ end
271
+
272
+ def should_attempt_to_load_dependency(dep)
273
+ Gem.source_index.should_receive(:search).with(dep).and_return([])
274
+ lambda { Buildr.application.load_gems }.should raise_missing_gem_error(dep)
275
+ end
276
+
277
+ def raise_missing_gem_error(dep)
278
+ raise_error(Gem::LoadError, /Build requires the gems #{dep.name} #{dep.requirement}, which cannot be found in local or remote repository./)
279
+ end
280
+ end
281
+
282
+ describe 'load_tasks' do
283
+ before do
284
+ class << Buildr.application
285
+ public :load_tasks
286
+ end
287
+ @original_loaded_features = $LOADED_FEATURES.dup
288
+ Buildr.application.options.rakelib = ["tasks"]
289
+ end
290
+
291
+ after do
292
+ $taskfiles = nil
293
+ ($LOADED_FEATURES - @original_loaded_features).each do |new_load|
294
+ $LOADED_FEATURES.delete(new_load)
295
+ end
296
+ end
297
+
298
+ def write_task(filename)
299
+ write filename, <<-RUBY
300
+ $taskfiles ||= []
301
+ $taskfiles << __FILE__
302
+ RUBY
303
+ end
304
+
305
+ def loaded_tasks
306
+ @loaded ||= Buildr.application.load_tasks
307
+ $taskfiles
308
+ end
309
+
310
+ it "should load {options.rakelib}/foo.rake" do
311
+ write_task 'tasks/foo.rake'
312
+ loaded_tasks.should have(1).task
313
+ loaded_tasks.first.should =~ %r{tasks/foo\.rake$}
314
+ end
315
+
316
+ it 'should load all *.rake files from the rakelib' do
317
+ write_task 'tasks/bar.rake'
318
+ write_task 'tasks/quux.rake'
319
+ loaded_tasks.should have(2).tasks
320
+ end
321
+
322
+ it 'should not load files which do not have the .rake extension' do
323
+ write_task 'tasks/foo.rb'
324
+ write_task 'tasks/bar.rake'
325
+ loaded_tasks.should have(1).task
326
+ loaded_tasks.first.should =~ %r{tasks/bar\.rake$}
327
+ end
328
+
329
+ it 'should load files only from the directory specified in the rakelib option' do
330
+ Buildr.application.options.rakelib = ['extensions']
331
+ write_task 'extensions/amp.rake'
332
+ write_task 'tasks/bar.rake'
333
+ write_task 'extensions/foo.rake'
334
+ loaded_tasks.should have(2).tasks
335
+ %w[amp foo].each do |filename|
336
+ loaded_tasks.select{|x| x =~ %r{extensions/#{filename}\.rake}}.should have(1).entry
337
+ end
338
+ end
339
+
340
+ it 'should load files from all the directories specified in the rakelib option' do
341
+ Buildr.application.options.rakelib = ['ext', 'more', 'tasks']
342
+ write_task 'ext/foo.rake'
343
+ write_task 'tasks/bar.rake'
344
+ write_task 'tasks/zeb.rake'
345
+ write_task 'more/baz.rake'
346
+ loaded_tasks.should have(4).tasks
347
+ end
348
+
349
+ it 'should not load files from the rakelib more than once' do
350
+ write_task 'tasks/new_one.rake'
351
+ write_task 'tasks/already.rake'
352
+ $LOADED_FEATURES << 'tasks/already.rake'
353
+
354
+ loaded_tasks.should have(1).task
355
+ loaded_tasks.first.should =~ %r{tasks/new_one\.rake$}
356
+ end
357
+ end
358
+
359
+ describe 'exception handling' do
360
+
361
+ it 'should exit when given a SystemExit exception' do
362
+ test_exit(3) { Buildr.application.standard_exception_handling { raise SystemExit.new(3) } }
363
+ end
364
+
365
+ it 'should exit with status 1 when given an OptionParser::ParseError exception' do
366
+ test_exit(1) { Buildr.application.standard_exception_handling { raise OptionParser::ParseError.new() } }
367
+ end
368
+
369
+ it 'should exit with status 1 when given any other type of exception exception' do
370
+ test_exit(1) { Buildr.application.standard_exception_handling { raise Exception.new() } }
371
+ end
372
+
373
+ it 'should print the class name and the message when receiving an exception (except when the exception is named Exception)' do
374
+
375
+ # Our fake $stderr for the exercise. We could start it with a matcher instead
376
+ class FakeStdErr
377
+
378
+ attr_accessor :messages
379
+
380
+ def puts(*args)
381
+ @messages ||= []
382
+ @messages += args
383
+ end
384
+
385
+ alias :write :puts
386
+ end
387
+
388
+ # Save the old $stderr and make sure to restore it in the end.
389
+ old_stderr = $stderr
390
+ begin
391
+
392
+ $stderr = FakeStdErr.new
393
+ test_exit(1) {
394
+ Buildr.application.send :standard_exception_handling do
395
+ class MyOwnNicelyNamedException < Exception
396
+ end
397
+ raise MyOwnNicelyNamedException.new('My message')
398
+ end
399
+ }.call
400
+ $stderr.messages.select {|msg| msg =~ /.*MyOwnNicelyNamedException : My message.*/}.size.should == 1
401
+ $stderr.messages.clear
402
+ test_exit(1) {
403
+ Buildr.application.send :standard_exception_handling do
404
+ raise Exception.new('My message')
405
+ end
406
+ }.call
407
+ $stderr.messages.select {|msg| msg =~ /.*My message.*/ && !(msg =~ /Exception/)}.size.should == 1
408
+ end
409
+ $stderr = old_stderr
410
+ end
411
+ end
412
+
413
+ end
414
+
415
+
416
+ describe Buildr, 'settings' do
417
+
418
+ describe 'user' do
419
+
420
+ it 'should be empty hash if no settings.yaml file' do
421
+ Buildr.settings.user.should == {}
422
+ end
423
+
424
+ it 'should return loaded settings.yaml file' do
425
+ write 'home/.buildr/settings.yaml', 'foo: bar'
426
+ Buildr.settings.user.should == { 'foo'=>'bar' }
427
+ end
428
+
429
+ it 'should return loaded settings.yml file' do
430
+ write 'home/.buildr/settings.yml', 'foo: bar'
431
+ Buildr.settings.user.should == { 'foo'=>'bar' }
432
+ end
433
+
434
+ it 'should fail if settings.yaml file is not a hash' do
435
+ write 'home/.buildr/settings.yaml', 'foo bar'
436
+ lambda { Buildr.settings.user }.should raise_error(RuntimeError, /expecting.*settings.yaml/i)
437
+ end
438
+
439
+ it 'should be empty hash if settings.yaml file is empty' do
440
+ write 'home/.buildr/settings.yaml'
441
+ Buildr.settings.user.should == {}
442
+ end
443
+ end
444
+
445
+ describe 'configuration' do
446
+ it 'should be empty hash if no build.yaml file' do
447
+ Buildr.settings.build.should == {}
448
+ end
449
+
450
+ it 'should return loaded build.yaml file' do
451
+ write 'build.yaml', 'foo: bar'
452
+ Buildr.settings.build.should == { 'foo'=>'bar' }
453
+ end
454
+
455
+ it 'should return loaded build.yml file' do
456
+ write 'build.yml', 'foo: bar'
457
+ Buildr.settings.build.should == { 'foo'=>'bar' }
458
+ end
459
+
460
+ it 'should fail if build.yaml file is not a hash' do
461
+ write 'build.yaml', 'foo bar'
462
+ lambda { Buildr.settings.build }.should raise_error(RuntimeError, /expecting.*build.yaml/i)
463
+ end
464
+
465
+ it 'should be empty hash if build.yaml file is empty' do
466
+ write 'build.yaml'
467
+ Buildr.settings.build.should == {}
468
+ end
469
+ end
470
+
471
+ describe 'profiles' do
472
+ it 'should be empty hash if no profiles.yaml file' do
473
+ Buildr.settings.profiles.should == {}
474
+ end
475
+
476
+ it 'should return loaded profiles.yaml file' do
477
+ write 'profiles.yaml', <<-YAML
478
+ development:
479
+ foo: bar
480
+ YAML
481
+ Buildr.settings.profiles.should == { 'development'=> { 'foo'=>'bar' } }
482
+ end
483
+
484
+ it 'should return loaded profiles.yml file' do
485
+ write 'profiles.yml', <<-YAML
486
+ development:
487
+ foo: bar
488
+ YAML
489
+ Buildr.settings.profiles.should == { 'development'=> { 'foo'=>'bar' } }
490
+ end
491
+
492
+ it 'should fail if profiles.yaml file is not a hash' do
493
+ write 'profiles.yaml', 'foo bar'
494
+ lambda { Buildr.settings.profiles }.should raise_error(RuntimeError, /expecting.*profiles.yaml/i)
495
+ end
496
+
497
+ it 'should be empty hash if profiles.yaml file is empty' do
498
+ write 'profiles.yaml'
499
+ Buildr.settings.profiles.should == {}
500
+ end
501
+ end
502
+
503
+ describe 'profile' do
504
+ before do
505
+ end
506
+
507
+ it 'should be empty hash if no profiles.yaml' do
508
+ Buildr.settings.profile.should == {}
509
+ end
510
+
511
+ it 'should be empty hash if no matching profile' do
512
+ write 'profiles.yaml', <<-YAML
513
+ test:
514
+ foo: bar
515
+ YAML
516
+ Buildr.settings.profile.should == {}
517
+ end
518
+
519
+ it 'should return profile matching environment name' do
520
+ write 'profiles.yaml', <<-YAML
521
+ development:
522
+ foo: bar
523
+ test:
524
+ foo: baz
525
+ YAML
526
+ Buildr.settings.profile.should == { 'foo'=>'bar' }
527
+ end
528
+ end
529
+
530
+ describe 'buildfile task' do
531
+ before do
532
+ @buildfile_time = Time.now - 10
533
+ write 'buildfile'; File.utime(@buildfile_time, @buildfile_time, 'buildfile')
534
+ end
535
+
536
+ it 'should point to the buildfile' do
537
+ Buildr.application.buildfile.should point_to_path('buildfile')
538
+ end
539
+
540
+ it 'should be a defined task' do
541
+ Buildr.application.buildfile.should == file(File.expand_path('buildfile'))
542
+ end
543
+
544
+ it 'should ignore any rake namespace' do
545
+ namespace 'dummy_ns' do
546
+ Buildr.application.buildfile.should point_to_path('buildfile')
547
+ end
548
+ end
549
+
550
+ it 'should have the same timestamp as the buildfile' do
551
+ Buildr.application.buildfile.timestamp.should be_close(@buildfile_time, 1)
552
+ end
553
+
554
+ it 'should have the same timestamp as build.yaml if the latter is newer' do
555
+ write 'build.yaml'; File.utime(@buildfile_time + 5, @buildfile_time + 5, 'build.yaml')
556
+ Buildr.application.run
557
+ Buildr.application.buildfile.timestamp.should be_close(@buildfile_time + 5, 1)
558
+ end
559
+
560
+ it 'should have the same timestamp as the buildfile if build.yaml is older' do
561
+ write 'build.yaml'; File.utime(@buildfile_time - 5, @buildfile_time - 5, 'build.yaml')
562
+ Buildr.application.run
563
+ Buildr.application.buildfile.timestamp.should be_close(@buildfile_time, 1)
564
+ end
565
+
566
+ it 'should have the same timestamp as build.rb in home dir if the latter is newer (until version 1.6)' do
567
+ Buildr::VERSION.should < '1.6'
568
+ buildfile_should_have_same_timestamp_as 'home/buildr.rb'
569
+ end
570
+
571
+ it 'should have the same timestamp as build.rb in home dir if the latter is newer' do
572
+ buildfile_should_have_same_timestamp_as 'home/.buildr/buildr.rb'
573
+ end
574
+
575
+ it 'should have the same timestamp as .buildr.rb in buildfile dir if the latter is newer' do
576
+ buildfile_should_have_same_timestamp_as '.buildr.rb'
577
+ end
578
+
579
+ it 'should have the same timestamp as _buildr.rb in buildfile dir if the latter is newer' do
580
+ buildfile_should_have_same_timestamp_as '_buildr.rb'
581
+ end
582
+
583
+ def buildfile_should_have_same_timestamp_as(file)
584
+ write file; File.utime(@buildfile_time + 5, @buildfile_time + 5, file)
585
+ Buildr.application.send :load_tasks
586
+ Buildr.application.buildfile.timestamp.should be_close(@buildfile_time + 5, 1)
587
+ end
588
+ end
589
+ end
590
+
591
+
592
+ describe Buildr do
593
+
594
+ describe 'environment' do
595
+ it 'should be same as Buildr.application.environment' do
596
+ Buildr.environment.should eql(Buildr.application.environment)
597
+ end
598
+ end
599
+
600
+ describe 'application' do
601
+ it 'should be same as Rake.application' do
602
+ Buildr.application.should == Rake.application
603
+ end
604
+ end
605
+
606
+ describe 'settings' do
607
+ it 'should be same as Buildr.application.settings' do
608
+ Buildr.settings.should == Buildr.application.settings
609
+ end
610
+ end
611
+
612
+ end
613
+
614
+ describe Rake do
615
+ describe 'define_task' do
616
+ it 'should restore call chain when invoke is called' do
617
+ task1 = Rake::Task.define_task('task1') do
618
+ end
619
+
620
+ task2 = Rake::Task.define_task('task2') do
621
+ chain1 = Thread.current[:rake_chain]
622
+ task1.invoke
623
+ chain2 = Thread.current[:rake_chain]
624
+ chain2.should == chain1
625
+ end
626
+
627
+ task2.invoke
628
+ end
629
+ end
630
+ end
631
+