Class: JarTools::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/jartools/cli.rb

Instance Method Summary collapse

Instance Method Details

#diff(jar1, jar2) ⇒ Object



52
53
54
# File 'lib/jartools/cli.rb', line 52

def diff(jar1, jar2)
  Diff.diff(jar1, jar2)
end

#manifest(jarfile) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/jartools/cli.rb', line 32

def manifest(jarfile)
  content = Zip::ZipFile.open(jarfile) { |zip|
    zip.file.read("META-INF/MANIFEST.MF") if zip.file.exists?("META-INF/MANIFEST.MF")
  }
  return unless content
  if options.raw
    say content
  else
    say content.gsub("\r\n", "\n").gsub("\r", "\n").split("\n").inject([]) { |result, raw_line|
      if raw_line =~ /^\s/
        result[-1] += raw_line.slice(1, raw_line.size)
      else
        result << raw_line
      end
      result
    }.join("\n")
  end
end

#packages(jarfile) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/jartools/cli.rb', line 14

def packages(jarfile)
  entry_names = []
  Zip::ZipFile.foreach(jarfile) { |entry|
    entry_names << entry.name
  }

  entry_names.select { |e| e =~ /\.class$/ }.
    collect { |e| e.sub(/\/[^\/]+$/, '').gsub('/', '.') }.
    uniq.sort.each { |pkg| say pkg }
end