assaf-buildr 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. data/CHANGELOG +887 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +62 -0
  7. data/_buildr +38 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +236 -0
  10. data/addon/buildr/emma.rb +238 -0
  11. data/addon/buildr/hibernate.rb +142 -0
  12. data/addon/buildr/javacc.rb +85 -0
  13. data/addon/buildr/jdepend.rb +60 -0
  14. data/addon/buildr/jetty.rb +248 -0
  15. data/addon/buildr/jibx.rb +86 -0
  16. data/addon/buildr/nailgun.rb +817 -0
  17. data/addon/buildr/openjpa.rb +90 -0
  18. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  21. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  25. data/addon/buildr/xmlbeans.rb +93 -0
  26. data/bin/buildr +28 -0
  27. data/buildr.buildfile +53 -0
  28. data/buildr.gemspec +58 -0
  29. data/doc/css/default.css +228 -0
  30. data/doc/css/print.css +100 -0
  31. data/doc/css/syntax.css +52 -0
  32. data/doc/images/apache-incubator-logo.png +0 -0
  33. data/doc/images/buildr-hires.png +0 -0
  34. data/doc/images/buildr.png +0 -0
  35. data/doc/images/favicon.png +0 -0
  36. data/doc/images/growl-icon.tiff +0 -0
  37. data/doc/images/note.png +0 -0
  38. data/doc/images/project-structure.png +0 -0
  39. data/doc/images/tip.png +0 -0
  40. data/doc/images/zbuildr.tif +0 -0
  41. data/doc/pages/artifacts.textile +207 -0
  42. data/doc/pages/building.textile +240 -0
  43. data/doc/pages/contributing.textile +208 -0
  44. data/doc/pages/download.textile +62 -0
  45. data/doc/pages/extending.textile +175 -0
  46. data/doc/pages/getting_started.textile +273 -0
  47. data/doc/pages/index.textile +42 -0
  48. data/doc/pages/languages.textile +407 -0
  49. data/doc/pages/mailing_lists.textile +17 -0
  50. data/doc/pages/more_stuff.textile +286 -0
  51. data/doc/pages/packaging.textile +427 -0
  52. data/doc/pages/projects.textile +274 -0
  53. data/doc/pages/recipes.textile +103 -0
  54. data/doc/pages/settings_profiles.textile +274 -0
  55. data/doc/pages/testing.textile +212 -0
  56. data/doc/pages/troubleshooting.textile +103 -0
  57. data/doc/pages/whats_new.textile +323 -0
  58. data/doc/print.haml +51 -0
  59. data/doc/print.toc.yaml +29 -0
  60. data/doc/scripts/buildr-git.rb +412 -0
  61. data/doc/scripts/install-jruby.sh +44 -0
  62. data/doc/scripts/install-linux.sh +64 -0
  63. data/doc/scripts/install-osx.sh +52 -0
  64. data/doc/site.haml +56 -0
  65. data/doc/site.toc.yaml +47 -0
  66. data/etc/KEYS +151 -0
  67. data/etc/git-svn-authors +16 -0
  68. data/lib/buildr.rb +35 -0
  69. data/lib/buildr/core.rb +27 -0
  70. data/lib/buildr/core/application.rb +489 -0
  71. data/lib/buildr/core/application_cli.rb +139 -0
  72. data/lib/buildr/core/build.rb +311 -0
  73. data/lib/buildr/core/checks.rb +382 -0
  74. data/lib/buildr/core/common.rb +154 -0
  75. data/lib/buildr/core/compile.rb +596 -0
  76. data/lib/buildr/core/environment.rb +120 -0
  77. data/lib/buildr/core/filter.rb +362 -0
  78. data/lib/buildr/core/generate.rb +195 -0
  79. data/lib/buildr/core/help.rb +118 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +892 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +558 -0
  84. data/lib/buildr/core/util.rb +289 -0
  85. data/lib/buildr/groovy.rb +18 -0
  86. data/lib/buildr/groovy/bdd.rb +105 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/ide.rb +19 -0
  89. data/lib/buildr/ide/eclipse.rb +212 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +189 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +210 -0
  94. data/lib/buildr/java.rb +23 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +449 -0
  97. data/lib/buildr/java/commands.rb +211 -0
  98. data/lib/buildr/java/compiler.rb +348 -0
  99. data/lib/buildr/java/deprecated.rb +141 -0
  100. data/lib/buildr/java/jruby.rb +117 -0
  101. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  102. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  103. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  104. data/lib/buildr/java/packaging.rb +713 -0
  105. data/lib/buildr/java/pom.rb +178 -0
  106. data/lib/buildr/java/rjb.rb +155 -0
  107. data/lib/buildr/java/test_result.rb +308 -0
  108. data/lib/buildr/java/tests.rb +324 -0
  109. data/lib/buildr/java/version_requirement.rb +172 -0
  110. data/lib/buildr/packaging.rb +21 -0
  111. data/lib/buildr/packaging/artifact.rb +730 -0
  112. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  113. data/lib/buildr/packaging/artifact_search.rb +140 -0
  114. data/lib/buildr/packaging/gems.rb +102 -0
  115. data/lib/buildr/packaging/package.rb +233 -0
  116. data/lib/buildr/packaging/tar.rb +104 -0
  117. data/lib/buildr/packaging/zip.rb +722 -0
  118. data/lib/buildr/resources/buildr.icns +0 -0
  119. data/lib/buildr/scala.rb +19 -0
  120. data/lib/buildr/scala/compiler.rb +109 -0
  121. data/lib/buildr/scala/tests.rb +203 -0
  122. data/rakelib/apache.rake +191 -0
  123. data/rakelib/changelog.rake +57 -0
  124. data/rakelib/doc.rake +103 -0
  125. data/rakelib/package.rake +73 -0
  126. data/rakelib/release.rake +65 -0
  127. data/rakelib/rspec.rake +83 -0
  128. data/rakelib/rubyforge.rake +53 -0
  129. data/rakelib/scm.rake +49 -0
  130. data/rakelib/setup.rake +86 -0
  131. data/rakelib/stage.rake +48 -0
  132. data/spec/addon/cobertura_spec.rb +77 -0
  133. data/spec/addon/emma_spec.rb +120 -0
  134. data/spec/addon/test_coverage_spec.rb +255 -0
  135. data/spec/core/application_spec.rb +412 -0
  136. data/spec/core/artifact_namespace_spec.rb +646 -0
  137. data/spec/core/build_spec.rb +415 -0
  138. data/spec/core/checks_spec.rb +537 -0
  139. data/spec/core/common_spec.rb +664 -0
  140. data/spec/core/compile_spec.rb +566 -0
  141. data/spec/core/generate_spec.rb +33 -0
  142. data/spec/core/project_spec.rb +754 -0
  143. data/spec/core/test_spec.rb +1091 -0
  144. data/spec/core/transport_spec.rb +500 -0
  145. data/spec/groovy/bdd_spec.rb +80 -0
  146. data/spec/groovy/compiler_spec.rb +239 -0
  147. data/spec/ide/eclipse_spec.rb +243 -0
  148. data/spec/java/ant.rb +28 -0
  149. data/spec/java/bdd_spec.rb +358 -0
  150. data/spec/java/compiler_spec.rb +446 -0
  151. data/spec/java/java_spec.rb +88 -0
  152. data/spec/java/packaging_spec.rb +1103 -0
  153. data/spec/java/tests_spec.rb +466 -0
  154. data/spec/packaging/archive_spec.rb +503 -0
  155. data/spec/packaging/artifact_spec.rb +754 -0
  156. data/spec/packaging/packaging_helper.rb +63 -0
  157. data/spec/packaging/packaging_spec.rb +589 -0
  158. data/spec/sandbox.rb +137 -0
  159. data/spec/scala/compiler_spec.rb +228 -0
  160. data/spec/scala/tests_spec.rb +215 -0
  161. data/spec/spec_helpers.rb +304 -0
  162. data/spec/version_requirement_spec.rb +123 -0
  163. metadata +369 -0
@@ -0,0 +1,120 @@
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 'yaml'
18
+
19
+
20
+ module Buildr
21
+
22
+ # Collection of options for controlling Buildr.
23
+ class Options
24
+
25
+ # We use this to present environment variable as arrays.
26
+ class EnvArray < Array #:nodoc:
27
+
28
+ def initialize(name)
29
+ @name = name.upcase
30
+ replace((ENV[@name] || ENV[@name.downcase] || '').split(/\s*,\s*/).reject(&:empty?))
31
+ end
32
+
33
+ (Array.instance_methods - Object.instance_methods - Enumerable.instance_methods).sort.each do |method|
34
+ class_eval %{def #{method}(*args, &block) ; result = super ; write ; result ; end}
35
+ end
36
+
37
+ private
38
+
39
+ def write
40
+ ENV[@name.downcase] = nil
41
+ ENV[@name] = map(&:to_s).join(',')
42
+ end
43
+
44
+ end
45
+
46
+
47
+ # Wraps around the proxy environment variables:
48
+ # * :http -- HTTP_PROXY
49
+ # * :exclude -- NO_PROXY
50
+ class Proxies
51
+
52
+ # Returns the HTTP_PROXY URL.
53
+ def http
54
+ ENV['HTTP_PROXY'] || ENV['http_proxy']
55
+ end
56
+
57
+ # Sets the HTTP_PROXY URL.
58
+ def http=(url)
59
+ ENV['http_proxy'] = nil
60
+ ENV['HTTP_PROXY'] = url
61
+ end
62
+
63
+ # Returns list of hosts to exclude from proxying (NO_PROXY).
64
+ def exclude
65
+ @exclude ||= EnvArray.new('NO_PROXY')
66
+ end
67
+
68
+ # Sets list of hosts to exclude from proxy (NO_PROXY). Accepts host name, array of names,
69
+ # or nil to clear the list.
70
+ def exclude=(url)
71
+ exclude.clear
72
+ exclude.concat [url].flatten if url
73
+ exclude
74
+ end
75
+
76
+ end
77
+
78
+ # :call-seq:
79
+ # proxy => options
80
+ #
81
+ # Returns the proxy options. Currently supported options are:
82
+ # * :http -- HTTP proxy for use when downloading.
83
+ # * :exclude -- Do not use proxy for these hosts/domains.
84
+ #
85
+ # For example:
86
+ # options.proxy.http = 'http://proxy.acme.com:8080'
87
+ # You can also set it using the environment variable HTTP_PROXY.
88
+ #
89
+ # You can exclude individual hosts from being proxied, or entire domains, for example:
90
+ # options.proxy.exclude = 'optimus'
91
+ # options.proxy.exclude = ['optimus', 'prime']
92
+ # options.proxy.exclude << '*.internal'
93
+ def proxy
94
+ @proxy ||= Proxies.new
95
+ end
96
+
97
+ end
98
+
99
+
100
+ class << self
101
+
102
+ # :call-seq:
103
+ # options => Options
104
+ #
105
+ # Returns the Buildr options. See Options.
106
+ def options
107
+ @options ||= Options.new
108
+ end
109
+
110
+ end
111
+
112
+ # :call-seq:
113
+ # options => Options
114
+ #
115
+ # Returns the Buildr options. See Options.
116
+ def options
117
+ Buildr.options
118
+ end
119
+
120
+ end
@@ -0,0 +1,362 @@
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
+ module Buildr
17
+
18
+ # A filter knows how to copy files from one directory to another, applying mappings to the
19
+ # contents of these files.
20
+ #
21
+ # You can specify the mapping using a Hash, and it will map ${key} fields found in each source
22
+ # file into the appropriate value in the target file. For example:
23
+ #
24
+ # filter.using 'version'=>'1.2', 'build'=>Time.now
25
+ #
26
+ # will replace all occurrences of <tt>${version}</tt> with <tt>1.2</tt>, and <tt>${build}</tt>
27
+ # with the current date/time.
28
+ #
29
+ # You can also specify the mapping by passing a proc or a method, that will be called for
30
+ # each source file, with the file name and content, returning the modified content.
31
+ #
32
+ # Without any mapping, the filter simply copies files from the source directory into the target
33
+ # directory.
34
+ #
35
+ # A filter has one target directory, but you can specify any number of source directories,
36
+ # either when creating the filter or calling #from. Include/exclude patterns are specified
37
+ # relative to the source directories, so:
38
+ # filter.include '*.png'
39
+ # will only include PNG files from any of the source directories.
40
+ #
41
+ # See Buildr#filter.
42
+ class Filter
43
+
44
+ def initialize #:nodoc:
45
+ clear
46
+ end
47
+
48
+ # Returns the list of source directories (each being a file task).
49
+ attr_reader :sources
50
+
51
+ # :call-seq:
52
+ # clear => self
53
+ #
54
+ # Clear filter sources and include/exclude patterns
55
+ def clear
56
+ @include = []
57
+ @exclude = []
58
+ @sources = FileList[]
59
+ @mapper = Mapper.new
60
+ self
61
+ end
62
+
63
+ # :call-seq:
64
+ # from(*sources) => self
65
+ #
66
+ # Adds additional directories from which to copy resources.
67
+ #
68
+ # For example:
69
+ # filter.from('src').into('target').using('build'=>Time.now)
70
+ def from(*sources)
71
+ @sources |= sources.flatten.map { |dir| file(File.expand_path(dir.to_s)) }
72
+ self
73
+ end
74
+
75
+ # The target directory as a file task.
76
+ attr_reader :target
77
+
78
+ # :call-seq:
79
+ # into(dir) => self
80
+ #
81
+ # Sets the target directory into which files are copied and returns self.
82
+ #
83
+ # For example:
84
+ # filter.from('src').into('target').using('build'=>Time.now)
85
+ def into(dir)
86
+ @target = file(File.expand_path(dir.to_s)) { |task| run if target == task }
87
+ self
88
+ end
89
+
90
+ # :call-seq:
91
+ # include(*files) => self
92
+ #
93
+ # Specifies files to include and returns self. See FileList#include.
94
+ #
95
+ # By default all files are included. You can use this method to only include specific
96
+ # files from the source directory.
97
+ def include(*files)
98
+ @include += files
99
+ self
100
+ end
101
+ alias :add :include
102
+
103
+ # :call-seq:
104
+ # exclude(*files) => self
105
+ #
106
+ # Specifies files to exclude and returns self. See FileList#exclude.
107
+ def exclude(*files)
108
+ @exclude += files
109
+ self
110
+ end
111
+
112
+ # The mapping. See #using.
113
+ def mapping #:nodoc:
114
+ @mapper.config
115
+ end
116
+
117
+ # The mapper to use. See #using.
118
+ def mapper #:nodoc:
119
+ @mapper.mapper_type
120
+ end
121
+
122
+ # :call-seq:
123
+ # using(mapping) => self
124
+ # using { |file_name, contents| ... } => self
125
+ #
126
+ # Specifies the mapping to use and returns self.
127
+ #
128
+ # The most typical mapping uses a Hash, and the default mapping uses the Maven style, so
129
+ # <code>${key}</code> are mapped to the values. You can change that by passing a different
130
+ # format as the first argument. Currently supports:
131
+ # * :ant -- Map <code>@key@</code>.
132
+ # * :maven -- Map <code>${key}</code> (default).
133
+ # * :ruby -- Map <code>#{key}</code>.
134
+ # * :erb -- Map <code><%= key %></code>.
135
+ # * Regexp -- Maps the matched data (e.g. <code>/=(.*?)=/</code>
136
+ #
137
+ # For example:
138
+ # filter.using 'version'=>'1.2'
139
+ # Is the same as:
140
+ # filter.using :maven, 'version'=>'1.2'
141
+ #
142
+ # You can also pass a proc or method. It will be called with the file name and content,
143
+ # to return the mapped content.
144
+ #
145
+ # Without any mapping, all files are copied as is.
146
+ #
147
+ # To register new mapping type see the Mapper class.
148
+ def using(*args, &block)
149
+ @mapper.using(*args, &block)
150
+ self
151
+ end
152
+
153
+ # :call-seq:
154
+ # run => boolean
155
+ #
156
+ # Runs the filter.
157
+ def run
158
+ sources.each { |source| raise "Source directory #{source} doesn't exist" unless File.exist?(source.to_s) }
159
+ raise 'No target directory specified, where am I going to copy the files to?' if target.nil?
160
+
161
+ copy_map = sources.flatten.map(&:to_s).inject({}) do |map, source|
162
+ files = Util.recursive_with_dot_files(source).
163
+ map { |file| Util.relative_path(file, source) }.
164
+ select { |file| @include.empty? || @include.any? { |pattern| File.fnmatch(pattern, file, File::FNM_PATHNAME) } }.
165
+ reject { |file| @exclude.any? { |pattern| File.fnmatch(pattern, file, File::FNM_PATHNAME) } }
166
+ files.each do |file|
167
+ src, dest = File.expand_path(file, source), File.expand_path(file, target.to_s)
168
+ map[file] = src if !File.exist?(dest) || File.stat(src).mtime > File.stat(dest).mtime
169
+ end
170
+ map
171
+ end
172
+
173
+ mkpath target.to_s
174
+ return false if copy_map.empty?
175
+
176
+ verbose(Buildr.application.options.trace || false) do
177
+ copy_map.each do |path, source|
178
+ dest = File.expand_path(path, target.to_s)
179
+ if File.directory?(source)
180
+ mkpath dest
181
+ else
182
+ mkpath File.dirname(dest)
183
+ if @mapper.mapper_type
184
+ mapped = @mapper.transform(File.open(source, 'rb') { |file| file.read }, path)
185
+ File.open(dest, 'wb') { |file| file.write mapped }
186
+ else # no mapping
187
+ cp source, dest
188
+ File.chmod(0664, dest)
189
+ end
190
+ end
191
+ end
192
+ touch target.to_s
193
+ end
194
+ true
195
+ end
196
+
197
+ # Returns the target directory.
198
+ def to_s
199
+ @target.to_s
200
+ end
201
+
202
+ # This class implements content replacement logic for Filter.
203
+ #
204
+ # To register a new template engine @:foo@, extend this class with a method like:
205
+ #
206
+ # def foo_transform(content, path = nil)
207
+ # # if this method yields a key, the value comes from the mapping hash
208
+ # content.gsub(/world/) { |str| yield :bar }
209
+ # end
210
+ #
211
+ # Then you can use :foo mapping type on a Filter
212
+ #
213
+ # filter.using :foo, :bar => :baz
214
+ #
215
+ # Or all by your own, simply
216
+ #
217
+ # Mapper.new(:foo, :bar => :baz).transform("Hello world") # => "Hello baz"
218
+ #
219
+ # You can handle configuration arguments by providing a @*_config@ method like:
220
+ #
221
+ # # The return value of this method is available with the :config accessor.
222
+ # def moo_config(*args, &block)
223
+ # raise ArgumentError, "Expected moo block" unless block_given?
224
+ # { :moos => args, :callback => block }
225
+ # end
226
+ #
227
+ # def moo_transform(content, path = nil)
228
+ # content.gsub(/moo+/i) do |str|
229
+ # moos = yield :moos # same than config[:moos]
230
+ # moo = moos[str.size - 3] || str
231
+ # config[:callback].call(moo)
232
+ # end
233
+ # end
234
+ #
235
+ # Usage for the @:moo@ mapper would be something like:
236
+ #
237
+ # mapper = Mapper.new(:moo, 'ooone', 'twoo') do |str|
238
+ # i = nil; str.capitalize.gsub(/\w/) { |s| s.send( (i = !i) ? 'upcase' : 'downcase' ) }
239
+ # end
240
+ # mapper.transform('Moo cow, mooo cows singing mooooo') # => 'OoOnE cow, TwOo cows singing MoOoOo'
241
+ class Mapper
242
+
243
+ attr_reader :mapper_type, :config
244
+
245
+ def initialize(*args, &block) #:nodoc:
246
+ using(*args, &block)
247
+ end
248
+
249
+ def using(*args, &block)
250
+ case args.first
251
+ when Hash # Maven hash mapping
252
+ using :maven, *args
253
+ when Binding # Erb binding
254
+ using :erb, *args
255
+ when Symbol # Mapping from a method
256
+ raise ArgumentError, "Unknown mapping type: #{args.first}" unless respond_to?("#{args.first}_transform", true)
257
+ configure(*args, &block)
258
+ when Regexp # Mapping using a regular expression
259
+ raise ArgumentError, 'Expected regular expression followed by mapping hash' unless args.size == 2 && Hash === args[1]
260
+ @mapper_type, @config = *args
261
+ else
262
+ unless args.empty? && block.nil?
263
+ raise ArgumentError, 'Expected proc, method or a block' if args.size > 1 || (args.first && block)
264
+ @mapper_type = :callback
265
+ config = args.first || block
266
+ raise ArgumentError, 'Expected proc, method or callable' unless config.respond_to?(:call)
267
+ @config = config
268
+ end
269
+ end
270
+ self
271
+ end
272
+
273
+ def transform(content, path = nil)
274
+ type = Regexp === mapper_type ? :regexp : mapper_type
275
+ raise ArgumentError, "Invalid mapper type: #{type.inspect}" unless respond_to?("#{type}_transform", true)
276
+ self.__send__("#{type}_transform", content, path) { |key| config[key] || config[key.to_s.to_sym] }
277
+ end
278
+
279
+ private
280
+ def configure(mapper_type, *args, &block)
281
+ configurer = method("#{mapper_type}_config") rescue nil
282
+ if configurer
283
+ @config = configurer.call(*args, &block)
284
+ else
285
+ raise ArgumentError, "Missing hash argument after :#{mapper_type}" unless args.size == 1 && Hash === args[0]
286
+ @config = *args
287
+ end
288
+ @mapper_type = mapper_type
289
+ end
290
+
291
+ def maven_transform(content, path = nil)
292
+ content.gsub(/\$\{.*?\}/) { |str| yield(str[2..-2]) || str }
293
+ end
294
+
295
+ def ant_transform(content, path = nil)
296
+ content.gsub(/@.*?@/) { |str| yield(str[1..-2]) || str }
297
+ end
298
+
299
+ def ruby_transform(content, path = nil)
300
+ content.gsub(/#\{.*?\}/) { |str| yield(str[2..-2]) || str }
301
+ end
302
+
303
+ def regexp_transform(content, path = nil)
304
+ content.gsub(mapper_type) { |str| yield(str.scan(mapper_type).join) || str }
305
+ end
306
+
307
+ def callback_transform(content, path = nil)
308
+ config.call(path, content)
309
+ end
310
+
311
+ def erb_transform(content, path = nil)
312
+ case config
313
+ when Binding, Proc
314
+ bnd = config
315
+ when Method
316
+ bnd = config.to_proc
317
+ when Hash
318
+ bnd = OpenStruct.new
319
+ table = config.inject({}) { |h, e| h[e.first.to_sym] = e.last; h }
320
+ bnd.instance_variable_set(:@table, table)
321
+ bnd = bnd.instance_eval { binding }
322
+ else
323
+ bnd = config.instance_eval { binding }
324
+ end
325
+ require 'erb'
326
+ ERB.new(content).result(bnd)
327
+ end
328
+
329
+ def erb_config(*args, &block)
330
+ if block_given?
331
+ raise ArgumentError, "Expected block or single argument, but both given." unless args.empty?
332
+ block
333
+ elsif args.size > 1
334
+ raise ArgumentError, "Expected block or single argument."
335
+ else
336
+ args.first
337
+ end
338
+ end
339
+
340
+ end # class Mapper
341
+
342
+ end
343
+
344
+ # :call-seq:
345
+ # filter(*source) => Filter
346
+ #
347
+ # Creates a filter that will copy files from the source directory(ies) into the target directory.
348
+ # You can extend the filter to modify files by mapping <tt>${key}</tt> into values in each
349
+ # of the copied files, and by including or excluding specific files.
350
+ #
351
+ # A filter is not a task, you must call the Filter#run method to execute it.
352
+ #
353
+ # For example, to copy all files from one directory to another:
354
+ # filter('src/files').into('target/classes').run
355
+ # To include only the text files, and replace each instance of <tt>${build}</tt> with the current
356
+ # date/time:
357
+ # filter('src/files').into('target/classes').include('*.txt').using('build'=>Time.now).run
358
+ def filter(*sources)
359
+ Filter.new.from(*sources)
360
+ end
361
+
362
+ end