buildr 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,8 +8,6 @@ module Buildr
8
8
 
9
9
  # Options accepted by #java and other methods here.
10
10
  JAVA_OPTIONS = [ :verbose, :classpath, :name, :java_args, :properties ]
11
- # Classpath dependencies available when running JUnit.
12
- JUNIT_REQUIRES = [ "junit:junit:jar:3.8.1", "jmock:jmock:jar:1.1.0" ]
13
11
 
14
12
  # Returned by Java#rjb, you can use this object to set the RJB classpath, specify blocks to be invoked
15
13
  # after loading RJB, and load RJB itself.
@@ -21,7 +19,7 @@ module Buildr
21
19
  # For that reason, you should not load RJB until the moment you need it. You can call #load or call
22
20
  # Java#rjb with a block. For the same reason, you may need to specify code to execute when loading
23
21
  # (see #onload).
24
- class RjbWrapper
22
+ class RjbWrapper #:nodoc:
25
23
 
26
24
  include Singleton
27
25
 
@@ -30,8 +28,8 @@ module Buildr
30
28
  @onload = []
31
29
  onload do
32
30
  onload do
33
- Rjb.load(Buildr.artifacts(classpath).each { |task| task.invoke if task.respond_to?(:invoke) }.
34
- map(&:to_s).join(File::PATH_SEPARATOR))
31
+ classpath = Buildr.artifacts(@classpath).each { |task| task.invoke if task.respond_to?(:invoke) }.map(&:to_s)
32
+ ::Rjb.load classpath.join(File::PATH_SEPARATOR), Buildr.options.java_args.flatten
35
33
  end
36
34
  end
37
35
  end
@@ -61,7 +59,7 @@ module Buildr
61
59
  end
62
60
 
63
61
  def method_missing(sym, *args, &block) #:nodoc:
64
- Rjb.send sym, *args, &block
62
+ ::Rjb.send sym, *args, &block
65
63
  end
66
64
  end
67
65
 
@@ -76,7 +74,7 @@ module Buildr
76
74
  # puts Java.version
77
75
  # => 1.5.0_10
78
76
  def version()
79
- @version ||= `"#{path_to_bin("java")}" -version 2>&1`.scan(/java version "(.*)"/)[0][0]
77
+ @version ||= Java.rjb { |rjb| rjb.import("java.lang.System").getProperty("java.version") }
80
78
  end
81
79
 
82
80
  # :call-seq:
@@ -119,7 +117,7 @@ module Buildr
119
117
  classpath = classpath_from(options)
120
118
  cmd_args << "-cp" << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
121
119
  options[:properties].each { |k, v| cmd_args << "-D#{k}=#{v}" } if options[:properties]
122
- cmd_args += options[:java_args].flatten if options[:java_args]
120
+ cmd_args += (options[:java_args] || Buildr.options.java_args).flatten
123
121
  cmd_args += args.flatten.compact
124
122
  unless Rake.application.options.dryrun
125
123
  puts "Running #{name}" if verbose
@@ -271,18 +269,22 @@ module Buildr
271
269
  # * :classpath -- One or more file names, tasks or artifact specifications.
272
270
  # These are all expanded into artifacts, and all tasks are invoked.
273
271
  # * :properties -- Hash of system properties (e.g. "path"=>base_dir).
272
+ # * :java_args -- Any additional arguments to pass (e.g. -hotspot, -xms)
274
273
  # * :verbose -- If true, prints the command and all its argument.
274
+ #
275
+ # *Deprecated:* Please use JUnitTask instead.Use the test task to run JUnit and other test frameworks.
275
276
  def junit(*args)
277
+ warn_deprecated "Use the test task to run JUnit and other test frameworks"
276
278
  options = Hash === args.last ? args.pop : {}
277
279
  options[:verbose] ||= Rake.application.options.trace || false
278
280
  rake_check_options options, :verbose, :classpath, :properties, :java_args
279
281
 
280
- classpath = classpath_from(options) + junit_artifacts
282
+ classpath = classpath_from(options) + JUnitTask::requires
281
283
  tests = args.flatten
282
284
  failed = tests.inject([]) do |failed, test|
283
285
  begin
284
286
  java "junit.textui.TestRunner", test, :classpath=>classpath, :properties=>options[:properties],
285
- :name=>"#{test}", :verbose=>options[:verbose]
287
+ :name=>"#{test}", :verbose=>options[:verbose], :java_args=>options[:java_args]
286
288
  failed
287
289
  rescue
288
290
  failed << test
@@ -291,6 +293,7 @@ module Buildr
291
293
  [ tests - failed, failed ]
292
294
  end
293
295
 
296
+
294
297
  # :call-seq:
295
298
  # rjb() => RjbWrapper
296
299
  # rjb() { ... }
@@ -336,14 +339,6 @@ module Buildr
336
339
  Buildr.artifacts(classpath).each { |t| t.invoke if t.respond_to?(:invoke) }.map(&:to_s)
337
340
  end
338
341
 
339
- # :call-seq:
340
- # junit_artifacts() => files
341
- #
342
- # Returns the JUnit artifacts as paths, after downloading and installing them (if necessary).
343
- def junit_artifacts()
344
- @junit_artifacts ||= Buildr.artifacts(JUNIT_REQUIRES).each { |task| task.invoke }.map(&:to_s)
345
- end
346
-
347
342
  def darwin?() #:nodoc:
348
343
  RUBY_PLATFORM =~ /darwin/i
349
344
  end
@@ -376,4 +371,33 @@ module Buildr
376
371
 
377
372
  include Java
378
373
 
374
+ class Options
375
+
376
+ # :call-seq:
377
+ # java_args => array
378
+ #
379
+ # Returns the Java arguments.
380
+ def java_args()
381
+ @java_args ||= (ENV["JAVA_OPTIONS"] || ENV["java_options"] || "").split(" ")
382
+ end
383
+
384
+ # :call-seq:
385
+ # java_args = array|string|nil
386
+ #
387
+ # Sets the Java arguments. These arguments are used when creating a JVM, including for use with RJB
388
+ # for most tasks (e.g. Ant, compile) and when forking a separate JVM (e.g. JUnit tests). You can also
389
+ # use the JAVA_OPTIONS environment variable.
390
+ #
391
+ # For example:
392
+ # options.java_args = "-verbose"
393
+ # Or:
394
+ # $ set JAVA_OPTIONS = "-Xms1g"
395
+ # $ buildr
396
+ def java_args=(args)
397
+ args = args.split if String === args
398
+ @java_args = args.to_a
399
+ end
400
+
401
+ end
402
+
379
403
  end
@@ -2,6 +2,7 @@ require "core/project"
2
2
  require "java/artifact"
3
3
  require "java/java"
4
4
  require "java/compile"
5
+ require "java/test"
5
6
  require "tasks/zip"
6
7
 
7
8
 
@@ -15,25 +16,17 @@ module Buildr
15
16
 
16
17
  MANIFEST_HEADER = "Manifest-Version: 1.0\nCreated-By: Buildr\n"
17
18
 
18
- # Extends the ZipTask to create a JAR file.
19
- #
20
- # This task supports two additional attributes: manifest and meta-inf.
21
- #
22
- # The manifest attribute specifies how to create the MANIFEST.MF file.
23
- # * A hash of manifest properties (name/value pairs).
24
- # * An array of hashes, one for each section of the manifest.
25
- # * A string providing the name of an existing manifest file.
26
- # * A file task can be used the same way.
27
- # * Proc or method called to return the contents of the manifest file.
28
- # * False to not generate a manifest file.
29
- #
30
- # The meta-inf attribute lists one or more files that should be copied into
31
- # the META-INF directory.
32
- #
33
- # For example:
34
- # package(:jar).using(:manifest=>"src/MANIFEST.MF")
35
- # package(:jar).meta_inf << file("README")
36
- class JarTask < ZipTask
19
+ # Adds support for MANIFEST.MF and other META-INF files.
20
+ module WithManifest
21
+
22
+ class << self
23
+ protected
24
+ def included(mod)
25
+ mod.alias_method_chain :initialize, :manifest
26
+ mod.alias_method_chain :invoke_prerequisites, :manifest
27
+ mod.alias_method_chain :create, :manifest
28
+ end
29
+ end
37
30
 
38
31
  # Specifies how to create the manifest file.
39
32
  attr_accessor :manifest
@@ -41,31 +34,21 @@ module Buildr
41
34
  # Specifies files to include in the META-INF directory.
42
35
  attr_accessor :meta_inf
43
36
 
44
- def initialize(*args) #:nodoc:
45
- super
46
- @manifest = true
47
- @meta_inf = []
48
- end
37
+ private
49
38
 
50
- def []=(key, value) #:nodoc:
51
- if key.to_sym == :manifest
52
- self.manifest = value
53
- elsif key.to_sym == :meta_inf
54
- self.meta_inf = [value].flatten
55
- else
56
- super key, value
57
- end
58
- value
39
+ def invoke_prerequisites_with_manifest()
40
+ prerequisites << file(manifest.to_s) if String === manifest || Rake::Task === manifest
41
+ [meta_inf].flatten.each { |file| prerequisites << file(file.to_s) }
42
+ invoke_prerequisites_without_manifest
59
43
  end
60
44
 
61
- def prerequisites() #:nodoc:
62
- super + [ String === manifest ? file(manifest) : nil ].compact +
63
- [meta_inf].flatten.map { |file| String === file ? file(file) : file }
45
+ def initialize_with_manifest(*args)
46
+ @manifest = false
47
+ @meta_inf = []
48
+ initialize_without_manifest *args
64
49
  end
65
50
 
66
- protected
67
-
68
- def create(zip) #:nodoc:
51
+ def create_with_manifest(zip) #:nodoc:
69
52
  [meta_inf].flatten.map(&:to_s).uniq.each { |file| zip.add "META-INF/#{File.basename(file)}", file }
70
53
  unless manifest == false
71
54
  zip.file.open("META-INF/MANIFEST.MF", "w") do |output|
@@ -80,13 +63,59 @@ module Buildr
80
63
  }.join("\n") << "\n"
81
64
  when Proc, Method
82
65
  output << manifest.call
83
- when String, Task
66
+ when String, Rake::Task
84
67
  output << File.read(manifest.to_s)
85
68
  end
86
69
  end
87
70
  end
88
71
  end
89
- super zip
72
+ create_without_manifest zip
73
+ end
74
+
75
+ end
76
+
77
+ class ::Buildr::ZipTask
78
+ include WithManifest
79
+ end
80
+
81
+
82
+ # Extends the ZipTask to create a JAR file.
83
+ #
84
+ # This task supports two additional attributes: manifest and meta-inf.
85
+ #
86
+ # The manifest attribute specifies how to create the MANIFEST.MF file.
87
+ # * A hash of manifest properties (name/value pairs).
88
+ # * An array of hashes, one for each section of the manifest.
89
+ # * A string providing the name of an existing manifest file.
90
+ # * A file task can be used the same way.
91
+ # * Proc or method called to return the contents of the manifest file.
92
+ # * False to not generate a manifest file.
93
+ #
94
+ # The meta-inf attribute lists one or more files that should be copied into
95
+ # the META-INF directory.
96
+ #
97
+ # For example:
98
+ # package(:jar).with(:manifest=>"src/MANIFEST.MF")
99
+ # package(:jar).meta_inf << file("README")
100
+ class JarTask < ZipTask
101
+
102
+ def initialize(*args) #:nodoc:
103
+ super
104
+ end
105
+
106
+ # :call-seq:
107
+ # with(options) => self
108
+ #
109
+ # Additional
110
+ # Pass options to the task. Returns self. ZipTask itself does not support any options,
111
+ # but other tasks (e.g. JarTask, WarTask) do.
112
+ #
113
+ # For example:
114
+ # package(:jar).with(:manifest=>"MANIFEST_MF")
115
+ def with(*args)
116
+ super args.pop if Hash === args.last
117
+ include :from=>args
118
+ self
90
119
  end
91
120
 
92
121
  end
@@ -100,19 +129,33 @@ module Buildr
100
129
  # directory.
101
130
  #
102
131
  # For example:
103
- # package(:war).using(:libs=>"log4j:log4j:jar:1.1")
132
+ # package(:war).with(:libs=>"log4j:log4j:jar:1.1")
104
133
  class WarTask < JarTask
105
134
 
106
- def []=(key, value) #:nodoc:
107
- case key.to_sym
108
- when :libs
109
- self.include Buildr.artifacts(value), :path=>"WEB-INF/lib"
110
- when :classes
111
- self.include value, :path=>"WEB-INF/classes", :as=>"."
112
- else
113
- super key, value
114
- end
115
- value
135
+ # Directories with class files to include under WEB-INF/classes.
136
+ attr_accessor :classes
137
+
138
+ # Artifacts to include under WEB-INF/libs.
139
+ attr_accessor :libs
140
+
141
+ def initialize(*args) #:nodoc:
142
+ super
143
+ @classes = []
144
+ @libs = []
145
+ end
146
+
147
+ def invoke_prerequisites() #:nodoc:
148
+ @classes.to_a.flatten.each { |classes| path("WEB-INF/classes").include classes, :as=>"." }
149
+ path("WEB-INF/lib").include Buildr.artifacts(@libs.to_a.flatten)
150
+ super
151
+ end
152
+
153
+ def libs=(value) #:nodoc:
154
+ @libs |= Buildr.artifacts(value)
155
+ end
156
+
157
+ def classes=(value) #:nodoc:
158
+ @classes |= [value].flatten.map { |dir| file(dir.to_s) }
116
159
  end
117
160
 
118
161
  end
@@ -121,6 +164,13 @@ module Buildr
121
164
  end
122
165
 
123
166
 
167
+ Project.on_define do |project|
168
+ # Need to run buildr before package, since package is often used as a dependency by tasks that
169
+ # expect build to happen.
170
+ task "package"=>task("build")
171
+ end
172
+
173
+
124
174
  class Project
125
175
 
126
176
  # Options accepted by #package method for all package types.
@@ -161,42 +211,31 @@ module Buildr
161
211
  end
162
212
 
163
213
  # :call-seq:
164
- # package(type, options?) => task
214
+ # package(type, spec?) => task
165
215
  #
166
216
  # Defines and returns a package created by this project.
167
217
  #
168
218
  # The first argument declares the package type. For example, :jar to create a JAR file.
169
- # The second argument provides additional options used when defining the package.
219
+ # The package is an artifact that takes its artifact specification from the project.
220
+ # You can override the artifact specification by passing various options in the second
221
+ # argument, for example:
222
+ # package(:zip, :classifier=>"sources")
170
223
  #
171
- # The following options are supported by all package types:
172
- # * :id -- The artifact identifier. By default, uses the project's #id property.
173
- # * :group -- The group identifier. By default, uses the project's #group property.
174
- # * :version -- The version number. By default, uses the project's #version property.
175
- # * :classifier -- Artifact classifier. By default, the artifact has no classifier.
224
+ # Packages that are ZIP files provides various ways to include additional files, directories,
225
+ # and even merge ZIPs together. Have a look at ZipTask for more information. In case you're
226
+ # wondering, JAR and WAR packages are ZIP files.
176
227
  #
177
- # The JAR packager adds the following options:
228
+ # You can also enhance a JAR package using the ZipTask#with method that accepts the following options:
178
229
  # * :manifest -- Specifies how to create the MANIFEST.MF. By default, uses the project's
179
230
  # #manifest property.
180
231
  # * :meta_inf -- Specifies files to be included in the META-INF directory. By default,
181
232
  # uses the project's #meta-inf property.
182
- # * :include -- List of files and directories to include in the JAR. By default,
183
- # includes the contents of the target/classes directory.
184
233
  #
185
- # The WAR packager adds the following options:
186
- # * :manifest -- See JAR.
187
- # * :meta_inf -- See JAR.
188
- # * :classes -- Directories of class files to include in WEB-INF/classes. By default,
189
- # includes the contents of the target/classes directory.
190
- # * :libs -- Artifacts and files to include in WEB-INF/libs. By default, includes the
191
- # compile classpath.
192
- # * :include -- List of files and directories to include in the JAR. By default,
193
- # includes the contents of the src/main/webapp directory.
194
- #
195
- # The ZIP packager adds the following options:
196
- # * :include -- List of file and directories to include in the ZIP.
197
- #
198
- # In addition, you can always enhance the package task directly, e.g. by calling the
199
- # ZipTask#include and ZipTask#with methods.
234
+ # The WAR package supports the same options and adds a few more:
235
+ # * :classes -- Directories of class files to include in WEB-INF/classes. Includes the compile
236
+ # target directory by default.
237
+ # * :libs -- Artifacts and files to include in WEB-INF/libs. Includes the compile classpath
238
+ # dependencies by default.
200
239
  #
201
240
  # For example:
202
241
  # define "project" do
@@ -205,28 +244,26 @@ module Buildr
205
244
  # end
206
245
  # define "webapp" do
207
246
  # compile.with project("beans")
208
- # package :war
247
+ # package(:war).with :libs=>MYSQL_JDBC
209
248
  # end
210
- # package :zip, :classifier=>"sources", :include=>"."
249
+ # package(:zip, :classifier=>"sources").include path_to(".")
211
250
  # end
212
251
  #
213
- # The first time you call package, it defines the new task. Afterwards, it only uses some of the
214
- # options (file_name, id, etc) to find an existing package task and return it.
215
- #
216
- # For example:
217
- # # Create a new package that includes an existing package.
218
- # package(:war).include project("foo:bar").package(:jar)
252
+ # Two other packaging types are:
253
+ # * package :sources -- Creates a ZIP file with the source code and classifier "sources", for use by IDEs.
254
+ # * package :javadoc -- Creates a ZIP file with the Javadocs and classifier "javadoc". You can use the
255
+ # javadoc method to further customize it.
219
256
  #
220
257
  # A package is also an artifact. The following tasks operate on packages created by the project:
221
- # rake deploy # Deploy packages created by the project
222
- # rake install # Install packages created by the project
223
- # rake package # Create packages
224
- # rake uninstall # Remove previously installed packages
258
+ # buildr upload # Upload packages created by the project
259
+ # buildr install # Install packages created by the project
260
+ # buildr package # Create packages
261
+ # buildr uninstall # Remove previously installed packages
225
262
  #
226
263
  # If you want to add additional packaging types, implement a method with the name package_as_[type]
227
- # that accepts two arguments, the file name and a hash of options. The method must yield to the
228
- # block with the package only when first called to define the package, and must return the package
229
- # from each call.
264
+ # that accepts two arguments, the file name and a hash of options. You can change the options and
265
+ # file name, e.g. to add a classifier or change the file type. Your method may be called multiple times,
266
+ # and must return the same file task on each call.
230
267
  def package(type = :jar, options = nil)
231
268
  options = options.nil? ? {} : options.dup
232
269
  options[:id] ||= self.id
@@ -237,7 +274,8 @@ module Buildr
237
274
 
238
275
  packager = method("package_as_#{type}") rescue
239
276
  fail("Don't know how to create a package of type #{type}")
240
- packager.call(file_name, options) do |package|
277
+ package = packager.call(file_name, options) { warn_deprecated "Yielding from package_as_ no longer necessary." }
278
+ unless packages.include?(package)
241
279
  # Make it an artifact using the specifications, and tell it how to create a POM.
242
280
  package.extend ActsAsArtifact
243
281
  package.send :apply_spec, Hash[*Artifact::ARTIFACT_ATTRIBUTES.map { |k| [ k,options[k]] }.flatten]
@@ -248,20 +286,11 @@ module Buildr
248
286
  pom.send :apply_spec, pom_spec
249
287
  pom.enhance do
250
288
  mkpath File.dirname(pom.name), :verbose=>false
251
- File.open(pom.name, "w") do |file|
252
- xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
253
- xml.instruct!
254
- xml.project do
255
- xml.modelVersion "4.0.0"
256
- xml.groupId pom.group
257
- xml.artifactId pom.id
258
- xml.version pom.version
259
- xml.classifier pom.classifier if pom.classifier
260
- end
261
- end
289
+ File.open(pom.name, "w") { |file| file.write pom.pom_xml }
262
290
  end
263
291
 
264
- # Make sure the package task creates it, and it invokes the build task first.
292
+ # We already run build before package, but we also need to do so if the package itself is
293
+ # used as a dependency, before we get to run the package task.
265
294
  task "package"=>package
266
295
  package.enhance [task("build")]
267
296
 
@@ -282,7 +311,7 @@ module Buildr
282
311
  [ installed, pom ].map(&:to_s).each { |file| rm file if File.exist?(file) }
283
312
  end
284
313
  end
285
- task("deploy") { deploy(package, pom) }
314
+ task("upload") { package.pom.invoke ; package.pom.upload ; package.upload }
286
315
 
287
316
  # Add the package to the list of packages created by this project, and
288
317
  # register it as an artifact. The later is required so if we look up the spec
@@ -291,6 +320,7 @@ module Buildr
291
320
  packages << package
292
321
  Artifact.register package, pom
293
322
  end
323
+ package
294
324
  end
295
325
 
296
326
  # :call-seq:
@@ -312,15 +342,19 @@ module Buildr
312
342
  unless Rake::Task.task_defined?(file_name)
313
343
  rake_check_options options, *PACKAGE_OPTIONS + [:manifest, :meta_inf, :include]
314
344
  Java::Packaging::JarTask.define_task(file_name).tap do |jar|
315
- jar.manifest = options.has_key?(:manifest) ? options[:manifest] : manifest
316
- jar.meta_inf = options[:meta_inf] || meta_inf
345
+ jar.with :manifest=>manifest, :meta_inf=>meta_inf
346
+ [:manifest, :meta_inf].each do |option|
347
+ if options.has_key?(option)
348
+ warn_deprecated "The :#{option} option in package(:jar) is deprecated, please use package(:jar).with(:#{option}=>) instead."
349
+ jar.with option=>options[option]
350
+ end
351
+ end
317
352
  if options[:include]
353
+ warn_deprecated "The :include option in package(:jar) is deprecated, please use package(:jar).include(files) instead."
318
354
  jar.include options[:include]
319
355
  else
320
- # Can only decide on this once we're done configuring the compile task.
321
- enhance { jar.include compile.target, :as=>"." }
356
+ jar.with compile.target unless compile.sources.empty?
322
357
  end
323
- yield jar
324
358
  end
325
359
  else
326
360
  rake_check_options options, *PACKAGE_OPTIONS
@@ -332,28 +366,33 @@ module Buildr
332
366
  unless Rake::Task.task_defined?(file_name)
333
367
  rake_check_options options, *PACKAGE_OPTIONS + [:manifest, :meta_inf, :classes, :libs, :include]
334
368
  Java::Packaging::WarTask.define_task(file_name).tap do |war|
335
- war.manifest = options.has_key?(:manifest) ? options[:manifest] : manifest
336
- war.meta_inf = options[:meta_inf] || meta_inf
369
+ war.with :manifest=>manifest, :meta_inf=>meta_inf
370
+ [:manifest, :meta_inf].each do |option|
371
+ if options.has_key?(option)
372
+ warn_deprecated "The :#{option} option in package :war is deprecated, please use package(:war).with(:#{option}=>) instead."
373
+ war.with option=>options[option]
374
+ end
375
+ end
337
376
  # Add libraries in WEB-INF lib, and classes in WEB-INF classes
338
- if options[:classes]
377
+ if options.has_key?(:classes)
378
+ warn_deprecated "The :classes option in package(:war) is deprecated, please use package(:war).with(:classes=>) instead."
339
379
  war.with :classes=>options[:classes]
340
380
  else
341
- # Can only decide on this once we're done configuring the compile task.
342
- enhance { war.with :classes=>compile.target unless compile.sources.empty? }
381
+ war.with :classes=>compile.target unless compile.sources.empty?
343
382
  end
344
- if options[:libs]
383
+ if options.has_key?(:libs)
384
+ warn_deprecated "The :libs option in package(:war) is deprecated, please use package(:war).with(:libs=>) instead."
345
385
  war.with :libs=>options[:libs].collect
346
386
  else
347
- # Can only decide on this once we're done configuring the compile task.
348
- enhance { war.with :libs=>compile.classpath }
387
+ war.with :libs=>compile.classpath
349
388
  end
350
389
  # Add included files, or the webapp directory.
351
- if options[:include]
390
+ if options.has_key?(:include)
391
+ warn_deprecated "The :include option in package(:war) is deprecated, please use package(:war).include(files) instead."
352
392
  war.include options[:include]
353
- elsif File.exist?(path_to("src/main/webapp"))
354
- war.include path_to("src/main/webapp"), :as=>"."
393
+ else
394
+ path_to("src/main/webapp").tap { |path| war.with path if File.exist?(path) }
355
395
  end
356
- yield war
357
396
  end
358
397
  else
359
398
  rake_check_options options, *PACKAGE_OPTIONS
@@ -366,9 +405,9 @@ module Buildr
366
405
  rake_check_options options, *PACKAGE_OPTIONS + [:include]
367
406
  ZipTask.define_task(file_name).tap do |zip|
368
407
  if options[:include]
408
+ warn_deprecated "The :include option in package(:zip) is deprecated, please use package(:zip).include(files) instead."
369
409
  zip.include options[:include]
370
410
  end
371
- yield zip
372
411
  end
373
412
  else
374
413
  rake_check_options options, *PACKAGE_OPTIONS
@@ -376,6 +415,85 @@ module Buildr
376
415
  file(file_name)
377
416
  end
378
417
 
418
+ def package_as_sources(file_name, options) #:nodoc:
419
+ rake_check_options options, *PACKAGE_OPTIONS
420
+ options.merge!(:type=>:zip, :classifier=>"sources")
421
+ file_name = path_to(:target, Artifact.hash_to_file_name(options))
422
+ ZipTask.define_task(file_name).tap { |zip| zip.include :from=>compile.sources } unless Rake::Task.task_defined?(file_name)
423
+ file(file_name)
424
+ end
425
+
426
+ def package_as_javadoc(file_name, options) #:nodoc:
427
+ rake_check_options options, *PACKAGE_OPTIONS
428
+ options.merge!(:type=>:zip, :classifier=>"javadoc")
429
+ file_name = path_to(:target, Artifact.hash_to_file_name(options))
430
+ unless Rake::Task.task_defined?(file_name)
431
+ ZipTask.define_task(file_name).tap { |zip| zip.include :from=>javadoc.target }
432
+ javadoc.options[:windowtitle] ||= project.comment || project.name
433
+ end
434
+ file(file_name)
435
+ end
436
+
437
+ end
438
+
439
+ class Project
440
+
441
+ # :call-seq:
442
+ # package_with_sources(options?)
443
+ #
444
+ # Call this when you want the project (and all its sub-projects) to create a source distribution.
445
+ # You can use the source distribution in an IDE when debugging.
446
+ #
447
+ # A source distribution is a ZIP package with the classifier "sources", which includes all the
448
+ # sources used by the compile task.
449
+ #
450
+ # Packages use the project's manifest and meta_inf properties, which you can override by passing
451
+ # different values (e.g. false to exclude the manifest) in the options.
452
+ #
453
+ # To create source distributions only for specific projects, use the :only and :except options,
454
+ # for example:
455
+ # package_with_sources :only=>["foo:bar", "foo:baz"]
456
+ #
457
+ # (Same as calling package :sources on each project/sub-project that has source directories.)
458
+ def package_with_sources(options = nil)
459
+ options ||= {}
460
+ enhance do
461
+ selected = options[:only] ? projects(options[:only]) :
462
+ options[:except] ? ([self] + projects - projects(options[:except])) :
463
+ [self] + projects
464
+ selected.reject { |project| project.compile.sources.empty? }.
465
+ each { |project| project.package(:sources) }
466
+ end
467
+ end
468
+
469
+ # :call-seq:
470
+ # package_with_javadoc(options?)
471
+ #
472
+ # Call this when you want the project (and all its sub-projects) to create a JavaDoc distribution.
473
+ # You can use the JavaDoc distribution in an IDE when coding against the API.
474
+ #
475
+ # A JavaDoc distribution is a ZIP package with the classifier "javadoc", which includes all the
476
+ # sources used by the compile task.
477
+ #
478
+ # Packages use the project's manifest and meta_inf properties, which you can override by passing
479
+ # different values (e.g. false to exclude the manifest) in the options.
480
+ #
481
+ # To create JavaDoc distributions only for specific projects, use the :only and :except options,
482
+ # for example:
483
+ # package_with_javadoc :only=>["foo:bar", "foo:baz"]
484
+ #
485
+ # (Same as calling package :javadoc on each project/sub-project that has source directories.)
486
+ def package_with_javadoc(options = nil)
487
+ options ||= {}
488
+ enhance do
489
+ selected = options[:only] ? projects(options[:only]) :
490
+ options[:except] ? ([self] + projects - projects(options[:except])) :
491
+ [self] + projects
492
+ selected.reject { |project| project.compile.sources.empty? }.
493
+ each { |project| project.package(:javadoc) }
494
+ end
495
+ end
496
+
379
497
  end
380
498
 
381
499
  end