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,622 @@
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/common'
18
+ require 'find'
19
+
20
+
21
+ module Buildr
22
+
23
+ # The underlying compiler used by CompileTask.
24
+ # To add a new compiler, extend Compiler::Base and add your compiler using:
25
+ # Buildr::Compiler.add MyCompiler
26
+ module Compiler
27
+
28
+ class << self
29
+
30
+ # Returns true if the specified compiler exists.
31
+ def has?(name)
32
+ compilers.any? { |compiler| compiler.to_sym == name.to_sym }
33
+ end
34
+
35
+ # Select a compiler by its name.
36
+ def select(name)
37
+ compilers.detect { |compiler| compiler.to_sym == name.to_sym }
38
+ end
39
+
40
+ # Adds a compiler to the list of supported compiler.
41
+ #
42
+ # For example:
43
+ # Buildr::Compiler << Buildr::Javac
44
+ def add(compiler)
45
+ @compilers ||= []
46
+ @compilers |= [compiler]
47
+ end
48
+ alias :<< :add
49
+
50
+ # Returns a list of available compilers.
51
+ def compilers
52
+ @compilers ||= []
53
+ end
54
+
55
+ private
56
+
57
+ # Only used by our specs.
58
+ def compilers=(compilers)
59
+ @compilers = compilers
60
+ end
61
+ end
62
+
63
+ # Base class for all compilers, with common functionality. Extend and over-ride as you see fit
64
+ # (see Javac as an example).
65
+ class Base #:nodoc:
66
+
67
+ class << self
68
+
69
+ # The compiler's identifier (e.g. :javac). Inferred from the class name.
70
+ def to_sym
71
+ @symbol ||= name.split('::').last.downcase.to_sym
72
+ end
73
+
74
+ # The compiled language (e.g. :java).
75
+ attr_reader :language
76
+ # Source directories to use if none were specified (e.g. 'java'). Defaults to #language.
77
+ attr_reader :sources
78
+ # Extension for source files (e.g. 'java'). Defaults to language.
79
+ attr_reader :source_ext
80
+ # The target path (e.g. 'classes')
81
+ attr_reader :target
82
+ # Extension for target files (e.g. 'class').
83
+ attr_reader :target_ext
84
+ # The default packaging type (e.g. :jar).
85
+ attr_reader :packaging
86
+
87
+ # Returns true if this compiler applies to any source code found in the listed source
88
+ # directories. For example, Javac returns true if any of the source directories contains
89
+ # a .java file. The default implementation looks to see if there are any files in the
90
+ # specified path with the extension #source_ext.
91
+ def applies_to?(project, task)
92
+ paths = task.sources + [sources].flatten.map { |src| Array(project.path_to(:source, task.usage, src.to_sym)) }
93
+ paths.flatten!
94
+ ext_glob = Array(source_ext).join(',')
95
+
96
+ paths.each { |path|
97
+ Find.find(path) {|found|
98
+ if (!File.directory?(found)) && found.match(/.*\.#{Array(source_ext).join('|')}/)
99
+ return true
100
+ end
101
+ } if File.exist? path
102
+ }
103
+ false
104
+ end
105
+
106
+ # Implementations can use this method to specify various compiler attributes.
107
+ # For example:
108
+ # specify :language=>:java, :target=>'classes', :target_ext=>'class', :packaging=>:jar
109
+ def specify(attrs)
110
+ attrs[:sources] ||= attrs[:language].to_s
111
+ attrs[:source_ext] ||= attrs[:language].to_s
112
+ attrs.each { |name, value| instance_variable_set("@#{name}", value) }
113
+ end
114
+
115
+ # Returns additional dependencies required by this language. For example, since the
116
+ # test framework picks on these, you can use the JUnit framework with Scala.
117
+ # Defaults to obtaining a list of artifact specifications from the REQUIRES constant.
118
+ def dependencies
119
+ []
120
+ end
121
+
122
+ end
123
+
124
+ # Construct a new compiler with the specified options. Note that options may
125
+ # change before the compiler is run.
126
+ def initialize(project, options)
127
+ @project = project
128
+ @options = options
129
+ end
130
+
131
+ # Options for this compiler.
132
+ attr_reader :options
133
+
134
+ # Determines if the compiler needs to run by checking if the target files exist,
135
+ # and if any source files or dependencies are newer than corresponding target files.
136
+ def needed?(sources, target, dependencies)
137
+ map = compile_map(sources, target)
138
+ return false if map.empty?
139
+ return true unless File.exist?(target.to_s)
140
+ source_files_not_yet_compiled = map.select { |source, target| !File.exist?(target) }.to_a
141
+ trace "Compile needed because source file #{source_files_not_yet_compiled[0][0]} has no corresponding #{source_files_not_yet_compiled[0][1]}" unless source_files_not_yet_compiled.empty?
142
+ return true if map.any? { |source, target| !File.exist?(target) || File.stat(source).mtime > File.stat(target).mtime }
143
+ oldest = map.map { |source, target| File.stat(target).mtime }.min
144
+ return dependencies.any? { |path| file(path).timestamp > oldest }
145
+ end
146
+
147
+ # Compile all files lists in sources (files and directories) into target using the
148
+ # specified dependencies.
149
+ def compile(sources, target, dependencies)
150
+ raise 'Not implemented'
151
+ end
152
+
153
+ # Returns additional dependencies required by this language. For example, since the
154
+ # test framework picks on these, you can use the JUnit framework with Scala.
155
+ def dependencies
156
+ self.class.dependencies
157
+ end
158
+
159
+ protected
160
+
161
+ # Use this to complain about CompileTask options not supported by this compiler.
162
+ #
163
+ # For example:
164
+ # def compile(files, task)
165
+ # check_options task, OPTIONS
166
+ # . . .
167
+ # end
168
+ def check_options(options, *supported)
169
+ unsupported = options.to_hash.keys - supported.flatten
170
+ raise ArgumentError, "No such option: #{unsupported.join(' ')}" unless unsupported.empty?
171
+ end
172
+
173
+ # Expands a list of source directories/files into a list of files that have the #source_ext extension.
174
+ def files_from_sources(sources)
175
+ ext_glob = Array(self.class.source_ext).join(',')
176
+ sources.flatten.map { |source| File.directory?(source) ? FileList["#{source}/**/*.{#{ext_glob}}"] : source }.
177
+ flatten.reject { |file| File.directory?(file) }.map { |file| File.expand_path(file) }.uniq
178
+ end
179
+
180
+ # The compile map is a hash that associates source files with target files based
181
+ # on a list of source directories and target directory. The compile task uses this
182
+ # to determine if there are source files to compile, and which source files to compile.
183
+ # The default method maps all files in the source directories with #source_ext into
184
+ # paths in the target directory with #target_ext (e.g. 'source/foo.java'=>'target/foo.class').
185
+ def compile_map(sources, target)
186
+ target_ext = self.class.target_ext
187
+ ext_glob = Array(self.class.source_ext).join(',')
188
+ sources.flatten.map{|f| File.expand_path(f)}.inject({}) do |map, source|
189
+ if File.directory?(source)
190
+ FileList["#{source}/**/*.{#{ext_glob}}"].reject { |file| File.directory?(file) }.
191
+ each { |file| map[file] = File.join(target, Util.relative_path(file, source).ext(target_ext)) }
192
+ else
193
+ # try to extract package name from .java or .scala files
194
+ if ['.java', '.scala', '.groovy'].include? File.extname(source)
195
+ package = findFirst(source, /^\s*package\s+(\S+)\s*;?\s*$/)
196
+ map[source] = package ? File.join(target, package[1].gsub('.', '/'), File.basename(source).ext(target_ext)) : target
197
+ elsif
198
+ map[source] = target
199
+ end
200
+ end
201
+ map
202
+ end
203
+ end
204
+
205
+ private
206
+
207
+ def findFirst(file, pattern)
208
+ match = nil
209
+ File.open(file, "r") do |infile|
210
+ while (line = infile.gets)
211
+ match = line.match(pattern)
212
+ break if match
213
+ end
214
+ end
215
+ match
216
+ end
217
+
218
+ end
219
+ end
220
+
221
+
222
+ # Compile task.
223
+ #
224
+ # Attempts to determine which compiler to use based on the project layout, for example,
225
+ # uses the Javac compiler if it finds any .java files in src/main/java. You can also
226
+ # select the compiler explicitly:
227
+ # compile.using(:scalac)
228
+ #
229
+ # Accepts multiple source directories that are invoked as prerequisites before compilation.
230
+ # You can pass a task as a source directory:
231
+ # compile.from(apt)
232
+ #
233
+ # Likewise, dependencies are invoked before compiling. All dependencies are evaluated as
234
+ # #artifacts, so you can pass artifact specifications and even projects:
235
+ # compile.with('module1.jar', 'log4j:log4j:jar:1.0', project('foo'))
236
+ #
237
+ # Creates a file task for the target directory, so executing that task as a dependency will
238
+ # execute the compile task first.
239
+ #
240
+ # Compiler options are inherited form a parent task, e.g. the foo:bar:compile task inherits
241
+ # its options from the foo:compile task. Even if foo is an empty project that does not compile
242
+ # any classes itself, you can use it to set compile options for all its sub-projects.
243
+ #
244
+ # Normally, the project will take care of setting the source and target directory, and you
245
+ # only need to set options and dependencies. See Project#compile.
246
+ class CompileTask < Rake::Task
247
+
248
+ def initialize(*args) #:nodoc:
249
+ super
250
+ parent_task = Project.parent_task(name)
251
+ inherit = lambda { |hash, key| parent_task.options[key] } if parent_task.respond_to?(:options)
252
+ @options = OpenObject.new &inherit
253
+ @sources = FileList[]
254
+ @dependencies = FileList[]
255
+
256
+ enhance do |task|
257
+ unless sources.empty?
258
+ raise 'No compiler selected and can\'t determine which compiler to use' unless compiler
259
+ raise 'No target directory specified' unless target
260
+ mkpath target.to_s
261
+ info "Compiling #{task.name.gsub(/:[^:]*$/, '')} into #{target.to_s}"
262
+ @compiler.compile(sources.map(&:to_s), target.to_s, dependencies.map(&:to_s))
263
+ # By touching the target we let other tasks know we did something,
264
+ # and also prevent recompiling again for dependencies.
265
+ touch target.to_s
266
+ end
267
+ end
268
+ end
269
+
270
+ # Source directories.
271
+ attr_accessor :sources
272
+
273
+ # :call-seq:
274
+ # from(*sources) => self
275
+ #
276
+ # Adds source directories and files to compile, and returns self.
277
+ #
278
+ # For example:
279
+ # compile.from('src/java').into('classes').with('module1.jar')
280
+ def from(*sources)
281
+ @sources |= sources.flatten
282
+ guess_compiler if @compiler.nil? && sources.flatten.any? { |source| File.exist?(source.to_s) }
283
+ self
284
+ end
285
+
286
+ # *Deprecated*: Use dependencies instead.
287
+ def classpath
288
+ Buildr.application.deprecated 'Use dependencies instead.'
289
+ dependencies
290
+ end
291
+
292
+ # *Deprecated*: Use dependencies= instead.
293
+ def classpath=(artifacts)
294
+ Buildr.application.deprecated 'Use dependencies= instead.'
295
+ self.dependencies = artifacts
296
+ end
297
+
298
+ # Compilation dependencies.
299
+ attr_accessor :dependencies
300
+
301
+ # :call-seq:
302
+ # with(*artifacts) => self
303
+ #
304
+ # Adds files and artifacts as dependencies, and returns self.
305
+ #
306
+ # Calls #artifacts on the arguments, so you can pass artifact specifications,
307
+ # tasks, projects, etc. Use this rather than setting the dependencies array directly.
308
+ #
309
+ # For example:
310
+ # compile.with('module1.jar', 'log4j:log4j:jar:1.0', project('foo'))
311
+ def with(*specs)
312
+ @dependencies |= Buildr.artifacts(specs.flatten).uniq
313
+ self
314
+ end
315
+
316
+ # The target directory for the compiled code.
317
+ attr_reader :target
318
+
319
+ # :call-seq:
320
+ # into(path) => self
321
+ #
322
+ # Sets the target directory and returns self. This will also set the compile task
323
+ # as a prerequisite to a file task on the target directory.
324
+ #
325
+ # For example:
326
+ # compile(src_dir).into(target_dir).with(artifacts)
327
+ # Both compile.invoke and file(target_dir).invoke will compile the source files.
328
+ def into(path)
329
+ @target = file(path.to_s).enhance([self]) unless @target.to_s == path.to_s
330
+ self
331
+ end
332
+
333
+ # Returns the compiler options.
334
+ attr_reader :options
335
+
336
+ # :call-seq:
337
+ # using(options) => self
338
+ #
339
+ # Sets the compiler options from a hash and returns self. Can also be used to
340
+ # select the compiler.
341
+ #
342
+ # For example:
343
+ # compile.using(:warnings=>true, :source=>'1.5')
344
+ # compile.using(:scala)
345
+ def using(*args)
346
+ args.pop.each { |key, value| options.send "#{key}=", value } if Hash === args.last
347
+ self.compiler = args.pop until args.empty?
348
+ self
349
+ end
350
+
351
+ # Returns the compiler if known. The compiler is either automatically selected
352
+ # based on existing source directories (e.g. src/main/java), or by requesting
353
+ # a specific compiler (see #using).
354
+ def compiler
355
+ guess_compiler unless @compiler
356
+ @compiler && @compiler.class.to_sym
357
+ end
358
+
359
+ # Returns the compiled language, if known. See also #compiler.
360
+ def language
361
+ compiler && @compiler.class.language
362
+ end
363
+
364
+ # Returns the default packaging type for this compiler, if known.
365
+ def packaging
366
+ compiler && @compiler.class.packaging
367
+ end
368
+
369
+ def timestamp #:nodoc:
370
+ # If we compiled successfully, then the target directory reflects that.
371
+ # If we didn't, see needed?
372
+ target ? target.timestamp : Rake::EARLY
373
+ end
374
+
375
+ # The project this task belongs to.
376
+ attr_reader :project
377
+
378
+ # The usage, one of :main or :test.
379
+ attr_reader :usage
380
+
381
+ protected
382
+
383
+ # Selects which compiler to use.
384
+ def compiler=(name) #:nodoc:
385
+ cls = Compiler.select(name) or raise ArgumentError, "No #{name} compiler available. Did you install it?"
386
+ return self if cls === @compiler
387
+ @compiler = cls.new(project, options)
388
+ from Array(cls.sources).map { |path| project.path_to(:source, usage, path) }.
389
+ select { |path| File.exist?(path) } if sources.empty?
390
+ into project.path_to(:target, usage, cls.target) unless target
391
+ with Array(@compiler.dependencies)
392
+ self
393
+ end
394
+
395
+ # Associates this task with project and particular usage (:main, :test).
396
+ def associate_with(project, usage) #:nodoc:
397
+ @project, @usage = project, usage
398
+ guess_compiler
399
+ end
400
+
401
+ # Try to guess if we have a compiler to match source files.
402
+ def guess_compiler #:nodoc:
403
+ candidate = Compiler.compilers.detect { |cls| cls.applies_to?(project, self) }
404
+ self.compiler = candidate if candidate
405
+ end
406
+
407
+ private
408
+
409
+ def needed? #:nodoc:
410
+ return false if sources.empty?
411
+ # Fail during invoke.
412
+ return true unless @compiler && target
413
+ return @compiler.needed?(sources.map(&:to_s), target.to_s, dependencies.map(&:to_s))
414
+ end
415
+
416
+ def invoke_prerequisites(args, chain) #:nodoc:
417
+ @sources = Array(@sources).map(&:to_s).uniq
418
+ @dependencies = FileList[@dependencies.uniq]
419
+ @prerequisites |= @dependencies + @sources
420
+ super
421
+ end
422
+
423
+ end
424
+
425
+
426
+ # The resources task is executed by the compile task to copy resource files over
427
+ # to the target directory. You can enhance this task in the normal way, but mostly
428
+ # you will use the task's filter.
429
+ #
430
+ # For example:
431
+ # resources.filter.using 'Copyright'=>'Acme Inc, 2007'
432
+ class ResourcesTask < Rake::Task
433
+
434
+ # Returns the filter used to copy resources over. See Buildr::Filter.
435
+ attr_reader :filter
436
+
437
+ def initialize(*args) #:nodoc:
438
+ super
439
+ @filter = Buildr::Filter.new
440
+ @filter.using Buildr.settings.profile['filter'] if Hash === Buildr.settings.profile['filter']
441
+ enhance do
442
+ target.invoke if target
443
+ end
444
+ end
445
+
446
+ # :call-seq:
447
+ # include(*files) => self
448
+ #
449
+ # Includes the specified files in the filter and returns self.
450
+ def include(*files)
451
+ filter.include *files
452
+ self
453
+ end
454
+
455
+ # :call-seq:
456
+ # exclude(*files) => self
457
+ #
458
+ # Excludes the specified files in the filter and returns self.
459
+ def exclude(*files)
460
+ filter.exclude *files
461
+ self
462
+ end
463
+
464
+ # :call-seq:
465
+ # from(*sources) => self
466
+ #
467
+ # Adds additional directories from which to copy resources.
468
+ #
469
+ # For example:
470
+ # resources.from _('src/etc')
471
+ def from(*sources)
472
+ filter.from *sources
473
+ self
474
+ end
475
+
476
+ # Returns the list of source directories (each being a file task).
477
+ def sources
478
+ filter.sources
479
+ end
480
+
481
+ # :call-seq:
482
+ # target => task
483
+ #
484
+ # Returns the filter's target directory as a file task.
485
+ def target
486
+ filter.into @project.path_to(:target, @usage, :resources) unless filter.target || sources.empty?
487
+ filter.target
488
+ end
489
+
490
+ def prerequisites #:nodoc:
491
+ super + filter.sources.flatten
492
+ end
493
+
494
+ protected
495
+
496
+ # Associates this task with project and particular usage (:main, :test).
497
+ def associate_with(project, usage) #:nodoc:
498
+ @project, @usage = project, usage
499
+ end
500
+
501
+ end
502
+
503
+
504
+ # Methods added to Project for compiling, handling of resources and generating source documentation.
505
+ module Compile
506
+
507
+ include Extension
508
+
509
+ first_time do
510
+ desc 'Compile all projects'
511
+ Project.local_task('compile') { |name| "Compiling #{name}" }
512
+ end
513
+
514
+ before_define(:compile) do |project|
515
+ resources = ResourcesTask.define_task('resources')
516
+ resources.send :associate_with, project, :main
517
+ project.path_to(:source, :main, :resources).tap { |dir| resources.from dir if File.exist?(dir) }
518
+
519
+ compile = CompileTask.define_task('compile'=>resources)
520
+ compile.send :associate_with, project, :main
521
+ project.recursive_task('compile')
522
+ end
523
+
524
+ after_define(:compile) do |project|
525
+ if project.compile.target
526
+ # This comes last because the target path is set inside the project definition.
527
+ project.build project.compile.target
528
+ project.clean do
529
+ rm_rf project.compile.target.to_s, :verbose=>false
530
+ end
531
+ end
532
+ end
533
+
534
+
535
+ # :call-seq:
536
+ # compile(*sources) => CompileTask
537
+ # compile(*sources) { |task| .. } => CompileTask
538
+ #
539
+ # The compile task does what its name suggests. This method returns the project's
540
+ # CompileTask. It also accepts a list of source directories and files to compile
541
+ # (equivalent to calling CompileTask#from on the task), and a block for any
542
+ # post-compilation work.
543
+ #
544
+ # The compile task attempts to guess which compiler to use. For example, if it finds
545
+ # any Java files in the src/main/java directory, it will use the Java compiler and
546
+ # create class files in the target/classes directory.
547
+ #
548
+ # You can also configure it yourself by telling it which compiler to use, pointing
549
+ # it as source directories and chooing a different target directory.
550
+ #
551
+ # For example:
552
+ # # Include Log4J and the api sub-project artifacts.
553
+ # compile.with 'log4j:log4j:jar:1.2', project('api')
554
+ # # Include Apt-generated source files.
555
+ # compile.from apt
556
+ # # For JavaC, force target compatibility.
557
+ # compile.options.source = '1.6'
558
+ # # Run the OpenJPA bytecode enhancer after compilation.
559
+ # compile { open_jpa_enhance }
560
+ # # Pick a given compiler.
561
+ # compile.using(:scalac).from('src/scala')
562
+ #
563
+ # For more information, see CompileTask.
564
+ def compile(*sources, &block)
565
+ task('compile').from(sources).enhance &block
566
+ end
567
+
568
+ # :call-seq:
569
+ # resources(*prereqs) => ResourcesTask
570
+ # resources(*prereqs) { |task| .. } => ResourcesTask
571
+ #
572
+ # The resources task is executed by the compile task to copy resources files
573
+ # from the resource directory into the target directory. By default the resources
574
+ # task copies files from the src/main/resources into the target/resources directory.
575
+ #
576
+ # This method returns the project's resources task. It also accepts a list of
577
+ # prerequisites and a block, used to enhance the resources task.
578
+ #
579
+ # Resources files are copied and filtered (see Buildr::Filter for more information).
580
+ # The default filter uses the profile properties for the current environment.
581
+ #
582
+ # For example:
583
+ # resources.from _('src/etc')
584
+ # resources.filter.using 'Copyright'=>'Acme Inc, 2007'
585
+ #
586
+ # Or in your profiles.yaml file:
587
+ # common:
588
+ # Copyright: Acme Inc, 2007
589
+ def resources(*prereqs, &block)
590
+ task('resources').enhance prereqs, &block
591
+ end
592
+
593
+ end
594
+
595
+
596
+ class Options
597
+
598
+ # Returns the debug option (environment variable DEBUG).
599
+ def debug
600
+ (ENV['DEBUG'] || ENV['debug']) !~ /(no|off|false)/
601
+ end
602
+
603
+ # Sets the debug option (environment variable DEBUG).
604
+ #
605
+ # You can turn this option off directly, or by setting the environment variable
606
+ # DEBUG to +no+. For example:
607
+ # buildr build DEBUG=no
608
+ #
609
+ # The release tasks runs a build with <tt>DEBUG=no</tt>.
610
+ def debug=(flag)
611
+ ENV['debug'] = nil
612
+ ENV['DEBUG'] = flag.to_s
613
+ end
614
+
615
+ end
616
+
617
+ end
618
+
619
+
620
+ class Buildr::Project
621
+ include Buildr::Compile
622
+ end