ittayd-buildr 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. data/CHANGELOG +62 -9
  2. data/NOTICE +1 -1
  3. data/README.rdoc +9 -21
  4. data/Rakefile +20 -39
  5. data/_buildr +1 -0
  6. data/{spec/java/ant.rb → _jbuildr} +11 -15
  7. metadata +30 -210
  8. data/DISCLAIMER +0 -7
  9. data/addon/buildr/antlr.rb +0 -65
  10. data/addon/buildr/cobertura.rb +0 -22
  11. data/addon/buildr/drb.rb +0 -281
  12. data/addon/buildr/emma.rb +0 -22
  13. data/addon/buildr/hibernate.rb +0 -142
  14. data/addon/buildr/javacc.rb +0 -85
  15. data/addon/buildr/jdepend.rb +0 -60
  16. data/addon/buildr/jetty.rb +0 -248
  17. data/addon/buildr/jibx.rb +0 -86
  18. data/addon/buildr/nailgun.rb +0 -221
  19. data/addon/buildr/openjpa.rb +0 -90
  20. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  22. data/addon/buildr/org/apache/buildr/BuildrNail.java +0 -41
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  26. data/addon/buildr/org/apache/buildr/JettyWrapper.java +0 -144
  27. data/addon/buildr/path.rb +0 -136
  28. data/addon/buildr/xmlbeans.rb +0 -93
  29. data/buildr.buildfile +0 -53
  30. data/buildr.gemspec +0 -58
  31. data/doc/css/default.css +0 -228
  32. data/doc/css/print.css +0 -100
  33. data/doc/css/syntax.css +0 -52
  34. data/doc/images/apache-incubator-logo.png +0 -0
  35. data/doc/images/buildr-hires.png +0 -0
  36. data/doc/images/buildr.png +0 -0
  37. data/doc/images/favicon.png +0 -0
  38. data/doc/images/growl-icon.tiff +0 -0
  39. data/doc/images/note.png +0 -0
  40. data/doc/images/project-structure.png +0 -0
  41. data/doc/images/tip.png +0 -0
  42. data/doc/images/zbuildr.tif +0 -0
  43. data/doc/pages/artifacts.textile +0 -207
  44. data/doc/pages/building.textile +0 -240
  45. data/doc/pages/contributing.textile +0 -208
  46. data/doc/pages/download.textile +0 -62
  47. data/doc/pages/extending.textile +0 -175
  48. data/doc/pages/getting_started.textile +0 -273
  49. data/doc/pages/index.textile +0 -42
  50. data/doc/pages/languages.textile +0 -407
  51. data/doc/pages/mailing_lists.textile +0 -17
  52. data/doc/pages/more_stuff.textile +0 -314
  53. data/doc/pages/packaging.textile +0 -427
  54. data/doc/pages/projects.textile +0 -274
  55. data/doc/pages/recipes.textile +0 -103
  56. data/doc/pages/settings_profiles.textile +0 -274
  57. data/doc/pages/testing.textile +0 -212
  58. data/doc/pages/troubleshooting.textile +0 -103
  59. data/doc/pages/whats_new.textile +0 -323
  60. data/doc/print.haml +0 -51
  61. data/doc/print.toc.yaml +0 -29
  62. data/doc/scripts/buildr-git.rb +0 -412
  63. data/doc/scripts/install-jruby.sh +0 -44
  64. data/doc/scripts/install-linux.sh +0 -64
  65. data/doc/scripts/install-osx.sh +0 -52
  66. data/doc/site.haml +0 -56
  67. data/doc/site.toc.yaml +0 -47
  68. data/etc/KEYS +0 -151
  69. data/etc/git-svn-authors +0 -16
  70. data/lib/buildr.rb +0 -33
  71. data/lib/buildr/core.rb +0 -29
  72. data/lib/buildr/core/application.rb +0 -665
  73. data/lib/buildr/core/build.rb +0 -311
  74. data/lib/buildr/core/checks.rb +0 -254
  75. data/lib/buildr/core/common.rb +0 -150
  76. data/lib/buildr/core/compile.rb +0 -590
  77. data/lib/buildr/core/environment.rb +0 -117
  78. data/lib/buildr/core/filter.rb +0 -366
  79. data/lib/buildr/core/generate.rb +0 -195
  80. data/lib/buildr/core/help.rb +0 -119
  81. data/lib/buildr/core/osx.rb +0 -49
  82. data/lib/buildr/core/progressbar.rb +0 -156
  83. data/lib/buildr/core/project.rb +0 -923
  84. data/lib/buildr/core/test.rb +0 -715
  85. data/lib/buildr/core/transports.rb +0 -560
  86. data/lib/buildr/core/util.rb +0 -294
  87. data/lib/buildr/groovy.rb +0 -18
  88. data/lib/buildr/groovy/bdd.rb +0 -106
  89. data/lib/buildr/groovy/compiler.rb +0 -138
  90. data/lib/buildr/ide.rb +0 -19
  91. data/lib/buildr/ide/eclipse.rb +0 -222
  92. data/lib/buildr/ide/idea.ipr.template +0 -300
  93. data/lib/buildr/ide/idea.rb +0 -190
  94. data/lib/buildr/ide/idea7x.ipr.template +0 -290
  95. data/lib/buildr/ide/idea7x.rb +0 -212
  96. data/lib/buildr/java.rb +0 -23
  97. data/lib/buildr/java/ant.rb +0 -92
  98. data/lib/buildr/java/bdd.rb +0 -451
  99. data/lib/buildr/java/cobertura.rb +0 -236
  100. data/lib/buildr/java/commands.rb +0 -211
  101. data/lib/buildr/java/compiler.rb +0 -348
  102. data/lib/buildr/java/deprecated.rb +0 -141
  103. data/lib/buildr/java/emma.rb +0 -238
  104. data/lib/buildr/java/jruby.rb +0 -117
  105. data/lib/buildr/java/jtestr_runner.rb.erb +0 -116
  106. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  107. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +0 -119
  108. data/lib/buildr/java/packaging.rb +0 -717
  109. data/lib/buildr/java/pom.rb +0 -174
  110. data/lib/buildr/java/rjb.rb +0 -155
  111. data/lib/buildr/java/test_result.rb +0 -307
  112. data/lib/buildr/java/tests.rb +0 -329
  113. data/lib/buildr/java/version_requirement.rb +0 -172
  114. data/lib/buildr/packaging.rb +0 -24
  115. data/lib/buildr/packaging/archive.rb +0 -488
  116. data/lib/buildr/packaging/artifact.rb +0 -759
  117. data/lib/buildr/packaging/artifact_namespace.rb +0 -972
  118. data/lib/buildr/packaging/artifact_search.rb +0 -140
  119. data/lib/buildr/packaging/gems.rb +0 -102
  120. data/lib/buildr/packaging/package.rb +0 -233
  121. data/lib/buildr/packaging/tar.rb +0 -186
  122. data/lib/buildr/packaging/version_requirement.rb +0 -172
  123. data/lib/buildr/packaging/zip.rb +0 -64
  124. data/lib/buildr/packaging/ziptask.rb +0 -313
  125. data/lib/buildr/resources/buildr.icns +0 -0
  126. data/lib/buildr/scala.rb +0 -19
  127. data/lib/buildr/scala/compiler.rb +0 -109
  128. data/lib/buildr/scala/tests.rb +0 -203
  129. data/rakelib/apache.rake +0 -191
  130. data/rakelib/changelog.rake +0 -57
  131. data/rakelib/doc.rake +0 -103
  132. data/rakelib/package.rake +0 -76
  133. data/rakelib/release.rake +0 -65
  134. data/rakelib/rspec.rake +0 -83
  135. data/rakelib/rubyforge.rake +0 -56
  136. data/rakelib/scm.rake +0 -49
  137. data/rakelib/setup.rake +0 -81
  138. data/rakelib/stage.rake +0 -48
  139. data/spec/addon/drb_spec.rb +0 -328
  140. data/spec/core/application_spec.rb +0 -419
  141. data/spec/core/build_spec.rb +0 -423
  142. data/spec/core/checks_spec.rb +0 -519
  143. data/spec/core/common_spec.rb +0 -670
  144. data/spec/core/compile_spec.rb +0 -582
  145. data/spec/core/generate_spec.rb +0 -33
  146. data/spec/core/project_spec.rb +0 -776
  147. data/spec/core/test_spec.rb +0 -1098
  148. data/spec/core/transport_spec.rb +0 -500
  149. data/spec/groovy/bdd_spec.rb +0 -80
  150. data/spec/groovy/compiler_spec.rb +0 -239
  151. data/spec/ide/eclipse_spec.rb +0 -311
  152. data/spec/java/bdd_spec.rb +0 -358
  153. data/spec/java/cobertura_spec.rb +0 -77
  154. data/spec/java/compiler_spec.rb +0 -446
  155. data/spec/java/emma_spec.rb +0 -120
  156. data/spec/java/java_spec.rb +0 -96
  157. data/spec/java/packaging_spec.rb +0 -1120
  158. data/spec/java/test_coverage_spec.rb +0 -255
  159. data/spec/java/tests_spec.rb +0 -471
  160. data/spec/packaging/archive_spec.rb +0 -503
  161. data/spec/packaging/artifact_namespace_spec.rb +0 -646
  162. data/spec/packaging/artifact_spec.rb +0 -795
  163. data/spec/packaging/packaging_helper.rb +0 -63
  164. data/spec/packaging/packaging_spec.rb +0 -589
  165. data/spec/sandbox.rb +0 -139
  166. data/spec/scala/compiler_spec.rb +0 -228
  167. data/spec/scala/tests_spec.rb +0 -215
  168. data/spec/spec_helpers.rb +0 -327
  169. data/spec/version_requirement_spec.rb +0 -123
@@ -1,311 +0,0 @@
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 'buildr/core/project'
18
- require 'buildr/core/common'
19
- require 'buildr/core/checks'
20
- require 'buildr/core/environment'
21
-
22
-
23
- module Buildr
24
-
25
- class Options
26
-
27
- # Runs the build in parallel when true (defaults to false). You can force a parallel build by
28
- # setting this option directly, or by running the parallel task ahead of the build task.
29
- #
30
- # This option only affects recursive tasks. For example:
31
- # buildr parallel package
32
- # will run all package tasks (from the sub-projects) in parallel, but each sub-project's package
33
- # task runs its child tasks (prepare, compile, resources, etc) in sequence.
34
- attr_accessor :parallel
35
-
36
- end
37
-
38
- task('parallel') { Buildr.options.parallel = true }
39
-
40
-
41
- module Build
42
-
43
- include Extension
44
-
45
- first_time do
46
- desc 'Build the project'
47
- Project.local_task('build') { |name| "Building #{name}" }
48
- desc 'Clean files generated during a build'
49
- Project.local_task('clean') { |name| "Cleaning #{name}" }
50
-
51
- desc 'The default task is build'
52
- task 'default'=>'build'
53
- end
54
-
55
- before_define do |project|
56
- project.recursive_task 'build'
57
- project.recursive_task 'clean'
58
- project.clean do
59
- verbose(true) do
60
- rm_rf project.path_to(:target)
61
- rm_rf project.path_to(:reports)
62
- end
63
- end
64
- end
65
-
66
-
67
- # *Deprecated:* Use +path_to(:target)+ instead.
68
- def target
69
- Buildr.application.deprecated 'Use path_to(:target) instead'
70
- layout.expand(:target)
71
- end
72
-
73
- # *Deprecated:* Use Layout instead.
74
- def target=(dir)
75
- Buildr.application.deprecated 'Use Layout instead'
76
- layout[:target] = _(dir)
77
- end
78
-
79
- # *Deprecated:* Use +path_to(:reports)+ instead.
80
- def reports()
81
- Buildr.application.deprecated 'Use path_to(:reports) instead'
82
- layout.expand(:reports)
83
- end
84
-
85
- # *Deprecated:* Use Layout instead.
86
- def reports=(dir)
87
- Buildr.application.deprecated 'Use Layout instead'
88
- layout[:reports] = _(dir)
89
- end
90
-
91
- # :call-seq:
92
- # build(*prereqs) => task
93
- # build { |task| .. } => task
94
- #
95
- # Returns the project's build task. With arguments or block, also enhances that task.
96
- def build(*prereqs, &block)
97
- task('build').enhance prereqs, &block
98
- end
99
-
100
- # :call-seq:
101
- # clean(*prereqs) => task
102
- # clean { |task| .. } => task
103
- #
104
- # Returns the project's clean task. With arguments or block, also enhances that task.
105
- def clean(*prereqs, &block)
106
- task('clean').enhance prereqs, &block
107
- end
108
-
109
- end
110
-
111
-
112
- class Svn
113
-
114
- class << self
115
- def commit(file, message)
116
- svn 'commit', '-m', message, file
117
- end
118
-
119
- def copy(dir, url, message)
120
- svn 'copy', dir, url, '-m', message
121
- end
122
-
123
- # Return the current SVN URL
124
- def repo_url
125
- svn('info').scan(/URL: (.*)/)[0][0]
126
- end
127
-
128
- def remove(url, message)
129
- svn 'remove', url, '-m', message
130
- end
131
-
132
- # Status check reveals modified files, but also SVN externals which we can safely ignore.
133
- def uncommitted_files
134
- svn('status', '--ignore-externals').reject { |line| line =~ /^X\s/ }
135
- end
136
-
137
- # :call-seq:
138
- # svn(*args)
139
- #
140
- # Executes SVN command and returns the output.
141
- def svn(*args)
142
- cmd = 'svn ' + args.map { |arg| arg[' '] ? %Q{"#{arg}"} : arg }.join(' ')
143
- trace cmd
144
- `#{cmd}`.tap { fail 'SVN command failed' unless $?.exitstatus == 0 }
145
- end
146
- end
147
- end
148
-
149
-
150
- class Release
151
-
152
- THIS_VERSION_PATTERN = /(THIS_VERSION|VERSION_NUMBER)\s*=\s*(["'])(.*)\2/
153
-
154
- class << self
155
-
156
- # Use this to specify a different tag name for tagging the release in source control.
157
- # You can set the tag name or a proc that will be called with the version number,
158
- # for example:
159
- # Release.tag_name = lambda { |ver| "foo-#{ver}" }
160
- attr_accessor :tag_name
161
-
162
- # :call-seq:
163
- # make()
164
- #
165
- # Make a release.
166
- def make
167
- check
168
- with_release_candidate_version do |release_candidate_buildfile|
169
- options = ['--buildfile', release_candidate_buildfile, 'DEBUG=no']
170
- options << '--environment' << Buildr.environment unless Buildr.environment.to_s.empty?
171
- buildr %w{clean upload}, options
172
- end
173
- tag_release
174
- commit_new_snapshot
175
- end
176
-
177
- # :call-seq:
178
- # extract_version() => this_version
179
- #
180
- # Extract the current version number from the buildfile.
181
- # Raise an error if not found.
182
- def extract_version
183
- buildfile = File.read(Buildr.application.buildfile.to_s)
184
- buildfile.scan(THIS_VERSION_PATTERN)[0][2]
185
- rescue
186
- fail 'Looking for THIS_VERSION = "..." in your Buildfile, none found'
187
- end
188
-
189
- # :call-seq:
190
- # tag_url(svn_url, version) => tag_url
191
- #
192
- # Returns the SVN url for the tag.
193
- # Can tag from the trunk or from branches.
194
- # Can handle the two standard repository layouts.
195
- # - http://my.repo/foo/trunk => http://my.repo/foo/tags/1.0.0
196
- # - http://my.repo/trunk/foo => http://my.repo/tags/foo/1.0.0
197
- def tag_url(svn_url, version)
198
- trunk_or_branches = Regexp.union(%r{^(.*)/trunk(.*)$}, %r{^(.*)/branches(.*)/([^/]*)$})
199
- match = trunk_or_branches.match(svn_url)
200
- prefix = match[1] || match[3]
201
- suffix = match[2] || match[4]
202
- tag = tag_name || version
203
- tag = tag.call(version) if Proc === tag
204
- prefix + '/tags' + suffix + '/' + tag
205
- end
206
-
207
- # :call-seq:
208
- # check()
209
- #
210
- # Check that we don't have any local changes in the working copy. Fails if it finds anything
211
- # in the working copy that is not checked into source control.
212
- def check
213
- fail "SVN URL must contain 'trunk' or 'branches/...'" unless Svn.repo_url =~ /(trunk)|(branches.*)$/
214
- fail "Uncommitted SVN files violate the First Principle Of Release!\n#{Svn.uncommitted_files}" unless Svn.uncommitted_files.empty?
215
- end
216
-
217
- protected
218
-
219
- # :call-seq:
220
- # buildr(tasks, options)
221
- #
222
- # Calls another instance of buildr.
223
- def buildr(tasks, options)
224
- sh "#{command} _#{Buildr::VERSION}_ #{tasks.join(' ')} #{options.join(' ')}"
225
- end
226
-
227
- def command #:nodoc:
228
- Config::CONFIG['arch'] =~ /dos|win32/i ? $PROGRAM_NAME.ext('cmd') : $PROGRAM_NAME
229
- end
230
-
231
- # :call-seq:
232
- # with_release_candidate_version() { |filename| ... }
233
- #
234
- # Yields to block with release candidate buildfile, before committing to use it.
235
- #
236
- # We need a Buildfile with upgraded version numbers to run the build, but we don't want the
237
- # Buildfile modified unless the build succeeds. So this method updates the version number in
238
- # a separate (Buildfile.next) file, yields to the block with that filename, and if successful
239
- # copies the new file over the existing one.
240
- #
241
- # The release version is the current version without '-SNAPSHOT'. So:
242
- # THIS_VERSION = 1.1.0-SNAPSHOT
243
- # becomes:
244
- # THIS_VERSION = 1.1.0
245
- # for the release buildfile.
246
- def with_release_candidate_version
247
- release_candidate_buildfile = Buildr.application.buildfile.to_s + '.next'
248
- release_candidate_buildfile_contents = change_version { |version| version[-1] = version[-1].to_i }
249
- File.open(release_candidate_buildfile, 'w') { |file| file.write release_candidate_buildfile_contents }
250
- begin
251
- yield release_candidate_buildfile
252
- mv release_candidate_buildfile, Buildr.application.buildfile.to_s
253
- ensure
254
- rm release_candidate_buildfile rescue nil
255
- end
256
- end
257
-
258
- # :call-seq:
259
- # change_version() { |this_version| ... } => buildfile
260
- #
261
- # Change version number in the current Buildfile, but without writing a new file (yet).
262
- # Returns the contents of the Buildfile with the modified version number.
263
- #
264
- # This method yields to the block with the current (this) version number as an array and expects
265
- # the block to update it.
266
- def change_version
267
- this_version = extract_version
268
- new_version = this_version.split('.')
269
- yield(new_version)
270
- new_version = new_version.join('.')
271
- buildfile = File.read(Buildr.application.buildfile.to_s)
272
- buildfile.gsub(THIS_VERSION_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{new_version}"}) }
273
- end
274
-
275
- # :call-seq:
276
- # tag_release()
277
- #
278
- # Tags the current working copy with the release version number.
279
- def tag_release
280
- version = extract_version
281
- info "Tagging release #{version}"
282
- url = tag_url Svn.repo_url, version
283
- Svn.remove url, 'Removing old copy' rescue nil
284
- Svn.copy Dir.pwd, url, "Release #{version}"
285
- end
286
-
287
- # :call-seq:
288
- # commit_new_snapshot()
289
- #
290
- # Last, we commit what we currently have in the working copy with an upgraded version number.
291
- def commit_new_snapshot
292
- buildfile = change_version { |version| version[-1] = (version[-1].to_i + 1).to_s + '-SNAPSHOT' }
293
- File.open(Buildr.application.buildfile.to_s, 'w') { |file| file.write buildfile }
294
- Svn.commit Buildr.application.buildfile.to_s, "Changed version number to #{extract_version}"
295
- info "Current version is now #{extract_version}"
296
- end
297
- end
298
- end
299
-
300
-
301
- desc 'Make a release'
302
- task 'release' do |task|
303
- Release.make
304
- end
305
-
306
- end
307
-
308
-
309
- class Buildr::Project
310
- include Buildr::Build
311
- end
@@ -1,254 +0,0 @@
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 'buildr/core/project'
18
- autoload :Spec, 'spec'
19
-
20
-
21
- module Buildr
22
- # Methods added to Project to allow checking the build.
23
- module Checks
24
-
25
- module Matchers #:nodoc:
26
-
27
- class << self
28
-
29
- # Define matchers that operate by calling a method on the tested object.
30
- # For example:
31
- # foo.should contain(bar)
32
- # calls:
33
- # foo.contain(bar)
34
- def match_using(*names)
35
- names.each do |name|
36
- matcher = Class.new do
37
- # Initialize with expected arguments (i.e. contain(bar) initializes with bar).
38
- define_method(:initialize) { |*args| @expects = args }
39
- # Matches against actual value (i.e. foo.should exist called with foo).
40
- define_method(:matches?) do |actual|
41
- @actual = actual
42
- return actual.send("#{name}?", *@expects) if actual.respond_to?("#{name}?")
43
- return actual.send(name, *@expects) if actual.respond_to?(name)
44
- raise "You can't check #{actual}, it doesn't respond to #{name}."
45
- end
46
- # Some matchers have arguments, others don't, treat appropriately.
47
- define_method :failure_message do
48
- args = " " + @expects.map{ |arg| "'#{arg}'" }.join(", ") unless @expects.empty?
49
- "Expected #{@actual} to #{name}#{args}"
50
- end
51
- define_method :negative_failure_message do
52
- args = " " + @expects.map{ |arg| "'#{arg}'" }.join(", ") unless @expects.empty?
53
- "Expected #{@actual} to not #{name}#{args}"
54
- end
55
- end
56
- # Define method to create matcher.
57
- define_method(name) { |*args| matcher.new(*args) }
58
- end
59
- end
60
-
61
- end
62
-
63
- # Define delegate matchers for exist and contain methods.
64
- match_using :exist, :contain
65
-
66
- end
67
-
68
-
69
- # An expectation has subject, description and block. The expectation is validated by running the block,
70
- # and can access the subject from the method #it. The description is used for reporting.
71
- #
72
- # The expectation is run by calling #run_against. You can share expectations by running them against
73
- # different projects (or any other context for that matter).
74
- #
75
- # If the subject is missing, it is set to the argument of #run_against, typically the project itself.
76
- # If the description is missing, it is set from the project. If the block is missing, the default behavior
77
- # prints "Pending" followed by the description. You can use this to write place holders and fill them later.
78
- class Expectation
79
-
80
- attr_reader :description, :subject, :block
81
-
82
- # :call-seq:
83
- # initialize(subject, description?) { .... }
84
- # initialize(description?) { .... }
85
- #
86
- # First argument is subject (returned from it method), second argument is description. If you omit the
87
- # description, it will be set from the subject. If you omit the subject, it will be set from the object
88
- # passed to run_against.
89
- def initialize(*args, &block)
90
- @description = args.pop if String === args.last
91
- @subject = args.shift
92
- raise ArgumentError, "Expecting subject followed by description, and either one is optional. Not quite sure what to do with this list of arguments." unless args.empty?
93
- @block = block || lambda { puts "Pending: #{description}" if verbose }
94
- end
95
-
96
- # :call-seq:
97
- # run_against(context)
98
- #
99
- # Runs this expectation against the context object. The context object is different from the subject,
100
- # but used as the subject if no subject specified (i.e. returned from the it method).
101
- #
102
- # This method creates a new context object modeled after the context argument, but a separate object
103
- # used strictly for running this expectation, and used only once. The context object will pass methods
104
- # to the context argument, so you can call any method, e.g. package(:jar).
105
- #
106
- # It also adds all matchers defined in Buildr and RSpec, and two additional methods:
107
- # * it() -- Returns the subject.
108
- # * description() -- Returns the description.
109
- def run_against(context)
110
- subject = @subject || context
111
- description = @description ? "#{subject} #{@description}" : subject.to_s
112
- # Define anonymous class and load it with:
113
- # - All instance methods defined in context, so we can pass method calls to the context.
114
- # - it() method to return subject, description() method to return description.
115
- # - All matchers defined by Buildr and RSpec.
116
- klass = Class.new
117
- klass.instance_eval do
118
- context.class.instance_methods.each do |method|
119
- define_method(method) { |*args| context.send(method, *args) } unless instance_methods.include?(method)
120
- end
121
- define_method(:it) { subject }
122
- define_method(:description) { description }
123
- include Spec::Matchers
124
- include Matchers
125
- end
126
-
127
- # Run the expectation. We only print the expectation name when tracing (to know they all ran),
128
- # or when we get a failure.
129
- begin
130
- trace description
131
- klass.new.instance_eval &@block
132
- rescue Exception=>error
133
- raise error.exception("#{description}\n#{error}").tap { |wrapped| wrapped.set_backtrace(error.backtrace) }
134
- end
135
- end
136
-
137
- end
138
-
139
-
140
- include Extension
141
-
142
- before_define do |project|
143
- # The check task can do any sort of interesting things, but the most important is running expectations.
144
- project.task("check") do |task|
145
- project.expectations.inject(true) do |passed, expect|
146
- begin
147
- expect.run_against project
148
- passed
149
- rescue Exception=>ex
150
- if verbose
151
- error ex.backtrace.select { |line| line =~ /#{Buildr.application.buildfile}/ }.join("\n")
152
- error ex
153
- end
154
- false
155
- end
156
- end or fail "Checks failed for project #{project.name} (see errors above)."
157
- end
158
- project.task("package").enhance do |task|
159
- # Run all actions before checks.
160
- task.enhance { project.task("check").invoke }
161
- end
162
- end
163
-
164
-
165
- # :call-seq:
166
- # check(description) { ... }
167
- # check(subject, description) { ... }
168
- #
169
- # Adds an expectation. The expectation is run against the project by the check task, executed after packaging.
170
- # You can access any package created by the project.
171
- #
172
- # An expectation is written using a subject, description and block to validate the expectation. For example:
173
- #
174
- # For example:
175
- # check package(:jar), "should exist" do
176
- # it.should exist
177
- # end
178
- # check package(:jar), "should contain a manifest" do
179
- # it.should contain("META-INF/MANIFEST.MF")
180
- # end
181
- # check package(:jar).path("com/acme"), "should contain classes" do
182
- # it.should_not be_empty
183
- # end
184
- # check package(:jar).entry("META-INF/MANIFEST"), "should be a recent license" do
185
- # it.should contain(/Copyright (C) 2007/)
186
- # end
187
- #
188
- # If you omit the subject, the project is used as the subject. If you omit the description, the subject is
189
- # used as description.
190
- #
191
- # During development you can write placeholder expectations by omitting the block. This will simply report
192
- # the expectation as pending.
193
- def check(*args, &block)
194
- expectations << Checks::Expectation.new(*args, &block)
195
- end
196
-
197
- # :call-seq:
198
- # expectations() => Expectation*
199
- #
200
- # Returns a list of expectations (see #check).
201
- def expectations()
202
- @expectations ||= []
203
- end
204
-
205
- end
206
-
207
- end
208
-
209
-
210
- module Rake #:nodoc:
211
- class FileTask
212
-
213
- # :call-seq:
214
- # exist?() => boolean
215
- #
216
- # Returns true if this file exists.
217
- def exist?()
218
- File.exist?(name)
219
- end
220
-
221
- # :call-seq:
222
- # empty?() => boolean
223
- #
224
- # Returns true if file/directory is empty.
225
- def empty?()
226
- File.directory?(name) ? Dir.glob("#{name}/*").empty? : File.read(name).empty?
227
- end
228
-
229
- # :call-seq:
230
- # contain?(pattern*) => boolean
231
- # contain?(file*) => boolean
232
- #
233
- # For a file, returns true if the file content matches against all the arguments. An argument may be
234
- # a string or regular expression.
235
- #
236
- # For a directory, return true if the directory contains the specified files. You can use relative
237
- # file names and glob patterns (using *, **, etc).
238
- def contain?(*patterns)
239
- if File.directory?(name)
240
- patterns.map { |pattern| "#{name}/#{pattern}" }.all? { |pattern| !Dir[pattern].empty? }
241
- else
242
- contents = File.read(name)
243
- patterns.map { |pattern| Regexp === pattern ? pattern : Regexp.new(Regexp.escape(pattern.to_s)) }.
244
- all? { |pattern| contents =~ pattern }
245
- end
246
- end
247
-
248
- end
249
- end
250
-
251
-
252
- class Buildr::Project
253
- include Buildr::Checks
254
- end