Class: JavaClass::ClassList::List

Inherits:
Object
  • Object
show all
Defined in:
lib/javaclass/classlist/list.rb

Overview

Classes to form a list of JDK classes to find classes which have been added in new releases. The list of classes. It list contains packages.

Author

Peter Kofler

Instance Method Summary collapse

Constructor Details

#initializeList

Returns a new instance of List.



12
13
14
# File 'lib/javaclass/classlist/list.rb', line 12

def initialize
  @packages = {}
end

Instance Method Details

#add_class(fileentry, is_public, version) ⇒ Object

Add a fileentry to the list. The fileentry is the file name of the class in the jar file. version is the version of the JDK scanned and is used if the class is new.



18
19
20
21
22
23
# File 'lib/javaclass/classlist/list.rb', line 18

def add_class(fileentry, is_public, version)
  class_name = fileentry.to_javaname.to_classname
  package_name = class_name.package
  @packages[package_name] = PackageEntry.new(package_name, version) unless @packages.has_key?(package_name)
  @packages[package_name].add_class(class_name, is_public, version)
end

#first_last_versionsObject

Return the first and last version of this list.



72
73
74
75
# File 'lib/javaclass/classlist/list.rb', line 72

def first_last_versions
  v = version
  [v.first, v.last]
end

#full_class_listObject

Create a full class list with version numbers and different versions to compare. This was the base for classlists and was saved in doc/fullClassList1x.txt. This usually was done with JarSearcher set skip_package_classes to false and contained different classlists merged together.



116
117
118
119
120
121
# File 'lib/javaclass/classlist/list.rb', line 116

def full_class_list
  v = first_last_versions
  packages.collect { |pkg| 
    pkg.classes.collect { |c| c.to_full_qualified_s(v[0], v[1]) }
  }.flatten.sort{|a,b| a.casecmp b }
end

#old_access_listObject

The access list is the raw list of all package access classes for one version. It was used to differ normal classes from hidden classes and was saved in doc/AccessLists/*_p.txt. This works only if JarSearcher was used with skip_package_classes set to false (default). If there are more versions loaded, then only the last version is printed. So we get consecutive lists of new package access classes with every JDK version.



91
92
93
94
95
96
# File 'lib/javaclass/classlist/list.rb', line 91

def old_access_list
  v = first_last_versions
  packages.collect { |pkg| 
    pkg.classes.find_all { |c| !c.public? && c.version == [v[1]]}.collect { |c| c.to_full_qualified_s(v[0], v[1]) }
  }.flatten.sort{|a,b| a.casecmp b }
end

#packagesObject



62
63
64
# File 'lib/javaclass/classlist/list.rb', line 62

def packages
  @packages.values.sort
end

#parse_line(line, maxversion) ⇒ Object

Parse a line from a fullClassList and fill the list again. maxversion is the maximum max version from the list, i.e. the highest possible value, so we can continue to use it.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/javaclass/classlist/list.rb', line 27

def parse_line(line, maxversion)
  class_name, versions = line.scan(/^([^\s]+)\s(?:\[(.*)\]\s)?-\s*$/)[0]
  
  # no [], so we have it from always and it is public
  first_vers = 0
  last_vers = maxversion
  is_public = true
  if versions
    # extract package access and drop it
    is_public = (versions !~ /p/)
    versions = versions.gsub(/p/, '')
    
    # \d, \d-\d, only \d, -\d, oder leer
    if versions =~ /^(\d)$/
      first_vers = $1.to_i
    elsif versions =~ /^(\d)-(\d)$/
      first_vers = $1.to_i
      last_vers = $2.to_i
    elsif versions =~ /^(?:bis\s|-)(\d)$/
      last_vers = $1.to_i
    elsif versions =~ /^only (\d)$/
      first_vers = $1.to_i
      last_vers = $1.to_i
    else
      raise "can't match version number #{versions} in line #{line.chomp}" unless versions == ''
    end
  end
  
  first_vers.upto(last_vers) do |v| 
    add_class(class_name, is_public, v) 
  end
rescue
  raise "#{$!} in line #{line.chomp}: class_name=#{class_name}, versions=#{versions}, first_vers=#{first_vers}, last_vers=#{last_vers}, is_public=#{is_public}"
end

#plain_class_listObject

The class list is the raw list of all classes for one version without version or package access descriptors. It was used to find differences and was saved in doc/ClassLists/*_classes.txt. This usually was done with JarSearcher set skip_package_classes to false. If a block is given it is invoked with ClassEntry and should return if to add the class or not.



102
103
104
105
106
107
108
109
110
# File 'lib/javaclass/classlist/list.rb', line 102

def plain_class_list
  packages.collect { |pkg|
    cls = pkg.classes
    if block_given?
      cls = cls.find_all { |c| yield(c) }
    end
    cls.collect { |c| c.full_name + "\n" }
  }.flatten.sort{|a,b| a.casecmp b }
end

#sizeObject

Return the number of classes in this list.



82
83
84
# File 'lib/javaclass/classlist/list.rb', line 82

def size
  @packages.values.inject(0) {|sum, p| sum + p.size }
end

#to_sObject



77
78
79
# File 'lib/javaclass/classlist/list.rb', line 77

def to_s
  packages.collect { |p| p.to_s }.join("\n")
end

#versionObject

Return the version list of all packages.



67
68
69
# File 'lib/javaclass/classlist/list.rb', line 67

def version
  packages.collect { |p| p.version }.flatten.uniq.sort
end