Class: RakeJava::JarTask

Inherits:
Rake::Task
  • Object
show all
Includes:
RakeJavaUtil
Defined in:
lib/rakejava.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RakeJavaUtil

#path_esc, #path_sep, #popd, #pushd, #pushd_stack, #separate, #space_sep, #winderz?

Constructor Details

#initialize(name, app) ⇒ JarTask

Returns a new instance of JarTask.



244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/rakejava.rb', line 244

def initialize name, app
   super
   @files = []

   # Deal with namespaces.  I have no idea if this 
   # is a total hack.
   name =~ /.*\:(.*)/
   if $1   
      @real_name = $1
   else    
      @real_name = name
   end     
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



242
243
244
# File 'lib/rakejava.rb', line 242

def files
  @files
end

#main_classObject

Returns the value of attribute main_class.



242
243
244
# File 'lib/rakejava.rb', line 242

def main_class
  @main_class
end

#manifestObject

Returns the value of attribute manifest.



242
243
244
# File 'lib/rakejava.rb', line 242

def manifest
  @manifest
end

#sign_infoObject

Returns the value of attribute sign_info.



242
243
244
# File 'lib/rakejava.rb', line 242

def sign_info
  @sign_info
end

Instance Method Details

#execute(args = nil) ⇒ Object



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/rakejava.rb', line 258

def execute args=nil
   super

   flags = "cf"
   jar = File.expand_path(@real_name)
 
   all_files = []
   @files.each do |file_list|
      all_files << file_list.to_a
   end
   all_files.flatten!
   
   actual_files = []
   all_files.each do |item|
      if File.directory?(item)
         actual_files << Dir["#{item}/**/*"].to_a.select { |f| File.file?(f) }
      else
         actual_files << item
      end
   end
   actual_files.flatten!
   actual_files.uniq!

   # Bail if there's already a jar file and none of the
   # source files are newer.
   if uptodate?(jar, actual_files)
      puts "Jar file is up to date. Nothing to do."
      return
   end
   
   if @main_class
      unless @manifest
         @manifest = {}
      end
      @manifest["Main-Class"] = @main_class
   end
   manifest_path = " "
   if @manifest
      flags << "m"
      if @manifest.kind_of? Hash
         manifest_path << create_manifest
      elsif @manifest.kind_of? String
         manifest_path << File.expand_path(@manifest)
      end
   end
   
   cmd = "jar #{flags} #{@real_name}#{manifest_path}"
   
   # Chop the roots off the paths and then add each to the jar command
   @files.each do |file_list|
      fixed_list = file_list.to_a.map {|f| f.sub(%r[^#{file_list.root}/], '')}
      fixed_list.each {|f| cmd << " -C #{file_list.root} #{path_esc(f)}"}
   end
   
   max_cmd_len = 500
   if cmd.length < max_cmd_len
      puts cmd
   else
      puts cmd[0..max_cmd_len] + "..."
   end

   system "#{cmd}"
   puts
   
   # Now, sign the jar if we're asked to.  This only supports the
   # arguments that I need for my project at the moment.
   if @sign_info
      cmd = "jarsigner"
      cmd << " -storetype #{@sign_info[:store_type]}"
      cmd << " -keystore #{@sign_info[:key_store]}"
      cmd << " -storepass #{@sign_info[:store_pass]}"
      cmd << " #{@real_name}"
      cmd << " #{@sign_info[:alias]}"
      puts squelch_pass(cmd, @sign_info[:store_pass])
      system "#{cmd}"
      puts
   end
end