Module: Buildr::Packaging::Java::WithManifest

Defined in:
lib/buildr/java/packaging.rb

Overview

Adds support for MANIFEST.MF and other META-INF files.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#manifestObject

Specifies how to create the manifest file.



154
155
156
# File 'lib/buildr/java/packaging.rb', line 154

def manifest
  @manifest
end

#meta_infObject

Specifies files to include in the META-INF directory.



157
158
159
# File 'lib/buildr/java/packaging.rb', line 157

def meta_inf
  @meta_inf
end

Class Method Details

.included(base) ⇒ Object



144
145
146
147
148
149
# File 'lib/buildr/java/packaging.rb', line 144

def included(base)
  base.class_eval do
    alias :initialize_without_manifest :initialize
    alias :initialize :initialize_with_manifest
  end
end

Instance Method Details

#initialize_with_manifest(*args) ⇒ Object

:nodoc:



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/buildr/java/packaging.rb', line 159

def initialize_with_manifest(*args) #:nodoc:
  initialize_without_manifest *args
  @manifest = false
  @meta_inf = []
  @dependencies = FileList[]

  prepare do
    @prerequisites << manifest if String === manifest || Rake::Task === manifest
    [meta_inf].flatten.map { |file| file.to_s }.uniq.each { |file| path('META-INF').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.
      @manifest_tmp = Tempfile.new('MANIFEST.MF')
      self.manifest = File.read(manifest.to_s) if String === manifest || Rake::Task === manifest
      self.manifest = Manifest.new(manifest) unless Manifest === manifest
      #@manifest_tmp.write Manifest::STANDARD_HEADER
      @manifest_tmp.write manifest.to_s
      @manifest_tmp.write "\n"
      @manifest_tmp.rewind
      path('META-INF').include @manifest_tmp.path, :as=>'MANIFEST.MF'
    end
  end
end