lib/jasper-command-line/jasper.rb in jasper-command-line-0.2.1 vs lib/jasper-command-line/jasper.rb in jasper-command-line-0.2.2

- old
+ new

@@ -84,30 +84,38 @@ jasper_print = JasperFillManager.fillReport(jasper_file, jasper_params) # Export it! if sign_options - file = Tempfile.new(['pdf-', '.pdf']) - signed_file = Tempfile.new(['signed-pdf-', '.pdf']) - begin - file.write JasperExportManager._invoke('exportReportToPdf', 'Lnet.sf.jasperreports.engine.JasperPrint;', jasper_print) + temp_file = Tempfile.new(['pdf-', '.pdf']) + temp_signed_file = Tempfile.new(['signed-pdf-', '.pdf']) + file = temp_file.path + signed_file = temp_signed_file.path - call_options = [ - '-n', - '-t', file.path, - '-s', sign_options[:key_file], - '-p', %Q["#{sign_options[:password]}"], - '-o', signed_file.path - ] - call_options.push '-l', %Q["#{sign_options[:location]}"] if sign_options[:location] - call_options.push '-r', %Q["#{sign_options[:reason]}"] if sign_options[:reason] + temp_file.close! + temp_signed_file.close! - `java -jar #{File.dirname(__FILE__)}/java/PortableSigner/PortableSigner.jar #{call_options.join(' ')}` + File.open(file, 'wb') { |f| f.write JasperExportManager._invoke('exportReportToPdf', 'Lnet.sf.jasperreports.engine.JasperPrint;', jasper_print) } - return File.read(signed_file.path) + call_options = [ + '-n', + '-t', file, + '-s', sign_options[:key_file], + '-p', %Q["#{sign_options[:password]}"], + '-o', signed_file + ] + call_options.push '-l', %Q["#{sign_options[:location]}"] if sign_options[:location] + call_options.push '-r', %Q["#{sign_options[:reason]}"] if sign_options[:reason] + + `java -jar #{File.dirname(__FILE__)}/java/PortableSigner/PortableSigner.jar #{call_options.join(' ')}` + + begin + return File.read(signed_file) ensure - file.close! - signed_file.close! + begin + File.unlink file, signed_file + rescue + end end else JasperExportManager._invoke('exportReportToPdf', 'Lnet.sf.jasperreports.engine.JasperPrint;', jasper_print) end \ No newline at end of file