lib/java/packaging.rb in buildr-1.2.2 vs lib/java/packaging.rb in buildr-1.2.3
- old
+ new
@@ -2,10 +2,11 @@
require "java/artifact"
require "java/java"
require "java/compile"
require "java/test"
require "tasks/zip"
+require "tasks/tar"
module Buildr
module Java
@@ -21,57 +22,54 @@
class << self
protected
def included(mod)
mod.alias_method_chain :initialize, :manifest
- mod.alias_method_chain :invoke_prerequisites, :manifest
- mod.alias_method_chain :create, :manifest
end
end
# Specifies how to create the manifest file.
attr_accessor :manifest
# Specifies files to include in the META-INF directory.
attr_accessor :meta_inf
- private
-
- def invoke_prerequisites_with_manifest()
- prerequisites << file(manifest.to_s) if String === manifest || Rake::Task === manifest
- [meta_inf].flatten.each { |file| prerequisites << file(file.to_s) }
- invoke_prerequisites_without_manifest
- end
-
- def initialize_with_manifest(*args)
+ def initialize_with_manifest(*args) #:nodoc:
+ initialize_without_manifest *args
@manifest = false
@meta_inf = []
- initialize_without_manifest *args
- end
- def create_with_manifest(zip) #:nodoc:
- [meta_inf].flatten.map(&:to_s).uniq.each { |file| zip.add "META-INF/#{File.basename(file)}", file }
- unless manifest == false
- zip.file.open("META-INF/MANIFEST.MF", "w") do |output|
- output << MANIFEST_HEADER
- if manifest
+ meta_inf_path = path("META-INF")
+ prepare do
+ @prerequisites << manifest if String === manifest || Rake::Task === manifest
+ [meta_inf].flatten.map { |file| file.to_s }.uniq.each { |file| meta_inf_path.include file }
+ end
+
+ 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|
+ @manifest_tmp.write MANIFEST_HEADER
case manifest
when Hash
- output << manifest.map { |pair| pair.map(&:to_s).join(": ") }.sort.join("\n") << "\n"
+ @manifest_tmp.write(manifest.map { |pair| pair.map{ |s| s.to_s }.join(": ") }.sort.join("\n") << "\n")
when Array
- output << manifest.reject { |section| section.empty? }.map { |section|
+ @manifest_tmp.write(manifest.reject { |section| section.empty? }.map { |section|
section.map { |pair| pair.join(": ") }.sort.join("\n").concat("\n")
- }.join("\n") << "\n"
+ }.join("\n") << "\n")
when Proc, Method
- output << manifest.call
+ @manifest_tmp.write manifest.call
when String, Rake::Task
- output << File.read(manifest.to_s)
+ @manifest_tmp.write File.read(manifest.to_s)
+ else
+ fail "Invalid manifest, expecting Hash, Array, file name/task or proc/method."
end
+ meta_inf_path.include @manifest_tmp.path, :as=>"MANIFEST.MF"
end
end
end
- create_without_manifest zip
end
end
class ::Buildr::ZipTask
@@ -140,26 +138,24 @@
def initialize(*args) #:nodoc:
super
@classes = []
@libs = []
+ prepare do
+ @classes.to_a.flatten.each { |classes| path("WEB-INF/classes").include classes, :as=>"." }
+ path("WEB-INF/lib").include Buildr.artifacts(@libs) unless @libs.nil? || @libs.empty?
+ end
end
- def invoke_prerequisites() #:nodoc:
- @classes.to_a.flatten.each { |classes| path("WEB-INF/classes").include classes, :as=>"." }
- path("WEB-INF/lib").include Buildr.artifacts(@libs.to_a.flatten)
- super
- end
-
def libs=(value) #:nodoc:
@libs |= Buildr.artifacts(value)
end
def classes=(value) #:nodoc:
@classes |= [value].flatten.map { |dir| file(dir.to_s) }
end
-
+
end
end
end
@@ -409,9 +405,23 @@
zip.include options[:include]
end
end
else
rake_check_options options, *PACKAGE_OPTIONS
+ end
+ 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)
+ 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)
end
file(file_name)
end
def package_as_sources(file_name, options) #:nodoc: