Generating blog posts

RSS

Improved properties files processing in Acceleo 3.1

I’ve just finished working on the new system to handle properties files that will be available in the next milestone, so let’s see what’s coming. In Acceleo, you can create a “.properties” file to store some properties that will be used during your generation. You can see in the following screenshot how to use a properties file in the current version of Acceleo.

There are several steps to respect in order to use a properties file:

  1. Change the “@generated” tag to “@notgenerated” in the javadoc of the method “getProperties()” in the Java class generated by Acceleo for your main module. Otherwise, any changes in the matching Acceleo module will override your modifications.
  2. Add the path of your properties file in the list returned by “getProperties()”. Follow the same convention for the path of the file as in the screenshot.
  3. Well, you have to create the properties file :)
  4. Finally, you have to use your properties in your generator

The main advantage of the properties file is to allow the creator of the generator to configure some details of the generation without modifying the generator. You could for example, have a property to determine if you want to generate the author of a class in the javadoc or to change your naming conventions, etc.

You also have access to a “properties” text area in the launch configuration of Acceleo. In Acceleo 3.0, this text area should not be used, as its behavior is buggy.

In Acceleo 3.1, I’ve improved this system with the help of Goulwen the leader of the EEF project. You can now use “getProperties()” or the text area of the launch configuration without any distinctions to enter the path of a properties file. This path can still be a project relative path like in the previous screenshot but you can also use the absolute path of the properties file (“/home/…./default.properties”). If you want to use a properties file with another kind of path, you can now override “getPropertiesLoaderService(AcceleoService acceleoService)” and you can create an AbstractAcceleoPropertiesLoaderService.

The basic implementation of this class will look for the properties file in your project of at the location of the given path. You just have to implement “alternatePropertiesLoading(String filepath): Properties” to look for the properties file by yourself and then return the matching “java.util.Properties” object. With this, you will be able to look for properties file in a bundle or next to your models with an Acceleo UI project, etc. If you want to handle by yourself the whole process you can override “initializeService(List<String> propertiesFiles)”.

These changes will be available in Acceleo 3.1 M6, available next week.