novoda-buildr 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/CHANGELOG +1050 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +45 -0
  6. data/_buildr +29 -0
  7. data/_jbuildr +29 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/xmlbeans.rb +93 -0
  27. data/bin/buildr +19 -0
  28. data/buildr.buildfile +58 -0
  29. data/buildr.gemspec +65 -0
  30. data/doc/_config.yml +1 -0
  31. data/doc/_layouts/default.html +88 -0
  32. data/doc/_layouts/preface.html +22 -0
  33. data/doc/artifacts.textile +211 -0
  34. data/doc/building.textile +245 -0
  35. data/doc/contributing.textile +252 -0
  36. data/doc/css/default.css +236 -0
  37. data/doc/css/print.css +101 -0
  38. data/doc/css/syntax.css +23 -0
  39. data/doc/download.textile +90 -0
  40. data/doc/extending.textile +205 -0
  41. data/doc/images/1442160941-frontcover.jpg +0 -0
  42. data/doc/images/asf-logo.gif +0 -0
  43. data/doc/images/asf-logo.png +0 -0
  44. data/doc/images/buildr-hires.png +0 -0
  45. data/doc/images/buildr.png +0 -0
  46. data/doc/images/favicon.png +0 -0
  47. data/doc/images/growl-icon.tiff +0 -0
  48. data/doc/images/note.png +0 -0
  49. data/doc/images/project-structure.png +0 -0
  50. data/doc/images/tip.png +0 -0
  51. data/doc/images/zbuildr.png +0 -0
  52. data/doc/images/zbuildr.tif +0 -0
  53. data/doc/index.textile +69 -0
  54. data/doc/installing.textile +265 -0
  55. data/doc/languages.textile +459 -0
  56. data/doc/mailing_lists.textile +25 -0
  57. data/doc/more_stuff.textile +457 -0
  58. data/doc/packaging.textile +429 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +276 -0
  61. data/doc/quick_start.textile +210 -0
  62. data/doc/scripts/buildr-git.rb +512 -0
  63. data/doc/scripts/gitflow.rb +296 -0
  64. data/doc/scripts/install-jruby.sh +44 -0
  65. data/doc/scripts/install-linux.sh +72 -0
  66. data/doc/scripts/install-osx.sh +52 -0
  67. data/doc/settings_profiles.textile +287 -0
  68. data/doc/testing.textile +233 -0
  69. data/etc/KEYS +151 -0
  70. data/lib/buildr.rb +36 -0
  71. data/lib/buildr/core.rb +35 -0
  72. data/lib/buildr/core/application.rb +662 -0
  73. data/lib/buildr/core/build.rb +463 -0
  74. data/lib/buildr/core/checks.rb +254 -0
  75. data/lib/buildr/core/common.rb +150 -0
  76. data/lib/buildr/core/compile.rb +608 -0
  77. data/lib/buildr/core/environment.rb +129 -0
  78. data/lib/buildr/core/filter.rb +363 -0
  79. data/lib/buildr/core/generate.rb +195 -0
  80. data/lib/buildr/core/help.rb +119 -0
  81. data/lib/buildr/core/osx.rb +46 -0
  82. data/lib/buildr/core/progressbar.rb +156 -0
  83. data/lib/buildr/core/project.rb +971 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +774 -0
  86. data/lib/buildr/core/transports.rb +559 -0
  87. data/lib/buildr/core/util.rb +449 -0
  88. data/lib/buildr/groovy.rb +19 -0
  89. data/lib/buildr/groovy/bdd.rb +106 -0
  90. data/lib/buildr/groovy/compiler.rb +138 -0
  91. data/lib/buildr/groovy/shell.rb +48 -0
  92. data/lib/buildr/ide.rb +19 -0
  93. data/lib/buildr/ide/eclipse.rb +424 -0
  94. data/lib/buildr/ide/eclipse.rb~ +424 -0
  95. data/lib/buildr/ide/eclipse/java.rb +53 -0
  96. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  97. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  98. data/lib/buildr/ide/idea.ipr.template +300 -0
  99. data/lib/buildr/ide/idea.rb +190 -0
  100. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  101. data/lib/buildr/ide/idea7x.rb +212 -0
  102. data/lib/buildr/java.rb +23 -0
  103. data/lib/buildr/java/ant.rb +94 -0
  104. data/lib/buildr/java/bdd.rb +464 -0
  105. data/lib/buildr/java/cobertura.rb +274 -0
  106. data/lib/buildr/java/commands.rb +217 -0
  107. data/lib/buildr/java/compiler.rb +349 -0
  108. data/lib/buildr/java/deprecated.rb +141 -0
  109. data/lib/buildr/java/emma.rb +244 -0
  110. data/lib/buildr/java/jruby.rb +117 -0
  111. data/lib/buildr/java/jtestr_runner.rb.erb +118 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  113. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  114. data/lib/buildr/java/packaging.rb +717 -0
  115. data/lib/buildr/java/pom.rb +174 -0
  116. data/lib/buildr/java/rjb.rb +155 -0
  117. data/lib/buildr/java/test_result.rb +327 -0
  118. data/lib/buildr/java/tests.rb +341 -0
  119. data/lib/buildr/java/version_requirement.rb +172 -0
  120. data/lib/buildr/packaging.rb +24 -0
  121. data/lib/buildr/packaging/archive.rb +491 -0
  122. data/lib/buildr/packaging/artifact.rb +750 -0
  123. data/lib/buildr/packaging/artifact_namespace.rb +980 -0
  124. data/lib/buildr/packaging/artifact_search.rb +140 -0
  125. data/lib/buildr/packaging/gems.rb +106 -0
  126. data/lib/buildr/packaging/package.rb +241 -0
  127. data/lib/buildr/packaging/tar.rb +186 -0
  128. data/lib/buildr/packaging/version_requirement.rb +172 -0
  129. data/lib/buildr/packaging/zip.rb +73 -0
  130. data/lib/buildr/packaging/ziptask.rb +316 -0
  131. data/lib/buildr/resources/buildr.icns +0 -0
  132. data/lib/buildr/scala.rb +25 -0
  133. data/lib/buildr/scala/bdd.rb +114 -0
  134. data/lib/buildr/scala/compiler.rb +196 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  137. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  138. data/lib/buildr/scala/shell.rb +60 -0
  139. data/lib/buildr/scala/tests.rb +157 -0
  140. data/lib/buildr/shell.rb +180 -0
  141. data/rakelib/all-in-one.rake +84 -0
  142. data/rakelib/checks.rake +57 -0
  143. data/rakelib/doc.rake +92 -0
  144. data/rakelib/jekylltask.rb +120 -0
  145. data/rakelib/package.rake +73 -0
  146. data/rakelib/release.rake +152 -0
  147. data/rakelib/rspec.rake +73 -0
  148. data/rakelib/setup.rake +54 -0
  149. data/rakelib/stage.rake +214 -0
  150. data/spec/addon/drb_spec.rb +328 -0
  151. data/spec/core/application_spec.rb +509 -0
  152. data/spec/core/build_spec.rb +678 -0
  153. data/spec/core/checks_spec.rb +519 -0
  154. data/spec/core/common_spec.rb +670 -0
  155. data/spec/core/compile_spec.rb +624 -0
  156. data/spec/core/extension_spec.rb +201 -0
  157. data/spec/core/generate_spec.rb +33 -0
  158. data/spec/core/project_spec.rb +762 -0
  159. data/spec/core/test_spec.rb +1175 -0
  160. data/spec/core/transport_spec.rb +537 -0
  161. data/spec/core/util_spec.rb +67 -0
  162. data/spec/groovy/bdd_spec.rb +80 -0
  163. data/spec/groovy/compiler_spec.rb +240 -0
  164. data/spec/ide/eclipse_spec.rb +650 -0
  165. data/spec/ide/idea7x_spec.rb +84 -0
  166. data/spec/java/ant_spec.rb +33 -0
  167. data/spec/java/bdd_spec.rb +379 -0
  168. data/spec/java/cobertura_spec.rb +85 -0
  169. data/spec/java/compiler_spec.rb +446 -0
  170. data/spec/java/emma_spec.rb +119 -0
  171. data/spec/java/java_spec.rb +124 -0
  172. data/spec/java/packaging_spec.rb +1140 -0
  173. data/spec/java/test_coverage_helper.rb +257 -0
  174. data/spec/java/tests_spec.rb +493 -0
  175. data/spec/packaging/archive_spec.rb +538 -0
  176. data/spec/packaging/artifact_namespace_spec.rb +697 -0
  177. data/spec/packaging/artifact_spec.rb +802 -0
  178. data/spec/packaging/packaging_helper.rb +63 -0
  179. data/spec/packaging/packaging_spec.rb +684 -0
  180. data/spec/sandbox.rb +148 -0
  181. data/spec/scala/bdd_spec.rb +119 -0
  182. data/spec/scala/compiler_spec.rb +284 -0
  183. data/spec/scala/scala.rb +38 -0
  184. data/spec/scala/tests_spec.rb +263 -0
  185. data/spec/spec_helpers.rb +340 -0
  186. data/spec/version_requirement_spec.rb +143 -0
  187. metadata +384 -0
@@ -0,0 +1,24 @@
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/packaging/artifact'
18
+ require 'buildr/packaging/package'
19
+ require 'buildr/packaging/archive'
20
+ require 'buildr/packaging/ziptask'
21
+ require 'buildr/packaging/tar'
22
+ require 'buildr/packaging/gems'
23
+ autoload :Zlib, 'zlib'
24
+ autoload :Zip, 'buildr/packaging/zip'
@@ -0,0 +1,491 @@
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
18
+
19
+ # Base class for ZipTask, TarTask and other archives.
20
+ class ArchiveTask < Rake::FileTask
21
+
22
+ # Which files go where. All the rules for including, excluding and merging files
23
+ # are handled by this object.
24
+ class Path #:nodoc:
25
+
26
+ # Returns the archive from this path.
27
+ attr_reader :root
28
+
29
+ def initialize(root, path)
30
+ @root = root
31
+ @path = path.empty? ? path : "#{path}/"
32
+ @includes = FileList[]
33
+ @excludes = []
34
+ # Expand source files added to this path.
35
+ expand_src = proc { @includes.map{ |file| file.to_s }.uniq }
36
+ @sources = [ expand_src ]
37
+ # Add files and directories added to this path.
38
+ @actions = [] << proc do |file_map|
39
+ expand_src.call.each do |path|
40
+ unless excluded?(path)
41
+ if File.directory?(path)
42
+ in_directory path do |file, rel_path|
43
+ dest = "#{@path}#{rel_path}"
44
+ trace "Adding #{dest}"
45
+ file_map[dest] = file
46
+ end
47
+ else
48
+ trace "Adding #{@path}#{File.basename(path)}"
49
+ file_map["#{@path}#{File.basename(path)}"] = path
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ # :call-seq:
57
+ # include(*files) => self
58
+ # include(*files, :path=>path) => self
59
+ # include(file, :as=>name) => self
60
+ # include(:from=>path) => self
61
+ # include(*files, :merge=>true) => self
62
+ def include(*args)
63
+ options = args.pop if Hash === args.last
64
+ files = args.flatten
65
+ raise 'AchiveTask.include() values should not include nil' if files.include? nil
66
+
67
+ if options.nil? || options.empty?
68
+ @includes.include *files.flatten
69
+ elsif options[:path]
70
+ sans_path = options.reject { |k,v| k == :path }
71
+ path(options[:path]).include *files + [sans_path]
72
+ elsif options[:as]
73
+ raise 'You can only use the :as option in combination with the :path option' unless options.size == 1
74
+ raise 'You can only use one file with the :as option' unless files.size == 1
75
+ include_as files.first.to_s, options[:as]
76
+ elsif options[:from]
77
+ raise 'You can only use the :from option in combination with the :path option' unless options.size == 1
78
+ raise 'You cannot use the :from option with file names' unless files.empty?
79
+ fail 'AchiveTask.include() :from value should not be nil' if [options[:from]].flatten.include? nil
80
+ [options[:from]].flatten.each { |path| include_as path.to_s, '.' }
81
+ elsif options[:merge]
82
+ raise 'You can only use the :merge option in combination with the :path option' unless options.size == 1
83
+ files.each { |file| merge file }
84
+ else
85
+ raise "Unrecognized option #{options.keys.join(', ')}"
86
+ end
87
+ self
88
+ end
89
+ alias :add :include
90
+ alias :<< :include
91
+
92
+ # :call-seq:
93
+ # exclude(*files) => self
94
+ def exclude(*files)
95
+ files = files.flatten.map(&:to_s)
96
+ @excludes |= files
97
+ @excludes |= files.reject { |f| f =~ /\*$/ }.map { |f| "#{f}/*" }
98
+ self
99
+ end
100
+
101
+ # :call-seq:
102
+ # merge(*files) => Merge
103
+ # merge(*files, :path=>name) => Merge
104
+ def merge(*args)
105
+ options = Hash === args.last ? args.pop : {}
106
+ files = args.flatten
107
+ rake_check_options options, :path
108
+ raise ArgumentError, "Expected at least one file to merge" if files.empty?
109
+ path = options[:path] || @path
110
+ expanders = files.collect do |file|
111
+ @sources << proc { file.to_s }
112
+ expander = ZipExpander.new(file)
113
+ @actions << proc { |file_map| expander.expand(file_map, path) }
114
+ expander
115
+ end
116
+ Merge.new(expanders)
117
+ end
118
+
119
+ # Returns a Path relative to this one.
120
+ def path(path)
121
+ return self if path.nil?
122
+ return root.path(path[1..-1]) if path[0] == ?/
123
+ root.path("#{@path}#{path}")
124
+ end
125
+
126
+ # Returns all the source files.
127
+ def sources #:nodoc:
128
+ @sources.map{ |source| source.call }.flatten
129
+ end
130
+
131
+ def add_files(file_map) #:nodoc:
132
+ @actions.each { |action| action.call(file_map) }
133
+ end
134
+
135
+ # :call-seq:
136
+ # exist => boolean
137
+ #
138
+ # Returns true if this path exists. This only works if the path has any entries in it,
139
+ # so exist on path happens to be the opposite of empty.
140
+ def exist?
141
+ !entries.empty?
142
+ end
143
+
144
+ # :call-seq:
145
+ # empty? => boolean
146
+ #
147
+ # Returns true if this path is empty (has no other entries inside).
148
+ def empty?
149
+ entries.all? { |entry| entry.empty? }
150
+ end
151
+
152
+ # :call-seq:
153
+ # contain(file*) => boolean
154
+ #
155
+ # Returns true if this ZIP file path contains all the specified files. You can use relative
156
+ # file names and glob patterns (using *, **, etc).
157
+ def contain?(*files)
158
+ files.all? { |file| entries.detect { |entry| File.fnmatch(file, entry.to_s) } }
159
+ end
160
+
161
+ # :call-seq:
162
+ # entry(name) => ZipEntry
163
+ #
164
+ # Returns a ZIP file entry. You can use this to check if the entry exists and its contents,
165
+ # for example:
166
+ # package(:jar).path("META-INF").entry("LICENSE").should contain(/Apache Software License/)
167
+ def entry(name)
168
+ root.entry("#{@path}#{name}")
169
+ end
170
+
171
+ def to_s
172
+ @path
173
+ end
174
+
175
+ protected
176
+
177
+ def include_as(source, as)
178
+ @sources << proc { source }
179
+ @actions << proc do |file_map|
180
+ file = source.to_s
181
+ unless excluded?(file)
182
+ if File.directory?(file)
183
+ in_directory file do |file, rel_path|
184
+ path = rel_path.split('/')[1..-1]
185
+ path.unshift as unless as == '.'
186
+ dest = "#{@path}#{path.join('/')}"
187
+ trace "Adding #{dest}"
188
+ file_map[dest] = file
189
+ end
190
+ else
191
+ trace "Adding #{@path}#{as}"
192
+ file_map["#{@path}#{as}"] = file
193
+ end
194
+ end
195
+ end
196
+ end
197
+
198
+ def in_directory(dir)
199
+ prefix = Regexp.new('^' + Regexp.escape(File.dirname(dir) + File::SEPARATOR))
200
+ Util.recursive_with_dot_files(dir).reject { |file| excluded?(file) }.
201
+ each { |file| yield file, file.sub(prefix, '') }
202
+ end
203
+
204
+ def excluded?(file)
205
+ @excludes.any? { |exclude| File.fnmatch(exclude, file) }
206
+ end
207
+
208
+ def entries #:nodoc:
209
+ return root.entries unless @path
210
+ @entries ||= root.entries.inject([]) { |selected, entry|
211
+ selected << entry.name.sub(@path, "") if entry.name.index(@path) == 0
212
+ selected
213
+ }
214
+ end
215
+
216
+ end
217
+
218
+
219
+ class Merge
220
+ def initialize(expanders)
221
+ @expanders = expanders
222
+ end
223
+
224
+ def include(*files)
225
+ @expanders.each { |expander| expander.include(*files) }
226
+ self
227
+ end
228
+ alias :<< :include
229
+
230
+ def exclude(*files)
231
+ @expanders.each { |expander| expander.exclude(*files) }
232
+ self
233
+ end
234
+ end
235
+
236
+
237
+ # Extend one Zip file into another.
238
+ class ZipExpander #:nodoc:
239
+
240
+ def initialize(zip_file)
241
+ @zip_file = zip_file.to_s
242
+ @includes = []
243
+ @excludes = []
244
+ end
245
+
246
+ def include(*files)
247
+ @includes |= files
248
+ self
249
+ end
250
+ alias :<< :include
251
+
252
+ def exclude(*files)
253
+ @excludes |= files
254
+ self
255
+ end
256
+
257
+ def expand(file_map, path)
258
+ @includes = ['*'] if @includes.empty?
259
+ Zip::ZipFile.open(@zip_file) do |source|
260
+ source.entries.reject { |entry| entry.directory? }.each do |entry|
261
+ if @includes.any? { |pattern| File.fnmatch(pattern, entry.name) } &&
262
+ !@excludes.any? { |pattern| File.fnmatch(pattern, entry.name) }
263
+ dest = path =~ /^\/?$/ ? entry.name : Util.relative_path(path + "/" + entry.name)
264
+ trace "Adding #{dest}"
265
+ file_map[dest] = lambda { |output| output.write source.read(entry) }
266
+ end
267
+ end
268
+ end
269
+ end
270
+
271
+ end
272
+
273
+
274
+ def initialize(*args) #:nodoc:
275
+ super
276
+ clean
277
+
278
+ # Make sure we're the last enhancements, so other enhancements can add content.
279
+ enhance do
280
+ @file_map = {}
281
+ enhance do
282
+ send 'create' if respond_to?(:create)
283
+ # We're here because the archive file does not exist, or one of the files is newer than the archive contents;
284
+ # we need to make sure the archive doesn't exist (e.g. opening an existing Zip will add instead of create).
285
+ # We also want to protect against partial updates.
286
+ rm name rescue nil
287
+ mkpath File.dirname(name)
288
+ begin
289
+ @paths.each do |name, object|
290
+ @file_map[name] = nil unless name.empty?
291
+ object.add_files(@file_map)
292
+ end
293
+ create_from @file_map
294
+ rescue
295
+ rm name rescue nil
296
+ raise
297
+ end
298
+ end
299
+ end
300
+ end
301
+
302
+ # :call-seq:
303
+ # clean => self
304
+ #
305
+ # Removes all previously added content from this archive.
306
+ # Use this method if you want to remove default content from a package.
307
+ # For example, package(:jar) by default includes compiled classes and resources,
308
+ # using this method, you can create an empty jar and afterwards add the
309
+ # desired content to it.
310
+ #
311
+ # package(:jar).clean.include path_to('desired/content')
312
+ def clean
313
+ @paths = { '' => Path.new(self, '') }
314
+ @prepares = []
315
+ self
316
+ end
317
+
318
+ # :call-seq:
319
+ # include(*files) => self
320
+ # include(*files, :path=>path) => self
321
+ # include(file, :as=>name) => self
322
+ # include(:from=>path) => self
323
+ # include(*files, :merge=>true) => self
324
+ #
325
+ # Include files in this archive, or when called on a path, within that path. Returns self.
326
+ #
327
+ # The first form accepts a list of files, directories and glob patterns and adds them to the archive.
328
+ # For example, to include the file foo, directory bar (including all files in there) and all files under baz:
329
+ # zip(..).include('foo', 'bar', 'baz/*')
330
+ #
331
+ # The second form is similar but adds files/directories under the specified path. For example,
332
+ # to add foo as bar/foo:
333
+ # zip(..).include('foo', :path=>'bar')
334
+ # The :path option is the same as using the path method:
335
+ # zip(..).path('bar').include('foo')
336
+ # All other options can be used in combination with the :path option.
337
+ #
338
+ # The third form adds a file or directory under a different name. For example, to add the file foo under the
339
+ # name bar:
340
+ # zip(..).include('foo', :as=>'bar')
341
+ #
342
+ # The fourth form adds the contents of a directory using the directory as a prerequisite:
343
+ # zip(..).include(:from=>'foo')
344
+ # Unlike <code>include('foo')</code> it includes the contents of the directory, not the directory itself.
345
+ # Unlike <code>include('foo/*')</code>, it uses the directory timestamp for dependency management.
346
+ #
347
+ # The fifth form includes the contents of another archive by expanding it into this archive. For example:
348
+ # zip(..).include('foo.zip', :merge=>true).include('bar.zip')
349
+ # You can also use the method #merge.
350
+ def include(*files)
351
+ fail "AchiveTask.include() called with nil values" if files.include? nil
352
+ @paths[''].include *files if files.compact.size > 0
353
+ self
354
+ end
355
+ alias :add :include
356
+ alias :<< :include
357
+
358
+ # :call-seq:
359
+ # exclude(*files) => self
360
+ #
361
+ # Excludes files and returns self. Can be used in combination with include to prevent some files from being included.
362
+ def exclude(*files)
363
+ @paths[''].exclude *files
364
+ self
365
+ end
366
+
367
+ # :call-seq:
368
+ # merge(*files) => Merge
369
+ # merge(*files, :path=>name) => Merge
370
+ #
371
+ # Merges another archive into this one by including the individual files from the merged archive.
372
+ #
373
+ # Returns an object that supports two methods: include and exclude. You can use these methods to merge
374
+ # only specific files. For example:
375
+ # zip(..).merge('src.zip').include('module1/*')
376
+ def merge(*files)
377
+ @paths[''].merge *files
378
+ end
379
+
380
+ # :call-seq:
381
+ # path(name) => Path
382
+ #
383
+ # Returns a path object. Use the path object to include files under a path, for example, to include
384
+ # the file 'foo' as 'bar/foo':
385
+ # zip(..).path('bar').include('foo')
386
+ #
387
+ # Returns a Path object. The Path object implements all the same methods, like include, exclude, merge
388
+ # and so forth. It also implements path and root, so that:
389
+ # path('foo').path('bar') == path('foo/bar')
390
+ # path('foo').root == root
391
+ def path(name)
392
+ return @paths[''] if name.nil?
393
+ normalized = name.split('/').inject([]) do |path, part|
394
+ case part
395
+ when '.', nil, ''
396
+ path
397
+ when '..'
398
+ path[0...-1]
399
+ else
400
+ path << part
401
+ end
402
+ end.join('/')
403
+ @paths[normalized] ||= Path.new(self, normalized)
404
+ end
405
+
406
+ # :call-seq:
407
+ # root => ArchiveTask
408
+ #
409
+ # Call this on an archive to return itself, and on a path to return the archive.
410
+ def root
411
+ self
412
+ end
413
+
414
+ # :call-seq:
415
+ # with(options) => self
416
+ #
417
+ # Passes options to the task and returns self. Some tasks support additional options, for example,
418
+ # the WarTask supports options like :manifest, :libs and :classes.
419
+ #
420
+ # For example:
421
+ # package(:jar).with(:manifest=>'MANIFEST_MF')
422
+ def with(options)
423
+ options.each do |key, value|
424
+ begin
425
+ send "#{key}=", value
426
+ rescue NoMethodError
427
+ raise ArgumentError, "#{self.class.name} does not support the option #{key}"
428
+ end
429
+ end
430
+ self
431
+ end
432
+
433
+ def invoke_prerequisites(args, chain) #:nodoc:
434
+ @prepares.each { |prepare| prepare.call(self) }
435
+ @prepares.clear
436
+ @prerequisites |= @paths.collect { |name, path| path.sources }.flatten
437
+ super
438
+ end
439
+
440
+ def needed? #:nodoc:
441
+ return true unless File.exist?(name)
442
+ # You can do something like:
443
+ # include('foo', :path=>'foo').exclude('foo/bar', path=>'foo').
444
+ # include('foo/bar', :path=>'foo/bar')
445
+ # This will play havoc if we handled all the prerequisites together
446
+ # under the task, so instead we handle them individually for each path.
447
+ #
448
+ # We need to check that any file we include is not newer than the
449
+ # contents of the Zip. The file itself but also the directory it's
450
+ # coming from, since some tasks touch the directory, e.g. when the
451
+ # content of target/classes is included into a WAR.
452
+ most_recent = @paths.collect { |name, path| path.sources }.flatten.
453
+ select { |file| File.exist?(file) }.collect { |file| File.stat(file).mtime }.max
454
+ File.stat(name).mtime < (most_recent || Rake::EARLY) || super
455
+ end
456
+
457
+ # :call-seq:
458
+ # empty? => boolean
459
+ #
460
+ # Returns true if this ZIP file is empty (has no other entries inside).
461
+ def empty?
462
+ path("").empty
463
+ end
464
+
465
+ # :call-seq:
466
+ # contain(file*) => boolean
467
+ #
468
+ # Returns true if this ZIP file contains all the specified files. You can use absolute
469
+ # file names and glob patterns (using *, **, etc).
470
+ def contain?(*files)
471
+ path("").contain?(*files)
472
+ end
473
+
474
+ protected
475
+
476
+ # Adds a prepare block. These blocks are called early on for adding more content to
477
+ # the archive, before invoking prerequsities. Anything you add here will be invoked
478
+ # as a prerequisite and used to determine whether or not to generate this archive.
479
+ # In contrast, enhance blocks are evaluated after it was decided to create this archive.
480
+ def prepare(&block)
481
+ @prepares << block
482
+ end
483
+
484
+ def []=(key, value) #:nodoc:
485
+ raise ArgumentError, "This task does not support the option #{key}."
486
+ end
487
+
488
+ end
489
+
490
+
491
+ end