novoda-buildr 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/CHANGELOG +1050 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +45 -0
  6. data/_buildr +29 -0
  7. data/_jbuildr +29 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/xmlbeans.rb +93 -0
  27. data/bin/buildr +19 -0
  28. data/buildr.buildfile +58 -0
  29. data/buildr.gemspec +65 -0
  30. data/doc/_config.yml +1 -0
  31. data/doc/_layouts/default.html +88 -0
  32. data/doc/_layouts/preface.html +22 -0
  33. data/doc/artifacts.textile +211 -0
  34. data/doc/building.textile +245 -0
  35. data/doc/contributing.textile +252 -0
  36. data/doc/css/default.css +236 -0
  37. data/doc/css/print.css +101 -0
  38. data/doc/css/syntax.css +23 -0
  39. data/doc/download.textile +90 -0
  40. data/doc/extending.textile +205 -0
  41. data/doc/images/1442160941-frontcover.jpg +0 -0
  42. data/doc/images/asf-logo.gif +0 -0
  43. data/doc/images/asf-logo.png +0 -0
  44. data/doc/images/buildr-hires.png +0 -0
  45. data/doc/images/buildr.png +0 -0
  46. data/doc/images/favicon.png +0 -0
  47. data/doc/images/growl-icon.tiff +0 -0
  48. data/doc/images/note.png +0 -0
  49. data/doc/images/project-structure.png +0 -0
  50. data/doc/images/tip.png +0 -0
  51. data/doc/images/zbuildr.png +0 -0
  52. data/doc/images/zbuildr.tif +0 -0
  53. data/doc/index.textile +69 -0
  54. data/doc/installing.textile +265 -0
  55. data/doc/languages.textile +459 -0
  56. data/doc/mailing_lists.textile +25 -0
  57. data/doc/more_stuff.textile +457 -0
  58. data/doc/packaging.textile +429 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +276 -0
  61. data/doc/quick_start.textile +210 -0
  62. data/doc/scripts/buildr-git.rb +512 -0
  63. data/doc/scripts/gitflow.rb +296 -0
  64. data/doc/scripts/install-jruby.sh +44 -0
  65. data/doc/scripts/install-linux.sh +72 -0
  66. data/doc/scripts/install-osx.sh +52 -0
  67. data/doc/settings_profiles.textile +287 -0
  68. data/doc/testing.textile +233 -0
  69. data/etc/KEYS +151 -0
  70. data/lib/buildr.rb +36 -0
  71. data/lib/buildr/core.rb +35 -0
  72. data/lib/buildr/core/application.rb +662 -0
  73. data/lib/buildr/core/build.rb +463 -0
  74. data/lib/buildr/core/checks.rb +254 -0
  75. data/lib/buildr/core/common.rb +150 -0
  76. data/lib/buildr/core/compile.rb +608 -0
  77. data/lib/buildr/core/environment.rb +129 -0
  78. data/lib/buildr/core/filter.rb +363 -0
  79. data/lib/buildr/core/generate.rb +195 -0
  80. data/lib/buildr/core/help.rb +119 -0
  81. data/lib/buildr/core/osx.rb +46 -0
  82. data/lib/buildr/core/progressbar.rb +156 -0
  83. data/lib/buildr/core/project.rb +971 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +774 -0
  86. data/lib/buildr/core/transports.rb +559 -0
  87. data/lib/buildr/core/util.rb +449 -0
  88. data/lib/buildr/groovy.rb +19 -0
  89. data/lib/buildr/groovy/bdd.rb +106 -0
  90. data/lib/buildr/groovy/compiler.rb +138 -0
  91. data/lib/buildr/groovy/shell.rb +48 -0
  92. data/lib/buildr/ide.rb +19 -0
  93. data/lib/buildr/ide/eclipse.rb +424 -0
  94. data/lib/buildr/ide/eclipse.rb~ +424 -0
  95. data/lib/buildr/ide/eclipse/java.rb +53 -0
  96. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  97. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  98. data/lib/buildr/ide/idea.ipr.template +300 -0
  99. data/lib/buildr/ide/idea.rb +190 -0
  100. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  101. data/lib/buildr/ide/idea7x.rb +212 -0
  102. data/lib/buildr/java.rb +23 -0
  103. data/lib/buildr/java/ant.rb +94 -0
  104. data/lib/buildr/java/bdd.rb +464 -0
  105. data/lib/buildr/java/cobertura.rb +274 -0
  106. data/lib/buildr/java/commands.rb +217 -0
  107. data/lib/buildr/java/compiler.rb +349 -0
  108. data/lib/buildr/java/deprecated.rb +141 -0
  109. data/lib/buildr/java/emma.rb +244 -0
  110. data/lib/buildr/java/jruby.rb +117 -0
  111. data/lib/buildr/java/jtestr_runner.rb.erb +118 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  113. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  114. data/lib/buildr/java/packaging.rb +717 -0
  115. data/lib/buildr/java/pom.rb +174 -0
  116. data/lib/buildr/java/rjb.rb +155 -0
  117. data/lib/buildr/java/test_result.rb +327 -0
  118. data/lib/buildr/java/tests.rb +341 -0
  119. data/lib/buildr/java/version_requirement.rb +172 -0
  120. data/lib/buildr/packaging.rb +24 -0
  121. data/lib/buildr/packaging/archive.rb +491 -0
  122. data/lib/buildr/packaging/artifact.rb +750 -0
  123. data/lib/buildr/packaging/artifact_namespace.rb +980 -0
  124. data/lib/buildr/packaging/artifact_search.rb +140 -0
  125. data/lib/buildr/packaging/gems.rb +106 -0
  126. data/lib/buildr/packaging/package.rb +241 -0
  127. data/lib/buildr/packaging/tar.rb +186 -0
  128. data/lib/buildr/packaging/version_requirement.rb +172 -0
  129. data/lib/buildr/packaging/zip.rb +73 -0
  130. data/lib/buildr/packaging/ziptask.rb +316 -0
  131. data/lib/buildr/resources/buildr.icns +0 -0
  132. data/lib/buildr/scala.rb +25 -0
  133. data/lib/buildr/scala/bdd.rb +114 -0
  134. data/lib/buildr/scala/compiler.rb +196 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  137. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  138. data/lib/buildr/scala/shell.rb +60 -0
  139. data/lib/buildr/scala/tests.rb +157 -0
  140. data/lib/buildr/shell.rb +180 -0
  141. data/rakelib/all-in-one.rake +84 -0
  142. data/rakelib/checks.rake +57 -0
  143. data/rakelib/doc.rake +92 -0
  144. data/rakelib/jekylltask.rb +120 -0
  145. data/rakelib/package.rake +73 -0
  146. data/rakelib/release.rake +152 -0
  147. data/rakelib/rspec.rake +73 -0
  148. data/rakelib/setup.rake +54 -0
  149. data/rakelib/stage.rake +214 -0
  150. data/spec/addon/drb_spec.rb +328 -0
  151. data/spec/core/application_spec.rb +509 -0
  152. data/spec/core/build_spec.rb +678 -0
  153. data/spec/core/checks_spec.rb +519 -0
  154. data/spec/core/common_spec.rb +670 -0
  155. data/spec/core/compile_spec.rb +624 -0
  156. data/spec/core/extension_spec.rb +201 -0
  157. data/spec/core/generate_spec.rb +33 -0
  158. data/spec/core/project_spec.rb +762 -0
  159. data/spec/core/test_spec.rb +1175 -0
  160. data/spec/core/transport_spec.rb +537 -0
  161. data/spec/core/util_spec.rb +67 -0
  162. data/spec/groovy/bdd_spec.rb +80 -0
  163. data/spec/groovy/compiler_spec.rb +240 -0
  164. data/spec/ide/eclipse_spec.rb +650 -0
  165. data/spec/ide/idea7x_spec.rb +84 -0
  166. data/spec/java/ant_spec.rb +33 -0
  167. data/spec/java/bdd_spec.rb +379 -0
  168. data/spec/java/cobertura_spec.rb +85 -0
  169. data/spec/java/compiler_spec.rb +446 -0
  170. data/spec/java/emma_spec.rb +119 -0
  171. data/spec/java/java_spec.rb +124 -0
  172. data/spec/java/packaging_spec.rb +1140 -0
  173. data/spec/java/test_coverage_helper.rb +257 -0
  174. data/spec/java/tests_spec.rb +493 -0
  175. data/spec/packaging/archive_spec.rb +538 -0
  176. data/spec/packaging/artifact_namespace_spec.rb +697 -0
  177. data/spec/packaging/artifact_spec.rb +802 -0
  178. data/spec/packaging/packaging_helper.rb +63 -0
  179. data/spec/packaging/packaging_spec.rb +684 -0
  180. data/spec/sandbox.rb +148 -0
  181. data/spec/scala/bdd_spec.rb +119 -0
  182. data/spec/scala/compiler_spec.rb +284 -0
  183. data/spec/scala/scala.rb +38 -0
  184. data/spec/scala/tests_spec.rb +263 -0
  185. data/spec/spec_helpers.rb +340 -0
  186. data/spec/version_requirement_spec.rb +143 -0
  187. metadata +384 -0
@@ -0,0 +1,341 @@
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/build'
18
+ require 'buildr/core/compile'
19
+ require 'buildr/java/ant'
20
+
21
+
22
+ module Buildr
23
+
24
+ class TestFramework::Java < TestFramework::Base
25
+
26
+ class << self
27
+
28
+ def applies_to?(project) #:nodoc:
29
+ project.test.compile.language == :java
30
+ end
31
+
32
+ def dependencies
33
+ unless @dependencies
34
+ super
35
+ # Add buildr utility classes (e.g. JavaTestFilter)
36
+ @dependencies |= [ File.join(File.dirname(__FILE__)) ]
37
+ end
38
+ @dependencies
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ # Add buildr utilities (JavaTestFilter) to classpath
45
+ Java.classpath << File.join(File.dirname(__FILE__))
46
+
47
+ # :call-seq:
48
+ # filter_classes(dependencies, criteria)
49
+ #
50
+ # Return a list of classnames that match the given criteria.
51
+ # The criteria parameter is a hash that must contain at least one of:
52
+ #
53
+ # * :class_names -- List of patterns to match against class name
54
+ # * :interfaces -- List of java interfaces or java classes
55
+ # * :class_annotations -- List of annotations on class level
56
+ # * :method_annotations -- List of annotations on method level
57
+ # * :fields -- List of java field names
58
+ #
59
+ def filter_classes(dependencies, criteria = {})
60
+ return [] unless task.compile.target
61
+ target = task.compile.target.to_s
62
+ candidates = Dir["#{target}/**/*.class"].
63
+ map { |file| Util.relative_path(file, target).ext('').gsub(File::SEPARATOR, '.') }.
64
+ reject { |name| name =~ /\$./ }
65
+ result = []
66
+ if criteria[:class_names]
67
+ result.concat candidates.select { |name| criteria[:class_names].flatten.any? { |pat| pat === name } }
68
+ end
69
+ begin
70
+ Java.load
71
+ filter = Java.org.apache.buildr.JavaTestFilter.new(dependencies.to_java(Java.java.lang.String))
72
+ if criteria[:interfaces]
73
+ filter.add_interfaces(criteria[:interfaces].to_java(Java.java.lang.String))
74
+ end
75
+ if criteria[:class_annotations]
76
+ filter.add_class_annotations(criteria[:class_annotations].to_java(Java.java.lang.String))
77
+ end
78
+ if criteria[:method_annotations]
79
+ filter.add_method_annotations(criteria[:method_annotations].to_java(Java.java.lang.String))
80
+ end
81
+ if criteria[:fields]
82
+ filter.add_fields(criteria[:fields].to_java(Java.java.lang.String))
83
+ end
84
+ result.concat filter.filter(candidates.to_java(Java.java.lang.String)).map(&:to_s)
85
+ rescue =>ex
86
+ info "#{ex.class}: #{ex.message}"
87
+ raise
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+
94
+ # JMock is available when using JUnit and TestNG, JBehave.
95
+ module JMock
96
+
97
+ VERSION = '1.2.0'
98
+
99
+ class << self
100
+ def version
101
+ Buildr.settings.build['jmock'] || VERSION
102
+ end
103
+
104
+ def dependencies
105
+ @dependencies ||= ["jmock:jmock:jar:#{version}"]
106
+ end
107
+
108
+ private
109
+ def const_missing(const)
110
+ return super unless const == :REQUIRES # TODO: remove in 1.5
111
+ Buildr.application.deprecated "Please use JMock.dependencies/.version instead of JMock::REQUIRES/VERSION"
112
+ dependencies
113
+ end
114
+ end
115
+ end
116
+
117
+
118
+ # JUnit test framework, the default test framework for Java tests.
119
+ #
120
+ # Support the following options:
121
+ # * :fork -- If true/:once (default), fork for each test class. If :each, fork for each individual
122
+ # test case. If false, run all tests in the same VM (fast, but dangerous).
123
+ # * :clonevm -- If true clone the VM each time it is forked.
124
+ # * :properties -- Hash of system properties available to the test case.
125
+ # * :environment -- Hash of environment variables available to the test case.
126
+ # * :java_args -- Arguments passed as is to the JVM.
127
+ class JUnit < TestFramework::Java
128
+
129
+ # Used by the junit:report task. Access through JUnit#report if you want to set various
130
+ # options for that task, for example:
131
+ # JUnit.report.frames = false
132
+ class Report
133
+
134
+ # Parameters passed to the Ant JUnitReport task.
135
+ attr_reader :params
136
+ # True (default) to produce a report using frames, false to produce a single-page report.
137
+ attr_accessor :frames
138
+ # Directory for the report style (defaults to using the internal style).
139
+ attr_accessor :style_dir
140
+ # Target directory for generated report.
141
+ attr_accessor :target
142
+
143
+ def initialize
144
+ @params = {}
145
+ @frames = true
146
+ @target = 'reports/junit'
147
+ end
148
+
149
+ # :call-seq:
150
+ # generate(projects, target?)
151
+ #
152
+ # Generates a JUnit report for these projects (must run JUnit tests first) into the
153
+ # target directory. You can specify a target, or let it pick the default one from the
154
+ # target attribute.
155
+ def generate(projects, target = @target.to_s)
156
+ html_in = File.join(target, 'html')
157
+ rm_rf html_in ; mkpath html_in
158
+
159
+ Buildr.ant('junit-report') do |ant|
160
+ ant.taskdef :name=>'junitreport', :classname=>'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator',
161
+ :classpath=>Buildr.artifacts(JUnit.ant_taskdef).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
162
+ ant.junitreport :todir=>target do
163
+ projects.select { |project| project.test.framework == :junit }.
164
+ map { |project| project.test.report_to.to_s }.select { |path| File.exist?(path) }.
165
+ each { |path| ant.fileset(:dir=>path) { ant.include :name=>'TEST-*.xml' } }
166
+ options = { :format=>frames ? 'frames' : 'noframes' }
167
+ options[:styledir] = style_dir if style_dir
168
+ ant.report options.merge(:todir=>html_in) do
169
+ params.each { |key, value| ant.param :name=>key, :expression=>value }
170
+ end
171
+ end
172
+ end
173
+ end
174
+
175
+ end
176
+
177
+ # JUnit version number.
178
+ VERSION = '4.7'
179
+
180
+ class << self
181
+ # :call-seq:
182
+ # report()
183
+ #
184
+ # Returns the Report object used by the junit:report task. You can use this object to set
185
+ # various options that affect your report, for example:
186
+ # JUnit.report.frames = false
187
+ # JUnit.report.params['title'] = 'My App'
188
+ def report
189
+ @report ||= Report.new
190
+ end
191
+
192
+ def version
193
+ Buildr.settings.build['junit'] || VERSION
194
+ end
195
+
196
+ def dependencies
197
+ @dependencies ||= ["junit:junit:jar:#{version}"]+ JMock.dependencies
198
+ end
199
+
200
+ def ant_taskdef #:nodoc:
201
+ "org.apache.ant:ant-junit:jar:#{Ant.version}"
202
+ end
203
+
204
+ private
205
+ def const_missing(const)
206
+ return super unless const == :REQUIRES # TODO: remove in 1.5
207
+ Buildr.application.deprecated "Please use JUnit.dependencies/.version instead of JUnit::REQUIRES/VERSION"
208
+ dependencies
209
+ end
210
+ end
211
+
212
+ def tests(dependencies) #:nodoc:
213
+ filter_classes(dependencies,
214
+ :interfaces => %w{junit.framework.TestCase},
215
+ :class_annotations => %w{org.junit.runner.RunWith},
216
+ :method_annotations => %w{org.junit.Test})
217
+ end
218
+
219
+ def run(tests, dependencies) #:nodoc:
220
+ # Use Ant to execute the Junit tasks, gives us performance and reporting.
221
+ Buildr.ant('junit') do |ant|
222
+ case options[:fork]
223
+ when false
224
+ forking = {}
225
+ when :each
226
+ forking = { :fork=>true, :forkmode=>'perTest' }
227
+ when true, :once
228
+ forking = { :fork=>true, :forkmode=>'once' }
229
+ else
230
+ fail 'Option fork must be :once, :each or false.'
231
+ end
232
+ mkpath task.report_to.to_s
233
+
234
+ taskdef = Buildr.artifact(JUnit.ant_taskdef)
235
+ taskdef.invoke
236
+ ant.taskdef :name=>'junit', :classname=>'org.apache.tools.ant.taskdefs.optional.junit.JUnitTask', :classpath=>taskdef.to_s
237
+
238
+ ant.junit forking.merge(:clonevm=>options[:clonevm] || false, :dir=>task.send(:project).path_to) do
239
+ ant.classpath :path=>dependencies.join(File::PATH_SEPARATOR)
240
+ (options[:properties] || []).each { |key, value| ant.sysproperty :key=>key, :value=>value }
241
+ (options[:environment] || []).each { |key, value| ant.env :key=>key, :value=>value }
242
+ Array(options[:java_args]).each { |value| ant.jvmarg :value=>value }
243
+ ant.formatter :type=>'plain'
244
+ ant.formatter :type=>'plain', :usefile=>false # log test
245
+ ant.formatter :type=>'xml'
246
+ ant.batchtest :todir=>task.report_to.to_s, :failureproperty=>'failed' do
247
+ ant.fileset :dir=>task.compile.target.to_s do
248
+ tests.each { |test| ant.include :name=>File.join(*test.split('.')).ext('class') }
249
+ end
250
+ end
251
+ end
252
+ return tests unless ant.project.getProperty('failed')
253
+ end
254
+ # But Ant doesn't tell us what went kaput, so we'll have to parse the test files.
255
+ tests.inject([]) do |passed, test|
256
+ report_file = File.join(task.report_to.to_s, "TEST-#{test}.txt")
257
+ if File.exist?(report_file)
258
+ report = File.read(report_file)
259
+ # The second line (if exists) is the status line and we scan it for its values.
260
+ status = (report.split("\n")[1] || '').scan(/(run|failures|errors):\s*(\d+)/i).
261
+ inject(Hash.new(0)) { |hash, pair| hash[pair[0].downcase.to_sym] = pair[1].to_i ; hash }
262
+ passed << test if status[:failures] == 0 && status[:errors] == 0
263
+ end
264
+ passed
265
+ end
266
+ end
267
+
268
+ namespace 'junit' do
269
+ desc "Generate JUnit tests report in #{report.target}"
270
+ task('report') do |task|
271
+ report.generate Project.projects
272
+ info "Generated JUnit tests report in #{report.target}"
273
+ end
274
+ end
275
+
276
+ task('clean') { rm_rf report.target.to_s }
277
+
278
+ end
279
+
280
+
281
+ # TestNG test framework. To use in your project:
282
+ # test.using :testng
283
+ #
284
+ # Support the following options:
285
+ # * :properties -- Hash of properties passed to the test suite.
286
+ # * :java_args -- Arguments passed to the JVM.
287
+ class TestNG < TestFramework::Java
288
+
289
+ VERSION = '5.10'
290
+
291
+ class << self
292
+ def version
293
+ Buildr.settings.build['testng'] || VERSION
294
+ end
295
+
296
+ def dependencies
297
+ ["org.testng:testng:jar:jdk15:#{version}"]+ JMock.dependencies
298
+ end
299
+
300
+ private
301
+ def const_missing(const)
302
+ return super unless const == :REQUIRES # TODO: remove in 1.5
303
+ Buildr.application.deprecated "Please use TestNG.dependencies/.version instead of TestNG::REQUIRES/VERSION"
304
+ dependencies
305
+ end
306
+ end
307
+
308
+ def tests(dependencies) #:nodoc:
309
+ filter_classes(dependencies,
310
+ :class_annotations => %w{org.testng.annotations.Test},
311
+ :method_annotations => %w{org.testng.annotations.Test})
312
+ end
313
+
314
+ def run(tests, dependencies) #:nodoc:
315
+ cmd_args = [ 'org.testng.TestNG', '-log', '2', '-sourcedir', task.compile.sources.join(';'), '-suitename', task.project.id ]
316
+ cmd_args << '-d' << task.report_to.to_s
317
+ # run all tests in the same suite
318
+ cmd_args << '-testclass' << tests
319
+ cmd_options = { :properties=>options[:properties], :java_args=>options[:java_args],
320
+ :classpath=>dependencies, :name => "TestNG in #{task.send(:project).name}" }
321
+
322
+ begin
323
+ Java::Commands.java cmd_args, cmd_options
324
+ return tests
325
+ rescue
326
+ # testng-failed.xml contains the list of failed tests *only*
327
+ report = File.read(File.join(task.report_to.to_s, 'testng-failed.xml'))
328
+ failed = report.scan(/<class name="(.*?)">/im).flatten
329
+ error "TestNG regexp returned unexpected failed tests #{failed.inspect}" unless (failed - tests).empty?
330
+ # return the list of passed tests
331
+ return tests - failed
332
+ end
333
+ end
334
+
335
+ end
336
+
337
+ end # Buildr
338
+
339
+
340
+ Buildr::TestFramework << Buildr::JUnit
341
+ Buildr::TestFramework << Buildr::TestNG
@@ -0,0 +1,172 @@
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
+ module Buildr
18
+
19
+ #
20
+ # See ArtifactNamespace#need
21
+ class VersionRequirement
22
+
23
+ CMP_PROCS = Gem::Requirement::OPS.dup
24
+ CMP_REGEX = Gem::Requirement::OP_RE.dup
25
+ CMP_CHARS = CMP_PROCS.keys.join
26
+ BOOL_CHARS = '\|\&\!'
27
+ VER_CHARS = '\w\.\-'
28
+
29
+ class << self
30
+ # is +str+ a version string?
31
+ def version?(str)
32
+ /^\s*[#{VER_CHARS}]+\s*$/ === str
33
+ end
34
+
35
+ # is +str+ a version requirement?
36
+ def requirement?(str)
37
+ /[#{BOOL_CHARS}#{CMP_CHARS}\(\)]/ === str
38
+ end
39
+
40
+ # :call-seq:
41
+ # VersionRequirement.create(" >1 <2 !(1.5) ") -> requirement
42
+ #
43
+ # parse the +str+ requirement
44
+ def create(str)
45
+ instance_eval normalize(str)
46
+ rescue StandardError => e
47
+ raise "Failed to parse #{str.inspect} due to: #{e}"
48
+ end
49
+
50
+ private
51
+ def requirement(req)
52
+ unless req =~ /^\s*(#{CMP_REGEX})?\s*([#{VER_CHARS}]+)\s*$/
53
+ raise "Invalid requirement string: #{req}"
54
+ end
55
+ comparator, version = $1, $2
56
+ version = Gem::Version.new(0).tap { |v| v.version = version }
57
+ VersionRequirement.new(nil, [$1, version])
58
+ end
59
+
60
+ def negate(vreq)
61
+ vreq.negative = !vreq.negative
62
+ vreq
63
+ end
64
+
65
+ def normalize(str)
66
+ str = str.strip
67
+ if str[/[^\s\(\)#{BOOL_CHARS + VER_CHARS + CMP_CHARS}]/]
68
+ raise "version string #{str.inspect} contains invalid characters"
69
+ end
70
+ str.gsub!(/\s+(and|\&\&)\s+/, ' & ')
71
+ str.gsub!(/\s+(or|\|\|)\s+/, ' | ')
72
+ str.gsub!(/(^|\s*)not\s+/, ' ! ')
73
+ pattern = /(#{CMP_REGEX})?\s*[#{VER_CHARS}]+/
74
+ left_pattern = /[#{VER_CHARS}\)]$/
75
+ right_pattern = /^(#{pattern}|\()/
76
+ str = str.split.inject([]) do |ary, i|
77
+ ary << '&' if ary.last =~ left_pattern && i =~ right_pattern
78
+ ary << i
79
+ end
80
+ str = str.join(' ')
81
+ str.gsub!(/!([^=])?/, ' negate \1')
82
+ str.gsub!(pattern) do |expr|
83
+ case expr.strip
84
+ when 'not', 'negate' then 'negate '
85
+ else 'requirement("' + expr + '")'
86
+ end
87
+ end
88
+ str.gsub!(/negate\s+\(/, 'negate(')
89
+ str
90
+ end
91
+ end
92
+
93
+ def initialize(op, *requirements) #:nodoc:
94
+ @op, @requirements = op, requirements
95
+ end
96
+
97
+ # Is this object a composed requirement?
98
+ # VersionRequirement.create('1').composed? -> false
99
+ # VersionRequirement.create('1 | 2').composed? -> true
100
+ # VersionRequirement.create('1 & 2').composed? -> true
101
+ def composed?
102
+ requirements.size > 1
103
+ end
104
+
105
+ # Return the last requirement on this object having an = operator.
106
+ def default
107
+ default = nil
108
+ requirements.reverse.find do |r|
109
+ if Array === r
110
+ if !negative && (r.first.nil? || r.first.include?('='))
111
+ default = r.last.to_s
112
+ end
113
+ else
114
+ default = r.default
115
+ end
116
+ end
117
+ default
118
+ end
119
+
120
+ # Test if this requirement can be satisfied by +version+
121
+ def satisfied_by?(version)
122
+ return false unless version
123
+ unless version.kind_of?(Gem::Version)
124
+ raise "Invalid version: #{version.inspect}" unless self.class.version?(version)
125
+ version = Gem::Version.new(0).tap { |v| v.version = version.strip }
126
+ end
127
+ message = op == :| ? :any? : :all?
128
+ result = requirements.send message do |req|
129
+ if Array === req
130
+ cmp, rv = *req
131
+ CMP_PROCS[cmp || '='].call(version, rv)
132
+ else
133
+ req.satisfied_by?(version)
134
+ end
135
+ end
136
+ negative ? !result : result
137
+ end
138
+
139
+ # Either modify the current requirement (if it's already an or operation)
140
+ # or create a new requirement
141
+ def |(other)
142
+ operation(:|, other)
143
+ end
144
+
145
+ # Either modify the current requirement (if it's already an and operation)
146
+ # or create a new requirement
147
+ def &(other)
148
+ operation(:&, other)
149
+ end
150
+
151
+ # return the parsed expression
152
+ def to_s
153
+ str = requirements.map(&:to_s).join(" " + @op.to_s + " ").to_s
154
+ str = "( " + str + " )" if negative || requirements.size > 1
155
+ str = "!" + str if negative
156
+ str
157
+ end
158
+
159
+ attr_accessor :negative
160
+ protected
161
+ attr_reader :requirements, :op
162
+ def operation(op, other)
163
+ @op ||= op
164
+ if negative == other.negative && @op == op && other.requirements.size == 1
165
+ @requirements << other.requirements.first
166
+ self
167
+ else
168
+ self.class.new(op, self, other)
169
+ end
170
+ end
171
+ end # VersionRequirement
172
+ end