realityforge-buildr 1.5.9

Sign up to get free protection for your applications and to get access to all the features.
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,62 @@
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
+ module Doc #:nodoc:
18
+
19
+ module JavadocDefaults
20
+ include Extension
21
+
22
+ # Default javadoc -windowtitle to project's comment or name
23
+ after_define(:javadoc => :doc) do |project|
24
+ if project.doc.engine? Javadoc
25
+ options = project.doc.options
26
+ options[:windowtitle] = (project.comment || project.name) unless options[:windowtitle]
27
+ project.doc.sourcepath = project.compile.sources.dup if project.doc.sourcepath.empty?
28
+ end
29
+ end
30
+ end
31
+
32
+ # A convenient task for creating Javadocs from the project's compile task. Minimizes all
33
+ # the hard work to calling #from and #using.
34
+ #
35
+ # For example:
36
+ # doc.from(projects('myapp:foo', 'myapp:bar')).using(:windowtitle=>'My App')
37
+ # Or, short and sweet:
38
+ # desc 'My App'
39
+ # define 'myapp' do
40
+ # . . .
41
+ # doc projects('myapp:foo', 'myapp:bar')
42
+ # end
43
+ class Javadoc < Base
44
+
45
+ specify :language => :java, :source_ext => 'java'
46
+
47
+ def generate(sources, target, options = {})
48
+ options = options.dup
49
+ options[trace?(:javadoc) ? :verbose : :quiet] = true
50
+ options[:output] = target
51
+
52
+ Java::Commands.javadoc(*sources.flatten.uniq, options)
53
+ end
54
+ end
55
+ end
56
+
57
+ class Project #:nodoc:
58
+ include JavadocDefaults
59
+ end
60
+ end
61
+
62
+ Buildr::Doc.engines << Buildr::Doc::Javadoc
@@ -0,0 +1,393 @@
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
+ module Packaging #:nodoc:
18
+
19
+ # Adds packaging for Java projects: JAR, WAR, AAR, EAR, Javadoc.
20
+ module Java
21
+
22
+ class Manifest
23
+
24
+ STANDARD_HEADER = { 'Manifest-Version'=>'1.0', 'Created-By'=>'Buildr' }
25
+ LINE_SEPARATOR = /\r\n|\n|\r[^\n]/ #:nodoc:
26
+ SECTION_SEPARATOR = /(#{LINE_SEPARATOR}){2}/ #:nodoc:
27
+
28
+ class << self
29
+
30
+ # :call-seq:
31
+ # parse(str) => manifest
32
+ #
33
+ # Parse a string in MANIFEST.MF format and return a new Manifest.
34
+ def parse(str)
35
+ sections = str.split(SECTION_SEPARATOR).reject { |s| s.strip.empty? }
36
+ new sections.map { |section|
37
+ lines = section.split(LINE_SEPARATOR).inject([]) { |merged, line|
38
+ if line[/^ /] == ' '
39
+ merged.last << line[1..-1]
40
+ else
41
+ merged << line
42
+ end
43
+ merged
44
+ }
45
+ lines.map { |line| line.scan(/(.*?):\s*(.*)/).first }.
46
+ inject({}) { |map, (key, value)| map.merge(key=>value) }
47
+ }
48
+ end
49
+
50
+ # :call-seq:
51
+ # from_zip(file) => manifest
52
+ #
53
+ # Parse the MANIFEST.MF entry of a ZIP (or JAR) file and return a new Manifest.
54
+ def from_zip(file)
55
+ Zip::File.open(file.to_s) do |zip|
56
+ return Manifest.parse zip.read('META-INF/MANIFEST.MF') if zip.find_entry('META-INF/MANIFEST.MF')
57
+ end
58
+ Manifest.new
59
+ end
60
+
61
+ # :call-seq:
62
+ # update_manifest(file) { |manifest| ... }
63
+ #
64
+ # Updates the MANIFEST.MF entry of a ZIP (or JAR) file. Reads the MANIFEST.MF,
65
+ # yields to the block with the Manifest object, and writes the modified object
66
+ # back to the file.
67
+ def update_manifest(file)
68
+ manifest = from_zip(file)
69
+ result = yield manifest
70
+ Zip::File.open(file.to_s) do |zip|
71
+ zip.get_output_stream('META-INF/MANIFEST.MF') do |out|
72
+ out.write manifest.to_s
73
+ out.write "\n"
74
+ end
75
+ end
76
+ result
77
+ end
78
+
79
+ end
80
+
81
+ # Returns a new Manifest object based on the argument:
82
+ # * nil -- Empty Manifest.
83
+ # * Hash -- Manifest with main section using the hash name/value pairs.
84
+ # * Array -- Manifest with one section from each entry (must be hashes).
85
+ # * String -- Parse (see Manifest#parse).
86
+ # * Proc/Method -- New Manifest from result of calling proc/method.
87
+ def initialize(arg = nil)
88
+ case arg
89
+ when nil, Hash then @sections = [arg || {}]
90
+ when Array then @sections = arg
91
+ when String then @sections = Manifest.parse(arg).sections
92
+ when Proc, Method then @sections = Manifest.new(arg.call).sections
93
+ else
94
+ fail 'Invalid manifest, expecting Hash, Array, file name/task or proc/method.'
95
+ end
96
+ # Add Manifest-Version and Created-By, if not specified.
97
+ STANDARD_HEADER.each do |name, value|
98
+ sections.first[name] ||= value
99
+ end
100
+ end
101
+
102
+ # The sections of this manifest.
103
+ attr_reader :sections
104
+
105
+ # The main (first) section of this manifest.
106
+ def main
107
+ sections.first
108
+ end
109
+
110
+ include Enumerable
111
+
112
+ # Iterate over each section and yield to block.
113
+ def each(&block)
114
+ @sections.each(&block)
115
+ end
116
+
117
+ # Convert to MANIFEST.MF format.
118
+ def to_s
119
+ @sections.map { |section|
120
+ keys = section.keys
121
+ keys.unshift('Name') if keys.delete('Name')
122
+ lines = keys.map { |key| manifest_wrap_at_72("#{key}: #{section[key]}") }
123
+ lines + ['']
124
+ }.flatten.join("\n")
125
+ end
126
+
127
+ private
128
+
129
+ def manifest_wrap_at_72(line)
130
+ return [line] if line.size < 72
131
+ [ line[0..70] ] + manifest_wrap_at_72(' ' + line[71..-1])
132
+ end
133
+
134
+ end
135
+
136
+
137
+ # Adds support for MANIFEST.MF and other META-INF files.
138
+ module WithManifest #:nodoc:
139
+
140
+ class << self
141
+ def included(base)
142
+ base.class_eval do
143
+ alias :initialize_without_manifest :initialize
144
+ alias :initialize :initialize_with_manifest
145
+ end
146
+ end
147
+
148
+ end
149
+
150
+ # Specifies how to create the manifest file.
151
+ attr_accessor :manifest
152
+
153
+ # Specifies files to include in the META-INF directory.
154
+ attr_accessor :meta_inf
155
+
156
+ def initialize_with_manifest(*args) #:nodoc:
157
+ initialize_without_manifest *args
158
+ @manifest = false
159
+ @meta_inf = []
160
+ @dependencies = FileList[]
161
+
162
+ prepare do
163
+ @prerequisites << manifest if String === manifest || Rake::Task === manifest
164
+ [meta_inf].flatten.map { |file| file.to_s }.uniq.each { |file| path('META-INF').include file }
165
+ end
166
+
167
+ enhance do
168
+ if manifest
169
+ # Tempfiles gets deleted on garbage collection, so we're going to hold on to it
170
+ # through instance variable not closure variable.
171
+ @manifest_tmp = Tempfile.new('MANIFEST.MF')
172
+ File.chmod 0644, @manifest_tmp.path
173
+ self.manifest = File.read(manifest.to_s) if String === manifest || Rake::Task === manifest
174
+ self.manifest = Manifest.new(manifest) unless Manifest === manifest
175
+ #@manifest_tmp.write Manifest::STANDARD_HEADER
176
+ @manifest_tmp.write manifest.to_s
177
+ @manifest_tmp.write "\n"
178
+ @manifest_tmp.close
179
+ path('META-INF').include @manifest_tmp.path, :as=>'MANIFEST.MF'
180
+ end
181
+ end
182
+ end
183
+
184
+ end
185
+
186
+ class ::Buildr::ZipTask
187
+ include WithManifest
188
+ end
189
+
190
+
191
+ # Extends the ZipTask to create a JAR file.
192
+ #
193
+ # This task supports two additional attributes: manifest and meta-inf.
194
+ #
195
+ # The manifest attribute specifies how to create the MANIFEST.MF file.
196
+ # * A hash of manifest properties (name/value pairs).
197
+ # * An array of hashes, one for each section of the manifest.
198
+ # * A string providing the name of an existing manifest file.
199
+ # * A file task can be used the same way.
200
+ # * Proc or method called to return the contents of the manifest file.
201
+ # * False to not generate a manifest file.
202
+ #
203
+ # The meta-inf attribute lists one or more files that should be copied into
204
+ # the META-INF directory.
205
+ #
206
+ # For example:
207
+ # package(:jar).with(:manifest=>'src/MANIFEST.MF')
208
+ # package(:jar).meta_inf << file('README')
209
+ class JarTask < ZipTask
210
+
211
+ def initialize(*args) #:nodoc:
212
+ super
213
+ enhance do
214
+ pom.invoke rescue nil if respond_to?(:pom) && pom && pom != self && classifier.nil?
215
+ end
216
+ end
217
+
218
+ # :call-seq:
219
+ # with(options) => self
220
+ #
221
+ # Additional
222
+ # Pass options to the task. Returns self. ZipTask itself does not support any options,
223
+ # but other tasks (e.g. JarTask, WarTask) do.
224
+ #
225
+ # For example:
226
+ # package(:jar).with(:manifest=>'MANIFEST_MF')
227
+ def with(*args)
228
+ super args.pop if Hash === args.last
229
+ fail 'package.with() should not contain nil values' if args.include? nil
230
+ include :from=>args if args.size > 0
231
+ self
232
+ end
233
+ end
234
+
235
+
236
+ # Extends the JarTask to create a WAR file.
237
+ #
238
+ # Supports all the same options as JarTask, in additon to these two options:
239
+ # * :libs -- An array of files, tasks, artifact specifications, etc that will be added
240
+ # to the WEB-INF/lib directory.
241
+ # * :classes -- A directory containing class files for inclusion in the WEB-INF/classes
242
+ # directory.
243
+ #
244
+ # For example:
245
+ # package(:war).with(:libs=>'log4j:log4j:jar:1.1')
246
+ class WarTask < JarTask
247
+
248
+ # Directories with class files to include under WEB-INF/classes.
249
+ attr_accessor :classes
250
+
251
+ # Artifacts to include under WEB-INF/libs.
252
+ attr_accessor :libs
253
+
254
+ def initialize(*args) #:nodoc:
255
+ super
256
+ @classes = []
257
+ @libs = []
258
+ enhance do |war|
259
+ @libs.each {|lib| lib.invoke if lib.respond_to?(:invoke) }
260
+ @classes.to_a.flatten.each { |classes| include classes, :as => 'WEB-INF/classes' }
261
+ path('WEB-INF/lib').include Buildr.artifacts(@libs) unless @libs.nil? || @libs.empty?
262
+ end
263
+ end
264
+
265
+ def libs=(value) #:nodoc:
266
+ @libs = Buildr.artifacts(value)
267
+ end
268
+
269
+ def classes=(value) #:nodoc:
270
+ @classes = [value].flatten.map { |dir| file(dir.to_s) }
271
+ end
272
+ end
273
+
274
+ include Extension
275
+
276
+ before_define(:package => :build) do |project|
277
+ if project.parent && project.parent.manifest
278
+ project.manifest = project.parent.manifest.dup
279
+ else
280
+ project.manifest = {
281
+ 'Build-By'=>ENV['USER'],
282
+ 'Implementation-Title'=>project.comment || project.name,
283
+ 'Implementation-Version'=>project.version }
284
+ end
285
+ if project.parent && project.parent.meta_inf
286
+ project.meta_inf = project.parent.meta_inf.dup
287
+ else
288
+ project.meta_inf = [project.file('LICENSE')].select { |file| File.exist?(file.to_s) }
289
+ end
290
+ end
291
+
292
+
293
+ # Manifest used for packaging. Inherited from parent project. The default value is a hash that includes
294
+ # the Build-By, Build-Jdk, Implementation-Title and Implementation-Version values.
295
+ # The later are taken from the project's comment (or name) and version number.
296
+ attr_accessor :manifest
297
+
298
+ # Files to always include in the package META-INF directory. The default value include
299
+ # the LICENSE file if one exists in the project's base directory.
300
+ attr_accessor :meta_inf
301
+
302
+ # :call-seq:
303
+ # package_with_sources(options?)
304
+ #
305
+ # Call this when you want the project (and all its sub-projects) to create a source distribution.
306
+ # You can use the source distribution in an IDE when debugging.
307
+ #
308
+ # A source distribution is a jar package with the classifier 'sources', which includes all the
309
+ # sources used by the compile task.
310
+ #
311
+ # Packages use the project's manifest and meta_inf properties, which you can override by passing
312
+ # different values (e.g. false to exclude the manifest) in the options.
313
+ #
314
+ # To create source distributions only for specific projects, use the :only and :except options,
315
+ # for example:
316
+ # package_with_sources :only=>['foo:bar', 'foo:baz']
317
+ #
318
+ # (Same as calling package :sources on each project/sub-project that has source directories.)
319
+ def package_with_sources(options = nil)
320
+ options ||= {}
321
+ enhance do
322
+ selected = options[:only] ? projects(options[:only]) :
323
+ options[:except] ? ([self] + projects - projects(options[:except])) :
324
+ [self] + projects
325
+ selected.reject { |project| project.compile.sources.empty? && project.resources.target.nil? }.
326
+ each { |project| project.package(:sources) }
327
+ end
328
+ end
329
+
330
+ # :call-seq:
331
+ # package_with_javadoc(options?)
332
+ #
333
+ # Call this when you want the project (and all its sub-projects) to create a JavaDoc distribution.
334
+ # You can use the JavaDoc distribution in an IDE when coding against the API.
335
+ #
336
+ # A JavaDoc distribution is a ZIP package with the classifier 'javadoc', which includes all the
337
+ # sources used by the compile task.
338
+ #
339
+ # Packages use the project's manifest and meta_inf properties, which you can override by passing
340
+ # different values (e.g. false to exclude the manifest) in the options.
341
+ #
342
+ # To create JavaDoc distributions only for specific projects, use the :only and :except options,
343
+ # for example:
344
+ # package_with_javadoc :only=>['foo:bar', 'foo:baz']
345
+ #
346
+ # (Same as calling package :doc on each project/sub-project that has source directories.)
347
+ def package_with_javadoc(options = nil)
348
+ options ||= {}
349
+ enhance do
350
+ selected = options[:only] ? projects(options[:only]) :
351
+ options[:except] ? ([self] + projects - projects(options[:except])) :
352
+ [self] + projects
353
+ selected.reject { |project| project.compile.sources.empty? }.
354
+ each { |project| project.package(:javadoc) }
355
+ end
356
+ end
357
+
358
+ def package_as_jar(file_name) #:nodoc:
359
+ Java::JarTask.define_task(file_name).tap do |jar|
360
+ jar.with :manifest=>manifest, :meta_inf=>meta_inf
361
+ jar.with [compile.target, resources.target].compact
362
+ end
363
+ end
364
+
365
+ def package_as_war(file_name) #:nodoc:
366
+ Java::WarTask.define_task(file_name).tap do |war|
367
+ war.with :manifest=>manifest, :meta_inf=>meta_inf
368
+ # Add libraries in WEB-INF lib, and classes in WEB-INF classes
369
+ war.with :classes=>[compile.target, resources.target].compact
370
+ war.with :libs=>compile.dependencies
371
+ webapp = path_to(:source, :main, :webapp)
372
+ war.with webapp if File.exist?(webapp)
373
+ war.enhance([assets])
374
+ war.include assets.to_s, :as => '.' unless assets.paths.empty?
375
+ end
376
+ end
377
+
378
+ def package_as_javadoc_spec(spec) #:nodoc:
379
+ spec.merge(:type=>:jar, :classifier=>'javadoc')
380
+ end
381
+
382
+ def package_as_javadoc(file_name) #:nodoc:
383
+ ZipTask.define_task(file_name).tap do |zip|
384
+ zip.include :from=>doc.target
385
+ end
386
+ end
387
+ end
388
+ end
389
+ end
390
+
391
+ class Buildr::Project #:nodoc:
392
+ include Buildr::Packaging::Java
393
+ end