ProGuard: shrink, optimize, obfuscate your Java executable


ProGuard is a free Java processor that can compress your .jar executable, rename internal classes to make reverse engeneering more difficult (see tools like JD-GUI and test it on your .jar), and finally optimize the program bytecode.

I used some external libraries in the project jSQL Injection, for exemple jSoup for HTML cleaning and Apache Commons Codec for additional string methods like Base64. These libraries are usually big .jar file that you include in your project, thus expanding your .jar executable’s size. As I use less than 1% of these libraries’ methods, I always wondered how to get rid of the extra space.

ProGuard can process your .jar as expected, it can reduce executable’s size by 50% (as seen on the screenshot), but you must be aware of problems appearing for example if you use introspection (a.k.a reflection). I do use introspection for internal design ; jSQL Model communicates to the View by Interaction classes implemented only in view, Model only sends Interaction classname as a String but won’t be aware of the GUI’s class’ instances, as known in MVC pattern. In that case ProGuard will rename GUI classes by obfuscation, but your model will keep sending unchanged Interaction classname as String, and therfore will generate errors like:

java.lang.ClassNotFoundException: com.jsql.view.interaction.MessageJava

So you must configure ProGuard tabs Shrinking and Obfuscation in order to add exceptions to keep your introspection classes working ; Click Add… button in the section Keep additional classes and class members, type your classes names or use wildcards like com.jsql.view.interaction.*, do not forget to click Add field… and Add method… to fill the corresponding class members (simply click Ok).

Now, in order to verify if your new ProGuard .jar executable has introduced regressions, you would like to test it via JUnit, at least that’s what I want to do, but it’s another journey and I wonder how to do this in Eclipse. Any help would be appreciate.

Tagged with: , , , ,
Posted in Java

Automatisation of your desktop with autoitx4java: AutoIt and Java COM Bridge


AutoIt allows automation of Desktop actions, like opening Windows Calculator, pressing buttons, processing a simple calculation like 1+1 and read text result directly from the native GUI controls.

The native language of AutoIt is BASIC-like and looks a lot like VBScript ; you write your code in a file .au3 which can be run with a double click, or write it directly in VBScript with a slightly different syntax This is particularly efficient with QC/QTP professional testing software.

But AutoIt is not designed to work with Java.

As a Java programer and a Selenium user, you may have to interact with your desktop for example if you have to verify Web upload ; dialog windows like ‘Save As…‘ or ‘Open File…‘ can’t be processed by Selenium therefore you would want to use AutoIt in Java.

In order to call methods from native .dll, you can use JACOB – Java COM Bridge. Fortunately Accessrichard already wrapped interfaces to AutoIt .dll in the Java library AutoItX4Java, so you finally can use AutoIt features directly from Java.

Nevertheless in the default example, you should modify the line which call your Notepad program and add the third parameter:"notepad", "C:/Windows/System32", AutoItX.SW_MAXIMIZE);

Also you should use command shortcuts like ALT+F or KeyUP with method controlSend(), not with send() ; something seems wrong with attach mode (see OPT_SEND_ATTACH_MODE) :

x.controlSend("[CLASS:Notepad]", "", "", "!f");
x.controlSend("[CLASS:Notepad]", "", "", "{UP 1}");
x.controlSend("[CLASS:Notepad]", "", "", "{ENTER}");

Modified example from AutoItX4Java

public class Test {
    public static void main(String[] args) {
        File file = new File("jacob-1.17-x64.dll"); //path to the jacob dll
        System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());

        AutoItX x = new AutoItX();
        String notepad = "Untitled - Notepad";
        String testString = "this is a test.";"notepad", "C:/Windows/System32", AutoItX.SW_MAXIMIZE);
        Assert.assertTrue(x.winExists(notepad, testString));
        x.winClose(notepad, testString);
        Assert.assertFalse(x.winExists(notepad, testString));
Tagged with: , , , ,
Posted in Java, Selenium

Tesseract and Tess4J

Tesseract is an OCR library best known to be maintained by Google teams. Thankfully there’s a Java wrapper that allows to combine this powerfull functionality to Selenium or whatever needs such technology. I already know about Sikuli, and I’m stunned with such great open source libraries.

The italicize text on the picture comes from another Selenium test, Asprise OCR. That other OCR gives messy results like:

Never M2suse the O, ne
Who Likes You
Never Say Busy To Th,e One
Who Needs You
Never cheat The One
Who ReaZZy Trust You,
Never foJnget The One
Who Zways Remember You.

Here Tess4j gives a perfect:

Never Misuse the One
Who Likes You,
Never Say Busy To The One
Who Needs You,
Never cheat The One
Who Really Trust You,
Never Forget The One
Who Always Remember You.

Tagged with: , , , , ,
Posted in Java

Playing with mobiles for Webdriver tests

Playing with mobiles for Webdriver tests

Need to test virtualisation of mobile platforms and crossbrowser OSs for my work. I would post tips and tricks.

Tagged with: , , , , ,
Posted in Selenium