You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Lars Kiesow <lk...@uos.de> on 2021/12/06 20:58:43 UTC
Usage of conditional in Karaf features
Hi everyone,
I'm wondering how exactly the conditionals are supposed to be used in
Karaf features:
<feature name="example" version="1.2.3">
<conditional>
<condition>xy</condition>
...
</conditional>
...
</feature>
I'm trying to activate a feature (or a list of bundles in that feature)
only if another feature specified in a condition is already installed.
I got this working alright, since I install these features dynamically
with some code anyway, but while it works, I am worried about potential
side-effects since I don't quite know how it is supposed to be working.
A simplified pseudo-code version of my code looks like this:
// get installed features
installedFeatures = featuresService.listInstalledFeatures()
// iterate over available features
for (Feature feature : featuresService.listFeatures()) {
// get all conditions
conditions = feature.getConditionals().getConditions()
// check if a condition matches an installed feature
if (conditions intersect installedFeatures) {
// install feature
featuresService.installFeature(feature);
}
}
Does anyone know if this could have any side-effects?
Or even better, can anyone give me a proper explanation or
documentation of how the conditionals in Karaf features work and how
they are supposed to be used?
Thanks,
Lars
Re: Usage of conditional in Karaf features
Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Lars,
Reusing your example:
<feature name="example" version="1.2.3">
<conditional>
<condition>xy</condition>
<bundle>foo</bundle>
</conditional>
...
</feature>
bundle foo will be installed only if condition predicate (feature xy) is
true.
If later, the condition will be satisfied then foo will be installed.
Concrete example:
<feature name="deployer" description="Karaf Deployer"
version="${project.version}">
<bundle
start-level="26">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.features/${project.version}</bundle>
<conditional>
<condition>pax-url-wrap</condition>
<bundle
start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.wrap/${project.version}</bundle>
</conditional>
<conditional>
<condition>req:osgi.extender;filter:="(&(osgi.extender=osgi.blueprint)(version>=1.0))"</condition>
<bundle
start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.blueprint/${project.version}</bundle>
</conditional>
<conditional>
<condition>kar</condition>
<bundle
start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.kar/${project.version}</bundle>
</conditional>
</feature>
it means:
1. wrap deployer will be installed only/when pax-url-wrap feature is
installed
2. blueprint deployer will be installed only/when a blueprint provider
is installed (osgi.extender)
3. kar deployer will be installed only/when kar feature is installed
The purpose is to have multi-form feature that triggers installation of
resources (bundle, config, configfile) when the condition is satisfied.
Regards
JB
On 06/12/2021 21:58, Lars Kiesow wrote:
> Hi everyone,
> I'm wondering how exactly the conditionals are supposed to be used in
> Karaf features:
>
>
> <feature name="example" version="1.2.3">
> <conditional>
> <condition>xy</condition>
> ...
> </conditional>
> ...
> </feature>
>
>
> I'm trying to activate a feature (or a list of bundles in that feature)
> only if another feature specified in a condition is already installed.
>
> I got this working alright, since I install these features dynamically
> with some code anyway, but while it works, I am worried about potential
> side-effects since I don't quite know how it is supposed to be working.
>
> A simplified pseudo-code version of my code looks like this:
>
>
> // get installed features
> installedFeatures = featuresService.listInstalledFeatures()
> // iterate over available features
> for (Feature feature : featuresService.listFeatures()) {
> // get all conditions
> conditions = feature.getConditionals().getConditions()
> // check if a condition matches an installed feature
> if (conditions intersect installedFeatures) {
> // install feature
> featuresService.installFeature(feature);
> }
> }
>
>
> Does anyone know if this could have any side-effects?
>
> Or even better, can anyone give me a proper explanation or
> documentation of how the conditionals in Karaf features work and how
> they are supposed to be used?
>
> Thanks,
> Lars
>