buildr-gemjar 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. data/.braids +8 -0
  2. data/.gitignore +5 -0
  3. data/.rvmrc +1 -0
  4. data/CHANGELOG.md +4 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +20 -0
  7. data/README.md +98 -0
  8. data/Rakefile +8 -0
  9. data/buildr-gemjar.gemspec +42 -0
  10. data/lib/buildr-gemjar.rb +162 -0
  11. data/lib/buildr-gemjar/version.rb +3 -0
  12. data/meta.rakefile +30 -0
  13. data/spec/buildr-gemjar/version_spec.rb +11 -0
  14. data/spec/buildr-gemjar_spec.rb +179 -0
  15. data/spec/repo_builder.rb +59 -0
  16. data/spec/spec_helper.rb +44 -0
  17. data/vendor/buildr/.gitignore +17 -0
  18. data/vendor/buildr/CHANGELOG +1283 -0
  19. data/vendor/buildr/Gemfile +4 -0
  20. data/vendor/buildr/LICENSE +176 -0
  21. data/vendor/buildr/NOTICE +26 -0
  22. data/vendor/buildr/README.rdoc +134 -0
  23. data/vendor/buildr/Rakefile +44 -0
  24. data/vendor/buildr/_buildr +35 -0
  25. data/vendor/buildr/_jbuildr +35 -0
  26. data/vendor/buildr/addon/buildr/antlr.rb +65 -0
  27. data/vendor/buildr/addon/buildr/bnd.rb +147 -0
  28. data/vendor/buildr/addon/buildr/cobertura.rb +22 -0
  29. data/vendor/buildr/addon/buildr/drb.rb +281 -0
  30. data/vendor/buildr/addon/buildr/emma.rb +22 -0
  31. data/vendor/buildr/addon/buildr/hibernate.rb +149 -0
  32. data/vendor/buildr/addon/buildr/javacc.rb +85 -0
  33. data/vendor/buildr/addon/buildr/jaxb_xjc.rb +72 -0
  34. data/vendor/buildr/addon/buildr/jdepend.rb +60 -0
  35. data/vendor/buildr/addon/buildr/jetty.rb +248 -0
  36. data/vendor/buildr/addon/buildr/jibx.rb +86 -0
  37. data/vendor/buildr/addon/buildr/nailgun.rb +221 -0
  38. data/vendor/buildr/addon/buildr/openjpa.rb +88 -0
  39. data/vendor/buildr/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  40. data/vendor/buildr/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  41. data/vendor/buildr/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  42. data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  43. data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  44. data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  45. data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  46. data/vendor/buildr/addon/buildr/protobuf.rb +88 -0
  47. data/vendor/buildr/addon/buildr/xmlbeans.rb +93 -0
  48. data/vendor/buildr/all-in-one/_buildr +19 -0
  49. data/vendor/buildr/all-in-one/buildr +368 -0
  50. data/vendor/buildr/all-in-one/buildr.cmd +1 -0
  51. data/vendor/buildr/bin/buildr +19 -0
  52. data/vendor/buildr/buildr.buildfile +58 -0
  53. data/vendor/buildr/buildr.gemspec +74 -0
  54. data/vendor/buildr/doc/_config.yml +1 -0
  55. data/vendor/buildr/doc/_layouts/default.html +90 -0
  56. data/vendor/buildr/doc/_layouts/preface.html +22 -0
  57. data/vendor/buildr/doc/artifacts.textile +217 -0
  58. data/vendor/buildr/doc/building.textile +276 -0
  59. data/vendor/buildr/doc/contributing.textile +268 -0
  60. data/vendor/buildr/doc/css/default.css +236 -0
  61. data/vendor/buildr/doc/css/print.css +101 -0
  62. data/vendor/buildr/doc/css/syntax.css +23 -0
  63. data/vendor/buildr/doc/download.textile +138 -0
  64. data/vendor/buildr/doc/extending.textile +212 -0
  65. data/vendor/buildr/doc/images/1442160941-frontcover.jpg +0 -0
  66. data/vendor/buildr/doc/images/asf-logo.gif +0 -0
  67. data/vendor/buildr/doc/images/asf-logo.png +0 -0
  68. data/vendor/buildr/doc/images/buildr-hires.png +0 -0
  69. data/vendor/buildr/doc/images/buildr.png +0 -0
  70. data/vendor/buildr/doc/images/favicon.png +0 -0
  71. data/vendor/buildr/doc/images/growl-icon.tiff +0 -0
  72. data/vendor/buildr/doc/images/note.png +0 -0
  73. data/vendor/buildr/doc/images/project-structure.png +0 -0
  74. data/vendor/buildr/doc/images/tip.png +0 -0
  75. data/vendor/buildr/doc/images/zbuildr.png +0 -0
  76. data/vendor/buildr/doc/images/zbuildr.tif +0 -0
  77. data/vendor/buildr/doc/index.textile +69 -0
  78. data/vendor/buildr/doc/installing.textile +284 -0
  79. data/vendor/buildr/doc/languages.textile +599 -0
  80. data/vendor/buildr/doc/mailing_lists.textile +29 -0
  81. data/vendor/buildr/doc/more_stuff.textile +845 -0
  82. data/vendor/buildr/doc/packaging.textile +618 -0
  83. data/vendor/buildr/doc/preface.textile +54 -0
  84. data/vendor/buildr/doc/projects.textile +276 -0
  85. data/vendor/buildr/doc/quick_start.textile +210 -0
  86. data/vendor/buildr/doc/releasing.textile +117 -0
  87. data/vendor/buildr/doc/scripts/buildr-git.rb +512 -0
  88. data/vendor/buildr/doc/scripts/gitflow.rb +296 -0
  89. data/vendor/buildr/doc/scripts/install-jruby.sh +44 -0
  90. data/vendor/buildr/doc/scripts/install-linux.sh +73 -0
  91. data/vendor/buildr/doc/scripts/install-osx.sh +52 -0
  92. data/vendor/buildr/doc/settings_profiles.textile +287 -0
  93. data/vendor/buildr/doc/testing.textile +247 -0
  94. data/vendor/buildr/etc/KEYS +189 -0
  95. data/vendor/buildr/lib/buildr.rb +44 -0
  96. data/vendor/buildr/lib/buildr/clojure.rb +34 -0
  97. data/vendor/buildr/lib/buildr/clojure/shell.rb +52 -0
  98. data/vendor/buildr/lib/buildr/core.rb +34 -0
  99. data/vendor/buildr/lib/buildr/core/application.rb +700 -0
  100. data/vendor/buildr/lib/buildr/core/build.rb +516 -0
  101. data/vendor/buildr/lib/buildr/core/cc.rb +166 -0
  102. data/vendor/buildr/lib/buildr/core/checks.rb +253 -0
  103. data/vendor/buildr/lib/buildr/core/common.rb +151 -0
  104. data/vendor/buildr/lib/buildr/core/compile.rb +622 -0
  105. data/vendor/buildr/lib/buildr/core/doc.rb +276 -0
  106. data/vendor/buildr/lib/buildr/core/environment.rb +129 -0
  107. data/vendor/buildr/lib/buildr/core/filter.rb +404 -0
  108. data/vendor/buildr/lib/buildr/core/generate.rb +197 -0
  109. data/vendor/buildr/lib/buildr/core/help.rb +119 -0
  110. data/vendor/buildr/lib/buildr/core/jrebel.rb +42 -0
  111. data/vendor/buildr/lib/buildr/core/linux.rb +30 -0
  112. data/vendor/buildr/lib/buildr/core/osx.rb +46 -0
  113. data/vendor/buildr/lib/buildr/core/progressbar.rb +161 -0
  114. data/vendor/buildr/lib/buildr/core/project.rb +975 -0
  115. data/vendor/buildr/lib/buildr/core/run.rb +43 -0
  116. data/vendor/buildr/lib/buildr/core/shell.rb +137 -0
  117. data/vendor/buildr/lib/buildr/core/test.rb +843 -0
  118. data/vendor/buildr/lib/buildr/core/transports.rb +565 -0
  119. data/vendor/buildr/lib/buildr/core/util.rb +537 -0
  120. data/vendor/buildr/lib/buildr/groovy.rb +20 -0
  121. data/vendor/buildr/lib/buildr/groovy/bdd.rb +106 -0
  122. data/vendor/buildr/lib/buildr/groovy/compiler.rb +153 -0
  123. data/vendor/buildr/lib/buildr/groovy/doc.rb +76 -0
  124. data/vendor/buildr/lib/buildr/groovy/shell.rb +57 -0
  125. data/vendor/buildr/lib/buildr/ide.rb +19 -0
  126. data/vendor/buildr/lib/buildr/ide/eclipse.rb +427 -0
  127. data/vendor/buildr/lib/buildr/ide/eclipse/java.rb +53 -0
  128. data/vendor/buildr/lib/buildr/ide/eclipse/plugin.rb +71 -0
  129. data/vendor/buildr/lib/buildr/ide/eclipse/scala.rb +68 -0
  130. data/vendor/buildr/lib/buildr/ide/idea.rb +576 -0
  131. data/vendor/buildr/lib/buildr/java.rb +25 -0
  132. data/vendor/buildr/lib/buildr/java/ant.rb +94 -0
  133. data/vendor/buildr/lib/buildr/java/bdd.rb +460 -0
  134. data/vendor/buildr/lib/buildr/java/cobertura.rb +297 -0
  135. data/vendor/buildr/lib/buildr/java/commands.rb +223 -0
  136. data/vendor/buildr/lib/buildr/java/compiler.rb +135 -0
  137. data/vendor/buildr/lib/buildr/java/deprecated.rb +141 -0
  138. data/vendor/buildr/lib/buildr/java/doc.rb +86 -0
  139. data/vendor/buildr/lib/buildr/java/ecj.rb +69 -0
  140. data/vendor/buildr/lib/buildr/java/emma.rb +244 -0
  141. data/vendor/buildr/lib/buildr/java/external.rb +73 -0
  142. data/vendor/buildr/lib/buildr/java/jruby.rb +122 -0
  143. data/vendor/buildr/lib/buildr/java/jtestr_result.rb +295 -0
  144. data/vendor/buildr/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  145. data/vendor/buildr/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  146. data/vendor/buildr/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  147. data/vendor/buildr/lib/buildr/java/packaging.rb +734 -0
  148. data/vendor/buildr/lib/buildr/java/pom.rb +178 -0
  149. data/vendor/buildr/lib/buildr/java/rjb.rb +154 -0
  150. data/vendor/buildr/lib/buildr/java/test_result.rb +101 -0
  151. data/vendor/buildr/lib/buildr/java/tests.rb +362 -0
  152. data/vendor/buildr/lib/buildr/java/version_requirement.rb +172 -0
  153. data/vendor/buildr/lib/buildr/packaging.rb +25 -0
  154. data/vendor/buildr/lib/buildr/packaging/archive.rb +535 -0
  155. data/vendor/buildr/lib/buildr/packaging/artifact.rb +903 -0
  156. data/vendor/buildr/lib/buildr/packaging/artifact_namespace.rb +984 -0
  157. data/vendor/buildr/lib/buildr/packaging/artifact_search.rb +140 -0
  158. data/vendor/buildr/lib/buildr/packaging/gems.rb +105 -0
  159. data/vendor/buildr/lib/buildr/packaging/package.rb +249 -0
  160. data/vendor/buildr/lib/buildr/packaging/tar.rb +189 -0
  161. data/vendor/buildr/lib/buildr/packaging/version_requirement.rb +192 -0
  162. data/vendor/buildr/lib/buildr/packaging/zip.rb +178 -0
  163. data/vendor/buildr/lib/buildr/packaging/ziptask.rb +356 -0
  164. data/vendor/buildr/lib/buildr/resources/buildr.icns +0 -0
  165. data/vendor/buildr/lib/buildr/resources/completed.png +0 -0
  166. data/vendor/buildr/lib/buildr/resources/failed.png +0 -0
  167. data/vendor/buildr/lib/buildr/resources/icons-license.txt +17 -0
  168. data/vendor/buildr/lib/buildr/run.rb +195 -0
  169. data/vendor/buildr/lib/buildr/scala.rb +26 -0
  170. data/vendor/buildr/lib/buildr/scala/bdd.rb +118 -0
  171. data/vendor/buildr/lib/buildr/scala/compiler.rb +242 -0
  172. data/vendor/buildr/lib/buildr/scala/doc.rb +142 -0
  173. data/vendor/buildr/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  174. data/vendor/buildr/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  175. data/vendor/buildr/lib/buildr/scala/shell.rb +52 -0
  176. data/vendor/buildr/lib/buildr/scala/tests.rb +171 -0
  177. data/vendor/buildr/lib/buildr/shell.rb +185 -0
  178. data/vendor/buildr/lib/buildr/version.rb +18 -0
  179. data/vendor/buildr/rakelib/all-in-one.rake +113 -0
  180. data/vendor/buildr/rakelib/checks.rake +57 -0
  181. data/vendor/buildr/rakelib/doc.rake +137 -0
  182. data/vendor/buildr/rakelib/metrics.rake +39 -0
  183. data/vendor/buildr/rakelib/package.rake +73 -0
  184. data/vendor/buildr/rakelib/release.rake +161 -0
  185. data/vendor/buildr/rakelib/rspec.rake +101 -0
  186. data/vendor/buildr/rakelib/setup.rake +66 -0
  187. data/vendor/buildr/rakelib/stage.rake +220 -0
  188. data/vendor/buildr/spec/addon/bnd_spec.rb +330 -0
  189. data/vendor/buildr/spec/addon/drb_spec.rb +328 -0
  190. data/vendor/buildr/spec/addon/jaxb_xjc_spec.rb +125 -0
  191. data/vendor/buildr/spec/core/application_spec.rb +631 -0
  192. data/vendor/buildr/spec/core/build_spec.rb +837 -0
  193. data/vendor/buildr/spec/core/cc_spec.rb +224 -0
  194. data/vendor/buildr/spec/core/checks_spec.rb +519 -0
  195. data/vendor/buildr/spec/core/common_spec.rb +725 -0
  196. data/vendor/buildr/spec/core/compile_spec.rb +658 -0
  197. data/vendor/buildr/spec/core/doc_spec.rb +195 -0
  198. data/vendor/buildr/spec/core/extension_spec.rb +201 -0
  199. data/vendor/buildr/spec/core/generate_spec.rb +33 -0
  200. data/vendor/buildr/spec/core/project_spec.rb +772 -0
  201. data/vendor/buildr/spec/core/run_spec.rb +93 -0
  202. data/vendor/buildr/spec/core/shell_spec.rb +146 -0
  203. data/vendor/buildr/spec/core/test_spec.rb +1320 -0
  204. data/vendor/buildr/spec/core/transport_spec.rb +544 -0
  205. data/vendor/buildr/spec/core/util_spec.rb +141 -0
  206. data/vendor/buildr/spec/groovy/bdd_spec.rb +80 -0
  207. data/vendor/buildr/spec/groovy/compiler_spec.rb +251 -0
  208. data/vendor/buildr/spec/groovy/doc_spec.rb +65 -0
  209. data/vendor/buildr/spec/ide/eclipse_spec.rb +739 -0
  210. data/vendor/buildr/spec/ide/idea_spec.rb +1144 -0
  211. data/vendor/buildr/spec/java/ant_spec.rb +37 -0
  212. data/vendor/buildr/spec/java/bdd_spec.rb +374 -0
  213. data/vendor/buildr/spec/java/cobertura_spec.rb +112 -0
  214. data/vendor/buildr/spec/java/commands_spec.rb +93 -0
  215. data/vendor/buildr/spec/java/compiler_spec.rb +252 -0
  216. data/vendor/buildr/spec/java/doc_spec.rb +56 -0
  217. data/vendor/buildr/spec/java/ecj_spec.rb +115 -0
  218. data/vendor/buildr/spec/java/emma_spec.rb +121 -0
  219. data/vendor/buildr/spec/java/external_spec.rb +56 -0
  220. data/vendor/buildr/spec/java/java_spec.rb +132 -0
  221. data/vendor/buildr/spec/java/packaging_spec.rb +1270 -0
  222. data/vendor/buildr/spec/java/run_spec.rb +78 -0
  223. data/vendor/buildr/spec/java/test_coverage_helper.rb +257 -0
  224. data/vendor/buildr/spec/java/tests_spec.rb +497 -0
  225. data/vendor/buildr/spec/packaging/archive_spec.rb +775 -0
  226. data/vendor/buildr/spec/packaging/artifact_namespace_spec.rb +743 -0
  227. data/vendor/buildr/spec/packaging/artifact_spec.rb +1066 -0
  228. data/vendor/buildr/spec/packaging/packaging_helper.rb +63 -0
  229. data/vendor/buildr/spec/packaging/packaging_spec.rb +719 -0
  230. data/vendor/buildr/spec/sandbox.rb +165 -0
  231. data/vendor/buildr/spec/scala/bdd_spec.rb +124 -0
  232. data/vendor/buildr/spec/scala/compiler_spec.rb +289 -0
  233. data/vendor/buildr/spec/scala/doc_spec.rb +88 -0
  234. data/vendor/buildr/spec/scala/scala.rb +38 -0
  235. data/vendor/buildr/spec/scala/tests_spec.rb +283 -0
  236. data/vendor/buildr/spec/spec_helpers.rb +369 -0
  237. data/vendor/buildr/spec/version_requirement_spec.rb +143 -0
  238. data/vendor/buildr/spec/xpath_matchers.rb +121 -0
  239. data/vendor/buildr/tests/BUILDR-320/Buildfile +29 -0
  240. data/vendor/buildr/tests/JavaSystemProperty/Buildfile +18 -0
  241. data/vendor/buildr/tests/JavaSystemProperty/src/test/java/FooTest.java +24 -0
  242. data/vendor/buildr/tests/compile_with_parent/Buildfile +18 -0
  243. data/vendor/buildr/tests/compile_with_parent/child/src/main/java/Foo.java +23 -0
  244. data/vendor/buildr/tests/helloWorld/Buildfile +20 -0
  245. data/vendor/buildr/tests/helloWorld/src/main/java/HelloWorld.java +23 -0
  246. data/vendor/buildr/tests/integration_testing.rb +56 -0
  247. data/vendor/buildr/tests/junit3/Buildfile +9 -0
  248. data/vendor/buildr/tests/junit3/src/main/java/Foo.java +23 -0
  249. data/vendor/buildr/tests/junit3/src/test/java/FooTest.java +28 -0
  250. data/vendor/buildr/tests/package_war_as_jar/Buildfile +15 -0
  251. data/vendor/buildr/tests/package_war_as_jar/src/main/java/Foo.java +19 -0
  252. metadata +524 -0
@@ -0,0 +1,297 @@
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>cobertura:html</code>, <code>cobertura:xml</code> and <code>cobertura:check</code> tasks.
23
+ # Require explicitly using <code>require "buildr/cobertura"</code>.
24
+ #
25
+ # You can generate cobertura reports for a single project
26
+ # using the project name as prefix:
27
+ #
28
+ # project_name:cobertura:html
29
+ #
30
+ # You can also specify which classes to include/exclude from instrumentation by
31
+ # passing a class name regexp to the <code>cobertura.include</code> or
32
+ # <code>cobertura.exclude</code> methods.
33
+ #
34
+ # define 'someModule' do
35
+ # cobertura.include 'some.package.*'
36
+ # cobertura.include /some.(foo|bar).*/
37
+ # cobertura.exclude 'some.foo.util.SimpleUtil'
38
+ # cobertura.exclude /*.Const(ants)?/i
39
+ # end
40
+ #
41
+ module Cobertura
42
+
43
+ VERSION = '1.9.4.1'
44
+
45
+ class << self
46
+ def version
47
+ Buildr.settings.build['cobertura'] || VERSION
48
+ end
49
+ end
50
+
51
+ REQUIRES = ArtifactNamespace.for(self).tap do |ns|
52
+ ns.cobertura! "net.sourceforge.cobertura:cobertura:jar:#{version}", '>=1.9'
53
+ ns.log4j! 'log4j:log4j:jar:1.2.9', ">=1.2.9"
54
+ ns.asm! 'asm:asm:jar:2.2.1', '>=2.2.1'
55
+ ns.asm_tree! 'asm:asm-tree:jar:2.2.1', '>=2.2.1'
56
+ ns.oro! 'oro:oro:jar:2.0.8', '>=2.0.8'
57
+ end
58
+
59
+ class << self
60
+ def dependencies
61
+ if (VersionRequirement.create('>=1.9.1').satisfied_by?(REQUIRES.cobertura.version))
62
+ [:asm, :asm_tree].each { |s| REQUIRES[s] = '3.0' unless REQUIRES[s].selected? }
63
+ end
64
+
65
+ REQUIRES.artifacts
66
+ end
67
+
68
+ def report_to(file = nil)
69
+ File.expand_path(File.join(*["reports/cobertura", file.to_s].compact))
70
+ end
71
+
72
+ def data_file()
73
+ File.expand_path("reports/cobertura.ser")
74
+ end
75
+
76
+ end
77
+
78
+ class CoberturaConfig # :nodoc:
79
+
80
+ def initialize(project)
81
+ @project = project
82
+ end
83
+
84
+ attr_reader :project
85
+ private :project
86
+
87
+ attr_writer :data_file, :instrumented_dir, :report_dir
88
+
89
+ def data_file
90
+ @data_file ||= project.path_to(:reports, 'cobertura.ser')
91
+ end
92
+
93
+ def instrumented_dir
94
+ @instrumented_dir ||= project.path_to(:target, :instrumented, :classes)
95
+ end
96
+
97
+ def report_dir
98
+ @report_dir ||= project.path_to(:reports, :cobertura)
99
+ end
100
+
101
+ def report_to(file = nil)
102
+ File.expand_path(File.join(*[report_dir, file.to_s].compact))
103
+ end
104
+
105
+ # :call-seq:
106
+ # project.cobertura.include(*classPatterns)
107
+ #
108
+ def include(*classPatterns)
109
+ includes.push(*classPatterns.map { |p| String === p ? Regexp.new(p) : p })
110
+ self
111
+ end
112
+
113
+ def includes
114
+ @includeClasses ||= []
115
+ end
116
+
117
+ # :call-seq:
118
+ # project.cobertura.exclude(*classPatterns)
119
+ #
120
+ def exclude(*classPatterns)
121
+ excludes.push(*classPatterns.map { |p| String === p ? Regexp.new(p) : p })
122
+ self
123
+ end
124
+
125
+ def excludes
126
+ @excludeClasses ||= []
127
+ end
128
+
129
+ def ignore(*regexps)
130
+ ignores.push(*regexps)
131
+ end
132
+
133
+ def ignores
134
+ @ignores ||= []
135
+ end
136
+
137
+ def sources
138
+ project.compile.sources
139
+ end
140
+
141
+ def check
142
+ @check ||= CoberturaCheck.new
143
+ end
144
+ end
145
+
146
+ class CoberturaCheck
147
+ attr_writer :branch_rate, :line_rate, :total_branch_rate, :total_line_rate, :package_line_rate, :package_branch_rate
148
+ attr_reader :branch_rate, :line_rate, :total_branch_rate, :total_line_rate, :package_line_rate, :package_branch_rate
149
+ end
150
+
151
+ module CoberturaExtension # :nodoc:
152
+ include Buildr::Extension
153
+
154
+ def cobertura
155
+ @cobertura_config ||= CoberturaConfig.new(self)
156
+ end
157
+
158
+ after_define do |project|
159
+ cobertura = project.cobertura
160
+
161
+ namespace 'cobertura' do
162
+ unless project.compile.target.nil?
163
+ # Instrumented bytecode goes in a different directory. This task creates before running the test
164
+ # cases and monitors for changes in the generate bytecode.
165
+ instrumented = project.file(cobertura.instrumented_dir => project.compile.target) do |task|
166
+ mkdir_p task.to_s
167
+ unless project.compile.sources.empty?
168
+ info "Instrumenting classes with cobertura data file #{cobertura.data_file}"
169
+ Buildr.ant "cobertura" do |ant|
170
+ ant.taskdef :resource=>"tasks.properties",
171
+ :classpath=>Buildr.artifacts(Cobertura.dependencies).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
172
+ ant.send "cobertura-instrument", :todir=>task.to_s, :datafile=>cobertura.data_file do
173
+ includes, excludes = cobertura.includes, cobertura.excludes
174
+
175
+ classes_dir = project.compile.target.to_s
176
+ if includes.empty? && excludes.empty?
177
+ ant.fileset :dir => classes_dir do
178
+ ant.include :name => "**/*.class"
179
+ end
180
+ else
181
+ includes = [//] if includes.empty?
182
+ Dir.glob(File.join(classes_dir, "**/*.class")) do |cls|
183
+ cls_name = cls.gsub(/#{classes_dir}\/?|\.class$/, '').gsub('/', '.')
184
+ if includes.any? { |p| p === cls_name } && !excludes.any? { |p| p === cls_name }
185
+ ant.fileset :file => cls
186
+ end
187
+ end
188
+ end
189
+
190
+ cobertura.ignores.each { |r| ant.ignore :regex => r }
191
+ end
192
+ end
193
+ end
194
+ touch task.to_s
195
+ end
196
+
197
+ task 'instrument' => instrumented
198
+
199
+ # We now have two target directories with bytecode. It would make sense to remove compile.target
200
+ # and add instrumented instead, but apparently Cobertura only creates some of the classes, so
201
+ # we need both directories and instrumented must come first.
202
+ project.test.dependencies.unshift cobertura.instrumented_dir
203
+ project.test.with Cobertura.dependencies
204
+ project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = cobertura.data_file
205
+
206
+ unless project.compile.sources.empty?
207
+ [:xml, :html].each do |format|
208
+ task format => ['instrument', 'test'] do
209
+ info "Creating test coverage reports in #{cobertura.report_to(format)}"
210
+ Buildr.ant "cobertura" do |ant|
211
+ ant.taskdef :resource=>"tasks.properties",
212
+ :classpath=>Buildr.artifacts(Cobertura.dependencies).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
213
+ ant.send "cobertura-report", :format=>format,
214
+ :destdir=>cobertura.report_to(format), :datafile=>cobertura.data_file do
215
+ cobertura.sources.flatten.each do |src|
216
+ ant.fileset(:dir=>src.to_s) if File.exist?(src.to_s)
217
+ end
218
+ end
219
+ end
220
+ end
221
+ end
222
+ end
223
+
224
+ task :check => [:instrument, :test] do
225
+ Buildr.ant "cobertura" do |ant|
226
+ ant.taskdef :classpath=>Cobertura.dependencies.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
227
+ params = { :datafile => Cobertura.data_file }
228
+
229
+ # oh so ugly...
230
+ params[:branchrate] = cobertura.check.branch_rate if cobertura.check.branch_rate
231
+ params[:linerate] = cobertura.check.line_rate if cobertura.check.line_rate
232
+ params[:totalbranchrate] = cobertura.check.total_branch_rate if cobertura.check.total_branch_rate
233
+ params[:totallinerate] = cobertura.check.total_line_rate if cobertura.check.total_line_rate
234
+ params[:packagebranchrate] = cobertura.check.package_branch_rate if cobertura.check.package_branch_rate
235
+ params[:packagelinerate] = cobertura.check.package_line_rate if cobertura.check.package_line_rate
236
+
237
+ ant.send("cobertura-check", params) do
238
+ end
239
+ end
240
+ end
241
+
242
+ end
243
+ end
244
+
245
+ project.clean do
246
+ rm_rf [cobertura.report_to, cobertura.data_file, cobertura.instrumented_dir]
247
+ end
248
+
249
+ end
250
+
251
+ end
252
+
253
+ class Buildr::Project
254
+ include CoberturaExtension
255
+ end
256
+
257
+ namespace "cobertura" do
258
+
259
+ task "instrument" do
260
+ Buildr.projects.each do |project|
261
+ project.cobertura.data_file = data_file
262
+ project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = data_file
263
+ instrument_task ="#{project.name}:cobertura:instrument"
264
+ task(instrument_task).invoke if Rake::Task.task_defined?(instrument_task)
265
+ end
266
+ end
267
+
268
+ [:xml, :html].each do |format|
269
+ report_target = report_to(format)
270
+ desc "Run the test cases and produce code coverage reports in #{report_target}"
271
+ task format => ["instrument", "test"] do
272
+ if Buildr.projects.detect { |project| !project.compile.sources.empty? }
273
+ info "Creating test coverage reports in #{report_target}"
274
+ Buildr.ant "cobertura" do |ant|
275
+ ant.taskdef :resource=>"tasks.properties",
276
+ :classpath=>Buildr.artifacts(Cobertura.dependencies).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
277
+ ant.send "cobertura-report", :destdir=>report_target, :format=>format, :datafile=>data_file do
278
+ Buildr.projects.map(&:cobertura).map(&:sources).flatten.each do |src|
279
+ ant.fileset :dir=>src.to_s if File.exist?(src.to_s)
280
+ end
281
+ end
282
+ end
283
+ end
284
+ end
285
+ end
286
+
287
+ task "clean" do
288
+ rm_rf [report_to, data_file]
289
+ end
290
+ end
291
+
292
+ task "clean" do
293
+ task("cobertura:clean").invoke if Dir.pwd == Rake.application.original_dir
294
+ end
295
+
296
+ end
297
+ end
@@ -0,0 +1,223 @@
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
+ # Base module for all things Java.
18
+ module Java
19
+
20
+ # JDK commands: java, javac, javadoc, etc.
21
+ module Commands
22
+
23
+ class << self
24
+
25
+ # :call-seq:
26
+ # java(class, *args, options?)
27
+ #
28
+ # Runs Java with the specified arguments.
29
+ #
30
+ # Each argument should be provided as separate array value, e.g.
31
+ #
32
+ # java("-jar", "yuicompressor-2.4.2.jar", "--type","css",
33
+ # "src/main/webapp/styles/styles-all.css",
34
+ # "-o", "src/main/webapp/styles/styles-all-min.css")
35
+ #
36
+ # The last argument may be a Hash with additional options:
37
+ # * :classpath -- One or more file names, tasks or artifact specifications.
38
+ # These are all expanded into artifacts, and all tasks are invoked.
39
+ # * :java_args -- Any additional arguments to pass (e.g. -hotspot, -xms)
40
+ # * :properties -- Hash of system properties (e.g. 'path'=>base_dir).
41
+ # * :name -- Shows this name, otherwise shows the first argument (the class name).
42
+ # * :verbose -- If true, prints the command and all its argument.
43
+ def java(*args, &block)
44
+ options = Hash === args.last ? args.pop : {}
45
+ options[:verbose] ||= trace?(:java)
46
+ rake_check_options options, :classpath, :java_args, :properties, :name, :verbose
47
+
48
+ name = options[:name]
49
+ if name.nil?
50
+ name = "java #{args.first}"
51
+ end
52
+
53
+ cmd_args = [path_to_bin('java')]
54
+ cp = classpath_from(options)
55
+ cmd_args << '-classpath' << cp.join(File::PATH_SEPARATOR) unless cp.empty?
56
+ options[:properties].each { |k, v| cmd_args << "-D#{k}=#{v}" } if options[:properties]
57
+ cmd_args += (options[:java_args] || (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split).flatten
58
+ cmd_args += args.flatten.compact
59
+ unless Buildr.application.options.dryrun
60
+ info "Running #{name}" if name && options[:verbose]
61
+ block = lambda { |ok, res| fail "Failed to execute #{name}, see errors above" unless ok } unless block
62
+ cmd_args = cmd_args.map(&:inspect).join(' ') if Util.win_os?
63
+ sh(*cmd_args) do |ok, ps|
64
+ block.call ok, ps
65
+ end
66
+ end
67
+ end
68
+
69
+ # :call-seq:
70
+ # apt(*files, options)
71
+ #
72
+ # Runs Apt with the specified arguments.
73
+ #
74
+ # The last argument may be a Hash with additional options:
75
+ # * :compile -- If true, compile source files to class files.
76
+ # * :source -- Specifies source compatibility with a given JVM release.
77
+ # * :output -- Directory where to place the generated source files, or the
78
+ # generated class files when compiling.
79
+ # * :classpath -- One or more file names, tasks or artifact specifications.
80
+ # These are all expanded into artifacts, and all tasks are invoked.
81
+ def apt(*args)
82
+ options = Hash === args.last ? args.pop : {}
83
+ rake_check_options options, :compile, :source, :output, :classpath
84
+
85
+ files = args.flatten.map(&:to_s).
86
+ collect { |arg| File.directory?(arg) ? FileList["#{arg}/**/*.java"] : arg }.flatten
87
+ cmd_args = [ trace?(:apt) ? '-verbose' : '-nowarn' ]
88
+ if options[:compile]
89
+ cmd_args << '-d' << options[:output].to_s
90
+ else
91
+ cmd_args << '-nocompile' << '-s' << options[:output].to_s
92
+ end
93
+ cmd_args << '-source' << options[:source] if options[:source]
94
+ cp = classpath_from(options)
95
+ cmd_args << '-classpath' << cp.join(File::PATH_SEPARATOR) unless cp.empty?
96
+ cmd_args += files
97
+ unless Buildr.application.options.dryrun
98
+ info 'Running apt'
99
+ trace (['apt'] + cmd_args).join(' ')
100
+ Java.load
101
+ ::Java::com.sun.tools.apt.Main.process(cmd_args.to_java(::Java::java.lang.String)) == 0 or
102
+ fail 'Failed to process annotations, see errors above'
103
+ end
104
+ end
105
+
106
+ # :call-seq:
107
+ # javac(*files, options)
108
+ #
109
+ # Runs Javac with the specified arguments.
110
+ #
111
+ # The last argument may be a Hash with additional options:
112
+ # * :output -- Target directory for all compiled class files.
113
+ # * :classpath -- One or more file names, tasks or artifact specifications.
114
+ # These are all expanded into artifacts, and all tasks are invoked.
115
+ # * :sourcepath -- Additional source paths to use.
116
+ # * :javac_args -- Any additional arguments to pass (e.g. -extdirs, -encoding)
117
+ # * :name -- Shows this name, otherwise shows the working directory.
118
+ def javac(*args)
119
+ options = Hash === args.last ? args.pop : {}
120
+ rake_check_options options, :classpath, :sourcepath, :output, :javac_args, :name
121
+
122
+ files = args.flatten.each { |f| f.invoke if f.respond_to?(:invoke) }.map(&:to_s).
123
+ collect { |arg| File.directory?(arg) ? FileList["#{File.expand_path(arg)}/**/*.java"] : File.expand_path(arg) }.flatten
124
+ name = options[:name] || Dir.pwd
125
+
126
+ cmd_args = []
127
+ cp = classpath_from(options)
128
+ cmd_args << '-classpath' << cp.join(File::PATH_SEPARATOR) unless cp.empty?
129
+ cmd_args << '-sourcepath' << [options[:sourcepath]].flatten.join(File::PATH_SEPARATOR) if options[:sourcepath]
130
+ cmd_args << '-d' << File.expand_path(options[:output].to_s) if options[:output]
131
+ cmd_args += options[:javac_args].flatten if options[:javac_args]
132
+ cmd_args += files
133
+ unless Buildr.application.options.dryrun
134
+ mkdir_p options[:output] if options[:output]
135
+ info "Compiling #{files.size} source files in #{name}"
136
+ trace (['javac'] + cmd_args).join(' ')
137
+ Java.load
138
+ ::Java::com.sun.tools.javac.Main.compile(cmd_args.to_java(::Java::java.lang.String)) == 0 or
139
+ fail 'Failed to compile, see errors above'
140
+ end
141
+ end
142
+
143
+ # :call-seq:
144
+ # javadoc(*files, options)
145
+ #
146
+ # Runs Javadocs with the specified files and options.
147
+ #
148
+ # This method accepts the following special options:
149
+ # * :output -- The output directory
150
+ # * :classpath -- Array of classpath dependencies.
151
+ # * :sourcepath -- Array of sourcepaths (paths or tasks).
152
+ # * :name -- Shows this name, otherwise shows the working directory.
153
+ #
154
+ # All other options are passed to Javadoc as following:
155
+ # * true -- As is, for example, :author=>true becomes -author
156
+ # * false -- Prefixed, for example, :index=>false becomes -noindex
157
+ # * string -- Option with value, for example, :windowtitle=>'My project' becomes -windowtitle "My project"
158
+ # * array -- Option with set of values separated by spaces.
159
+ def javadoc(*args)
160
+ options = Hash === args.last ? args.pop : {}
161
+ fail "No output defined for javadoc" if options[:output].nil?
162
+ options[:output] = File.expand_path(options[:output].to_s)
163
+ cmd_args = [ '-d', options[:output], trace?(:javadoc) ? '-verbose' : '-quiet' ]
164
+ options.reject { |key, value| [:output, :name, :sourcepath, :classpath].include?(key) }.
165
+ each { |key, value| value.invoke if value.respond_to?(:invoke) }.
166
+ each do |key, value|
167
+ case value
168
+ when true, nil
169
+ cmd_args << "-#{key}"
170
+ when false
171
+ cmd_args << "-no#{key}"
172
+ when Hash
173
+ value.each { |k,v| cmd_args << "-#{key}" << k.to_s << v.to_s }
174
+ else
175
+ cmd_args += Array(value).map { |item| ["-#{key}", item.to_s] }.flatten
176
+ end
177
+ end
178
+ [:sourcepath, :classpath].each do |option|
179
+ options[option].to_a.flatten.tap do |paths|
180
+ cmd_args << "-#{option}" << paths.flatten.map(&:to_s).join(File::PATH_SEPARATOR) unless paths.empty?
181
+ end
182
+ end
183
+ files = args.each {|arg| arg.invoke if arg.respond_to?(:invoke)}.collect {|arg| arg.is_a?(Project) ? arg.compile.sources.collect{|dir| Dir["#{File.expand_path(dir.to_s)}/**/*.java"]} : File.expand_path(arg.to_s) }
184
+ cmd_args += files.flatten.uniq.map(&:to_s)
185
+ name = options[:name] || Dir.pwd
186
+ unless Buildr.application.options.dryrun
187
+ info "Generating Javadoc for #{name}"
188
+ trace (['javadoc'] + cmd_args).join(' ')
189
+ Java.load
190
+ ::Java::com.sun.tools.javadoc.Main.execute(cmd_args.to_java(::Java::java.lang.String)) == 0 or
191
+ fail 'Failed to generate Javadocs, see errors above'
192
+ end
193
+ end
194
+
195
+ protected
196
+
197
+ # :call-seq:
198
+ # path_to_bin(cmd?) => path
199
+ #
200
+ # Returns the path to the specified Java command (with no argument to java itself).
201
+ def path_to_bin(name = nil)
202
+ home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
203
+ bin = Util.normalize_path(File.join(home, 'bin'))
204
+ fail 'JAVA_HOME environment variable does not point to a valid JRE/JDK installation.' unless File.exist? bin
205
+ Util.normalize_path(File.join(bin, name.to_s))
206
+ end
207
+
208
+ # :call-seq:
209
+ # classpath_from(options) => files
210
+ #
211
+ # Extracts the classpath from the options, expands it by calling artifacts, invokes
212
+ # each of the artifacts and returns an array of paths.
213
+ def classpath_from(options)
214
+ Buildr.artifacts(options[:classpath] || []).map(&:to_s).
215
+ map { |t| task(t).invoke; File.expand_path(t) }
216
+ end
217
+
218
+ end
219
+
220
+ end
221
+
222
+ end
223
+