HSQLDB CodeSwitcher

Code Switcher

CodeSwitcher is a tool to manage different version of Java source code. It allows to compile HSQLDB for different JDKs, and switch between debug and runtime versions. It is something like a precompiler in C and C++, but it works directly on the source code and does not create intermediate output or any extra files.

It is possible to use the Code Switcher in batch operations where multiple versions of an application are built. CodeSwitcher is (of course) a Java application.

CodeSwitcher is used internally in HSQLDB build scripts. You do not have to use it separately to compile HSQLDB.

CodeSwitcher reads the source code of a file, removes comments where appropriate and comments the blocks that are not used for a particular version of the file. This operation is done for all files of a defined directory, and all subdirectories.

This is an example source code before CodeSwitcher is used:

 
      ...
//#ifdef JAVA2
      pProperties.store(out,"hsqldb database");
//#else
/*
      pProperties.save(out,"hsqldb database");
*/
//#endif
      ...

The next step is to run CodeSwitcher. This is done using a command line:

java org.hsqldb.util.CodeSwitcher . -JAVA2

The '.' means the program works on the current directory (all subdirectories are processed recursively). '-JAVA2' means the code labelled with JAVA2 must be switched off. And this is how the source code looks after CodeSwitcher has processed this file:

 
      ...
//#ifdef JAVA2
/*
      pProperties.store(out,"hsqldb database");
*/
//#else
      pProperties.save(out,"hsqldb database");
//#endif
      ...

For detailed information on the command line options run 'java org.hsqldb.util.CodeSwitcher'.

This text is based on HypersonicSQL documentation, updated to reflect the latest version of HSQLDB