Sunday, July 26, 2009

Cheat Sheet for configuring API Tooling for existing projects

This topic are covered in previous post too. Here am providing a Cheat Sheet for easy access. Do feel free to post your feedback/suggestions/bugs in comments to this post.

The process of registering a cheat sheet in your Eclipse installation can be found in Eclipse help.

Sunday, July 19, 2009

Friday, July 17, 2009

System library validation

This is a new feature available in Eclipse 3.5.  API Tools can now validate the code against the Execution Environment mentioned in the bundle manifest.

Consider a scenario where the system JRE on developers machine (where Eclipse IDE is running) is version 1.5. But the bundle execution environment will be JVM 1.4. This is such cases, it is very easy to make the mistakes of accessing the functions that may not be available at runtime.

API Tooling can catch such errors easily if the Execution Environments are available.

Installing Execution Environments

Open the API Tooling preferences (Window > Preferences > Plug-in Development > API Errors/Warnings).

API Errors/Warnings
By default the severity level is set to Ignore. Change it to Warning or Error. Click the link install them now. This shall open the Install wizard.

Install wizard

Work with the Galileo release site Galileo - The execution environments are categorized under General Purpose Tools > PDE/API Tools Environment Descriptions. Install the ones you need.

Once installed the API preferences page will show the available execution environments.

API Errors/Warnings

System Library Validation in action

Consider a plug-in is execution environment marked as Java 1.4.

Execution Environment section on Overview page of Manifest Editor

Manifest File

If such a plug-in tries to access Java 1.5, there won't be any compilation errors (we will discuss the JDK Compliance level towards the end of this post).

For example, see the snippet below.

String name ="ankur";
name.contentEquals(new StringBuilder("ankur"));

This code will compile fine but will fail at runtime as contentEquals won't take StringBuilder in 1.4. That's an 1.5 API.

Once the API Preference for System Libraries is set to warning or error, same will be reported in the Problems view.

API Tooling validating against System Library

Compiler compliance level Vs System Library Validation

The problem we just discussed above can be also caught by setting the compiler compliance level appropriately. Where it differs is that the compiler setting are restricted to the JDK version. The API Tooling focuses on the execution environment from OSGi perspective. As you would have noticed there are non-Java specific environment descriptions too like CDC-Foundation and OSGi/Miminum.

Another major difference is that API Tooling does not need JRE/JDK. It checks the usage against the environment descriptions. The descriptions are just the environment API and thus occupy very less space. For example, the 1.5 JRE takes close to 50MB while the descriptions for the same takes less than 2 MB.