realityforge-buildr 1.5.9

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 (85) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.md +3 -0
  6. data/Rakefile +50 -0
  7. data/addon/buildr/checkstyle-report.xsl +104 -0
  8. data/addon/buildr/checkstyle.rb +254 -0
  9. data/addon/buildr/git_auto_version.rb +36 -0
  10. data/addon/buildr/gpg.rb +90 -0
  11. data/addon/buildr/gwt.rb +413 -0
  12. data/addon/buildr/jacoco.rb +161 -0
  13. data/addon/buildr/pmd.rb +185 -0
  14. data/addon/buildr/single_intermediate_layout.rb +71 -0
  15. data/addon/buildr/spotbugs.rb +265 -0
  16. data/addon/buildr/top_level_generate_dir.rb +37 -0
  17. data/addon/buildr/wsgen.rb +192 -0
  18. data/bin/buildr +20 -0
  19. data/buildr.gemspec +61 -0
  20. data/lib/buildr.rb +86 -0
  21. data/lib/buildr/core/application.rb +705 -0
  22. data/lib/buildr/core/assets.rb +96 -0
  23. data/lib/buildr/core/build.rb +587 -0
  24. data/lib/buildr/core/common.rb +167 -0
  25. data/lib/buildr/core/compile.rb +599 -0
  26. data/lib/buildr/core/console.rb +124 -0
  27. data/lib/buildr/core/doc.rb +275 -0
  28. data/lib/buildr/core/environment.rb +128 -0
  29. data/lib/buildr/core/filter.rb +405 -0
  30. data/lib/buildr/core/help.rb +114 -0
  31. data/lib/buildr/core/progressbar.rb +161 -0
  32. data/lib/buildr/core/project.rb +994 -0
  33. data/lib/buildr/core/test.rb +776 -0
  34. data/lib/buildr/core/transports.rb +456 -0
  35. data/lib/buildr/core/util.rb +77 -0
  36. data/lib/buildr/ide/idea.rb +1664 -0
  37. data/lib/buildr/java/commands.rb +230 -0
  38. data/lib/buildr/java/compiler.rb +85 -0
  39. data/lib/buildr/java/custom_pom.rb +300 -0
  40. data/lib/buildr/java/doc.rb +62 -0
  41. data/lib/buildr/java/packaging.rb +393 -0
  42. data/lib/buildr/java/pom.rb +191 -0
  43. data/lib/buildr/java/test_result.rb +54 -0
  44. data/lib/buildr/java/tests.rb +111 -0
  45. data/lib/buildr/packaging/archive.rb +586 -0
  46. data/lib/buildr/packaging/artifact.rb +1113 -0
  47. data/lib/buildr/packaging/artifact_namespace.rb +1010 -0
  48. data/lib/buildr/packaging/artifact_search.rb +138 -0
  49. data/lib/buildr/packaging/package.rb +237 -0
  50. data/lib/buildr/packaging/version_requirement.rb +189 -0
  51. data/lib/buildr/packaging/zip.rb +189 -0
  52. data/lib/buildr/packaging/ziptask.rb +387 -0
  53. data/lib/buildr/version.rb +18 -0
  54. data/rakelib/release.rake +99 -0
  55. data/spec/addon/checkstyle_spec.rb +58 -0
  56. data/spec/core/application_spec.rb +576 -0
  57. data/spec/core/build_spec.rb +922 -0
  58. data/spec/core/common_spec.rb +670 -0
  59. data/spec/core/compile_spec.rb +656 -0
  60. data/spec/core/console_spec.rb +65 -0
  61. data/spec/core/doc_spec.rb +194 -0
  62. data/spec/core/extension_spec.rb +200 -0
  63. data/spec/core/project_spec.rb +736 -0
  64. data/spec/core/test_spec.rb +1131 -0
  65. data/spec/core/transport_spec.rb +452 -0
  66. data/spec/core/util_spec.rb +154 -0
  67. data/spec/ide/idea_spec.rb +1952 -0
  68. data/spec/java/commands_spec.rb +79 -0
  69. data/spec/java/compiler_spec.rb +274 -0
  70. data/spec/java/custom_pom_spec.rb +165 -0
  71. data/spec/java/doc_spec.rb +55 -0
  72. data/spec/java/packaging_spec.rb +786 -0
  73. data/spec/java/pom_spec.rb +162 -0
  74. data/spec/java/test_coverage_helper.rb +257 -0
  75. data/spec/java/tests_spec.rb +224 -0
  76. data/spec/packaging/archive_spec.rb +686 -0
  77. data/spec/packaging/artifact_namespace_spec.rb +757 -0
  78. data/spec/packaging/artifact_spec.rb +1351 -0
  79. data/spec/packaging/packaging_helper.rb +63 -0
  80. data/spec/packaging/packaging_spec.rb +690 -0
  81. data/spec/sandbox.rb +166 -0
  82. data/spec/spec_helpers.rb +420 -0
  83. data/spec/version_requirement_spec.rb +145 -0
  84. data/spec/xpath_matchers.rb +123 -0
  85. metadata +295 -0
@@ -0,0 +1,405 @@
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 #:nodoc:
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
+ # In the same way, you can use regular expressions, so:
41
+ # filter.include /picture_.*\.png/
42
+ # will only include PNG files starting with picture_ from any of the sources directories.
43
+ #
44
+ # See Buildr#filter.
45
+ class Filter
46
+
47
+ def initialize #:nodoc:
48
+ clear
49
+ end
50
+
51
+ # Returns the list of source directories (each being a file task).
52
+ attr_reader :sources
53
+
54
+ # :call-seq:
55
+ # clear => self
56
+ #
57
+ # Clear filter sources and include/exclude patterns
58
+ def clear
59
+ @include = []
60
+ @exclude = []
61
+ @sources = FileList[]
62
+ @mapper = Mapper.new
63
+ self
64
+ end
65
+
66
+ # :call-seq:
67
+ # from(*sources) => self
68
+ #
69
+ # Adds additional directories from which to copy resources.
70
+ #
71
+ # For example:
72
+ # filter.from('src').into('target').using('build'=>Time.now)
73
+ def from(*sources)
74
+ @sources |= sources.flatten.map { |dir| file(File.expand_path(dir.to_s)) }
75
+ self
76
+ end
77
+
78
+ # The target directory as a file task.
79
+ def target
80
+ return nil unless @target_dir
81
+ unless @target
82
+ @target = file(File.expand_path(@target_dir)) { |task| run if @target == task }
83
+ @target.enhance @include.select {|f| f.is_a?(Rake::FileTask)}
84
+ @target.enhance @exclude.select {|f| f.is_a?(Rake::FileTask)}
85
+ @target.enhance copy_map.values
86
+ end
87
+ @target
88
+ end
89
+
90
+ # :call-seq:
91
+ # into(dir) => self
92
+ #
93
+ # Sets the target directory into which files are copied and returns self.
94
+ #
95
+ # For example:
96
+ # filter.from('src').into('target').using('build'=>Time.now)
97
+ def into(dir)
98
+ @target_dir = dir.to_s
99
+ @target = nil
100
+ self
101
+ end
102
+
103
+ # :call-seq:
104
+ # include(*files) => self
105
+ #
106
+ # Specifies files to include and returns self. See FileList#include.
107
+ #
108
+ # By default all files are included. You can use this method to only include specific
109
+ # files from the source directory.
110
+ def include(*files)
111
+ @include += files.flatten
112
+ self
113
+ end
114
+ alias :add :include
115
+
116
+ # :call-seq:
117
+ # exclude(*files) => self
118
+ #
119
+ # Specifies files to exclude and returns self. See FileList#exclude.
120
+ def exclude(*files)
121
+ @exclude += files.flatten
122
+ self
123
+ end
124
+
125
+ # The mapping. See #using.
126
+ def mapping #:nodoc:
127
+ @mapper.config
128
+ end
129
+
130
+ # The mapper to use. See #using.
131
+ def mapper #:nodoc:
132
+ @mapper.mapper_type
133
+ end
134
+
135
+ # :call-seq:
136
+ # using(mapping) => self
137
+ # using { |file_name, contents| ... } => self
138
+ #
139
+ # Specifies the mapping to use and returns self.
140
+ #
141
+ # The most typical mapping uses a Hash, and the default mapping uses the Maven style, so
142
+ # <code>${key}</code> are mapped to the values. You can change that by passing a different
143
+ # format as the first argument. Currently supports:
144
+ # * :ant -- Map <code>@key@</code>.
145
+ # * :maven -- Map <code>${key}</code> (default).
146
+ # * :ruby -- Map <code>#{key}</code>.
147
+ # * :erb -- Map <code><%= key %></code>.
148
+ # * Regexp -- Maps the matched data (e.g. <code>/=(.*?)=/</code>
149
+ #
150
+ # For example:
151
+ # filter.using 'version'=>'1.2'
152
+ # Is the same as:
153
+ # filter.using :maven, 'version'=>'1.2'
154
+ #
155
+ # You can also pass a proc or method. It will be called with the file name and content,
156
+ # to return the mapped content.
157
+ #
158
+ # Without any mapping, all files are copied as is.
159
+ #
160
+ # To register new mapping type see the Mapper class.
161
+ def using(*args, &block)
162
+ @mapper.using(*args, &block)
163
+ self
164
+ end
165
+
166
+ # :call-seq:
167
+ # run => boolean
168
+ #
169
+ # Runs the filter.
170
+ def run
171
+ copy_map = copy_map()
172
+
173
+ mkpath target.to_s
174
+ return false if copy_map.empty?
175
+
176
+ copy_map.each do |path, source|
177
+ dest = File.expand_path(path, target.to_s)
178
+ if File.directory?(source)
179
+ mkpath dest
180
+ else
181
+ mkpath File.dirname(dest)
182
+ if @mapper.mapper_type
183
+ mapped = @mapper.transform(File.open(source, 'rb') { |file| file.read }, path)
184
+ File.open(dest, 'wb') { |file| file.write mapped }
185
+ else # no mapping
186
+ cp source, dest
187
+ end
188
+ end
189
+ File.chmod(File.stat(source).mode | 0200, dest)
190
+ end
191
+ touch target.to_s
192
+ true
193
+ end
194
+
195
+ # Returns the target directory.
196
+ def to_s
197
+ target.to_s
198
+ end
199
+
200
+ protected
201
+
202
+ # :call-seq:
203
+ # pattern_match(file, pattern) => boolean
204
+ #
205
+ # This method returns true if the file name matches the pattern.
206
+ # The pattern may be a String, a Regexp or a Proc.
207
+ #
208
+ def pattern_match(file, pattern)
209
+ case
210
+ when pattern.is_a?(Regexp)
211
+ return file.match(pattern)
212
+ when pattern.is_a?(String)
213
+ return File.fnmatch(pattern, file)
214
+ when pattern.is_a?(Proc)
215
+ return pattern.call(file)
216
+ when pattern.is_a?(Rake::FileTask)
217
+ return pattern.to_s.match(file)
218
+ else
219
+ raise "Cannot interpret pattern #{pattern}"
220
+ end
221
+ end
222
+
223
+ private
224
+ def copy_map
225
+ raise 'No target directory specified, where am I going to copy the files to?' if target.nil?
226
+
227
+ sources.flatten.map(&:to_s).inject({}) do |map, source|
228
+ files = Util.recursive_with_dot_files(source).
229
+ map { |file| Util.relative_path(file, source) }.
230
+ select { |file| @include.empty? || @include.any? { |pattern| pattern_match(file, pattern) } }.
231
+ reject { |file| @exclude.any? { |pattern| pattern_match(file, pattern) } }
232
+ files.each do |file|
233
+ src, dest = File.expand_path(file, source), File.expand_path(file, target.to_s)
234
+ map[file] = src if !File.exist?(dest) || File.stat(src).mtime >= File.stat(dest).mtime
235
+ end
236
+ map
237
+ end
238
+ end
239
+
240
+ # This class implements content replacement logic for Filter.
241
+ #
242
+ # To register a new template engine @:foo@, extend this class with a method like:
243
+ #
244
+ # def foo_transform(content, path = nil)
245
+ # # if this method yields a key, the value comes from the mapping hash
246
+ # content.gsub(/world/) { |str| yield :bar }
247
+ # end
248
+ #
249
+ # Then you can use :foo mapping type on a Filter
250
+ #
251
+ # filter.using :foo, :bar => :baz
252
+ #
253
+ # Or all by your own, simply
254
+ #
255
+ # Mapper.new(:foo, :bar => :baz).transform("Hello world") # => "Hello baz"
256
+ #
257
+ # You can handle configuration arguments by providing a @*_config@ method like:
258
+ #
259
+ # # The return value of this method is available with the :config accessor.
260
+ # def moo_config(*args, &block)
261
+ # raise ArgumentError, "Expected moo block" unless block_given?
262
+ # { :moos => args, :callback => block }
263
+ # end
264
+ #
265
+ # def moo_transform(content, path = nil)
266
+ # content.gsub(/moo+/i) do |str|
267
+ # moos = yield :moos # same than config[:moos]
268
+ # moo = moos[str.size - 3] || str
269
+ # config[:callback].call(moo)
270
+ # end
271
+ # end
272
+ #
273
+ # Usage for the @:moo@ mapper would be something like:
274
+ #
275
+ # mapper = Mapper.new(:moo, 'ooone', 'twoo') do |str|
276
+ # i = nil; str.capitalize.gsub(/\w/) { |s| s.send( (i = !i) ? 'upcase' : 'downcase' ) }
277
+ # end
278
+ # mapper.transform('Moo cow, mooo cows singing mooooo') # => 'OoOnE cow, TwOo cows singing MoOoOo'
279
+ class Mapper
280
+
281
+ attr_reader :mapper_type, :config
282
+
283
+ def initialize(*args, &block) #:nodoc:
284
+ using(*args, &block)
285
+ end
286
+
287
+ def using(*args, &block)
288
+ case args.first
289
+ when Hash # Maven hash mapping
290
+ using :maven, *args
291
+ when Binding # Erb binding
292
+ using :erb, *args
293
+ when Symbol # Mapping from a method
294
+ raise ArgumentError, "Unknown mapping type: #{args.first}" unless respond_to?("#{args.first}_transform", true)
295
+ configure(*args, &block)
296
+ when Regexp # Mapping using a regular expression
297
+ raise ArgumentError, 'Expected regular expression followed by mapping hash' unless args.size == 2 && Hash === args[1]
298
+ @mapper_type, @config = *args
299
+ else
300
+ unless args.empty? && block.nil?
301
+ raise ArgumentError, 'Expected proc, method or a block' if args.size > 1 || (args.first && block)
302
+ @mapper_type = :callback
303
+ config = args.first || block
304
+ raise ArgumentError, 'Expected proc, method or callable' unless config.respond_to?(:call)
305
+ @config = config
306
+ end
307
+ end
308
+ self
309
+ end
310
+
311
+ BINARY_FILES = %w[*.png *.gif *.jpg *.jpeg]
312
+
313
+ def is_binary?(content, path)
314
+ !!path && BINARY_FILES.any? { |glob| File.fnmatch(glob, path) }
315
+ end
316
+
317
+ def transform(content, path = nil)
318
+ return content if is_binary?(content, path)
319
+ type = Regexp === mapper_type ? :regexp : mapper_type
320
+ raise ArgumentError, "Invalid mapper type: #{type.inspect}" unless respond_to?("#{type}_transform", true)
321
+ self.__send__("#{type}_transform", content, path) { |key| config[key] || config[key.to_s.to_sym] }
322
+ end
323
+
324
+ private
325
+ def configure(mapper_type, *args, &block)
326
+ configurer = method("#{mapper_type}_config") rescue nil
327
+ if configurer
328
+ @config = configurer.call(*args, &block)
329
+ else
330
+ raise ArgumentError, "Missing hash argument after :#{mapper_type}" unless args.size == 1 && Hash === args[0]
331
+ @config = {} unless Hash === @config
332
+ args.first.each_pair { |k, v| @config[k] = v.to_s }
333
+ end
334
+ @mapper_type = mapper_type
335
+ end
336
+
337
+ def maven_transform(content, path = nil)
338
+ content.gsub(/\$\{.*?\}/) { |str| yield(str[2..-2]) || str }
339
+ end
340
+
341
+ def ant_transform(content, path = nil)
342
+ content.gsub(/@.*?@/) { |str| yield(str[1..-2]) || str }
343
+ end
344
+
345
+ def ruby_transform(content, path = nil)
346
+ content.gsub(/#\{.*?\}/) { |str| yield(str[2..-2]) || str }
347
+ end
348
+
349
+ def regexp_transform(content, path = nil)
350
+ content.gsub(mapper_type) { |str| yield(str.scan(mapper_type).join) || str }
351
+ end
352
+
353
+ def callback_transform(content, path = nil)
354
+ config.call(path, content)
355
+ end
356
+
357
+ def erb_transform(content, path = nil)
358
+ case config
359
+ when Binding
360
+ bnd = config
361
+ when Hash
362
+ bnd = OpenStruct.new
363
+ table = config.inject({}) { |h, e| h[e.first.to_sym] = e.last; h }
364
+ bnd.instance_variable_set(:@table, table)
365
+ bnd = bnd.instance_eval { binding }
366
+ else
367
+ bnd = config.instance_eval { binding }
368
+ end
369
+ ERB.new(content).result(bnd)
370
+ end
371
+
372
+ def erb_config(*args, &block)
373
+ if block_given?
374
+ raise ArgumentError, "Expected block or single argument, but both given." unless args.empty?
375
+ block
376
+ elsif args.size > 1
377
+ raise ArgumentError, "Expected block or single argument."
378
+ else
379
+ args.first
380
+ end
381
+ end
382
+
383
+ end # class Mapper
384
+
385
+ end
386
+
387
+ # :call-seq:
388
+ # filter(*source) => Filter
389
+ #
390
+ # Creates a filter that will copy files from the source directory(ies) into the target directory.
391
+ # You can extend the filter to modify files by mapping <tt>${key}</tt> into values in each
392
+ # of the copied files, and by including or excluding specific files.
393
+ #
394
+ # A filter is not a task, you must call the Filter#run method to execute it.
395
+ #
396
+ # For example, to copy all files from one directory to another:
397
+ # filter('src/files').into('target/classes').run
398
+ # To include only the text files, and replace each instance of <tt>${build}</tt> with the current
399
+ # date/time:
400
+ # filter('src/files').into('target/classes').include('*.txt').using('build'=>Time.now).run
401
+ def filter(*sources)
402
+ Filter.new.from(*sources)
403
+ end
404
+
405
+ end
@@ -0,0 +1,114 @@
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 #:nodoc:
17
+
18
+ module Help #:nodoc:
19
+ class << self
20
+
21
+ def <<(arg)
22
+ if arg.respond_to?(:call)
23
+ texters << arg
24
+ else
25
+ texters << lambda { arg }
26
+ end
27
+ end
28
+
29
+ def to_s
30
+ texters.map(&:call).join("\n")
31
+ end
32
+
33
+ protected
34
+ def texters
35
+ @texters ||= []
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+ class << self
42
+ def help(&block)
43
+ Help << block if block_given?
44
+ Help
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+
51
+ task 'help' do
52
+ # Greeter
53
+ puts 'Usage:'
54
+ puts ' buildr [-f rakefile] {options} targets...'
55
+ puts
56
+
57
+ # Show only the top-level projects.
58
+ projects.reject(&:parent).tap do |top_level|
59
+ unless top_level.empty?
60
+ puts 'Top-level projects (buildr help:projects for full list):'
61
+ width = [top_level.map(&:name).map(&:size), 20].flatten.max
62
+ top_level.each do |project|
63
+ puts project.comment.to_s.empty? ? project.name : (" %-#{width}s # %s" % [project.name, project.comment])
64
+ end
65
+ puts
66
+ end
67
+ end
68
+
69
+ # Show all the top-level tasks, excluding projects.
70
+ puts 'Common tasks:'
71
+ task('help:tasks').invoke
72
+ puts
73
+ puts 'For help on command line options:'
74
+ puts ' buildr --help'
75
+ puts Buildr.help.to_s
76
+ end
77
+
78
+
79
+ module Buildr
80
+
81
+ # :call-seq:
82
+ # help() { ... }
83
+ #
84
+ # Use this to enhance the help task, e.g. to print some important information about your build,
85
+ # configuration options, build instructions, etc.
86
+ def help(&block)
87
+ Buildr.help << block
88
+ end
89
+
90
+ end
91
+
92
+
93
+ namespace 'help' do
94
+
95
+ desc 'List all projects defined by this buildfile'
96
+ task 'projects' do
97
+ width = projects.map(&:name).map(&:size).max
98
+ projects.each do |project|
99
+ puts project.comment.to_s.empty? ? " #{project.name}" : (" %-#{width}s # %s" % [project.name, project.comment])
100
+ end
101
+ end
102
+
103
+ desc 'List all tasks available from this buildfile'
104
+ task 'tasks' do
105
+ Buildr.application.tasks.select(&:comment).reject { |task| Project === task }.tap do |tasks|
106
+ width = [tasks.map(&:name).map(&:size), 20].flatten.max
107
+ tasks.each do |task|
108
+ printf " %-#{width}s # %s\n", task.name, task.comment
109
+ end
110
+ puts
111
+ end
112
+ end
113
+
114
+ end