lib/java/packaging.rb in buildr-1.2.3 vs lib/java/packaging.rb in buildr-1.2.4
- old
+ new
@@ -13,11 +13,11 @@
# This module includes comming packaging classes. Each one is also reflected by
# a packaging method. Generally, you would want to use the packaging method from
# the project definition, since it does all the heavy lifting.
module Packaging
- MANIFEST_HEADER = "Manifest-Version: 1.0\nCreated-By: Buildr\n"
+ MANIFEST_HEADER = ["Manifest-Version: 1.0", "Created-By: Buildr"]
# Adds support for MANIFEST.MF and other META-INF files.
module WithManifest
class << self
@@ -47,10 +47,14 @@
enhance do
if manifest
# Tempfiles gets deleted on garbage collection, so we're going to hold on to it
# through instance variable not closure variable.
Tempfile.open "MANIFEST.MF" do |@manifest_tmp|
+ lines = String === manifest || Rake::Task === manifest ? manifest_lines_from(File.read(manifest.to_s)) :
+ manifest_lines_from(manifest)
+ @manifest_tmp.write((MANIFEST_HEADER + lines).join("\n"))
+=begin
@manifest_tmp.write MANIFEST_HEADER
case manifest
when Hash
@manifest_tmp.write(manifest.map { |pair| pair.map{ |s| s.to_s }.join(": ") }.sort.join("\n") << "\n")
when Array
@@ -62,16 +66,44 @@
when String, Rake::Task
@manifest_tmp.write File.read(manifest.to_s)
else
fail "Invalid manifest, expecting Hash, Array, file name/task or proc/method."
end
+=end
meta_inf_path.include @manifest_tmp.path, :as=>"MANIFEST.MF"
end
end
end
end
+ private
+
+ def manifest_lines_from(arg)
+ case arg
+ when Hash
+ arg.map { |name, value| "#{name}: #{value}" }.sort.
+ map { |line| manifest_wrap_at_72(line) }.flatten
+ when Array
+ arg.map { |section|
+ name = section.has_key?("Name") ? ["Name: #{section["Name"]}"] : []
+ name + section.except("Name").map { |name, value| "#{name}: #{value}" }.sort + [""]
+ }.flatten.map { |line| manifest_wrap_at_72(line) }.flatten
+ when Proc, Method
+ manifest_lines_from(arg.call)
+ when String
+ arg.split("\n").map { |line| manifest_wrap_at_72(line) }.flatten
+ else
+ fail "Invalid manifest, expecting Hash, Array, file name/task or proc/method."
+ end
+ end
+
+ def manifest_wrap_at_72(arg)
+ #return arg.map { |line| manifest_wrap_at_72(line) }.flatten.join("\n") if Array === arg
+ return arg if arg.size < 72
+ [ arg[0..70], manifest_wrap_at_72(" " + arg[71..-1]) ]
+ end
+
end
class ::Buildr::ZipTask
include WithManifest
end
@@ -411,17 +443,17 @@
file(file_name)
end
def package_as_tar(file_name, options) #:nodoc:
unless Rake::Task.task_defined?(file_name)
- TarballTask.define_task(file_name).with(options)
+ TarballTask.define_task(file_name)
end
file(file_name)
end
def package_as_tgz(file_name, options) #:nodoc:
unless Rake::Task.task_defined?(file_name)
- TarballTask.define_task(file_name).with(options)
+ TarballTask.define_task(file_name)
end
file(file_name)
end
def package_as_sources(file_name, options) #:nodoc: