buildr 1.2.10 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data/CHANGELOG +566 -268
  2. data/DISCLAIMER +7 -1
  3. data/KEYS +151 -0
  4. data/NOTICE +23 -8
  5. data/README +122 -22
  6. data/Rakefile +49 -229
  7. data/{lib → addon}/buildr/antlr.rb +23 -10
  8. data/addon/buildr/cobertura.rb +232 -0
  9. data/{lib → addon}/buildr/hibernate.rb +20 -4
  10. data/{lib → addon}/buildr/javacc.rb +27 -12
  11. data/addon/buildr/jdepend.rb +60 -0
  12. data/{lib → addon}/buildr/jetty.rb +34 -18
  13. data/addon/buildr/nailgun.rb +892 -0
  14. data/{lib → addon}/buildr/openjpa.rb +23 -6
  15. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  16. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  17. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  18. data/{lib/buildr/jetty → addon/buildr/org/apache/buildr}/JettyWrapper.java +19 -0
  19. data/{lib → addon}/buildr/xmlbeans.rb +39 -14
  20. data/bin/buildr +21 -7
  21. data/buildr.gemspec +50 -0
  22. data/doc/css/default.css +225 -0
  23. data/doc/css/print.css +95 -0
  24. data/doc/css/syntax.css +43 -0
  25. data/doc/images/apache-incubator-logo.png +0 -0
  26. data/doc/images/buildr-hires.png +0 -0
  27. data/doc/images/buildr.png +0 -0
  28. data/doc/images/note.png +0 -0
  29. data/doc/images/tip.png +0 -0
  30. data/doc/images/zbuildr.tif +0 -0
  31. data/doc/pages/artifacts.textile +317 -0
  32. data/doc/pages/building.textile +501 -0
  33. data/doc/pages/contributing.textile +178 -0
  34. data/doc/pages/download.textile +25 -0
  35. data/doc/pages/extending.textile +229 -0
  36. data/doc/pages/getting_started.textile +337 -0
  37. data/doc/pages/index.textile +63 -0
  38. data/doc/pages/mailing_lists.textile +17 -0
  39. data/doc/pages/more_stuff.textile +367 -0
  40. data/doc/pages/packaging.textile +592 -0
  41. data/doc/pages/projects.textile +449 -0
  42. data/doc/pages/recipes.textile +127 -0
  43. data/doc/pages/settings_profiles.textile +339 -0
  44. data/doc/pages/testing.textile +475 -0
  45. data/doc/pages/troubleshooting.textile +121 -0
  46. data/doc/pages/whats_new.textile +389 -0
  47. data/doc/print.haml +52 -0
  48. data/doc/print.toc.yaml +28 -0
  49. data/doc/scripts/buildr-git.rb +411 -0
  50. data/doc/scripts/install-jruby.sh +44 -0
  51. data/doc/scripts/install-linux.sh +64 -0
  52. data/doc/scripts/install-osx.sh +52 -0
  53. data/doc/site.haml +55 -0
  54. data/doc/site.toc.yaml +44 -0
  55. data/lib/buildr.rb +28 -45
  56. data/lib/buildr/core.rb +27 -0
  57. data/lib/buildr/core/application.rb +373 -0
  58. data/lib/buildr/core/application_cli.rb +134 -0
  59. data/lib/{core → buildr/core}/build.rb +91 -77
  60. data/lib/{core → buildr/core}/checks.rb +116 -95
  61. data/lib/buildr/core/common.rb +155 -0
  62. data/lib/buildr/core/compile.rb +594 -0
  63. data/lib/buildr/core/environment.rb +120 -0
  64. data/lib/buildr/core/filter.rb +258 -0
  65. data/lib/{core → buildr/core}/generate.rb +22 -5
  66. data/lib/buildr/core/help.rb +118 -0
  67. data/lib/buildr/core/progressbar.rb +156 -0
  68. data/lib/{core → buildr/core}/project.rb +468 -213
  69. data/lib/buildr/core/test.rb +690 -0
  70. data/lib/{core → buildr/core}/transports.rb +107 -127
  71. data/lib/buildr/core/util.rb +235 -0
  72. data/lib/buildr/ide.rb +19 -0
  73. data/lib/{java → buildr/ide}/eclipse.rb +86 -60
  74. data/lib/{java → buildr/ide}/idea.ipr.template +16 -0
  75. data/lib/buildr/ide/idea.rb +194 -0
  76. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  77. data/lib/buildr/ide/idea7x.rb +210 -0
  78. data/lib/buildr/java.rb +26 -0
  79. data/lib/buildr/java/ant.rb +71 -0
  80. data/lib/buildr/java/bdd_frameworks.rb +267 -0
  81. data/lib/buildr/java/commands.rb +210 -0
  82. data/lib/buildr/java/compilers.rb +432 -0
  83. data/lib/buildr/java/deprecated.rb +141 -0
  84. data/lib/buildr/java/groovyc.rb +137 -0
  85. data/lib/buildr/java/jruby.rb +99 -0
  86. data/lib/buildr/java/org/apache/buildr/BuildrNail$Main.class +0 -0
  87. data/lib/buildr/java/org/apache/buildr/BuildrNail.class +0 -0
  88. data/lib/buildr/java/org/apache/buildr/BuildrNail.java +41 -0
  89. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  90. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +116 -0
  91. data/lib/buildr/java/packaging.rb +706 -0
  92. data/lib/{java → buildr/java}/pom.rb +20 -4
  93. data/lib/buildr/java/rjb.rb +142 -0
  94. data/lib/buildr/java/test_frameworks.rb +290 -0
  95. data/lib/buildr/java/version_requirement.rb +172 -0
  96. data/lib/buildr/packaging.rb +21 -0
  97. data/lib/{java → buildr/packaging}/artifact.rb +170 -179
  98. data/lib/buildr/packaging/artifact_namespace.rb +957 -0
  99. data/lib/buildr/packaging/artifact_search.rb +140 -0
  100. data/lib/buildr/packaging/gems.rb +102 -0
  101. data/lib/buildr/packaging/package.rb +233 -0
  102. data/lib/{tasks → buildr/packaging}/tar.rb +18 -1
  103. data/lib/{tasks → buildr/packaging}/zip.rb +153 -105
  104. data/rakelib/apache.rake +126 -0
  105. data/rakelib/changelog.rake +56 -0
  106. data/rakelib/doc.rake +103 -0
  107. data/rakelib/package.rake +44 -0
  108. data/rakelib/release.rake +53 -0
  109. data/rakelib/rspec.rake +81 -0
  110. data/rakelib/rubyforge.rake +45 -0
  111. data/rakelib/scm.rake +49 -0
  112. data/rakelib/setup.rake +59 -0
  113. data/rakelib/stage.rake +45 -0
  114. data/spec/application_spec.rb +316 -0
  115. data/spec/archive_spec.rb +494 -0
  116. data/spec/artifact_namespace_spec.rb +635 -0
  117. data/spec/artifact_spec.rb +738 -0
  118. data/spec/build_spec.rb +193 -0
  119. data/spec/checks_spec.rb +537 -0
  120. data/spec/common_spec.rb +579 -0
  121. data/spec/compile_spec.rb +561 -0
  122. data/spec/groovy_compilers_spec.rb +239 -0
  123. data/spec/java_bdd_frameworks_spec.rb +238 -0
  124. data/spec/java_compilers_spec.rb +446 -0
  125. data/spec/java_packaging_spec.rb +1042 -0
  126. data/spec/java_test_frameworks_spec.rb +414 -0
  127. data/spec/packaging_helper.rb +63 -0
  128. data/spec/packaging_spec.rb +589 -0
  129. data/spec/project_spec.rb +739 -0
  130. data/spec/sandbox.rb +116 -0
  131. data/spec/scala_compilers_spec.rb +239 -0
  132. data/spec/spec.opts +6 -0
  133. data/spec/spec_helpers.rb +283 -0
  134. data/spec/test_spec.rb +871 -0
  135. data/spec/transport_spec.rb +300 -0
  136. data/spec/version_requirement_spec.rb +115 -0
  137. metadata +188 -77
  138. data/lib/buildr/cobertura.rb +0 -89
  139. data/lib/buildr/jdepend.rb +0 -40
  140. data/lib/buildr/jetty/JettyWrapper$1.class +0 -0
  141. data/lib/buildr/jetty/JettyWrapper$BuildrHandler.class +0 -0
  142. data/lib/buildr/jetty/JettyWrapper.class +0 -0
  143. data/lib/buildr/scala.rb +0 -368
  144. data/lib/core/application.rb +0 -188
  145. data/lib/core/common.rb +0 -562
  146. data/lib/core/help.rb +0 -72
  147. data/lib/core/rake_ext.rb +0 -81
  148. data/lib/java/ant.rb +0 -71
  149. data/lib/java/compile.rb +0 -589
  150. data/lib/java/idea.rb +0 -159
  151. data/lib/java/java.rb +0 -432
  152. data/lib/java/packaging.rb +0 -581
  153. data/lib/java/test.rb +0 -795
  154. data/lib/tasks/concat.rb +0 -35
@@ -0,0 +1,116 @@
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
+ # The local repository we use for testing is void of any artifacts, which will break given
18
+ # that the code requires several artifacts. So we establish them first using the real local
19
+ # repository and cache these across test cases.
20
+ Buildr.application.instance_eval { @rakefile = File.expand_path('buildfile') }
21
+ repositories.remote << 'http://repo1.maven.org/maven2'
22
+ require 'buildr/java/groovyc'
23
+ Java.load # Anything added to the classpath.
24
+ artifacts(TestFramework.frameworks.map(&:dependencies).flatten).each { |a| file(a).invoke }
25
+
26
+ ENV['HOME'] = File.expand_path('tmp/home')
27
+
28
+ # We need to run all tests inside a _sandbox, tacking a snapshot of Buildr before the test,
29
+ # and restoring everything to its previous state after the test. Damn state changes.
30
+ module Sandbox
31
+
32
+ class << self
33
+ attr_reader :tasks, :rules
34
+
35
+ def included(spec)
36
+ spec.before(:each) { sandbox }
37
+ spec.after(:each) { reset }
38
+ end
39
+ end
40
+
41
+ @tasks = Buildr.application.tasks.collect do |original|
42
+ prerequisites = original.send(:prerequisites).map(&:to_s)
43
+ actions = original.instance_eval { @actions }.clone
44
+ lambda do
45
+ original.class.send(:define_task, original.name=>prerequisites).tap do |task|
46
+ task.comment = original.comment
47
+ actions.each { |action| task.enhance &action }
48
+ end
49
+ end
50
+ end
51
+ @rules = Buildr.application.instance_variable_get(:@rules)
52
+
53
+ def sandbox
54
+ # Create a temporary directory where we can create files, e.g,
55
+ # for projects, compilation. We need a place that does not depend
56
+ # on the current directory.
57
+ temp = File.join(File.dirname(__FILE__), '../tmp')
58
+ FileUtils.mkpath temp
59
+ Dir.chdir temp
60
+
61
+ @_sandbox = {}
62
+ Buildr.application = Buildr::Application.new
63
+ Sandbox.tasks.each { |block| block.call }
64
+ Buildr.application.instance_variable_set :@rules, Sandbox.rules.clone
65
+ Buildr.application.instance_eval { @rakefile = File.expand_path('buildfile') }
66
+
67
+ @_sandbox[:load_path] = $LOAD_PATH.clone
68
+ @_sandbox[:loaded_features] = $LOADED_FEATURES.clone
69
+
70
+ # Later on we'll want to lose all the on_define created during the test.
71
+ @_sandbox[:on_define] = Project.class_eval { (@on_define || []).dup }
72
+ @_sandbox[:layout] = Layout.default.clone
73
+
74
+ # Create a local repository we can play with. However, our local repository will be void
75
+ # of some essential artifacts (e.g. JUnit artifacts required by build task), so we create
76
+ # these first (see above) and keep them across test cases.
77
+ @_sandbox[:artifacts] = Artifact.class_eval { @artifacts }.clone
78
+ Buildr.repositories.local = File.expand_path('repository')
79
+ ENV['HOME'] = File.expand_path('home')
80
+
81
+ @_sandbox[:env_keys] = ENV.keys
82
+ ['DEBUG', 'TEST', 'HTTP_PROXY', 'USER'].each { |k| ENV.delete(k) ; ENV.delete(k.downcase) }
83
+
84
+ # Remove testing local repository, and reset all repository settings.
85
+ Buildr.repositories.instance_eval do
86
+ @local = @remote = @release_to = nil
87
+ end
88
+ Buildr.options.proxy.http = nil
89
+
90
+ # Don't output crap to the console.
91
+ trace false
92
+ verbose false
93
+ #task('buildr:initialize').invoke
94
+ end
95
+
96
+ # Call this from teardown.
97
+ def reset
98
+ # Get rid of all the projects and the on_define blocks we used.
99
+ Project.clear
100
+ on_define = @_sandbox[:on_define]
101
+ Project.class_eval { @on_define = on_define }
102
+ Layout.default = @_sandbox[:layout].clone
103
+
104
+ $LOAD_PATH.replace @_sandbox[:load_path]
105
+ $LOADED_FEATURES.replace @_sandbox[:loaded_features]
106
+ FileUtils.rm_rf Dir.pwd
107
+
108
+ # Get rid of all artifacts.
109
+ @_sandbox[:artifacts].tap { |artifacts| Artifact.class_eval { @artifacts = artifacts } }
110
+
111
+ # Restore options.
112
+ Buildr.options.test = nil
113
+ (ENV.keys - @_sandbox[:env_keys]).each { |key| ENV.delete key }
114
+ end
115
+
116
+ end
@@ -0,0 +1,239 @@
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.join(File.dirname(__FILE__), 'spec_helpers')
18
+
19
+
20
+ describe 'scalac compiler' do
21
+ it 'should identify itself from source directories' do
22
+ write 'src/main/scala/com/example/Test.scala', 'package com.example; class Test { val i = 1 }'
23
+ define('foo').compile.compiler.should eql(:scalac)
24
+ end
25
+
26
+ it 'should report the language as :scala' do
27
+ define('foo').compile.using(:scalac).language.should eql(:scala)
28
+ end
29
+
30
+ it 'should set the target directory to target/classes' do
31
+ define 'foo' do
32
+ lambda { compile.using(:scalac) }.should change { compile.target.to_s }.to(File.expand_path('target/classes'))
33
+ end
34
+ end
35
+
36
+ it 'should not override existing target directory' do
37
+ define 'foo' do
38
+ compile.into('classes')
39
+ lambda { compile.using(:scalac) }.should_not change { compile.target }
40
+ end
41
+ end
42
+
43
+ it 'should not change existing list of sources' do
44
+ define 'foo' do
45
+ compile.from('sources')
46
+ lambda { compile.using(:scalac) }.should_not change { compile.sources }
47
+ end
48
+ end
49
+
50
+ it 'should include as classpath dependency' do
51
+ write 'src/dependency/Dependency.scala', 'class Dependency {}'
52
+ define 'dependency', :version=>'1.0' do
53
+ compile.from('src/dependency').into('target/dependency')
54
+ package(:jar)
55
+ end
56
+ write 'src/test/DependencyTest.scala', 'class DependencyTest { var d: Dependency = _ }'
57
+ lambda { define('foo').compile.from('src/test').with(project('dependency')).invoke }.should run_task('foo:compile')
58
+ file('target/classes/DependencyTest.class').should exist
59
+ end
60
+
61
+ def define_test1_project
62
+ write 'src/main/scala/com/example/Test1.scala', 'package com.example; class Test1 { val i = 1 }'
63
+ define 'test1', :version=>'1.0' do
64
+ package(:jar)
65
+ end
66
+ end
67
+
68
+ it 'should compile a simple .scala file into a .class file' do
69
+ define_test1_project
70
+ task('test1:compile').invoke
71
+ file('target/classes/com/example/Test1.class').should exist
72
+ end
73
+
74
+ it 'should package .class into a .jar file' do
75
+ define_test1_project
76
+ task('test1:package').invoke
77
+ file('target/test1-1.0.jar').should exist
78
+ Zip::ZipFile.open(project('test1').package(:jar).to_s) do |zip|
79
+ zip.file.exist?('com/example/Test1.class').should be_true
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+
86
+ describe 'scalac compiler options' do
87
+ def compile_task
88
+ @compile_task ||= define('foo').compile.using(:scalac)
89
+ end
90
+
91
+ def scalac_args
92
+ compile_task.instance_eval { @compiler }.send(:scalac_args)
93
+ end
94
+
95
+ it 'should set warnings option to false by default' do
96
+ compile_task.options.warnings.should be_false
97
+ end
98
+
99
+ it 'should set wranings option to true when running with --verbose option' do
100
+ verbose true
101
+ compile_task.options.warnings.should be_true
102
+ end
103
+
104
+ it 'should use -nowarn argument when warnings is false' do
105
+ compile_task.using(:warnings=>false)
106
+ scalac_args.should include('-nowarn')
107
+ end
108
+
109
+ it 'should not use -nowarn argument when warnings is true' do
110
+ compile_task.using(:warnings=>true)
111
+ scalac_args.should_not include('-nowarn')
112
+ end
113
+
114
+ it 'should not use -verbose argument by default' do
115
+ scalac_args.should_not include('-verbose')
116
+ end
117
+
118
+ it 'should use -verbose argument when running with --trace option' do
119
+ trace true
120
+ scalac_args.should include('-verbose')
121
+ end
122
+
123
+ it 'should set debug option to true by default' do
124
+ compile_task.options.debug.should be_true
125
+ end
126
+
127
+ it 'should set debug option to false based on Buildr.options' do
128
+ Buildr.options.debug = false
129
+ compile_task.options.debug.should be_false
130
+ end
131
+
132
+ it 'should set debug option to false based on debug environment variable' do
133
+ ENV['debug'] = 'no'
134
+ compile_task.options.debug.should be_false
135
+ end
136
+
137
+ it 'should set debug option to false based on DEBUG environment variable' do
138
+ ENV['DEBUG'] = 'no'
139
+ compile_task.options.debug.should be_false
140
+ end
141
+
142
+ it 'should use -g argument when debug option is true' do
143
+ compile_task.using(:debug=>true)
144
+ scalac_args.should include('-g')
145
+ end
146
+
147
+ it 'should not use -g argument when debug option is false' do
148
+ compile_task.using(:debug=>false)
149
+ scalac_args.should_not include('-g')
150
+ end
151
+
152
+ it 'should set deprecation option to false by default' do
153
+ compile_task.options.deprecation.should be_false
154
+ end
155
+
156
+ it 'should use -deprecation argument when deprecation is true' do
157
+ compile_task.using(:deprecation=>true)
158
+ scalac_args.should include('-deprecation')
159
+ end
160
+
161
+ it 'should not use -deprecation argument when deprecation is false' do
162
+ compile_task.using(:deprecation=>false)
163
+ scalac_args.should_not include('-deprecation')
164
+ end
165
+
166
+ it 'should set optimise option to false by default' do
167
+ compile_task.options.optimise.should be_false
168
+ end
169
+
170
+ it 'should use -optimise argument when deprecation is true' do
171
+ compile_task.using(:optimise=>true)
172
+ scalac_args.should include('-optimise')
173
+ end
174
+
175
+ it 'should not use -optimise argument when deprecation is false' do
176
+ compile_task.using(:optimise=>false)
177
+ scalac_args.should_not include('-optimise')
178
+ end
179
+
180
+ it 'should not set source option by default' do
181
+ compile_task.options.source.should be_nil
182
+ scalac_args.should_not include('-source')
183
+ end
184
+
185
+ it 'should not set target option by default' do
186
+ compile_task.options.target.should be_nil
187
+ scalac_args.should_not include('-target')
188
+ end
189
+
190
+ it 'should use -source nn argument if source option set' do
191
+ compile_task.using(:source=>'1.5')
192
+ scalac_args.should include('-source', '1.5')
193
+ end
194
+
195
+ it 'should use -target:xxx argument if target option set' do
196
+ compile_task.using(:target=>'1.5')
197
+ scalac_args.should include('-target:jvm-1.5')
198
+ end
199
+
200
+ it 'should not set other option by default' do
201
+ compile_task.options.other.should be_nil
202
+ end
203
+
204
+ it 'should pass other argument if other option is string' do
205
+ compile_task.using(:other=>'-unchecked')
206
+ scalac_args.should include('-unchecked')
207
+ end
208
+
209
+ it 'should pass other argument if other option is array' do
210
+ compile_task.using(:other=>['-unchecked', '-Xprint-types'])
211
+ scalac_args.should include('-unchecked', '-Xprint-types')
212
+ end
213
+
214
+ it 'should complain about options it doesn\'t know' do
215
+ write 'source/Test.scala', 'class Test {}'
216
+ compile_task.using(:unknown=>'option')
217
+ lambda { compile_task.from('source').invoke }.should raise_error(ArgumentError, /no such option/i)
218
+ end
219
+
220
+ it 'should inherit options from parent' do
221
+ define 'foo' do
222
+ compile.using(:warnings=>true, :debug=>true, :deprecation=>true, :source=>'1.5', :target=>'1.4')
223
+ define 'bar' do
224
+ compile.using(:scalac)
225
+ compile.options.warnings.should be_true
226
+ compile.options.debug.should be_true
227
+ compile.options.deprecation.should be_true
228
+ compile.options.source.should eql('1.5')
229
+ compile.options.target.should eql('1.4')
230
+ end
231
+ end
232
+ end
233
+
234
+ after do
235
+ Buildr.options.debug = nil
236
+ ENV.delete "debug"
237
+ ENV.delete "DEBUG"
238
+ end
239
+ end
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ specdoc
4
+ --loadby
5
+ mtime
6
+ --backtrace
@@ -0,0 +1,283 @@
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
+ # This file gets loaded twice when running 'spec spec/*' and not with pleasent results,
18
+ # so ignore the second attempt to load it.
19
+ unless self.class.const_defined?('SpecHelpers')
20
+
21
+ require 'rubygems'
22
+ $LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__))
23
+ require 'buildr'
24
+
25
+ require File.expand_path('sandbox', File.dirname(__FILE__))
26
+
27
+ module SpecHelpers
28
+
29
+ include Checks::Matchers
30
+
31
+ module ::Kernel #:nodoc:
32
+ def warn(message)
33
+ $warning ||= []
34
+ $warning << message
35
+ end
36
+ end
37
+
38
+ class << Buildr.application
39
+ alias :deprecated_without_capture :deprecated
40
+ def deprecated(message)
41
+ verbose(true) { deprecated_without_capture message }
42
+ end
43
+ end
44
+
45
+ class WarningMatcher
46
+ def initialize(message)
47
+ @expect = message
48
+ end
49
+
50
+ def matches?(target)
51
+ $warning = []
52
+ target.call
53
+ return Regexp === @expect ? $warning.join('\n') =~ @expect : $warning.include?(@expect.to_s)
54
+ end
55
+
56
+ def failure_message
57
+ $warning ? "Expected warning #{@expect.source}, found #{$warning}" : "Expected warning #{@expect.source}, no warning issued"
58
+ end
59
+
60
+ def negative_failure_message
61
+ "Found unexpected #{$warning}"
62
+ end
63
+ end
64
+
65
+ # Tests if a warning was issued. You can use a string or regular expression.
66
+ #
67
+ # For example:
68
+ # lambda { warn 'ze test' }.should warn_that(/ze test/)
69
+ def warn_that(message)
70
+ WarningMatcher.new message
71
+ end
72
+
73
+
74
+ class ::Rake::Task
75
+ alias :execute_without_a_record :execute
76
+ def execute(args)
77
+ $executed ||= []
78
+ $executed << name
79
+ execute_without_a_record args
80
+ end
81
+ end
82
+
83
+ class InvokeMatcher
84
+ def initialize(*tasks)
85
+ @expecting = tasks.map { |task| [task].flatten.map(&:to_s) }
86
+ end
87
+
88
+ def matches?(target)
89
+ $executed = []
90
+ target.call
91
+ return false unless all_ran?
92
+ return !@but_not.any_ran? if @but_not
93
+ return true
94
+ end
95
+
96
+ def failure_message
97
+ return @but_not.negative_failure_message if all_ran? && @but_not
98
+ "Expected the tasks #{expected} to run, but #{remaining} did not run, or not in the order we expected them to."
99
+ end
100
+
101
+ def negative_failure_message
102
+ if all_ran?
103
+ "Expected the tasks #{expected} to not run, but they all ran."
104
+ else
105
+ "Expected the tasks #{expected} to not run, and all but #{remaining} ran."
106
+ end
107
+ end
108
+
109
+ def but_not(*tasks)
110
+ @but_not = InvokeMatcher.new(*tasks)
111
+ self
112
+ end
113
+
114
+ protected
115
+
116
+ def expected
117
+ @expecting.map { |tests| tests.join('=>') }.join(', ')
118
+ end
119
+
120
+ def remaining
121
+ @remaining.map { |tests| tests.join('=>') }.join(', ')
122
+ end
123
+
124
+ def all_ran?
125
+ @remaining ||= $executed.inject(@expecting) do |expecting, executed|
126
+ expecting.map { |tasks| tasks.first == executed ? tasks[1..-1] : tasks }.reject(&:empty?)
127
+ end
128
+ @remaining.empty?
129
+ end
130
+
131
+ def any_ran?
132
+ all_ran?
133
+ @remaining.size < @expecting.size
134
+ end
135
+
136
+ end
137
+
138
+ # Tests that all the tasks ran, in the order specified. Can also be used to test that some
139
+ # tasks and not others ran.
140
+ #
141
+ # Takes a list of arguments. Each argument can be a task name, matching only if that task ran.
142
+ # Each argument can be an array of task names, matching only if all these tasks ran in that order.
143
+ # So run_tasks('foo', 'bar') expects foo and bar to run in any order, but run_task(['foo', 'bar'])
144
+ # expects foo to run before bar.
145
+ #
146
+ # You can call but_not on the matchers to specify that certain tasks must not execute.
147
+ #
148
+ # For example:
149
+ # # Either task
150
+ # lambda { task('compile').invoke }.should run_tasks('compile', 'resources')
151
+ # # In that order
152
+ # lambda { task('build').invoke }.should run_tasks(['compile', 'test'])
153
+ # # With exclusion
154
+ # lambda { task('build').invoke }.should run_tasks('compile').but_not('install')
155
+ def run_tasks(*tasks)
156
+ InvokeMatcher.new *tasks
157
+ end
158
+
159
+ # Tests that a task ran. Similar to run_tasks, but accepts a single task name.
160
+ #
161
+ # For example:
162
+ # lambda { task('build').invoke }.should run_task('test')
163
+ def run_task(task)
164
+ InvokeMatcher.new [task]
165
+ end
166
+
167
+ class UriPathMatcher
168
+ def initialize(re)
169
+ @expression = re
170
+ end
171
+
172
+ def matches?(uri)
173
+ @uri = uri
174
+ uri.path =~ @expression
175
+ end
176
+
177
+ def description
178
+ "URI with path matching #{@expression}"
179
+ end
180
+ end
181
+
182
+ # Matches a parsed URI's path against the given regular expression
183
+ def uri(re)
184
+ UriPathMatcher.new(re)
185
+ end
186
+
187
+
188
+ class AbsolutePathMatcher
189
+ def initialize(path)
190
+ @expected = File.expand_path(path.to_s)
191
+ end
192
+
193
+ def matches?(path)
194
+ @provided = File.expand_path(path.to_s)
195
+ @provided == @expected
196
+ end
197
+
198
+ def failure_message
199
+ "Expected path #{@expected}, but found path #{@provided}"
200
+ end
201
+
202
+ def negative_failure_message
203
+ "Expected a path other than #{@expected}"
204
+ end
205
+ end
206
+
207
+ def point_to_path(path)
208
+ AbsolutePathMatcher.new(path)
209
+ end
210
+
211
+
212
+ def suppress_stdout
213
+ stdout = $stdout
214
+ $stdout = StringIO.new
215
+ begin
216
+ yield
217
+ ensure
218
+ $stdout = stdout
219
+ end
220
+ end
221
+
222
+ def dryrun
223
+ Buildr.application.options.dryrun = true
224
+ begin
225
+ suppress_stdout { yield }
226
+ ensure
227
+ Buildr.application.options.dryrun = false
228
+ end
229
+ end
230
+
231
+ # We run tests with tracing off. Then things break. And we need to figure out what went wrong.
232
+ # So just use trace() as you would use verbose() to find and squash the bug.
233
+ def trace(value = nil)
234
+ old_value = Buildr.application.options.trace
235
+ Buildr.application.options.trace = value unless value.nil?
236
+ if block_given?
237
+ begin
238
+ yield
239
+ ensure
240
+ Buildr.application.options.trace = old_value
241
+ end
242
+ end
243
+ Buildr.application.options.trace
244
+ end
245
+
246
+ # Change the Buildr original directory, faking invocation from a different directory.
247
+ def in_original_dir(dir)
248
+ begin
249
+ original_dir = Buildr.application.original_dir
250
+ Buildr.application.instance_eval { @original_dir = File.expand_path(dir) }
251
+ yield
252
+ ensure
253
+ Buildr.application.instance_eval { @original_dir = original_dir }
254
+ end
255
+ end
256
+
257
+
258
+ # Buildr's define method creates a project definition but does not evaluate it
259
+ # (that happens once the buildfile is loaded), and we include Buildr's define in
260
+ # the test context so we can use it without prefixing with Buildr. This just patches
261
+ # define to evaluate the project definition before returning it.
262
+ def define(name, properties = nil, &block) #:yields:project
263
+ Project.define(name, properties, &block).tap { |project| project.invoke }
264
+ end
265
+
266
+ end
267
+
268
+
269
+ # Allow using matchers within the project definition.
270
+ class Buildr::Project
271
+ include ::Spec::Matchers, SpecHelpers
272
+ end
273
+
274
+
275
+ Spec::Runner.configure do |config|
276
+ # Make all Buildr methods accessible from test cases, and add various helper methods.
277
+ config.include Buildr, SpecHelpers
278
+
279
+ # Sanbdox Buildr for each test.
280
+ config.include Sandbox
281
+ end
282
+
283
+ end