I'm using Fabric8 v.1.2.0.redhat-133.
I have a profile with by bundle and some configuration file inside, for example:
Bundle: mvn:my-gr/my-art/1-SNAPSHOT
Configuration file: config.xml
I can invoke
ProfileManager manager = ProfileManagerLocator.getProfileManager();
Profile profile = manager.getProfile("1.0", "profile-name");
byte[] brokerConf = profile.getFileConfiguration("config.xml");
inside my bundle's code and get the file. It works. But in this case I need to know the name of the profile.
Is there a way to get the name of current bundle's profile?
Or is there a better way to get config.xml
, maybe not with ProfileManager
?
This is not possible because on OSGi level profiles do not exist. Profiles are a Fuse concept which can list features and bundles. Features are a Karaf concept, and only bundles are real OSGi artifacts. That means that the OSGi container is not aware of any features or profiles and can therefor not tell you which feature or profile was responsible for installing the bundle. Even if it could there would still be the fact that multiple features and profiles could have your bundle on their list, making it impossible to say which profile is the 'current' one.
If you want to access a file from a profile you should use the profile URL handler. See http://fabric8.io/gitbook/urlHandlers.html