#!/usr/bin/env ruby # Compare .json files of different ExtJS versions # For running when gem not installed $:.unshift File.dirname(File.dirname(__FILE__)) + "/lib" require "rubygems" require "jsduck/json_duck" def read_class(filename) JsDuck::JsonDuck.read(filename) end def read_all_classes(dir, ignore_private=false) map = {} Dir[dir+"/*.json"].each do |filename| print "." STDOUT.flush cls = read_class(filename) unless ignore_private && cls["private"] map[cls["name"]] = cls cls["alternateClassNames"].each do |name| map[name] = cls end end end puts "OK" map end # Gathers class members that are in cls1, but are missing in cls2 def compare_classes(cls1, cls2) diff = [] cls1["members"].each_pair do |group_name, group_items| group_items.find_all {|m1| !m1["private"] && !m1["meta"]["protected"] && m1["owner"] == cls1["name"] }.each do |m1| match = cls2["members"][group_name].find do |m2| m2["name"] == m1["name"] && !m2["meta"]["protected"] && !m2["private"] end if !match && m1["name"] != "constructor" && m1["name"] != "" other = nil ["cfg", "property", "method", "event"].each do |g| other = other || cls2["members"][g].find {|m2| m2["name"] == m1["name"] } other = other || cls2["statics"][g].find {|m2| m2["name"] == m1["name"] } end diff << { :type => group_name, :name => m1["name"], :other => other ? { :type => other["tagname"], :static => other["meta"]["static"], :private => other["private"], :protected => other["meta"]["protected"], } : nil } end end end diff end old_classes = read_all_classes(ARGV[0], :ignore_private) new_classes = read_all_classes(ARGV[1]) out_file = ARGV[2] diff_data = [] old_classes.each_pair do |name, cls| if name == cls["name"] new_cls = new_classes[cls["name"]] # Remap classes like Array to Ext.Array new_cls = new_classes["Ext."+cls["name"]] unless new_cls diff_data << { :name => cls["name"], :found => !!new_cls, :new_name => new_cls && new_cls["name"], :diff => new_cls ? compare_classes(cls, new_cls) : [], } end end # Choose title based on filename if out_file =~ /touch/ title = "Comparison of Touch 1.1.1 and Touch 2.0.0" else title = "Comparison of Ext 4.0.7 and Ext 4.1.0" end # do HTML output html = [] html << <<-EOHTML
" + dd.find_all {|c| !c[:found] }.length.to_s + " classes not found
" html << "" + dd.find_all {|c| c[:found] && c[:name] == c[:new_name] }.length.to_s + " classes with same name
" html << "" + dd.find_all {|c| c[:found] && c[:name] != c[:new_name] }.length.to_s + " renamed classes
" html << "" + dd.find_all {|c| c[:diff].length > 0 }.length.to_s + " classes with missing members
" html << "" + dd.map {|c| c[:diff].length }.inject {|sum,x| sum + x }.to_s + " missing members
" html << "" + dd.map {|c| c[:diff].find_all {|m| !m[:other]}.length }.inject {|sum,x| sum + x }.to_s + " completely missing members
" html << "" html << "" File.open(out_file, 'w') {|f| f.write(html.join("\n")) }