buildr 1.3.5-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +998 -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 +244 -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 +79 -0
  40. data/doc/extending.textile +186 -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 +266 -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 +430 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +271 -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 +280 -0
  68. data/doc/testing.textile +222 -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 +656 -0
  73. data/lib/buildr/core/build.rb +452 -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 +362 -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 +866 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +723 -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 +334 -0
  94. data/lib/buildr/ide/eclipse/java.rb +53 -0
  95. data/lib/buildr/ide/eclipse/plugin.rb +68 -0
  96. data/lib/buildr/ide/eclipse/scala.rb +66 -0
  97. data/lib/buildr/ide/idea.ipr.template +300 -0
  98. data/lib/buildr/ide/idea.rb +190 -0
  99. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  100. data/lib/buildr/ide/idea7x.rb +212 -0
  101. data/lib/buildr/java.rb +23 -0
  102. data/lib/buildr/java/ant.rb +94 -0
  103. data/lib/buildr/java/bdd.rb +459 -0
  104. data/lib/buildr/java/cobertura.rb +274 -0
  105. data/lib/buildr/java/commands.rb +213 -0
  106. data/lib/buildr/java/compiler.rb +349 -0
  107. data/lib/buildr/java/deprecated.rb +141 -0
  108. data/lib/buildr/java/emma.rb +244 -0
  109. data/lib/buildr/java/jruby.rb +117 -0
  110. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  111. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +137 -0
  113. data/lib/buildr/java/packaging.rb +716 -0
  114. data/lib/buildr/java/pom.rb +174 -0
  115. data/lib/buildr/java/rjb.rb +155 -0
  116. data/lib/buildr/java/test_result.rb +353 -0
  117. data/lib/buildr/java/tests.rb +333 -0
  118. data/lib/buildr/java/version_requirement.rb +172 -0
  119. data/lib/buildr/packaging.rb +24 -0
  120. data/lib/buildr/packaging/archive.rb +488 -0
  121. data/lib/buildr/packaging/artifact.rb +749 -0
  122. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  123. data/lib/buildr/packaging/artifact_search.rb +140 -0
  124. data/lib/buildr/packaging/gems.rb +102 -0
  125. data/lib/buildr/packaging/package.rb +238 -0
  126. data/lib/buildr/packaging/tar.rb +186 -0
  127. data/lib/buildr/packaging/version_requirement.rb +172 -0
  128. data/lib/buildr/packaging/zip.rb +73 -0
  129. data/lib/buildr/packaging/ziptask.rb +316 -0
  130. data/lib/buildr/resources/buildr.icns +0 -0
  131. data/lib/buildr/scala.rb +25 -0
  132. data/lib/buildr/scala/bdd.rb +109 -0
  133. data/lib/buildr/scala/compiler.rb +195 -0
  134. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  137. data/lib/buildr/scala/shell.rb +55 -0
  138. data/lib/buildr/scala/tests.rb +157 -0
  139. data/lib/buildr/shell.rb +180 -0
  140. data/rakelib/checks.rake +57 -0
  141. data/rakelib/doc.rake +92 -0
  142. data/rakelib/jekylltask.rb +120 -0
  143. data/rakelib/package.rake +73 -0
  144. data/rakelib/release.rake +149 -0
  145. data/rakelib/rspec.rake +73 -0
  146. data/rakelib/setup.rake +54 -0
  147. data/rakelib/stage.rake +213 -0
  148. data/rakelib/stage.rake~ +213 -0
  149. data/spec/addon/drb_spec.rb +328 -0
  150. data/spec/core/application_spec.rb +502 -0
  151. data/spec/core/build_spec.rb +677 -0
  152. data/spec/core/checks_spec.rb +519 -0
  153. data/spec/core/common_spec.rb +670 -0
  154. data/spec/core/compile_spec.rb +583 -0
  155. data/spec/core/extension_spec.rb +93 -0
  156. data/spec/core/generate_spec.rb +33 -0
  157. data/spec/core/project_spec.rb +762 -0
  158. data/spec/core/test_spec.rb +1098 -0
  159. data/spec/core/transport_spec.rb +537 -0
  160. data/spec/core/util_spec.rb +67 -0
  161. data/spec/groovy/bdd_spec.rb +80 -0
  162. data/spec/groovy/compiler_spec.rb +240 -0
  163. data/spec/ide/eclipse_spec.rb +501 -0
  164. data/spec/ide/idea7x_spec.rb +84 -0
  165. data/spec/java/ant_spec.rb +33 -0
  166. data/spec/java/bdd_spec.rb +382 -0
  167. data/spec/java/cobertura_spec.rb +85 -0
  168. data/spec/java/compiler_spec.rb +446 -0
  169. data/spec/java/emma_spec.rb +119 -0
  170. data/spec/java/java_spec.rb +124 -0
  171. data/spec/java/packaging_spec.rb +1134 -0
  172. data/spec/java/test_coverage_helper.rb +257 -0
  173. data/spec/java/tests_spec.rb +493 -0
  174. data/spec/packaging/archive_spec.rb +527 -0
  175. data/spec/packaging/artifact_namespace_spec.rb +654 -0
  176. data/spec/packaging/artifact_spec.rb +795 -0
  177. data/spec/packaging/packaging_helper.rb +63 -0
  178. data/spec/packaging/packaging_spec.rb +684 -0
  179. data/spec/sandbox.rb +142 -0
  180. data/spec/scala/bdd_spec.rb +119 -0
  181. data/spec/scala/compiler_spec.rb +284 -0
  182. data/spec/scala/scala.rb +38 -0
  183. data/spec/scala/tests_spec.rb +261 -0
  184. data/spec/spec_helpers.rb +340 -0
  185. data/spec/version_requirement_spec.rb +129 -0
  186. metadata +383 -0
@@ -0,0 +1,198 @@
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/shell'
18
+ require 'buildr/java/commands'
19
+ require 'buildr/core/util'
20
+
21
+ module Buildr
22
+ module Shell
23
+
24
+ class BeanShell < Base
25
+
26
+ include JavaRebel
27
+
28
+ VERSION = '2.0b4'
29
+
30
+ class << self
31
+ def version
32
+ Buildr.settings.build['bsh'] || VERSION
33
+ end
34
+
35
+ def artifact
36
+ "org.beanshell:bsh:jar:#{version}"
37
+ end
38
+
39
+ def lang
40
+ :java
41
+ end
42
+
43
+ def to_sym
44
+ :bsh
45
+ end
46
+ end
47
+
48
+ def launch
49
+ cp = project.compile.dependencies + [project.path_to(:target, :classes), Buildr.artifact(BeanShell.artifact)]
50
+ Java::Commands.java 'bsh.Console', {
51
+ :properties => rebel_props(project),
52
+ :classpath => cp,
53
+ :java_args => rebel_args
54
+ }
55
+ end
56
+
57
+ end # BeanShell
58
+
59
+
60
+ class JIRB < Base
61
+ include JavaRebel
62
+
63
+ JRUBY_VERSION = '1.3.1'
64
+
65
+ class << self
66
+ def lang
67
+ :none
68
+ end
69
+ end
70
+
71
+ def launch
72
+ if jruby_home # if JRuby is installed, use it
73
+ cp = project.compile.dependencies +
74
+ [project.path_to(:target, :classes)] +
75
+ Dir.glob("#{jruby_home}#{File::SEPARATOR}lib#{File::SEPARATOR}*.jar")
76
+
77
+ props = {
78
+ 'jruby.home' => jruby_home,
79
+ 'jruby.lib' => "#{jruby_home}#{File::SEPARATOR}lib"
80
+ }
81
+
82
+ if not Util.win_os?
83
+ uname = `uname -m`
84
+ cpu = if uname =~ /i[34567]86/
85
+ 'i386'
86
+ elsif uname == 'i86pc'
87
+ 'x86'
88
+ elsif uname =~ /amd64|x86_64/
89
+ 'amd64'
90
+ end
91
+
92
+ os = `uname -s | tr '[A-Z]' '[a-z]'`
93
+ path = if os == 'darwin'
94
+ 'darwin'
95
+ else
96
+ "#{os}-#{cpu}"
97
+ end
98
+
99
+ props['jna.boot.library.path'] = "#{jruby_home}/lib/native/#{path}"
100
+ end
101
+
102
+ props['jruby.script'] = if Util.win_os? then 'jruby.bat' else 'jruby' end
103
+ props['jruby.shell'] = if Util.win_os? then 'cmd.exe' else '/bin/sh' end
104
+
105
+ args = [
106
+ "-Xbootclasspath/a:#{Dir.glob("#{jruby_home}#{File::SEPARATOR}lib#{File::SEPARATOR}jruby*.jar").join File::PATH_SEPARATOR}"
107
+ ]
108
+
109
+ Java::Commands.java 'org.jruby.Main', "#{jruby_home}#{File::SEPARATOR}bin#{File::SEPARATOR}jirb", {
110
+ :properties => props.merge(rebel_props(project)),
111
+ :classpath => cp,
112
+ :java_args => args + rebel_args
113
+ }
114
+ else
115
+ cp = project.compile.dependencies + [
116
+ jruby_artifact,
117
+ project.path_to(:target, :classes)
118
+ ]
119
+
120
+ Java::Commands.java 'org.jruby.Main', '--command', 'irb', {
121
+ :properties => rebel_props(project),
122
+ :classpath => cp,
123
+ :java_args => rebel_args
124
+ }
125
+ end
126
+ end
127
+ private
128
+ def jruby_home
129
+ @jruby_home ||= RUBY_PLATFORM =~ /java/ ? Config::CONFIG['prefix'] : ENV['JRUBY_HOME']
130
+ end
131
+
132
+ def jruby_artifact
133
+ version = Buildr.settings.build['jruby'] || JRUBY_VERSION
134
+ "org.jruby:jruby-complete:jar:#{version}"
135
+ end
136
+
137
+ end
138
+
139
+ class Clojure < Base
140
+ include JavaRebel
141
+
142
+ JLINE_VERSION = '0.9.94'
143
+
144
+ class << self
145
+ def lang
146
+ :none
147
+ end
148
+
149
+ def to_sym
150
+ :clj # more common than `clojure`
151
+ end
152
+ end
153
+
154
+ # don't build if it's *only* Clojure sources
155
+ def build?
156
+ !has_source?(:clojure) or has_source?(:java) or has_source?(:scala) or has_source?(:groovy)
157
+ end
158
+
159
+ def launch
160
+ fail 'Are we forgetting something? CLOJURE_HOME not set.' unless clojure_home
161
+
162
+ cp = project.compile.dependencies +
163
+ [
164
+ if build?
165
+ project.path_to(:target, :classes)
166
+ else
167
+ project.path_to(:src, :main, :clojure)
168
+ end,
169
+ File.expand_path('clojure.jar', clojure_home),
170
+ 'jline:jline:jar:0.9.94'
171
+ ]
172
+
173
+ if build?
174
+ Java::Commands.java 'jline.ConsoleRunner', 'clojure.lang.Repl', {
175
+ :properties => rebel_props(project),
176
+ :classpath => cp,
177
+ :java_args => rebel_args
178
+ }
179
+ else
180
+ Java::Commands.java 'jline.ConsoleRunner', 'clojure.lang.Repl', :classpath => cp
181
+ end
182
+ end
183
+
184
+ private
185
+ def clojure_home
186
+ @home ||= ENV['CLOJURE_HOME']
187
+ end
188
+
189
+ def has_source?(lang)
190
+ File.exists? project.path_to(:src, :main, lang)
191
+ end
192
+ end
193
+ end
194
+ end
195
+
196
+ Buildr::ShellProviders << Buildr::Shell::BeanShell
197
+ Buildr::ShellProviders << Buildr::Shell::JIRB
198
+ Buildr::ShellProviders << Buildr::Shell::Clojure
@@ -0,0 +1,723 @@
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/build'
19
+ require 'buildr/core/compile'
20
+
21
+
22
+ module Buildr
23
+
24
+ # The underlying test framework used by TestTask.
25
+ # To add a new test framework, extend TestFramework::Base and add your framework using:
26
+ # Buildr::TestFramework << MyFramework
27
+ module TestFramework
28
+
29
+ class << self
30
+
31
+ # Returns true if the specified test framework exists.
32
+ def has?(name)
33
+ frameworks.any? { |framework| framework.to_sym == name.to_sym }
34
+ end
35
+
36
+ # Select a test framework by its name.
37
+ def select(name)
38
+ frameworks.detect { |framework| framework.to_sym == name.to_sym }
39
+ end
40
+
41
+ # Identify which test framework applies for this project.
42
+ def select_from(project)
43
+ # Look for a suitable test framework based on the compiled language,
44
+ # which may return multiple candidates, e.g. JUnit and TestNG for Java.
45
+ # Pick the one used in the parent project, if not, whichever comes first.
46
+ candidates = frameworks.select { |framework| framework.applies_to?(project) }
47
+ parent = project.parent
48
+ parent && candidates.detect { |framework| framework.to_sym == parent.test.framework } || candidates.first
49
+ end
50
+
51
+ # Adds a test framework to the list of supported frameworks.
52
+ #
53
+ # For example:
54
+ # Buildr::TestFramework << Buildr::JUnit
55
+ def add(framework)
56
+ @frameworks ||= []
57
+ @frameworks |= [framework]
58
+ end
59
+ alias :<< :add
60
+
61
+ # Returns a list of available test frameworks.
62
+ def frameworks
63
+ @frameworks ||= []
64
+ end
65
+
66
+ end
67
+
68
+ # Base class for all test frameworks, with common functionality. Extend and over-ride as you see fit
69
+ # (see JUnit as an example).
70
+ class Base
71
+
72
+ class << self
73
+
74
+ # The framework's identifier (e.g. :junit). Inferred from the class name.
75
+ def to_sym
76
+ @symbol ||= name.split('::').last.downcase.to_sym
77
+ end
78
+
79
+ # Returns true if this framework applies to the current project. For example, JUnit returns
80
+ # true if the tests are written in Java.
81
+ def applies_to?(project)
82
+ raise 'Not implemented'
83
+ end
84
+
85
+ # Returns a list of dependencies for this framework. Default is an empty list,
86
+ # override to add dependencies.
87
+ def dependencies
88
+ @dependencies ||= []
89
+ end
90
+
91
+ end
92
+
93
+ # Construct a new test framework with the specified options. Note that options may
94
+ # change before the framework is run.
95
+ def initialize(test_task, options)
96
+ @options = options
97
+ @task = test_task
98
+ end
99
+
100
+ # Options for this test framework.
101
+ attr_reader :options
102
+ # The test task we belong to
103
+ attr_reader :task
104
+
105
+ # Returns a list of dependenices for this framework. Defaults to calling the #dependencies
106
+ # method on the class.
107
+ def dependencies
108
+ self.class.dependencies
109
+ end
110
+
111
+ # TestTask calls this method to return a list of test names that can be run in this project.
112
+ # It then applies the include/exclude patterns to arrive at the list of tests that will be
113
+ # run, and call the #run method with that list.
114
+ #
115
+ # This method should return a list suitable for using with the #run method, but also suitable
116
+ # for the user to manage. For example, JUnit locates all the tests in the test.compile.target
117
+ # directory, and returns the class names, which are easier to work with than file names.
118
+ def tests(dependencies)
119
+ raise 'Not implemented'
120
+ end
121
+
122
+ # TestTask calls this method to run the named (and only those) tests. This method returns
123
+ # the list of tests that ran successfully.
124
+ def run(tests, dependencies)
125
+ raise 'Not implemented'
126
+ end
127
+
128
+ end
129
+
130
+ end
131
+
132
+
133
+ # The test task controls the entire test lifecycle.
134
+ #
135
+ # You can use the test task in three ways. You can access and configure specific test tasks,
136
+ # e.g. enhance the #compile task, or run code during #setup/#teardown.
137
+ #
138
+ # You can use convenient methods that handle the most common settings. For example,
139
+ # add dependencies using #with, or include only specific tests using #include.
140
+ #
141
+ # You can also enhance this task directly. This task will first execute the #compile task, followed
142
+ # by the #setup task, run the unit tests, any other enhancements, and end by executing #teardown.
143
+ #
144
+ # The test framework is determined based on the available test files, for example, if the test
145
+ # cases are written in Java, then JUnit is selected as the test framework. You can also select
146
+ # a specific test framework, for example, to use TestNG instead of JUnit:
147
+ # test.using :testng
148
+ class TestTask < Rake::Task
149
+
150
+ class << self
151
+
152
+ # Used by the local test and integration tasks to
153
+ # a) Find the local project(s),
154
+ # b) Find all its sub-projects and narrow down to those that have either unit or integration tests,
155
+ # c) Run all the (either unit or integration) tests, and
156
+ # d) Ignore failure if necessary.
157
+ def run_local_tests(integration) #:nodoc:
158
+ Project.local_projects do |project|
159
+ # !(foo ^ bar) tests for equality and accepts nil as false (and select is less obfuscated than reject on ^).
160
+ projects = ([project] + project.projects).select { |project| !(project.test.options[:integration] ^ integration) }
161
+ projects.each do |project|
162
+ info "Testing #{project.name}"
163
+ begin
164
+ project.test.invoke
165
+ rescue
166
+ raise unless Buildr.options.test == :all
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ # Used by the test/integration rule to only run tests that match the specified names.
173
+ def only_run(tests) #:nodoc:
174
+ tests = tests.map { |name| name =~ /\*/ ? name : "*#{name}*" }
175
+ # Since the tests may reside in a sub-project, we need to set the include/exclude pattern on
176
+ # all sub-projects, but only invoke test on the local project.
177
+ Project.projects.each { |project| project.test.send :only_run, tests }
178
+ end
179
+ end
180
+
181
+ # Default options already set on each test task.
182
+ def default_options
183
+ { :fail_on_failure=>true, :fork=>:once, :properties=>{}, :environment=>{} }
184
+ end
185
+
186
+ def initialize(*args) #:nodoc:
187
+ super
188
+ @dependencies = FileList[]
189
+ @include = []
190
+ @exclude = []
191
+ @forced_need = false
192
+ parent_task = Project.parent_task(name)
193
+ if parent_task.respond_to?(:options)
194
+ @options = OpenObject.new { |hash, key| hash[key] = parent_task.options[key].clone rescue hash[key] = parent_task.options[key] }
195
+ else
196
+ @options = OpenObject.new(default_options)
197
+ end
198
+ enhance [application.buildfile.name] do
199
+ run_tests if framework
200
+ end
201
+ end
202
+
203
+ # The dependencies used for running the tests. Includes the compiled files (compile.target)
204
+ # and their dependencies. Will also include anything you pass to #with, shared between the
205
+ # testing compile and run dependencies.
206
+ attr_reader :dependencies
207
+
208
+ # *Deprecated*: Use dependencies instead.
209
+ def classpath
210
+ Buildr.application.deprecated 'Use dependencies instead.'
211
+ dependencies
212
+ end
213
+
214
+ # *Deprecated*: Use dependencies= instead.
215
+ def classpath=(artifacts)
216
+ Buildr.application.deprecated 'Use dependencies= instead.'
217
+ self.dependencies = artifacts
218
+ end
219
+
220
+ def execute(args) #:nodoc:
221
+ if Buildr.options.test == false
222
+ info "Skipping tests for #{project.name}"
223
+ return
224
+ end
225
+ setup.invoke
226
+ begin
227
+ super
228
+ rescue RuntimeError
229
+ raise if options[:fail_on_failure]
230
+ ensure
231
+ teardown.invoke
232
+ end
233
+ end
234
+
235
+ # :call-seq:
236
+ # compile(*sources) => CompileTask
237
+ # compile(*sources) { |task| .. } => CompileTask
238
+ #
239
+ # The compile task is similar to the Project's compile task. However, it compiles all
240
+ # files found in the src/test/{source} directory into the target/test/{code} directory.
241
+ # This task is executed by the test task before running any tests.
242
+ #
243
+ # Once the project definition is complete, all dependencies from the regular
244
+ # compile task are copied over, so you only need to specify dependencies
245
+ # specific to your tests. You can do so by calling #with on the test task.
246
+ # The dependencies used here are also copied over to the junit task.
247
+ def compile(*sources, &block)
248
+ @project.task('test:compile').from(sources).enhance &block
249
+ end
250
+
251
+ # :call-seq:
252
+ # resources(*prereqs) => ResourcesTask
253
+ # resources(*prereqs) { |task| .. } => ResourcesTask
254
+ #
255
+ # Executes by the #compile task to copy resource files over. See Project#resources.
256
+ def resources(*prereqs, &block)
257
+ @project.task('test:resources').enhance prereqs, &block
258
+ end
259
+
260
+ # :call-seq:
261
+ # setup(*prereqs) => task
262
+ # setup(*prereqs) { |task| .. } => task
263
+ #
264
+ # Returns the setup task. The setup task is executed at the beginning of the test task,
265
+ # after compiling the test files.
266
+ def setup(*prereqs, &block)
267
+ @project.task('test:setup').enhance prereqs, &block
268
+ end
269
+
270
+ # :call-seq:
271
+ # teardown(*prereqs) => task
272
+ # teardown(*prereqs) { |task| .. } => task
273
+ #
274
+ # Returns the teardown task. The teardown task is executed at the end of the test task.
275
+ def teardown(*prereqs, &block)
276
+ @project.task('test:teardown').enhance prereqs, &block
277
+ end
278
+
279
+ # :call-seq:
280
+ # with(*specs) => self
281
+ #
282
+ # Specify artifacts (specs, tasks, files, etc) to include in the dependencies list
283
+ # when compiling and running tests.
284
+ def with(*artifacts)
285
+ @dependencies |= Buildr.artifacts(artifacts.flatten).uniq
286
+ compile.with artifacts
287
+ self
288
+ end
289
+
290
+ # Returns various test options.
291
+ attr_reader :options
292
+
293
+ # :call-seq:
294
+ # using(options) => self
295
+ #
296
+ # Sets various test options from a hash and returns self. For example:
297
+ # test.using :fork=>:each, :properties=>{ 'url'=>'http://localhost:8080' }
298
+ #
299
+ # Can also be used to select the test framework, or to run these tests as
300
+ # integration tests. For example:
301
+ # test.using :testng
302
+ # test.using :integration
303
+ #
304
+ # The :fail_on_failure option specifies whether the task should fail if
305
+ # any of the tests fail (default), or should report the failures but continue
306
+ # running the build (when set to false).
307
+ #
308
+ # All other options depend on the capability of the test framework. These options
309
+ # should be used the same way across all frameworks that support them:
310
+ # * :fork -- Fork once for each project (:once, default), for each test in each
311
+ # project (:each), or don't fork at all (false).
312
+ # * :properties -- Properties pass to the test, e.g. in Java as system properties.
313
+ # * :environment -- Environment variables. This hash is made available in the
314
+ # form of environment variables.
315
+ def using(*args)
316
+ args.pop.each { |key, value| options[key.to_sym] = value } if Hash === args.last
317
+ args.each do |name|
318
+ if TestFramework.has?(name)
319
+ self.framework = name
320
+ elsif name == :integration
321
+ options[:integration] = true
322
+ else
323
+ Buildr.application.deprecated "Please replace with using(:#{name}=>true)"
324
+ options[name.to_sym] = true
325
+ end
326
+ end
327
+ self
328
+ end
329
+
330
+ # :call-seq:
331
+ # include(*names) => self
332
+ #
333
+ # Include only the specified tests. Unless specified, the default is to include
334
+ # all tests identified by the test framework. This method accepts multiple arguments
335
+ # and returns self.
336
+ #
337
+ # Tests are specified by their full name, but you can use glob patterns to select
338
+ # multiple tests, for example:
339
+ # test.include 'com.example.FirstTest' # FirstTest only
340
+ # test.include 'com.example.*' # All tests under com/example
341
+ # test.include 'com.example.Module*' # All tests starting with Module
342
+ # test.include '*.{First,Second}Test' # FirstTest, SecondTest
343
+ def include(*names)
344
+ @include += names
345
+ self
346
+ end
347
+
348
+ # :call-seq:
349
+ # exclude(*names) => self
350
+ #
351
+ # Exclude the specified tests. This method accepts multiple arguments and returns self.
352
+ # See #include for the type of arguments you can use.
353
+ def exclude(*names)
354
+ @exclude += names
355
+ self
356
+ end
357
+
358
+ # *Deprecated*: Use tests instead.
359
+ def classes
360
+ Buildr.application.deprecated 'Call tests instead of classes'
361
+ tests
362
+ end
363
+
364
+ # After running the task, returns all tests selected to run, based on availability and include/exclude pattern.
365
+ attr_reader :tests
366
+ # After running the task, returns all the tests that failed, empty array if all tests passed.
367
+ attr_reader :failed_tests
368
+ # After running the task, returns all the tests that passed, empty array if no tests passed.
369
+ attr_reader :passed_tests
370
+
371
+ # :call-seq:
372
+ # framework => symbol
373
+ #
374
+ # Returns the test framework, e.g. :junit, :testng.
375
+ def framework
376
+ unless @framework
377
+ # Start with all frameworks that apply (e.g. JUnit and TestNG for Java),
378
+ # and pick the first (default) one, unless already specified in parent project.
379
+ candidates = TestFramework.frameworks.select { |cls| cls.applies_to?(@project) }
380
+ candidate = @project.parent && candidates.detect { |framework| framework.to_sym == @project.parent.test.framework } ||
381
+ candidates.first
382
+ self.framework = candidate if candidate
383
+ end
384
+ @framework && @framework.class.to_sym
385
+ end
386
+
387
+ # :call-seq:
388
+ # report_to => file
389
+ #
390
+ # Test frameworks that can produce reports, will write them to this directory.
391
+ #
392
+ # This is framework dependent, so unless you use the default test framework, call this method
393
+ # after setting the test framework.
394
+ def report_to
395
+ @report_to ||= file(@project.path_to(:reports, framework)=>self)
396
+ end
397
+
398
+ # The path to the file that stores the time stamp of the last successful test run.
399
+ def last_successful_run_file #:nodoc:
400
+ File.join(report_to.to_s, 'last_successful_run')
401
+ end
402
+
403
+ # The time stamp of the last successful test run. Or Rake::EARLY if no successful test run recorded.
404
+ def timestamp #:nodoc:
405
+ File.exist?(last_successful_run_file) ? File.mtime(last_successful_run_file) : Rake::EARLY
406
+ end
407
+
408
+ # The project this task belongs to.
409
+ attr_reader :project
410
+
411
+ protected
412
+
413
+ def associate_with(project)
414
+ @project = project
415
+ end
416
+
417
+ def framework=(name)
418
+ cls = TestFramework.select(name) or raise ArgumentError, "No #{name} test framework available. Did you install it?"
419
+ #cls.inherit_options.reject { |name| options.has_key?(name) }.
420
+ # each { |name| options[name] = @parent_task.options[name] } if @parent_task.respond_to?(:options)
421
+ @framework = cls.new(self, options)
422
+ # Test framework dependency.
423
+ with @framework.dependencies
424
+ end
425
+
426
+ # :call-seq:
427
+ # include?(name) => boolean
428
+ #
429
+ # Returns true if the specified test name matches the inclusion/exclusion pattern. Used to determine
430
+ # which tests to execute.
431
+ def include?(name)
432
+ (@include.empty? || @include.any? { |pattern| File.fnmatch(pattern, name) }) &&
433
+ !@exclude.any? { |pattern| File.fnmatch(pattern, name) }
434
+ end
435
+
436
+ # Runs the tests using the selected test framework.
437
+ def run_tests
438
+ dependencies = Buildr.artifacts(self.dependencies).map(&:to_s).uniq
439
+ rm_rf report_to.to_s
440
+ @tests = @framework.tests(dependencies).select { |test| include?(test) }.sort
441
+ if @tests.empty?
442
+ @passed_tests, @failed_tests = [], []
443
+ else
444
+ info "Running tests in #{@project.name}"
445
+ begin
446
+ # set the baseDir system property if not set
447
+ @framework.options[:properties] = { 'baseDir' => @project.test.compile.target.to_s }.merge(@framework.options[:properties] || {})
448
+ @passed_tests = @framework.run(@tests, dependencies)
449
+ rescue Exception=>ex
450
+ error "Test framework error: #{ex.message}"
451
+ error ex.backtrace.join("\n") if Buildr.application.options.trace
452
+ @passed_tests = []
453
+ end
454
+ @failed_tests = @tests - @passed_tests
455
+ unless @failed_tests.empty?
456
+ error "The following tests failed:\n#{@failed_tests.join("\n")}"
457
+ fail 'Tests failed!'
458
+ end
459
+ end
460
+ record_successful_run unless @forced_need
461
+ end
462
+
463
+ # Call this method when a test run is successful to record the current system time.
464
+ def record_successful_run #:nodoc:
465
+ mkdir_p report_to.to_s
466
+ touch last_successful_run_file
467
+ end
468
+
469
+ # Limit running tests to specific list.
470
+ def only_run(tests)
471
+ @include = Array(tests)
472
+ @exclude.clear
473
+ @forced_need = true
474
+ end
475
+
476
+ def invoke_prerequisites(args, chain) #:nodoc:
477
+ @prerequisites |= FileList[@dependencies.uniq]
478
+ super
479
+ end
480
+
481
+ def needed? #:nodoc:
482
+ latest_prerequisite = @prerequisites.map { |p| application[p, @scope] }.max { |a,b| a.timestamp<=>b.timestamp }
483
+ needed = (timestamp == Rake::EARLY) || latest_prerequisite.timestamp > timestamp
484
+ trace "Testing#{needed ? ' ' : ' not '}needed. " +
485
+ "Latest prerequisite change: #{latest_prerequisite.timestamp} (#{latest_prerequisite.to_s}). " +
486
+ "Last successful test run: #{timestamp}."
487
+ return needed || @forced_need || Buildr.options.test == :all
488
+ end
489
+ end
490
+
491
+
492
+ # The integration tests task. Buildr has one such task (see Buildr#integration) that runs
493
+ # all tests marked with :integration=>true, and has a setup/teardown tasks separate from
494
+ # the unit tests.
495
+ class IntegrationTestsTask < Rake::Task
496
+
497
+ def initialize(*args) #:nodoc:
498
+ super
499
+ @setup = task("#{name}:setup")
500
+ @teardown = task("#{name}:teardown")
501
+ enhance do
502
+ info 'Running integration tests...'
503
+ TestTask.run_local_tests true
504
+ end
505
+ end
506
+
507
+ def execute(args) #:nodoc:
508
+ setup.invoke
509
+ begin
510
+ super
511
+ ensure
512
+ teardown.invoke
513
+ end
514
+ end
515
+
516
+ # :call-seq:
517
+ # setup(*prereqs) => task
518
+ # setup(*prereqs) { |task| .. } => task
519
+ #
520
+ # Returns the setup task. The setup task is executed before running the integration tests.
521
+ def setup(*prereqs, &block)
522
+ @setup.enhance prereqs, &block
523
+ end
524
+
525
+ # :call-seq:
526
+ # teardown(*prereqs) => task
527
+ # teardown(*prereqs) { |task| .. } => task
528
+ #
529
+ # Returns the teardown task. The teardown task is executed after running the integration tests.
530
+ def teardown(*prereqs, &block)
531
+ @teardown.enhance prereqs, &block
532
+ end
533
+
534
+ end
535
+
536
+
537
+ # Methods added to Project to support compilation and running of tests.
538
+ module Test
539
+
540
+ include Extension
541
+
542
+ first_time do
543
+ desc 'Run all tests'
544
+ task('test') { TestTask.run_local_tests false }
545
+
546
+ # This rule takes a suffix and runs that tests in the current project. For example;
547
+ # buildr test:MyTest
548
+ # will run the test com.example.MyTest, if such a test exists for this project.
549
+ #
550
+ # If you want to run multiple test, separate them with a comma. You can also use glob
551
+ # (* and ?) patterns to match multiple tests, see the TestTask#include method.
552
+ rule /^test:.*$/ do |task|
553
+ # The map works around a JRuby bug whereby the string looks fine, but fails in fnmatch.
554
+ TestTask.only_run task.name.scan(/test:(.*)/)[0][0].split(',').map { |t| "#{t}" }
555
+ task('test').invoke
556
+ end
557
+
558
+ IntegrationTestsTask.define_task('integration')
559
+
560
+ # Similar to test:[pattern] but for integration tests.
561
+ rule /^integration:.*$/ do |task|
562
+ unless task.name.split(':')[1] =~ /^(setup|teardown)$/
563
+ # The map works around a JRuby bug whereby the string looks fine, but fails in fnmatch.
564
+ TestTask.only_run task.name[/integration:(.*)/, 1].split(',').map { |t| "#{t}" }
565
+ task('integration').invoke
566
+ end
567
+ end
568
+
569
+ end
570
+
571
+ before_define do |project|
572
+ # Define a recursive test task, and pass it a reference to the project so it can discover all other tasks.
573
+ test = TestTask.define_task('test')
574
+ test.send :associate_with, project
575
+
576
+ # Similar to the regular resources task but using different paths.
577
+ resources = ResourcesTask.define_task('test:resources')
578
+ resources.send :associate_with, project, :test
579
+ project.path_to(:source, :test, :resources).tap { |dir| resources.from dir if File.exist?(dir) }
580
+
581
+ # Similar to the regular compile task but using different paths.
582
+ compile = CompileTask.define_task('test:compile'=>[project.compile, resources])
583
+ compile.send :associate_with, project, :test
584
+ test.enhance [compile]
585
+
586
+ # Define these tasks once, otherwise we may get a namespace error.
587
+ test.setup ; test.teardown
588
+ end
589
+
590
+ after_define do |project|
591
+ test = project.test
592
+ # Dependency on compiled tests and resources. Dependencies added using with.
593
+ test.dependencies.concat [test.compile.target, test.resources.target].compact
594
+ # Dependency on compiled code, its dependencies and resources.
595
+ test.with [project.compile.target, project.resources.target].compact
596
+ test.with project.compile.dependencies
597
+ # Picking up the test frameworks adds further dependencies.
598
+ test.framework
599
+
600
+ project.build test unless test.options[:integration]
601
+
602
+ project.clean do
603
+ rm_rf test.compile.target.to_s if test.compile.target
604
+ rm_rf test.report_to.to_s
605
+ end
606
+ end
607
+
608
+
609
+ # :call-seq:
610
+ # test(*prereqs) => TestTask
611
+ # test(*prereqs) { |task| .. } => TestTask
612
+ #
613
+ # Returns the test task. The test task controls the entire test lifecycle.
614
+ #
615
+ # You can use the test task in three ways. You can access and configure specific
616
+ # test tasks, e.g. enhance the compile task by calling test.compile, setup for
617
+ # the tests by enhancing test.setup and so forth.
618
+ #
619
+ # You can use convenient methods that handle the most common settings. For example,
620
+ # add dependencies using test.with, or include only specific tests using test.include.
621
+ #
622
+ # You can also enhance this task directly. This method accepts a list of arguments
623
+ # that are used as prerequisites and an optional block that will be executed by the
624
+ # test task.
625
+ #
626
+ # This task compiles the project and the tests (in that order) before running any tests.
627
+ # It execute the setup task, runs all the tests, any enhancements, and ends with the
628
+ # teardown tasks.
629
+ def test(*prereqs, &block)
630
+ task('test').enhance prereqs, &block
631
+ end
632
+
633
+ # :call-seq:
634
+ # integration { |task| .... }
635
+ # integration => IntegrationTestTask
636
+ #
637
+ # Use this method to return the integration tests task, or enhance it with a block to execute.
638
+ #
639
+ # There is one integration tests task you can execute directly, or as a result of running the package
640
+ # task (or tasks that depend on it, like install and upload). It contains all the tests marked with
641
+ # :integration=>true, all other tests are considered unit tests and run by the test task before packaging.
642
+ # So essentially: build=>test=>packaging=>integration=>install/upload.
643
+ #
644
+ # You add new tests from projects that define integration tests using the regular test task,
645
+ # but with the following addition:
646
+ # test.using :integration
647
+ #
648
+ # Use this method to enhance the setup and teardown tasks that are executed before (and after) all
649
+ # integration tests are run, for example, to start a Web server or create a database.
650
+ def integration(*deps, &block)
651
+ Rake::Task['rake:integration'].enhance deps, &block
652
+ end
653
+
654
+ end
655
+
656
+
657
+ # :call-seq:
658
+ # integration { |task| .... }
659
+ # integration => IntegrationTestTask
660
+ #
661
+ # Use this method to return the integration tests task.
662
+ def integration(*deps, &block)
663
+ Rake::Task['rake:integration'].enhance deps, &block
664
+ end
665
+
666
+ class Options
667
+
668
+ # Runs tests after the build when true (default). This forces tests to execute
669
+ # after the build, including when running build related tasks like install, upload and release.
670
+ #
671
+ # Set to false to not run any tests. Set to :all to run all tests, ignoring failures.
672
+ #
673
+ # This option is set from the environment variable 'test', so you can also do:
674
+
675
+ # Returns the test option (environment variable TEST). Possible values are:
676
+ # * :false -- Do not run any tests (also accepts 'no' and 'skip').
677
+ # * :true -- Run all tests, stop on failure (default if not set).
678
+ # * :all -- Run all tests, ignore failures.
679
+ def test
680
+ case value = ENV['TEST'] || ENV['test']
681
+ when /^(no|off|false|skip)$/i
682
+ false
683
+ when /^all$/i
684
+ :all
685
+ when /^(yes|on|true)$/i, nil
686
+ true
687
+ else
688
+ warn "Expecting the environment variable test to be 'no' or 'all', not sure what to do with #{value}, so I'm just going to run all the tests and stop at failure."
689
+ true
690
+ end
691
+ end
692
+
693
+ # Sets the test option (environment variable TEST). Possible values are true, false or :all.
694
+ #
695
+ # You can also set this from the environment variable, e.g.:
696
+ #
697
+ # buildr # With tests
698
+ # buildr test=no # Without tests
699
+ # buildr test=all # Ignore failures
700
+ # set TEST=no
701
+ # buildr # Without tests
702
+ def test=(flag)
703
+ ENV['test'] = nil
704
+ ENV['TEST'] = flag.to_s
705
+ end
706
+
707
+ end
708
+
709
+ Buildr.help << <<-HELP
710
+ To run a full build without running any tests:
711
+ buildr test=no
712
+ To run specific test:
713
+ buildr test:MyTest
714
+ To run integration tests:
715
+ buildr integration
716
+ HELP
717
+
718
+ end
719
+
720
+
721
+ class Buildr::Project
722
+ include Buildr::Test
723
+ end