localization dependency in unit test

Background: I built component X. Component X has OSGI-INF/l10n/messages.properties. In component X, ResourceBundle.getBundle works fine when unit testing X in its own project. Problem: When component X is referenced (via Maven) from separate project Y, Y invokes X, and the call to ResourceBundle.getBundle down inside X brings back a bundle missing the properties defined in X. I've read the “Understanding Bundles Deployment” docs and looking at the framework code it looks like the DeploymentPreprocessor.java class is responsible to process the OSGI-INF/deployment-fragment.xml files and merge all the various component properties into a single messages.properties, messages_xx_yy.properties, etc. However, it does not appear that DeploymentPreprocessor.java runs in the unit test environment. I could duplicate the properties X needs in the Y project, so that X doesn't fail. This seems bad. Does anyone have a best practice here? (Or maybe I'm just doing something wrong?)

0 votes

1 answers



You're right, the pre-deployment is not played as part of the runtime feature. You can try to add this logic by implementing a new feature for. Here is the code snipset that do the pre-deployment.

 String rootPath = Environment.getDefault().getRuntimeHome().getAbsolutePath();
    File root = new File(rootPath);
    DeploymentPreprocessor processor = new DeploymentPreprocessor(root);
    // initialize
    // and predeploy
0 votes