ittayd-buildr 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. data/CHANGELOG +915 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +64 -0
  7. data/_buildr +28 -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/path.rb +136 -0
  27. data/addon/buildr/xmlbeans.rb +93 -0
  28. data/bin/buildr +19 -0
  29. data/buildr.buildfile +53 -0
  30. data/buildr.gemspec +58 -0
  31. data/doc/css/default.css +228 -0
  32. data/doc/css/print.css +100 -0
  33. data/doc/css/syntax.css +52 -0
  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 +207 -0
  44. data/doc/pages/building.textile +240 -0
  45. data/doc/pages/contributing.textile +208 -0
  46. data/doc/pages/download.textile +62 -0
  47. data/doc/pages/extending.textile +175 -0
  48. data/doc/pages/getting_started.textile +273 -0
  49. data/doc/pages/index.textile +42 -0
  50. data/doc/pages/languages.textile +407 -0
  51. data/doc/pages/mailing_lists.textile +17 -0
  52. data/doc/pages/more_stuff.textile +314 -0
  53. data/doc/pages/packaging.textile +427 -0
  54. data/doc/pages/projects.textile +274 -0
  55. data/doc/pages/recipes.textile +103 -0
  56. data/doc/pages/settings_profiles.textile +274 -0
  57. data/doc/pages/testing.textile +212 -0
  58. data/doc/pages/troubleshooting.textile +103 -0
  59. data/doc/pages/whats_new.textile +323 -0
  60. data/doc/print.haml +51 -0
  61. data/doc/print.toc.yaml +29 -0
  62. data/doc/scripts/buildr-git.rb +412 -0
  63. data/doc/scripts/install-jruby.sh +44 -0
  64. data/doc/scripts/install-linux.sh +64 -0
  65. data/doc/scripts/install-osx.sh +52 -0
  66. data/doc/site.haml +56 -0
  67. data/doc/site.toc.yaml +47 -0
  68. data/etc/KEYS +151 -0
  69. data/etc/git-svn-authors +16 -0
  70. data/lib/buildr/core/application.rb +665 -0
  71. data/lib/buildr/core/build.rb +311 -0
  72. data/lib/buildr/core/checks.rb +254 -0
  73. data/lib/buildr/core/common.rb +150 -0
  74. data/lib/buildr/core/compile.rb +590 -0
  75. data/lib/buildr/core/environment.rb +117 -0
  76. data/lib/buildr/core/filter.rb +366 -0
  77. data/lib/buildr/core/generate.rb +195 -0
  78. data/lib/buildr/core/help.rb +119 -0
  79. data/lib/buildr/core/osx.rb +49 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +923 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +560 -0
  84. data/lib/buildr/core/util.rb +294 -0
  85. data/lib/buildr/core.rb +29 -0
  86. data/lib/buildr/groovy/bdd.rb +106 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/groovy.rb +18 -0
  89. data/lib/buildr/ide/eclipse.rb +222 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +190 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +212 -0
  94. data/lib/buildr/ide.rb +19 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +451 -0
  97. data/lib/buildr/java/cobertura.rb +236 -0
  98. data/lib/buildr/java/commands.rb +211 -0
  99. data/lib/buildr/java/compiler.rb +348 -0
  100. data/lib/buildr/java/deprecated.rb +141 -0
  101. data/lib/buildr/java/emma.rb +238 -0
  102. data/lib/buildr/java/jruby.rb +117 -0
  103. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  104. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  105. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  106. data/lib/buildr/java/packaging.rb +717 -0
  107. data/lib/buildr/java/pom.rb +174 -0
  108. data/lib/buildr/java/rjb.rb +155 -0
  109. data/lib/buildr/java/test_result.rb +307 -0
  110. data/lib/buildr/java/tests.rb +329 -0
  111. data/lib/buildr/java/version_requirement.rb +172 -0
  112. data/lib/buildr/java.rb +23 -0
  113. data/lib/buildr/packaging/archive.rb +488 -0
  114. data/lib/buildr/packaging/artifact.rb +759 -0
  115. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  116. data/lib/buildr/packaging/artifact_search.rb +140 -0
  117. data/lib/buildr/packaging/gems.rb +102 -0
  118. data/lib/buildr/packaging/package.rb +233 -0
  119. data/lib/buildr/packaging/tar.rb +186 -0
  120. data/lib/buildr/packaging/version_requirement.rb +172 -0
  121. data/lib/buildr/packaging/zip.rb +64 -0
  122. data/lib/buildr/packaging/ziptask.rb +313 -0
  123. data/lib/buildr/packaging.rb +24 -0
  124. data/lib/buildr/resources/buildr.icns +0 -0
  125. data/lib/buildr/scala/compiler.rb +109 -0
  126. data/lib/buildr/scala/tests.rb +203 -0
  127. data/lib/buildr/scala.rb +19 -0
  128. data/lib/buildr.rb +33 -0
  129. data/rakelib/apache.rake +191 -0
  130. data/rakelib/changelog.rake +57 -0
  131. data/rakelib/doc.rake +103 -0
  132. data/rakelib/package.rake +76 -0
  133. data/rakelib/release.rake +65 -0
  134. data/rakelib/rspec.rake +83 -0
  135. data/rakelib/rubyforge.rake +56 -0
  136. data/rakelib/scm.rake +49 -0
  137. data/rakelib/setup.rake +81 -0
  138. data/rakelib/stage.rake +48 -0
  139. data/spec/addon/drb_spec.rb +328 -0
  140. data/spec/core/application_spec.rb +419 -0
  141. data/spec/core/build_spec.rb +423 -0
  142. data/spec/core/checks_spec.rb +519 -0
  143. data/spec/core/common_spec.rb +670 -0
  144. data/spec/core/compile_spec.rb +582 -0
  145. data/spec/core/generate_spec.rb +33 -0
  146. data/spec/core/project_spec.rb +776 -0
  147. data/spec/core/test_spec.rb +1098 -0
  148. data/spec/core/transport_spec.rb +500 -0
  149. data/spec/groovy/bdd_spec.rb +80 -0
  150. data/spec/groovy/compiler_spec.rb +239 -0
  151. data/spec/ide/eclipse_spec.rb +311 -0
  152. data/spec/java/ant.rb +33 -0
  153. data/spec/java/bdd_spec.rb +358 -0
  154. data/spec/java/cobertura_spec.rb +77 -0
  155. data/spec/java/compiler_spec.rb +446 -0
  156. data/spec/java/emma_spec.rb +120 -0
  157. data/spec/java/java_spec.rb +96 -0
  158. data/spec/java/packaging_spec.rb +1120 -0
  159. data/spec/java/test_coverage_spec.rb +255 -0
  160. data/spec/java/tests_spec.rb +471 -0
  161. data/spec/packaging/archive_spec.rb +503 -0
  162. data/spec/packaging/artifact_namespace_spec.rb +646 -0
  163. data/spec/packaging/artifact_spec.rb +795 -0
  164. data/spec/packaging/packaging_helper.rb +63 -0
  165. data/spec/packaging/packaging_spec.rb +589 -0
  166. data/spec/sandbox.rb +139 -0
  167. data/spec/scala/compiler_spec.rb +228 -0
  168. data/spec/scala/tests_spec.rb +215 -0
  169. data/spec/spec_helpers.rb +327 -0
  170. data/spec/version_requirement_spec.rb +123 -0
  171. metadata +377 -0
@@ -0,0 +1,238 @@
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/java'
18
+
19
+
20
+ module Buildr
21
+
22
+ # Provides the <code>emma:html</code> and <code>emma:xml</code> tasks.
23
+ # Require explicitly using <code>require "buildr/emma"</code>.
24
+ #
25
+ # You can generate emma reports for a single project
26
+ # using the project name as prefix:
27
+ #
28
+ # project_name:emma:html
29
+ #
30
+ # You can also specify which classes to include/exclude from instrumentation by
31
+ # passing a class name regexp to the <code>emma.include</code> or
32
+ # <code>emma.exclude</code> methods.
33
+ #
34
+ # define 'someModule' do
35
+ # emma.include 'some.package.*'
36
+ # emma.exclude 'some.foo.util.SimpleUtil'
37
+ # end
38
+ module Emma
39
+
40
+ class << self
41
+
42
+ REQUIRES = ['emma:emma_ant:jar:2.0.5312', 'emma:emma:jar:2.0.5312'] unless const_defined?('REQUIRES')
43
+
44
+ def requires()
45
+ @requires ||= Buildr.artifacts(REQUIRES).each(&:invoke).map(&:to_s)
46
+ end
47
+
48
+ def report_to format=nil
49
+ File.expand_path('reports/emma')
50
+ end
51
+
52
+ def data_file()
53
+ File.join(report_to, 'coverage.es')
54
+ end
55
+
56
+ def ant
57
+ Buildr.ant 'emma' do |ant|
58
+ ant.taskdef :classpath=>requires.join(File::PATH_SEPARATOR), :resource=>'emma_ant.properties'
59
+ ant.emma :verbosity=>(Buildr.application.options.trace ? 'verbose' : 'warning') do
60
+ yield ant
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ class EmmaConfig # :nodoc:
67
+
68
+ def initialize(project)
69
+ @project = project
70
+ end
71
+
72
+ attr_reader :project
73
+ private :project
74
+
75
+ attr_writer :metadata_file, :coverage_file, :instrumented_dir, :report_dir
76
+
77
+ def coverage_file
78
+ @coverage_file ||= File.join(report_dir, 'coverage.ec')
79
+ end
80
+
81
+ def metadata_file
82
+ @metadata_file ||= File.join(report_dir, 'coverage.em')
83
+ end
84
+
85
+ def instrumented_dir
86
+ @instrumented_dir ||= project.path_to(:target, :instrumented, :classes)
87
+ end
88
+
89
+ def report_dir
90
+ @report_dir ||= project.path_to(:reports, :emma)
91
+ end
92
+
93
+ def report_to format
94
+ report_dir
95
+ end
96
+
97
+ # :call-seq:
98
+ # project.emma.include(*classPatterns)
99
+ #
100
+ def include(*classPatterns)
101
+ includes.push(*classPatterns)
102
+ self
103
+ end
104
+
105
+ def includes
106
+ @includeClasses ||= []
107
+ end
108
+
109
+ # :call-seq:
110
+ # project.emma.exclude(*classPatterns)
111
+ #
112
+ def exclude(*classPatterns)
113
+ excludes.push(*classPatterns)
114
+ self
115
+ end
116
+
117
+ def excludes
118
+ @excludeClasses ||= []
119
+ end
120
+
121
+ def sources
122
+ project.compile.sources
123
+ end
124
+ end
125
+
126
+ module EmmaExtension # :nodoc:
127
+ include Buildr::Extension
128
+
129
+ def emma
130
+ @emma_config ||= EmmaConfig.new(self)
131
+ end
132
+
133
+ after_define do |project|
134
+ emma = project.emma
135
+
136
+ namespace 'emma' do
137
+ unless project.compile.target.nil?
138
+ # Instrumented bytecode goes in a different directory. This task creates before running the test
139
+ # cases and monitors for changes in the generate bytecode.
140
+ instrumented = project.file(emma.instrumented_dir => project.compile.target) do |task|
141
+ unless project.compile.sources.empty?
142
+ info "Instrumenting classes with emma metadata file #{emma.metadata_file}"
143
+ Emma.ant do |ant|
144
+ ant.instr :instrpath=>project.compile.target.to_s, :destdir=>task.to_s, :metadatafile=>emma.metadata_file do
145
+ ant.filter :includes=>emma.includes.join(', ') unless emma.includes.empty?
146
+ ant.filter :excludes=>emma.excludes.join(', ') unless emma.excludes.empty?
147
+ end
148
+ end
149
+ touch task.to_s, :verbose=>false
150
+ end
151
+ end
152
+
153
+ task 'instrument' => instrumented
154
+
155
+ # We now have two target directories with bytecode.
156
+ project.test.dependencies.unshift emma.instrumented_dir
157
+ project.test.with Emma.requires
158
+ project.test.options[:properties]["emma.coverage.out.file"] = emma.coverage_file
159
+
160
+ [:xml, :html].each do |format|
161
+ task format => ['instrument', 'test'] do
162
+ missing_required_files = [emma.metadata_file, emma.coverage_file].reject { |f| File.exist?(f) }
163
+ if missing_required_files.empty?
164
+ info "Creating test coverage reports in #{emma.report_dir}"
165
+ mkdir_p emma.report_dir, :verbose=>false
166
+ Emma.ant do |ant|
167
+ ant.report do
168
+ ant.infileset :file=>emma.metadata_file
169
+ ant.infileset :file=>emma.coverage_file
170
+ ant.send format, :outfile=>File.join(emma.report_to(format),"coverage.#{format}")
171
+ ant.sourcepath do
172
+ emma.sources.flatten.each do |src|
173
+ ant.dirset(:dir=>src.to_s) if File.exist?(src.to_s)
174
+ end
175
+ end
176
+ end
177
+ end
178
+ else
179
+ info "No test coverage report for #{project}. Missing: #{missing_required_files.join(', ')}"
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
185
+
186
+ project.clean do
187
+ rm_rf [emma.report_dir, emma.coverage_file, emma.metadata_file, emma.instrumented_dir], :verbose=>false
188
+ end
189
+
190
+ end
191
+
192
+ end
193
+
194
+ class Buildr::Project
195
+ include EmmaExtension
196
+ end
197
+
198
+ namespace "emma" do
199
+
200
+ Project.local_task('instrument') { |name| "Instrumenting #{name}" }
201
+
202
+ [:xml, :html].each do |format|
203
+ desc "Run the test cases and produce code coverage reports in #{format}"
204
+ task format => ['instrument', 'test'] do
205
+ info "Creating test coverage reports in #{format}"
206
+ mkdir_p report_to(format), :verbose=>false
207
+ Emma.ant do |ant|
208
+ ant.merge :outfile=>data_file do
209
+ Buildr.projects.each do |project|
210
+ [project.emma.metadata_file, project.emma.coverage_file].each do |data_file|
211
+ ant.fileset :file=>data_file if File.exist?(data_file)
212
+ end
213
+ end
214
+ end
215
+ ant.report do
216
+ ant.infileset :file=>data_file
217
+ ant.send format, :outfile=>File.join(report_to(format), "coverage.#{format}")
218
+ ant.sourcepath do
219
+ Buildr.projects.map(&:emma).map(&:sources).flatten.map(&:to_s).each do |src|
220
+ ant.dirset :dir=>src if File.exist?(src)
221
+ end
222
+ end
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ task :clean do
229
+ rm_rf [report_to, data_file], :verbose=>false
230
+ end
231
+ end
232
+
233
+ task :clean do
234
+ task('emma:clean').invoke if Dir.pwd == Rake.application.original_dir
235
+ end
236
+
237
+ end
238
+ end
@@ -0,0 +1,117 @@
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 'java'
18
+ require 'jruby'
19
+
20
+
21
+ # Buildr runs along side a JVM, using either RJB or JRuby. The Java module allows
22
+ # you to access Java classes and create Java objects.
23
+ #
24
+ # Java classes are accessed as static methods on the Java module, for example:
25
+ # str = Java.java.lang.String.new('hai!')
26
+ # str.toUpperCase
27
+ # => 'HAI!'
28
+ # Java.java.lang.String.isInstance(str)
29
+ # => true
30
+ # Java.com.sun.tools.javac.Main.compile(args)
31
+ #
32
+ # The classpath attribute allows Buildr to add JARs and directories to the classpath,
33
+ # for example, we use it to load Ant and various Ant tasks, code generators, test
34
+ # frameworks, and so forth.
35
+ #
36
+ # When using an artifact specification, Buildr will automatically download and
37
+ # install the artifact before adding it to the classpath.
38
+ #
39
+ # For example, Ant is loaded as follows:
40
+ # Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
41
+ #
42
+ # Artifacts can only be downloaded after the Buildfile has loaded, giving it
43
+ # a chance to specify which remote repositories to use, so adding to classpath
44
+ # does not by itself load any libraries. You must call Java.load before accessing
45
+ # any Java classes to give Buildr a chance to load the libraries specified in the
46
+ # classpath.
47
+ #
48
+ # When building an extension, make sure to follow these rules:
49
+ # 1. Add to the classpath when the extension is loaded (i.e. in module or class
50
+ # definition), so the first call to Java.load anywhere in the code will include
51
+ # the libraries you specify.
52
+ # 2. Call Java.load once before accessing any Java classes, allowing Buildr to
53
+ # set up the classpath.
54
+ # 3. Only call Java.load when invoked, otherwise you may end up loading the JVM
55
+ # with a partial classpath, or before all remote repositories are listed.
56
+ # 4. Check on a clean build with empty local repository.
57
+ module Java
58
+
59
+ # Since we already have a JVM loaded, we can use it to guess where JAVA_HOME is.
60
+ # We set JAVA_HOME early so we can use it without calling Java.load first.
61
+ ENV['JAVA_HOME'] ||= java.lang.System.getProperty("java.home")
62
+
63
+ class << self
64
+
65
+ # Returns the classpath, an array listing directories, JAR files and
66
+ # artifacts. Use when loading the extension to add any additional
67
+ # libraries used by that extension.
68
+ #
69
+ # For example, Ant is loaded as follows:
70
+ # Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
71
+ def classpath
72
+ @classpath ||= []
73
+ end
74
+
75
+ # Most platforms requires tools.jar to be on the classpath, tools.jar contains the
76
+ # Java compiler (OS X and AIX are two exceptions we know about, may be more).
77
+ # Guess where tools.jar is from JAVA_HOME, which hopefully points to the JDK,
78
+ # but maybe the JRE. Return nil if not found.
79
+ def tools_jar #:nodoc:
80
+ @tools_jar ||= ['lib/tools.jar', '../lib/tools.jar'].map { |path| File.expand_path(path, ENV['JAVA_HOME']) }.
81
+ find { |path| File.exist?(path) }
82
+ end
83
+
84
+ # Loads the JVM and all the libraries listed on the classpath. Call this
85
+ # method before accessing any Java class, but only call it from methods
86
+ # used in the build, giving the Buildfile a chance to load all extensions
87
+ # that append to the classpath and specify which remote repositories to use.
88
+ def load
89
+ return self if @loaded
90
+
91
+ # Adding jars to the jruby's $CLASSPATH should be the correct thing, however it
92
+ # seems like some tools require their jars on system class loader (javadoc, junit, etc)
93
+ # cp.each { |path| $CLASSPATH << path }
94
+
95
+ # Use system ClassLoader to add classpath
96
+ sysloader = java.lang.ClassLoader.getSystemClassLoader
97
+ add_url_method = java.lang.Class.forName('java.net.URLClassLoader').
98
+ getDeclaredMethod('addURL', [java.net.URL.java_class].to_java(java.lang.Class))
99
+ add_url_method.setAccessible(true)
100
+ add_path = lambda { |path| add_url_method.invoke(sysloader, [java.io.File.new(path).toURI.toURL].to_java(java.net.URL)) }
101
+
102
+ # Most platforms requires tools.jar to be on the classpath.
103
+ add_path[tools_jar] if tools_jar
104
+
105
+ classpath.map! { |path| Proc === path ? path.call : path }
106
+ Buildr.artifacts(classpath).map(&:to_s).each do |path|
107
+ file(path).invoke
108
+ add_path[path]
109
+ end
110
+
111
+ @loaded = true
112
+ self
113
+ end
114
+
115
+ end
116
+
117
+ end
@@ -0,0 +1,116 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ # ___ ___ _ _ ___ _____ ___ ___ ___ _____ _____ _ _ ___ ___
17
+ # | \ / _ \ | \| |/ _ \_ _| | __| \_ _|_ _| |_ _| || |_ _/ __|
18
+ # | |) | (_) | | .` | (_) || | | _|| |) | | | | | | | __ || |\__ \
19
+ # |___/ \___/ |_|\_|\___/ |_| |___|___/___| |_| |_| |_||_|___|___/
20
+ #
21
+ # ___ ___ _ ___
22
+ # | __|_ _| | | __| CHANGES TO THIS FILE WILL BE LOST
23
+ # | _| | || |__| _| AUTO-GENERATED BY BUILDR on <%= Time.now %>
24
+ # |_| |___|____|___| PREFER TO EDIT JtestR CONFIGURATION FILE:
25
+ #
26
+ # <%= user_config %>
27
+
28
+ begin
29
+
30
+ <%= jruby_gem %>
31
+ <%= dependencies.map(&:to_s).inspect %>.each { |dep| $CLASSPATH << dep }
32
+ <%= runner.gems.inspect %>.each { |ary| JRuby.gem(*ary.flatten) }
33
+ <%= runner.requires.inspect %>.each { |rb| Kernel.require rb }
34
+
35
+ jtestr = JtestR::TestRunner.new
36
+
37
+ class << jtestr
38
+ def config(&block)
39
+ @config_blocks ||= []
40
+ @config_blocks << block if block
41
+ @config_blocks
42
+ end
43
+
44
+ def load_configuration
45
+ super
46
+ config.each { |block| @configuration.instance_eval(&block) }
47
+ end
48
+ end
49
+
50
+ jtestr.config do
51
+ classpath [] # already loaded
52
+ add_common_classpath false
53
+
54
+ <% ts = ( @jtestr_tests[:junit] & tests ).map { |c| 'Java.' + c } %>
55
+ junit [<%= ts.join(', ') %>]
56
+
57
+ <% ts = ( @jtestr_tests[:testng] & tests ).map { |c| 'Java.' + c } %>
58
+ testng [<%= ts.join(', ') %>]
59
+
60
+ <% ts = @jtestr_tests[:testunit] & tests %>
61
+ test_unit <%= ts.inspect %>
62
+
63
+ <% ts = @jtestr_tests[:story] & tests %>
64
+ story <%= ts.inspect %>
65
+
66
+ <% ts = @jtestr_tests[:rspec] & tests %>
67
+ rspec <%= ts.inspect %>
68
+
69
+ <% ts = @jtestr_tests[:expect] & tests %>
70
+ expectations <%= ts.inspect %>
71
+
72
+ ignore __FILE__
73
+
74
+ if File.file?(<%= user_config.inspect %>)
75
+ ignore <%= user_config.inspect %>
76
+ load <%= user_config.inspect %>
77
+ end
78
+ end # config
79
+
80
+ fake_out = StringIO.new
81
+
82
+ <% if runner.output == false %>
83
+ output = fake_out
84
+ <% elsif runner.output.kind_of?(String) %>
85
+ output = File.open(<%= result.output.inspect %>, 'w')
86
+ <% else %>
87
+ output = STDOUT
88
+ <% end %>
89
+
90
+
91
+ args = [ '<%= spec_dir %>', # the directory to search for jtestr files
92
+ JtestR::SimpleLogger::ERR, # log level
93
+ JtestR::GenericResultHandler::QUIET, #output level
94
+ fake_out, # output STDOUT
95
+ [], # groups to run
96
+ Buildr::TestFramework::TestResult::RSpecResultHandler, # result handler
97
+ [] # classpath
98
+ ]
99
+
100
+ argv = <%= runner.rspec.inspect %> || []
101
+ argv.push *<%= tests.inspect %>
102
+ Buildr::TestFramework::TestResult::RSpecResultHandler.init(argv, output, output)
103
+
104
+ jtestr.run *args
105
+
106
+ rescue => e
107
+ Buildr::TestFramework::TestResult::Error.dump_yaml('<%= runner.result %>', e) rescue \
108
+ puts "-[--- ERROR ---]-", e.class, e.message, *e.backtrace
109
+ end
110
+
111
+ exit 0 # let buildr find the erros from the result yaml
112
+
113
+ # Local Variables:
114
+ # mode: ruby
115
+ # End:
116
+
@@ -0,0 +1,119 @@
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
14
+ * under the License.
15
+ */
16
+
17
+
18
+ package org.apache.buildr;
19
+
20
+ import java.lang.reflect.Method;
21
+ import java.lang.reflect.Modifier;
22
+ import java.io.File;
23
+ import java.io.IOException;
24
+ import java.net.URL;
25
+ import java.net.URLClassLoader;
26
+ import java.net.MalformedURLException;
27
+ import java.util.Iterator;
28
+ import java.util.Vector;
29
+
30
+ public class JavaTestFilter {
31
+
32
+ private ClassLoader _loader;
33
+ private Vector methodAnnotations = new Vector();
34
+ private Vector classAnnotations = new Vector();
35
+ private Vector interfaces = new Vector();
36
+
37
+ public JavaTestFilter(String[] paths) throws IOException {
38
+ URL[] urls = new URL[paths.length];
39
+ for (int i = 0 ; i < paths.length ; ++i) {
40
+ File file = new File(paths[i]).getCanonicalFile();
41
+ if (file.exists())
42
+ urls[i] = file.toURL();
43
+ else
44
+ throw new IOException("No file or directory with the name " + file);
45
+ }
46
+ _loader = new URLClassLoader(urls, getClass().getClassLoader());
47
+ }
48
+
49
+ public JavaTestFilter addInterfaces(String[] names) throws ClassNotFoundException {
50
+ for (int i = names.length; i -- > 0;) {
51
+ String name = names[i];
52
+ interfaces.add(_loader.loadClass(name));
53
+ }
54
+ return this;
55
+ }
56
+
57
+ public JavaTestFilter addClassAnnotations(String[] names) throws ClassNotFoundException {
58
+ for (int i = names.length; i -- > 0;) {
59
+ String name = names[i];
60
+ classAnnotations.add(_loader.loadClass(name));
61
+ }
62
+ return this;
63
+ }
64
+
65
+ public JavaTestFilter addMethodAnnotations(String[] names) throws ClassNotFoundException {
66
+ for (int i = names.length; i -- > 0;) {
67
+ String name = names[i];
68
+ methodAnnotations.add(_loader.loadClass(name));
69
+ }
70
+ return this;
71
+ }
72
+
73
+ private boolean isTest(Class cls) {
74
+ if (Modifier.isAbstract(cls.getModifiers()) || !Modifier.isPublic(cls.getModifiers()))
75
+ return false;
76
+ if (interfaces != null) {
77
+ for (Iterator it = interfaces.iterator(); it.hasNext(); ) {
78
+ Class iface = (Class) it.next();
79
+ if (iface.isAssignableFrom(cls)) { return true; }
80
+ }
81
+ }
82
+ if (classAnnotations != null) {
83
+ for (Iterator it = classAnnotations.iterator(); it.hasNext(); ) {
84
+ Class annotation = (Class) it.next();
85
+ if (cls.isAnnotationPresent(annotation)) { return true; }
86
+ }
87
+ }
88
+ if (methodAnnotations != null) {
89
+ Method[] methods = cls.getMethods();
90
+ for (int j = methods.length ; j-- > 0 ;) {
91
+ for (Iterator it = methodAnnotations.iterator(); it.hasNext(); ) {
92
+ Class annotation = (Class) it.next();
93
+ if (methods[j].isAnnotationPresent(annotation)) { return true; }
94
+ }
95
+ }
96
+ }
97
+ return false;
98
+ }
99
+
100
+
101
+ public String[] filter(String[] names) throws ClassNotFoundException {
102
+ Vector testCases = new Vector();
103
+ for (int i = names.length ; i-- > 0 ;) {
104
+ Class cls = _loader.loadClass(names[i]);
105
+ if (isTest(cls)) { testCases.add(names[i]); }
106
+ }
107
+ String[] result = new String[testCases.size()];
108
+ testCases.toArray(result);
109
+ return result;
110
+ }
111
+
112
+ }
113
+
114
+ /*
115
+ * Local Variables:
116
+ * indent-tabs-mode: nil
117
+ * c-basic-offset: 2
118
+ * End:
119
+ */