Class: JavaClass::ClassList::List
- 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. This is the list containing packages (PackageEntry).
- Author
-
Peter Kofler
Instance Method Summary collapse
-
#add_class(fileentry, is_public, version) ⇒ Object
Add a fileentry to the list.
-
#first_last_versions ⇒ Object
Return the first and last version of this list.
-
#full_class_list ⇒ Object
Create a full class list with version numbers and different versions to compare.
-
#initialize ⇒ List
constructor
A new instance of List.
-
#old_access_list ⇒ Object
The access list is the raw list of all package access classes for one version.
- #packages ⇒ Object
-
#parse_line(line, maxversion) ⇒ Object
Parse a line from a
fullClassList
and fill the list again. -
#plain_class_list ⇒ Object
The class list is the raw list of all classes for one version without version or package access descriptors.
-
#size ⇒ Object
Return the number of classes in this list.
- #to_s ⇒ Object
-
#version ⇒ Object
Return the version list of all packages.
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
12 13 14 |
# File 'lib/javaclass/classlist/list.rb', line 12 def initialize @packages = Hash.new # package_name (String) => PackageEntry 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.full_name, is_public, version) end |
#first_last_versions ⇒ Object
Return the first and last version of this list.
85 86 87 88 |
# File 'lib/javaclass/classlist/list.rb', line 85 def first_last_versions v = version [v.first, v.last] end |
#full_class_list ⇒ Object
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.
129 130 131 132 133 134 |
# File 'lib/javaclass/classlist/list.rb', line 129 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_list ⇒ Object
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.
104 105 106 107 108 109 |
# File 'lib/javaclass/classlist/list.rb', line 104 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 |
#packages ⇒ Object
75 76 77 |
# File 'lib/javaclass/classlist/list.rb', line 75 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 |
# 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/, '') first_vers, last_vers = *split_version(versions, first_vers, last_vers) 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_list ⇒ Object
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.
115 116 117 118 119 120 121 122 123 |
# File 'lib/javaclass/classlist/list.rb', line 115 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 |
#size ⇒ Object
Return the number of classes in this list.
95 96 97 |
# File 'lib/javaclass/classlist/list.rb', line 95 def size @packages.values.inject(0) {|sum, p| sum + p.size } end |
#to_s ⇒ Object
90 91 92 |
# File 'lib/javaclass/classlist/list.rb', line 90 def to_s packages.collect { |p| p.to_s }.join("\n") end |
#version ⇒ Object
Return the version list of all packages.
80 81 82 |
# File 'lib/javaclass/classlist/list.rb', line 80 def version packages.collect { |p| p.version }.flatten.uniq.sort end |