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,20 @@
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/groovy/compiler'
18
+ require 'buildr/groovy/bdd'
19
+ require 'buildr/groovy/doc'
20
+ require 'buildr/groovy/shell'
@@ -0,0 +1,106 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ module Buildr::Groovy
18
+
19
+ # EasyB is a Groovy based BDD framework.
20
+ # To use in your project:
21
+ #
22
+ # test.using :easyb
23
+ #
24
+ # This framework will search in your project for:
25
+ # src/spec/groovy/**/*Story.groovy
26
+ # src/spec/groovy/**/*Specification.groovy
27
+ #
28
+ # Support the following options:
29
+ # * :format -- Report format :txt or :xml, default is :txt
30
+ # * :properties -- Hash of properties passed to the test suite.
31
+ # * :java_args -- Arguments passed to the JVM.
32
+ class EasyB < TestFramework::JavaBDD
33
+ @lang = :groovy
34
+ @bdd_dir = :spec
35
+
36
+ VERSION = "0.9"
37
+ TESTS_PATTERN = [ /(Story|Specification).groovy$/ ]
38
+ OPTIONS = [:format, :properties, :java_args]
39
+
40
+ class << self
41
+ def version
42
+ Buildr.settings.build['jbehave'] || VERSION
43
+ end
44
+
45
+ def dependencies
46
+ @dependencies ||= ["org.easyb:easyb:jar:#{version}",
47
+ 'org.codehaus.groovy:groovy:jar:1.5.3','asm:asm:jar:2.2.3',
48
+ 'commons-cli:commons-cli:jar:1.0','antlr:antlr:jar:2.7.7']
49
+ end
50
+
51
+ def applies_to?(project) #:nodoc:
52
+ %w{
53
+ **/*Specification.groovy **/*Story.groovy
54
+ }.any? { |glob| !Dir[project.path_to(:source, bdd_dir, lang, glob)].empty? }
55
+ end
56
+
57
+ private
58
+ def const_missing(const)
59
+ return super unless const == :REQUIRES # TODO: remove in 1.5
60
+ Buildr.application.deprecated "Please use JBehave.dependencies/.version instead of JBehave::REQUIRES/VERSION"
61
+ dependencies
62
+ end
63
+ end
64
+
65
+ def tests(dependencies) #:nodoc:
66
+ Dir[task.project.path_to(:source, bdd_dir, lang, "**/*.groovy")].
67
+ select { |name| TESTS_PATTERN.any? { |pat| pat === name } }
68
+ end
69
+
70
+ def run(tests, dependencies) #:nodoc:
71
+ options = { :format => :txt }.merge(self.options).only(*OPTIONS)
72
+
73
+ if :txt == options[:format]
74
+ easyb_format, ext = 'txtstory', '.txt'
75
+ elsif :xml == options[:format]
76
+ easyb_format, ext = 'xmlbehavior', '.xml'
77
+ else
78
+ raise "Invalid format #{options[:format]} expected one of :txt :xml"
79
+ end
80
+
81
+ cmd_args = [ 'org.disco.easyb.BehaviorRunner' ]
82
+ cmd_options = { :properties => options[:properties],
83
+ :java_args => options[:java_args],
84
+ :classpath => dependencies }
85
+
86
+ tests.inject([]) do |passed, test|
87
+ name = test.sub(/.*?groovy[\/\\]/, '').pathmap('%X')
88
+ report = File.join(task.report_to.to_s, name + ext)
89
+ mkpath report.pathmap('%d')
90
+ begin
91
+ Java::Commands.java cmd_args,
92
+ "-#{easyb_format}", report,
93
+ test, cmd_options.merge(:name => name)
94
+ rescue => e
95
+ passed
96
+ else
97
+ passed << test
98
+ end
99
+ end
100
+ end
101
+
102
+ end # EasyB
103
+
104
+ end
105
+
106
+ Buildr::TestFramework << Buildr::Groovy::EasyB
@@ -0,0 +1,153 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ module Buildr::Groovy
18
+
19
+ REQUIRES = ArtifactNamespace.for(self) do |ns|
20
+ ns.jansi! 'org.fusesource.jansi:jansi:jar:1.2.1'
21
+ ns.jline! 'jline:jline:jar:0.9.94'
22
+ end
23
+
24
+ class << self
25
+ def dependencies #:nodoc:
26
+ REQUIRES.artifacts + Groovyc.dependencies
27
+ end
28
+ end
29
+
30
+ # Groovyc compiler:
31
+ # compile.using(:groovyc)
32
+ #
33
+ # You need to require 'buildr/groovy/compiler' if you need to use this compiler.
34
+ #
35
+ # Used by default if .groovy files are found in the src/main/groovy directory (or src/test/groovy)
36
+ # and sets the target directory to target/classes (or target/test/classes).
37
+ #
38
+ # Groovyc is a joint compiler, this means that when selected for a project, this compiler is used
39
+ # to compile both groovy and java sources. It's recommended that Groovy sources are placed in the
40
+ # src/main/groovy directory, even though this compiler also looks in src/main/java
41
+ #
42
+ # Groovyc accepts the following options:
43
+ #
44
+ # * :encoding -- Encoding of source files
45
+ # * :verbose -- Asks the compiler for verbose output, true when running in verbose mode.
46
+ # * :fork -- Whether to execute groovyc using a spawned instance of the JVM; defaults to no
47
+ # * :memoryInitialSize -- The initial size of the memory for the underlying VM, if using fork mode; ignored otherwise.
48
+ # Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)
49
+ # * :memoryMaximumSize -- The maximum size of the memory for the underlying VM, if using fork mode; ignored otherwise.
50
+ # Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)
51
+ # * :listfiles -- Indicates whether the source files to be compiled will be listed; defaults to no
52
+ # * :stacktrace -- If true each compile error message will contain a stacktrace
53
+ # * :warnings -- Issue warnings when compiling. True when running in verbose mode.
54
+ # * :debug -- Generates bytecode with debugging information. Set from the debug
55
+ # environment variable/global option.
56
+ # * :deprecation -- If true, shows deprecation messages. False by default.
57
+ # * :optimise -- Generates faster bytecode by applying optimisations to the program.
58
+ # * :source -- Source code compatibility.
59
+ # * :target -- Bytecode compatibility.
60
+ # * :javac -- Hash of options passed to the ant javac task
61
+ #
62
+ class Groovyc < Compiler::Base
63
+
64
+ # The groovyc compiler jars are added to classpath at load time,
65
+ # if you want to customize artifact versions, you must set them on the
66
+ #
67
+ # artifact_ns(Buildr::Groovy::Groovyc).groovy = '1.7.1'
68
+ #
69
+ # namespace before this file is required.
70
+ REQUIRES = ArtifactNamespace.for(self) do |ns|
71
+ ns.groovy! 'org.codehaus.groovy:groovy:jar:>=1.7.5'
72
+ ns.commons_cli! 'commons-cli:commons-cli:jar:>=1.2'
73
+ ns.asm! 'asm:asm:jar:>=3.2'
74
+ ns.antlr! 'antlr:antlr:jar:>=2.7.7'
75
+ end
76
+
77
+ ANT_TASK = 'org.codehaus.groovy.ant.Groovyc'
78
+ GROOVYC_OPTIONS = [:encoding, :verbose, :fork, :memoryInitialSize, :memoryMaximumSize, :listfiles, :stacktrace]
79
+ JAVAC_OPTIONS = [:optimise, :warnings, :debug, :deprecation, :source, :target, :javac]
80
+ OPTIONS = GROOVYC_OPTIONS + JAVAC_OPTIONS
81
+
82
+ class << self
83
+ def dependencies #:nodoc:
84
+ REQUIRES.artifacts
85
+ end
86
+
87
+ def applies_to?(project, task) #:nodoc:
88
+ paths = task.sources + [sources].flatten.map { |src| Array(project.path_to(:source, task.usage, src.to_sym)) }
89
+ paths.flatten!
90
+ # Just select if we find .groovy files
91
+ paths.any? { |path| !Dir["#{path}/**/*.groovy"].empty? }
92
+ end
93
+ end
94
+
95
+ # Groovy dependencies don't need to go into JVM's system classpath.
96
+ # In fact, if they end up there it causes trouble because Groovy has issues
97
+ # loading other classes such as test frameworks (e.g. JUnit).
98
+ #
99
+ # Java.classpath << lambda { dependencies }
100
+
101
+ specify :language => :groovy, :sources => [:groovy, :java], :source_ext => [:groovy, :java],
102
+ :target => 'classes', :target_ext => 'class', :packaging => :jar
103
+
104
+ def initialize(project, options) #:nodoc:
105
+ super
106
+ options[:debug] = Buildr.options.debug if options[:debug].nil?
107
+ options[:deprecation] ||= false
108
+ options[:optimise] ||= false
109
+ options[:verbose] ||= trace?(:groovyc) if options[:verbose].nil?
110
+ options[:warnings] = verbose if options[:warnings].nil?
111
+ options[:javac] = OpenObject.new if options[:javac].nil?
112
+ end
113
+
114
+ # http://groovy.codehaus.org/The+groovyc+Ant+Task
115
+ def compile(sources, target, dependencies) #:nodoc:
116
+ return if Buildr.application.options.dryrun
117
+ Buildr.ant 'groovyc' do |ant|
118
+ classpath = dependencies
119
+ ant.taskdef :name => 'groovyc', :classname => ANT_TASK, :classpath => classpath.join(File::PATH_SEPARATOR)
120
+ ant.groovyc groovyc_options(sources, target) do
121
+ sources.each { |src| ant.src :path => src }
122
+ ant.classpath do
123
+ classpath.each { |dep| ant.pathelement :path => dep }
124
+ end
125
+ ant.javac(javac_options)
126
+ end
127
+ end
128
+ end
129
+
130
+ private
131
+ def groovyc_options(sources, target)
132
+ check_options options, OPTIONS
133
+ groovyc_options = options.to_hash.only(*GROOVYC_OPTIONS)
134
+ groovyc_options[:destdir] = File.expand_path(target)
135
+ groovyc_options
136
+ end
137
+
138
+ def javac_options
139
+ check_options options, OPTIONS
140
+ javac_options = options.to_hash.only(*JAVAC_OPTIONS)
141
+ javac_options[:optimize] = (javac_options.delete(:optimise) || false)
142
+ javac_options[:nowarn] = (javac_options.delete(:warnings) || verbose).to_s !~ /^(true|yes|on)$/i
143
+ other = javac_options.delete(:javac) || {}
144
+ javac_options.merge!(other)
145
+ javac_options
146
+ end
147
+
148
+ end
149
+ end
150
+
151
+ # Groovy compiler comes first, ahead of Javac, this allows it to pick
152
+ # projects that mix Groovy and Java code by spotting Groovy code first.
153
+ Buildr::Compiler.compilers.unshift Buildr::Groovy::Groovyc
@@ -0,0 +1,76 @@
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
+ require 'buildr/core/doc'
17
+ require 'buildr/groovy/compiler' # ensure Groovy dependencies are ready
18
+
19
+ module Buildr
20
+ module Doc
21
+
22
+ module GroovydocDefaults
23
+ include Extension
24
+
25
+ # Default groovydoc -doc-title to project's comment or name
26
+ after_define(:groovydoc => :doc) do |project|
27
+ if project.doc.engine? Groovydoc
28
+ options = project.doc.options
29
+ options[:windowtitle] = (project.comment || project.name) unless options[:windowtitle]
30
+ end
31
+ end
32
+ end
33
+
34
+ class Groovydoc < Base
35
+ specify :language => :groovy, :source_ext => ['java', 'groovy']
36
+
37
+ def generate(sources, target, options = {})
38
+ mkdir_p target
39
+ cmd_args = [ '-d', target, trace?(:groovydoc) ? '-verbose' : nil ].compact
40
+ options.reject { |key, value| [:sourcepath, :classpath].include?(key) }.
41
+ each { |key, value| value.invoke if value.respond_to?(:invoke) }.
42
+ each do |key, value|
43
+ case value
44
+ when true, nil
45
+ cmd_args << "-#{key}"
46
+ when false
47
+ cmd_args << "-no#{key}"
48
+ when Hash
49
+ value.each { |k,v| cmd_args << "-#{key}" << k.to_s << v.to_s }
50
+ else
51
+ cmd_args += Array(value).map { |item| ["-#{key}", item.to_s] }.flatten
52
+ end
53
+ end
54
+ [:sourcepath, :classpath].each do |option|
55
+ Array(options[option]).flatten.tap do |paths|
56
+ cmd_args << "-#{option}" << paths.flatten.map(&:to_s).join(File::PATH_SEPARATOR) unless paths.empty?
57
+ end
58
+ end
59
+ cmd_args += sources.flatten.uniq
60
+ unless Buildr.application.options.dryrun
61
+ info "Generating Groovydoc for #{project.name}"
62
+ trace (['groovydoc'] + cmd_args).join(' ')
63
+ result = Java::Commands.java('org.codehaus.groovy.tools.groovydoc.Main', cmd_args,
64
+ :classpath => Buildr::Groovy.dependencies)
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ class Project
71
+ include GroovydocDefaults
72
+ end
73
+ end
74
+
75
+ Buildr::Doc.engines << Buildr::Doc::Groovydoc
76
+
@@ -0,0 +1,57 @@
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
+ require 'buildr/shell'
17
+
18
+ module Buildr
19
+ module Groovy
20
+ class GroovySH < Buildr::Shell::Base
21
+ include JRebel
22
+
23
+ SUFFIX = if Util.win_os? then '.bat' else '' end
24
+
25
+ specify :name => :groovy, :languages => [:groovy]
26
+
27
+ def launch(task)
28
+ cp = Groovy.dependencies +
29
+ project.compile.dependencies +
30
+ [ project.path_to(:target, :classes) ] +
31
+ task.classpath
32
+ props = jrebel_props(project).merge(task.properties)
33
+ java_args = jrebel_args + task.java_args
34
+
35
+ groovy_home = nil
36
+ if groovy_home
37
+ cmd_args = " -classpath '#{cp.join(File::SEPARATOR)}'"
38
+ trace "groovysh #{cmd_args}"
39
+ system(File.expand_path("bin#{File::SEPARATOR}groovysh#{SUFFIX}", groovy_home) + cmd_args)
40
+ else
41
+ Java::Commands.java 'org.codehaus.groovy.tools.shell.Main', {
42
+ :properties => props,
43
+ :classpath => cp,
44
+ :java_args => java_args
45
+ }
46
+ end
47
+ end
48
+
49
+ private
50
+ def groovy_home
51
+ @home ||= ENV['GROOVY_HOME']
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ Buildr::Shell.providers << Buildr::Groovy::GroovySH
@@ -0,0 +1,19 @@
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/ide/eclipse'
18
+ require 'buildr/ide/idea'
19
+
@@ -0,0 +1,427 @@
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/packaging'
19
+
20
+
21
+ module Buildr
22
+ module Eclipse #:nodoc:
23
+ include Extension
24
+
25
+ class Eclipse
26
+
27
+ attr_reader :options
28
+ attr_writer :name
29
+
30
+ def initialize(project)
31
+ @project = project
32
+ @options = Options.new(project)
33
+ end
34
+
35
+ def name
36
+ return @name if @name
37
+ return @project.id.split('-').last if @options.short_names
38
+ @project.id
39
+ end
40
+
41
+ # :call-seq:
42
+ # classpath_variables :VAR => '/path/to/location'
43
+ # Sets classpath variables to be used for library path substitution
44
+ # on the project.
45
+ #
46
+ def classpath_variables(*values)
47
+ fail "eclipse.classpath_variables expects a single hash argument" if values.size > 1
48
+ if values.size == 1
49
+ fail "eclipse.classpath_variables expects a Hash argument" unless values[0].is_a? Hash
50
+ # convert keys to strings
51
+ values = values[0].inject({}) { |h, (k,v)| h[k.to_s] = @project.path_to(v); h }
52
+ @variables = values.merge(@variables || {})
53
+ end
54
+ @variables || (@project.parent ? @project.parent.eclipse.classpath_variables : default_classpath_variables)
55
+ end
56
+
57
+ def default_classpath_variables
58
+ vars = {}
59
+ vars[:SCALA_HOME] = ENV['SCALA_HOME'] if ENV['SCALA_HOME']
60
+ vars[:JAVA_HOME] = ENV['JAVA_HOME'] if ENV['JAVA_HOME']
61
+ vars
62
+ end
63
+
64
+ # :call-seq:
65
+ # natures=(natures)
66
+ # Sets the Eclipse project natures on the project.
67
+ #
68
+ def natures=(var)
69
+ @natures = arrayfy(var)
70
+ end
71
+
72
+ # :call-seq:
73
+ # natures() => [n1, n2]
74
+ # Returns the Eclipse project natures on the project.
75
+ # They may be derived from the parent project if no specific natures have been set
76
+ # on the project.
77
+ #
78
+ # An Eclipse project nature is used internally by Eclipse to determine the aspects of a project.
79
+ def natures(*values)
80
+ if values.size > 0
81
+ @natures ||= []
82
+ @natures += values.flatten
83
+ else
84
+ @natures || (@project.parent ? @project.parent.eclipse.natures : [])
85
+ end
86
+ end
87
+
88
+ # :call-seq:
89
+ # classpath_containers=(cc)
90
+ # Sets the Eclipse project classpath containers on the project.
91
+ #
92
+ def classpath_containers=(var)
93
+ @classpath_containers = arrayfy(var)
94
+ end
95
+
96
+ # :call-seq:
97
+ # classpath_containers() => [con1, con2]
98
+ # Returns the Eclipse project classpath containers on the project.
99
+ # They may be derived from the parent project if no specific classpath containers have been set
100
+ # on the project.
101
+ #
102
+ # A classpath container is an Eclipse pre-determined ensemble of dependencies made available to
103
+ # the project classpath.
104
+ def classpath_containers(*values)
105
+ if values.size > 0
106
+ @classpath_containers ||= []
107
+ @classpath_containers += values.flatten
108
+ else
109
+ @classpath_containers || (@project.parent ? @project.parent.eclipse.classpath_containers : [])
110
+ end
111
+ end
112
+
113
+ # :call-seq:
114
+ # exclude_libs() => [lib1, lib2]
115
+ # Returns the an array of libraries to be excluded from the generated Eclipse classpath
116
+ def exclude_libs(*values)
117
+ if values.size > 0
118
+ @exclude_libs ||= []
119
+ @exclude_libs += values.flatten
120
+ else
121
+ @exclude_libs || (@project.parent ? @project.parent.eclipse.exclude_libs : [])
122
+ end
123
+ end
124
+
125
+ # :call-seq:
126
+ # exclude_libs=(lib1, lib2)
127
+ # Sets libraries to be excluded from the generated Eclipse classpath
128
+ #
129
+ def exclude_libs=(libs)
130
+ @exclude_libs = arrayfy(libs)
131
+ end
132
+
133
+ # :call-seq:
134
+ # builders=(builders)
135
+ # Sets the Eclipse project builders on the project.
136
+ #
137
+ def builders=(var)
138
+ @builders = arrayfy(var)
139
+ end
140
+
141
+ # :call-seq:
142
+ # builders() => [b1, b2]
143
+ # Returns the Eclipse project builders on the project.
144
+ # They may be derived from the parent project if no specific builders have been set
145
+ # on the project.
146
+ #
147
+ # A builder is an Eclipse background job that parses the source code to produce built artifacts.
148
+ def builders(*values)
149
+ if values.size > 0
150
+ @builders ||= []
151
+ @builders += values.flatten
152
+ else
153
+ @builders || (@project.parent ? @project.parent.eclipse.builders : [])
154
+ end
155
+ end
156
+
157
+ private
158
+
159
+ def arrayfy(obj)
160
+ obj.is_a?(Array) ? obj : [obj]
161
+ end
162
+ end
163
+
164
+ class Options
165
+
166
+ attr_writer :m2_repo_var, :short_names
167
+
168
+ def initialize(project)
169
+ @project = project
170
+ end
171
+
172
+ # The classpath variable used to point at the local maven2 repository.
173
+ # Example:
174
+ # eclipse.options.m2_repo_var = 'M2_REPO'
175
+ def m2_repo_var(*values)
176
+ fail "m2_repo_var can only accept one value: #{values}" if values.size > 1
177
+ if values.size > 0
178
+ @m2_repo_var = values[0]
179
+ else
180
+ @m2_repo_var || (@project.parent ? @project.parent.eclipse.options.m2_repo_var : 'M2_REPO')
181
+ end
182
+ end
183
+
184
+ def short_names
185
+ @short_names || (@project.parent ? @project.parent.eclipse.options.short_names : false)
186
+ end
187
+ end
188
+
189
+ def eclipse
190
+ @eclipse ||= Eclipse.new(self)
191
+ @eclipse
192
+ end
193
+
194
+ first_time do
195
+ # Global task "eclipse" generates artifacts for all projects.
196
+ desc 'Generate Eclipse artifacts for all projects'
197
+ Project.local_task('eclipse'=>'artifacts') { |name| "Generating Eclipse project for #{name}" }
198
+ end
199
+
200
+ before_define do |project|
201
+ project.recursive_task('eclipse')
202
+ end
203
+
204
+ after_define(:eclipse => :package) do |project|
205
+ # Need to enhance because using project.projects during load phase of the
206
+ # buildfile has harmful side-effects on project definition order
207
+ project.enhance do
208
+ eclipse = project.task('eclipse')
209
+ # We don't create the .project and .classpath files if the project contains projects.
210
+ if project.projects.empty?
211
+
212
+ eclipse.enhance [ file(project.path_to('.classpath')), file(project.path_to('.project')) ]
213
+
214
+ # The only thing we need to look for is a change in the Buildfile.
215
+ file(project.path_to('.classpath')=>Buildr.application.buildfile) do |task|
216
+ if (project.eclipse.natures.reject { |x| x.is_a?(Symbol) }.size > 0)
217
+ info "Writing #{task.name}"
218
+
219
+ m2repo = Buildr::Repositories.instance.local
220
+
221
+ File.open(task.name, 'w') do |file|
222
+ classpathentry = ClasspathEntryWriter.new project, file
223
+ classpathentry.write do
224
+ # Note: Use the test classpath since Eclipse compiles both "main" and "test" classes using the same classpath
225
+ cp = project.test.compile.dependencies.map(&:to_s) - [ project.compile.target.to_s, project.resources.target.to_s ]
226
+ cp = cp.uniq
227
+
228
+ # Convert classpath elements into applicable Project objects
229
+ cp.collect! { |path| Buildr.projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path }
230
+
231
+ # Remove excluded libs
232
+ cp -= project.eclipse.exclude_libs.map(&:to_s)
233
+
234
+ # project_libs: artifacts created by other projects
235
+ project_libs, others = cp.partition { |path| path.is_a?(Project) }
236
+
237
+ # Separate artifacts under known classpath variable paths
238
+ # including artifacts located in local Maven2 repository
239
+ vars = []
240
+ project.eclipse.classpath_variables.merge(project.eclipse.options.m2_repo_var => m2repo).each do |name, path|
241
+ matching, others = others.partition { |f| File.expand_path(f.to_s).index(path) == 0 }
242
+ matching.each do |m|
243
+ vars << [m, name, path]
244
+ end
245
+ end
246
+
247
+ # Generated: Any non-file classpath elements in the project are assumed to be generated
248
+ libs, generated = others.partition { |path| File.file?(path.to_s) }
249
+
250
+ classpathentry.src project.compile.sources + generated
251
+ classpathentry.src project.resources
252
+
253
+ if project.test.compile.target
254
+ classpathentry.src project.test.compile
255
+ classpathentry.src project.test.resources
256
+ end
257
+
258
+ # Classpath elements from other projects
259
+ classpathentry.src_projects project_libs
260
+
261
+ classpathentry.output project.compile.target if project.compile.target
262
+ classpathentry.lib libs
263
+ classpathentry.var vars
264
+
265
+ project.eclipse.classpath_containers.each { |container|
266
+ classpathentry.con container
267
+ }
268
+ end
269
+ end
270
+ end
271
+ end
272
+
273
+ # The only thing we need to look for is a change in the Buildfile.
274
+ file(project.path_to('.project')=>Buildr.application.buildfile) do |task|
275
+ info "Writing #{task.name}"
276
+ File.open(task.name, 'w') do |file|
277
+ xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
278
+ xml.projectDescription do
279
+ xml.name project.eclipse.name
280
+ xml.projects
281
+ unless project.eclipse.builders.empty?
282
+ xml.buildSpec do
283
+ project.eclipse.builders.each { |builder|
284
+ xml.buildCommand do
285
+ xml.name builder
286
+ end
287
+ }
288
+ end
289
+ end
290
+ unless project.eclipse.natures.empty?
291
+ xml.natures do
292
+ project.eclipse.natures.each { |nature|
293
+ xml.nature nature unless nature.is_a? Symbol
294
+ }
295
+ end
296
+ end
297
+ end
298
+ end
299
+ end
300
+ end
301
+ end
302
+ end
303
+
304
+
305
+ # Writes 'classpathentry' tags in an xml file.
306
+ # It converts tasks to paths.
307
+ # It converts absolute paths to relative paths.
308
+ # It ignores duplicate directories.
309
+ class ClasspathEntryWriter #:nodoc:
310
+ def initialize project, target
311
+ @project = project
312
+ @xml = Builder::XmlMarkup.new(:target=>target, :indent=>2)
313
+ @excludes = [ '**/.svn/', '**/CVS/' ].join('|')
314
+ @paths_written = []
315
+ end
316
+
317
+ def write &block
318
+ @xml.classpath &block
319
+ end
320
+
321
+ def con path
322
+ @xml.classpathentry :kind=>'con', :path=>path
323
+ end
324
+
325
+ def lib libs
326
+ libs.map(&:to_s).sort.uniq.each do |path|
327
+ @xml.classpathentry :kind=>'lib', :path=>relative(path)
328
+ end
329
+ end
330
+
331
+ # Write a classpathentry of kind 'src'.
332
+ # Accept an array of absolute paths or a task.
333
+ def src arg
334
+ if [:sources, :target].all? { |message| arg.respond_to?(message) }
335
+ src_from_task arg
336
+ else
337
+ src_from_absolute_paths arg
338
+ end
339
+ end
340
+
341
+ # Write a classpathentry of kind 'src' for dependent projects.
342
+ # Accept an array of projects.
343
+ def src_projects project_libs
344
+ project_libs.map { |project| project.eclipse.name }.sort.uniq.each do |eclipse_name|
345
+ @xml.classpathentry :kind=>'src', :combineaccessrules=>'false', :path=>"/#{eclipse_name}"
346
+ end
347
+ end
348
+
349
+ def output target
350
+ @xml.classpathentry :kind=>'output', :path=>relative(target)
351
+ end
352
+
353
+ # Write a classpathentry of kind 'var' (variable) for a library in a local repo.
354
+ # * +libs+ is an array of library paths.
355
+ # * +var_name+ is a variable name as defined in Eclipse (e.g., 'M2_REPO').
356
+ # * +var_value+ is the value of this variable (e.g., '/home/me/.m2').
357
+ # E.g., <tt>var([lib1, lib2], 'M2_REPO', '/home/me/.m2/repo')</tt>
358
+ def var(libs)
359
+ libs.each do |lib_path, var_name, var_value|
360
+ lib_artifact = file(lib_path)
361
+
362
+ attribs = { :kind => 'var', :path => lib_path }
363
+
364
+ if lib_artifact.respond_to? :sources_artifact
365
+ attribs[:sourcepath] = lib_artifact.sources_artifact
366
+ end
367
+
368
+ if lib_artifact.respond_to? :javadoc_artifact
369
+ attribs[:javadocpath] = lib_artifact.javadoc_artifact
370
+ end
371
+
372
+ # make all paths relative
373
+ attribs.each_key do |k|
374
+ attribs[k] = attribs[k].to_s.sub(var_value, var_name.to_s) if k.to_s =~ /path/
375
+ end
376
+
377
+ @xml.classpathentry attribs
378
+ end
379
+ end
380
+
381
+ private
382
+
383
+ # Find a path relative to the project's root directory if possible. If the
384
+ # two paths do not share the same root the absolute path is returned. This
385
+ # can happen on Windows, for instance, when the two paths are not on the
386
+ # same drive.
387
+ def relative path
388
+ path or raise "Invalid path '#{path.inspect}'"
389
+ msg = [:to_path, :to_str, :to_s].find { |msg| path.respond_to? msg }
390
+ path = path.__send__(msg)
391
+ begin
392
+ Util.relative_path(File.expand_path(path), @project.path_to)
393
+ rescue ArgumentError
394
+ File.expand_path(path)
395
+ end
396
+ end
397
+
398
+ def src_from_task task
399
+ src_from_absolute_paths task.sources, task.target
400
+ end
401
+
402
+ def src_from_absolute_paths absolute_paths, output=nil
403
+ relative_paths = absolute_paths.map { |src| relative(src) }
404
+ relative_paths.sort.uniq.each do |path|
405
+ unless @paths_written.include?(path)
406
+ attributes = { :kind=>'src', :path=>path, :excluding=>@excludes }
407
+ attributes[:output] = relative(output) if output
408
+ @xml.classpathentry attributes
409
+ @paths_written << path
410
+ end
411
+ end
412
+ end
413
+ end
414
+
415
+ end
416
+
417
+ end # module Buildr
418
+
419
+ class Buildr::Project
420
+ include Buildr::Eclipse
421
+ end
422
+
423
+ # Order is significant for auto-detection, from most specific to least
424
+ require 'buildr/ide/eclipse/plugin'
425
+ require 'buildr/ide/eclipse/scala'
426
+ require 'buildr/ide/eclipse/java'
427
+