Entries from January 2009 ↓

More Perl geekness: getting the .class bytecode version

I’ve been looking for a decent tool to determine the byte code version for a Java .class file. You know, the one based on the numbers after the CAFEBABE magic (you can read more about this here or here).
There are some tools around for this, but most of them written in Java. I really don’t see the point in starting a JVM just to read 4 bytes from a file, so I wrote a short Perl script for this. Again, I am no Perl expert so this is probably not the best solution performance-wise and such.

Usage

1. Running the script with no arguments – will result in scanning the current directory recursively for .class files. The results are grouped by directory and a total number of files is also displayed. Directories that do not contain any .class files will be ignored, in order to keep a clean output. Below is a short sample.

cosmin@cosminaru:~/work/quizine$ bcversion.pl

* /home/cosmin/work/quizine/src/main/webroot/WEB-INF/classes/org/quizine (2 files)
	QuizineException.class -> 1.6
	ApplicationContext.class -> 1.6

* /home/cosmin/work/quizine/src/main/webroot/WEB-INF/classes/org/quizine/web (2 files)
	ErrorHandlerFilter.class -> 1.6
	SessionContext.class -> 1.6

* /home/cosmin/work/quizine/src/main/webroot/WEB-INF/classes/org/quizine/web/actions (1 files)
	ActionBase.class -> 1.6

2. If you provide one or more arguments, the script will only scan the content of these arguments. If the argument is a file then the byte code version is displayed for that file. If it is a directory then it will be scanned recursively, just like above.
Note: The paths from the argument list should all be relative to the current directory in order for the script to work correctly.

cosmin@cosminaru:~.../model/quiz$ bcversion.pl AbstractQuestion.class result
* AbstractQuestion.class -> 1.6

* /home/cosmin/work/quizine/src/main/webroot/WEB-INF/classes/org/quizine/model/quiz/result (5 files)
	QuestionnaireResult.class -> 1.6
	BooleanAnswer.class -> 1.6
	AbstractAnswer.class -> 1.6
	SingleChoiceAnswer.class -> 1.6
	MultipleChoiceAnswer.class -> 1.6

I’ll probably want to scan JAR files and directories containing JAR files. But the really poor Perl docs for reading ZIP buffers didn’t quite help me. If you think think you can give a hand with that, drop a note :) .

Download:

You can get the script from here.

TestNG XSLT 1.0

TestNG-XSLT, a small project of mine, has finally made it to 1.0. It’s currently tested only with Firefox 3.x and Internet Explorer 7, but it will probably work on most modern browsers. For the moment I thought it is more important to target the popular browsers and leave the more exotic ones for later.

Some of noteworthy features that I’ve added since the project start:

  • Maven plugin with access to all transformer features and settings.
  • SVG pie chart with the overview of the pass/fail/skip status.
  • Configurable CSS style sheet – you can build your own “skin” by overwriting the built-in styles and setting the testNgXslt.cssFile parameter. More about this here.
  • Ability to change the report title, to generate information about test durations and other settings configurable through XSL transformer parameters.
  • Other smaller or bigger issues and feature requests reported by users.

I want to thank all the guys that used this and came up with bugs, feature requests and suggestions: Andreas Guther, Xuan Ngo, Francis Henninger, Csongor Gyuricza, Andreas Kuhtz and others.

Last, but not least, I would like to mention that Haw-Bin Chai has managed to successfully integrate TestNG-XSLT in Lightest, a lightweight testing framework based on TestNG and Groovy.

The download is available here. If you use Maven, make sure you update your pom.xml to get the 1.0.9 version of the plugin.