You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

package-diff.py 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #!/usr/bin/python
  2. import sys,os,re
  3. from sets import Set
  4. ################################################################################
  5. # Configuration
  6. ################################################################################
  7. downloadsite = "http://vaadin.com/download"
  8. latestfile = "/LATEST"
  9. JAPIZE = "japize"
  10. JAPICOMPAT = "japicompat"
  11. ################################################################################
  12. # Utility Functions
  13. ################################################################################
  14. def command(cmd, dryrun=0):
  15. if not dryrun:
  16. if os.system(cmd):
  17. print "Command '%s' failed, exiting." % (cmd)
  18. sys.exit(1)
  19. else:
  20. print "Dry run - not executing."
  21. ################################################################################
  22. # List files in an archive.
  23. ################################################################################
  24. def listZipFiles(archive):
  25. pin = os.popen("unzip -l -qq %s | cut -c 29- | sort" % (archive), "r")
  26. files = map(lambda x: x.strip(), pin.readlines())
  27. pin.close()
  28. cleanedfiles = []
  29. for file in files:
  30. # Remove archive file name from the file names
  31. slashpos = file.find("/")
  32. if slashpos != -1:
  33. cleanedname = file[slashpos+1:]
  34. else:
  35. cleanedname = file
  36. # Purge GWT compilation files.
  37. if cleanedname.find(".cache.html") != -1:
  38. continue
  39. cleanedfiles.append(cleanedname)
  40. return cleanedfiles
  41. ################################################################################
  42. # Difference of two lists of files
  43. ################################################################################
  44. def diffFiles(a, b):
  45. diff = Set(a).difference(Set(b))
  46. difffiles = []
  47. for item in diff:
  48. difffiles.append(item)
  49. difffiles.sort()
  50. return difffiles
  51. ################################################################################
  52. # Lists files inside a Zip file (a JAR)
  53. ################################################################################
  54. def listJarFiles(jarfile):
  55. # Read the jar content listing
  56. pin = os.popen("unzip -ql %s" % jarfile, "r")
  57. lines = map(lambda x: x[:-1], pin.readlines())
  58. pin.close()
  59. # Determine the position of file names
  60. namepos = lines[0].find("Name")
  61. files = []
  62. for i in xrange(2, len(lines)-2):
  63. filename = lines[i][namepos:]
  64. files.append(filename)
  65. return files
  66. ################################################################################
  67. # Lists files inside a Vaadin Jar inside a ZIP
  68. ################################################################################
  69. # For Vaadin 6.3 Zip
  70. def listZipVaadinJarFiles(zipfile, vaadinversion):
  71. jarfile = "vaadin-%s/WebContent/vaadin-%s.jar" % (vaadinversion, vaadinversion)
  72. extractedjar = "/tmp/vaadinjar-tmp-%d.jar" % (os.getpid())
  73. zipcmd = "unzip -p %s %s > %s " % (zipfile, jarfile, extractedjar)
  74. command (zipcmd)
  75. files = listJarFiles(extractedjar)
  76. command ("rm %s" % (extractedjar))
  77. return files
  78. ################################################################################
  79. # JAPI - Java API Differences
  80. ################################################################################
  81. def japize(version, zipfile):
  82. jarfile = "/tmp/vaadin-tmp.jar"
  83. packagedjar = "vaadin-%s/WebContent/vaadin-%s.jar" % (version, version)
  84. command ("unzip -p %s %s > %s " % (zipfile, packagedjar, jarfile))
  85. cmd = "%s as %s apis %s +com.vaadin, $JAVA_HOME/jre/lib/rt.jar lib/core/**/*.jar 2>/dev/null" % (JAPIZE, version, jarfile)
  86. command (cmd)
  87. return "%s.japi.gz" % (version)
  88. def japicompat(japi1, japi2):
  89. cmd = "%s -q %s %s" % (JAPICOMPAT, japi1, japi2)
  90. pin = os.popen(cmd, "r")
  91. lines = "".join(pin.readlines())
  92. pin.close()
  93. return lines
  94. ################################################################################
  95. #
  96. ################################################################################
  97. # Download the installation package of the latest version
  98. wgetcmd = "wget -q -O - %s" % (downloadsite+latestfile)
  99. pin = os.popen(wgetcmd, "r")
  100. latestdata = pin.readlines()
  101. pin.close()
  102. latestversion = latestdata[0].strip()
  103. latestpath = latestdata[1].strip()
  104. latestURL = downloadsite + "/" + latestpath + "/"
  105. latestfilename = "vaadin-%s.zip" % (latestversion)
  106. latestpackage = latestURL + latestfilename
  107. locallatestpackage = "/tmp/%s" % (latestfilename)
  108. print "Latest version: %s" % (latestversion)
  109. print "Latest version path: %s" % (latestpath)
  110. print "Latest version URL: %s" % (latestURL)
  111. # Check if it already exists
  112. try:
  113. os.stat(locallatestpackage)
  114. print "Latest package already exists in %s" % (locallatestpackage)
  115. # File exists
  116. except OSError:
  117. # File does not exist, get it.
  118. print "Downloading latest release package %s to %s" % (latestpackage, locallatestpackage)
  119. wgetcmd = "wget -q -O %s %s" % (locallatestpackage, latestpackage)
  120. command (wgetcmd)
  121. # List files in latest version.
  122. latestfiles = listZipFiles(locallatestpackage)
  123. # List files in built version.
  124. builtversion = sys.argv[1]
  125. builtpackage = "build/result/vaadin-%s.zip" % (builtversion)
  126. builtfiles = listZipFiles(builtpackage)
  127. # Report differences
  128. print "\n--------------------------------------------------------------------------------\nVaadin ZIP differences"
  129. # New files
  130. newfiles = diffFiles(builtfiles, latestfiles)
  131. print "\n%d new files:" % (len(newfiles))
  132. for item in newfiles:
  133. print item
  134. # Removed files
  135. removed = diffFiles(latestfiles, builtfiles)
  136. print "\n%d removed files:" % (len(removed))
  137. for item in removed:
  138. print item
  139. print "\n--------------------------------------------------------------------------------\nVaadin JAR differences"
  140. latestJarFiles = listZipVaadinJarFiles(locallatestpackage, latestversion)
  141. builtJarFiles = listZipVaadinJarFiles(builtpackage, builtversion)
  142. # New files
  143. newfiles = diffFiles(builtJarFiles, latestJarFiles)
  144. print "\n%d new files:" % (len(newfiles))
  145. for item in newfiles:
  146. print item
  147. # Removed files
  148. removed = diffFiles(latestJarFiles, builtJarFiles)
  149. print "\n%d removed files:" % (len(removed))
  150. for item in removed:
  151. print item
  152. print "\n--------------------------------------------------------------------------------\nVaadin API differences"
  153. oldjapi = japize(latestversion, locallatestpackage)
  154. newjapi = japize(builtversion, builtpackage)
  155. print "\n--------------------------------------------------------------------------------\nLost API features\n"
  156. japidiff1 = japicompat(oldjapi, newjapi)
  157. print japidiff1
  158. print "\n--------------------------------------------------------------------------------\nNew API features\n"
  159. japidiff2 = japicompat(newjapi, oldjapi)
  160. print japidiff2
  161. # Purge downloaded package
  162. command("rm %s" % (locallatestpackage))