You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Alex Soto <al...@envieta.com> on 2020/02/26 18:53:00 UTC

Features Conditional on JDK version

In Features XML, is it possible to add a bundle conditionally based on JDK version?

<conditional>
	<condition>???</condition>
</conditonal>

BTW, I could not find documentation about what can be put in the condition tag.
I looked here https://karaf.apache.org/manual/latest/provisioning <https://karaf.apache.org/manual/latest/provisioning> but there is no mention of this.

Best regards,
Alex soto





Re: Features Conditional on JDK version

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Ok that?s possible using java.se capability condition. Let me find an example.

  

Regards

JB

  

Le mer. 26 f?vr. 2020 ? 20:49, Alex Soto <al...@envieta.com> a ?crit :  

> The use case is: I wish my solution to be able to run in various Java
versions.

>

> For example, if deployed in Java 8, I do not need to provide JAXB jars, but
I do for JDK11.

>

>  
>  
>

>

>  
>

>

>> On Feb 26, 2020, at 2:30 PM, Jean-Baptiste Onofre
<[jb@nanthrax.net](mailto:jb@nanthrax.net)> wrote:

>>

>>  
>

>>

>> Hi Alex,

>>

>>  
>

>>

>> Can you quickly explain what you are looking for ?

>>

>>  
>

>>

>> You can to install a feature matching a condition, where the condition is a
bundle or a capability (provided by another bundle or feature) ?

>>

>>  
>

>>

>> Regards

>>

>> JB  
>

>>

>>  
>

>>

>>> Le 26 f?vr. 2020 ? 20:27, Alex Soto
<[alex.soto@envieta.com](mailto:alex.soto@envieta.com)> a ?crit :

>>>

>>>  
>

>>>

>>> Thanks JB,

>>>

>>>  
>

>>>

>>> Can you point me to capability documentation?

>>>

>>>  
>

>>>

>>>  
>

>>>

>>> Best regards,  
> Alex soto  
>  
>  
>  
>

>>>

>>>  
>

>>>

>>>> On Feb 26, 2020, at 2:25 PM, Jean-Baptiste Onofre
<[jb@nanthrax.net](mailto:jb@nanthrax.net)> wrote:

>>>>

>>>>  
>

>>>>

>>>> Hi,

>>>>

>>>>  
>

>>>>

>>>> No, a condition is actually another feature.

>>>>

>>>>  
>

>>>>

>>>> So, the content of the feature will be installed only if the condition
feature is installed (or when it will be installed).

>>>>

>>>>  
>

>>>>

>>>> In your case, you can maybe use a capability ?

>>>>

>>>>  
>

>>>>

>>>> Regards

>>>>

>>>> JB  
>

>>>>

>>>>  
>

>>>>

>>>>> Le 26 f?vr. 2020 ? 19:53, Alex Soto
<[alex.soto@envieta.com](mailto:alex.soto@envieta.com)> a ?crit :

>>>>>

>>>>>  
>

>>>>>

>>>>> In Features XML, is it possible to add a bundle conditionally based on
JDK version?

>>>>>

>>>>>  
>

>>>>>

>>>>> <conditional>  
>  <condition>???</condition>

>>>>>

>>>>> </conditonal>

>>>>>

>>>>>  
>

>>>>>

>>>>> BTW, I could not find documentation about what can be put in the
condition tag.

>>>>>

>>>>> I looked here
[https://karaf.apache.org/manual/latest/provisioning](https://karaf.apache.org/manual/latest/provisioning)
but there is no mention of this.

>>>>>

>>>>>  
>

>>>>>

>>>>> Best regards,  
> Alex soto  
>  
>  
>  
>

>>>>>

>>>>>  
>

>>>>

>>>>  
>

>>>

>>>  
>

>>

>>  
>

>

>  
>


Re: Features Conditional on JDK version

Posted by Alex Soto <al...@envieta.com>.
The use case is: I wish my solution to be able to run in various Java versions.
For example, if deployed in Java 8, I do not need to provide JAXB jars, but I do for JDK11.



> On Feb 26, 2020, at 2:30 PM, Jean-Baptiste Onofre <jb...@nanthrax.net> wrote:
> 
> Hi Alex,
> 
> Can you quickly explain what you are looking for ?
> 
> You can to install a feature matching a condition, where the condition is a bundle or a capability (provided by another bundle or feature) ?
> 
> Regards
> JB
> 
>> Le 26 févr. 2020 à 20:27, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a écrit :
>> 
>> Thanks JB,
>> 
>> Can you point me to capability documentation?
>> 
>> 
>> Best regards,
>> Alex soto
>> 
>> 
>> 
>> 
>>> On Feb 26, 2020, at 2:25 PM, Jean-Baptiste Onofre <jb@nanthrax.net <ma...@nanthrax.net>> wrote:
>>> 
>>> Hi,
>>> 
>>> No, a condition is actually another feature.
>>> 
>>> So, the content of the feature will be installed only if the condition feature is installed (or when it will be installed).
>>> 
>>> In your case, you can maybe use a capability ?
>>> 
>>> Regards
>>> JB
>>> 
>>>> Le 26 févr. 2020 à 19:53, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a écrit :
>>>> 
>>>> In Features XML, is it possible to add a bundle conditionally based on JDK version?
>>>> 
>>>> <conditional>
>>>> 	<condition>???</condition>
>>>> </conditonal>
>>>> 
>>>> BTW, I could not find documentation about what can be put in the condition tag.
>>>> I looked here https://karaf.apache.org/manual/latest/provisioning <https://karaf.apache.org/manual/latest/provisioning> but there is no mention of this.
>>>> 
>>>> Best regards,
>>>> Alex soto
>>>> 
>>>> 
>>>> 
>>>> 
>>> 
>> 
> 


Re: Features Conditional on JDK version

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Hi Alex,

Can you quickly explain what you are looking for ?

You can to install a feature matching a condition, where the condition is a bundle or a capability (provided by another bundle or feature) ?

Regards
JB

> Le 26 févr. 2020 à 20:27, Alex Soto <al...@envieta.com> a écrit :
> 
> Thanks JB,
> 
> Can you point me to capability documentation?
> 
> 
> Best regards,
> Alex soto
> 
> 
> 
> 
>> On Feb 26, 2020, at 2:25 PM, Jean-Baptiste Onofre <jb@nanthrax.net <ma...@nanthrax.net>> wrote:
>> 
>> Hi,
>> 
>> No, a condition is actually another feature.
>> 
>> So, the content of the feature will be installed only if the condition feature is installed (or when it will be installed).
>> 
>> In your case, you can maybe use a capability ?
>> 
>> Regards
>> JB
>> 
>>> Le 26 févr. 2020 à 19:53, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a écrit :
>>> 
>>> In Features XML, is it possible to add a bundle conditionally based on JDK version?
>>> 
>>> <conditional>
>>> 	<condition>???</condition>
>>> </conditonal>
>>> 
>>> BTW, I could not find documentation about what can be put in the condition tag.
>>> I looked here https://karaf.apache.org/manual/latest/provisioning <https://karaf.apache.org/manual/latest/provisioning> but there is no mention of this.
>>> 
>>> Best regards,
>>> Alex soto
>>> 
>>> 
>>> 
>>> 
>> 
> 


Re: Features Conditional on JDK version

Posted by Alex Soto <al...@envieta.com>.
Thanks JB,

Can you point me to capability documentation?


Best regards,
Alex soto




> On Feb 26, 2020, at 2:25 PM, Jean-Baptiste Onofre <jb...@nanthrax.net> wrote:
> 
> Hi,
> 
> No, a condition is actually another feature.
> 
> So, the content of the feature will be installed only if the condition feature is installed (or when it will be installed).
> 
> In your case, you can maybe use a capability ?
> 
> Regards
> JB
> 
>> Le 26 févr. 2020 à 19:53, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a écrit :
>> 
>> In Features XML, is it possible to add a bundle conditionally based on JDK version?
>> 
>> <conditional>
>> 	<condition>???</condition>
>> </conditonal>
>> 
>> BTW, I could not find documentation about what can be put in the condition tag.
>> I looked here https://karaf.apache.org/manual/latest/provisioning <https://karaf.apache.org/manual/latest/provisioning> but there is no mention of this.
>> 
>> Best regards,
>> Alex soto
>> 
>> 
>> 
>> 
> 


Re: Features Conditional on JDK version

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Hi,

No, a condition is actually another feature.

So, the content of the feature will be installed only if the condition feature is installed (or when it will be installed).

In your case, you can maybe use a capability ?

Regards
JB

> Le 26 févr. 2020 à 19:53, Alex Soto <al...@envieta.com> a écrit :
> 
> In Features XML, is it possible to add a bundle conditionally based on JDK version?
> 
> <conditional>
> 	<condition>???</condition>
> </conditonal>
> 
> BTW, I could not find documentation about what can be put in the condition tag.
> I looked here https://karaf.apache.org/manual/latest/provisioning <https://karaf.apache.org/manual/latest/provisioning> but there is no mention of this.
> 
> Best regards,
> Alex soto
> 
> 
> 
> 


Re: Features Conditional on JDK version

Posted by Alex Soto <al...@envieta.com>.
Thanks!



> On Feb 27, 2020, at 10:49 AM, Jean-Baptiste Onofre <jb...@nanthrax.net> wrote:
> 
> Hi,
> 
> That’s an issue in the bundle (JAXB is affected AFAIR) itself (already reported). I have to implement a workaround to avoid this with JDK 9+.
> 
> About condition, they are evaluated at runtime by the resolver. Thanks to that, if later you install a condition feature, then the inner resources will be installed.
> 
> Regards
> JB
> 
>> Le 27 févr. 2020 à 16:34, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a écrit :
>> 
>> Thank you JB,
>> 
>> I have made the changes you suggested, but the behavior is very strange; the first time I run, I get this error:
>> 
>> java.lang.ArrayIndexOutOfBoundsException: 19
>> 	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:576)
>> 	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:494)
>> 	at aQute.bnd.osgi.Clazz.parseClassFileWithCollector(Clazz.java:483)
>> 	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:473)
>> 	at aQute.bnd.osgi.Analyzer.analyzeJar(Analyzer.java:2177)
>> 	at aQute.bnd.osgi.Analyzer.analyzeBundleClasspath(Analyzer.java:2083)
>> 	at aQute.bnd.osgi.Analyzer.analyze(Analyzer.java:138)
>> 	at aQute.bnd.osgi.Analyzer.calcManifest(Analyzer.java:616)
>> 	at org.ops4j.pax.swissbox.bnd.BndUtils.createBundle(BndUtils.java:161)
>> 	at org.ops4j.pax.url.wrap.internal.Connection.getInputStream(Connection.java:83)
>> 	at java.net.URL.openStream(URL.java:1045)
>> 	at org.apache.karaf.features.internal.download.impl.SimpleDownloadTask.download(SimpleDownloadTask.java:78)
>> 	at org.apache.karaf.features.internal.download.impl.AbstractRetryableDownloadTask.run(AbstractRetryableDownloadTask.java:60)
>> 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>> 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>> 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
>> 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
>> 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
>> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
>> 	at java.lang.Thread.run(Thread.java:748)
>> java.lang.ArrayIndexOutOfBoundsException: 19
>> 	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:576)
>> 	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:494)
>> 	at aQute.bnd.osgi.Clazz.parseClassFileWithCollector(Clazz.java:483)
>> 	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:473)
>> 	at aQute.bnd.osgi.Analyzer.analyzeJar(Analyzer.java:2177)
>> 	at aQute.bnd.osgi.Analyzer.analyzeBundleClasspath(Analyzer.java:2083)
>> 	at aQute.bnd.osgi.Analyzer.analyze(Analyzer.java:138)
>> 	at aQute.bnd.osgi.Analyzer.calcManifest(Analyzer.java:616)
>> 	at org.ops4j.pax.swissbox.bnd.BndUtils.createBundle(BndUtils.java:161)
>> 	at org.ops4j.pax.url.wrap.internal.Connection.getInputStream(Connection.java:83)
>> 	at java.net.URL.openStream(URL.java:1045)
>> 	at org.apache.karaf.features.internal.download.impl.SimpleDownloadTask.download(SimpleDownloadTask.java:78)
>> 	at org.apache.karaf.features.internal.download.impl.AbstractRetryableDownloadTask.run(AbstractRetryableDownloadTask.java:60)
>> 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>> 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>> 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
>> 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
>> 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
>> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
>> 	at java.lang.Thread.run(Thread.java:748)
>> 
>> Followed by multiple errors of the kind:
>> 
>> Uses constraint violation. Unable to resolve resource XXXX.  because it is exposed to package 'javax.xml.bind' from resources jakarta.xml.bind-api [jakarta.xml.bind-api [52](R 52.0)] and org.apache.felix.framework [org.apache.felix.framework [0](R 0)] via two dependency chains.
>> 
>> 
>> However, after I exit Karaf and run it again, the errors disappear, and the bundles in the conditional are not deployed as expected.
>> All of the above happens when  building the code with Java 13 (although passing —release 1.8 to the compiler).
>> 
>> I wonder, is the condition evaluated at build time or at runtime?
>> 
>> Now, when I compile with Java 8,  I still get the Index out of bound errors from BND the first time it runs, but not the uses constraints violation errors.
>> 
>> 
>> Best regards,
>> Alex soto
>> 
>> 
>> 
>> 
>>> On Feb 27, 2020, at 9:46 AM, Jean-Baptiste Onofre <jb@nanthrax.net <ma...@nanthrax.net>> wrote:
>>> 
>>> Hi Alex,
>>> 
>>> Can you try this condition:
>>> 
>>> <condition>req:osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(!(version>=1.8)))"</condition>
>>> 
>>> And also remove the dependency flag.
>>> 
>>> Regards
>>> JB
>>> 
>>>> Le 27 févr. 2020 à 15:42, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a écrit :
>>>> 
>>>> Perhaps I am still doing something wrong, or not understanding how the condition works.
>>>> I have this in my features.xml:
>>>> 
>>>> 
>>>> 		<conditional>
>>>> 			<!-- From Java 9 and up add JaveEE dependencies -->
>>>> 			<condition>req:osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(version>=9))"</condition>
>>>> 
>>>> 			<bundle dependency="true">mvn:jakarta.xml.bind/jakarta.xml.bind-api/${jaxb.version}</bundle>
>>>> 			<bundle dependency="true">mvn:com.sun.activation/javax.activation/1.2.0</bundle>
>>>> 			<bundle dependency="true">wrap:mvn:org.glassfish.jaxb/txw2/${jaxb.version}</bundle>
>>>> 			<bundle dependency="true">mvn:com.sun.istack/istack-commons-runtime/3.0.8</bundle>
>>>> 			<bundle dependency="true">mvn:org.jvnet.staxex/stax-ex/1.8.1</bundle>
>>>> 			<bundle dependency="true">mvn:com.sun.xml.fastinfoset/FastInfoset/1.2.16</bundle>
>>>> 			<bundle dependency="true">wrap:mvn:org.glassfish.jaxb/jaxb-runtime/${jaxb.version}</bundle>
>>>> 		</conditional>
>>>> 
>>>> 
>>>> But when I run on Java 8, the above bundles are deployed, but my intention is the opposite. 
>>>> Of course this causes a lot of errors. Please help.
>>>> 
>>>> Best regards,
>>>> Alex soto
>>>> 
>>>> 
>>>> 
>>>> 
>>>>> On Feb 26, 2020, at 4:21 PM, Jean-Baptiste Onofré <jb@nanthrax.net <ma...@nanthrax.net>> wrote:
>>>>> 
>>>>> Thanks Guillaume, it?s what I was looking for. 
>>>>> 
>>>>> Regards 
>>>>> JB
>>>>> 
>>>>> Le mer. 26 f?vr. 2020 ? 21:31, Guillaume Nodet <gnodet@apache.org <ma...@apache.org>> a ?crit :
>>>>> This should be doable using something like in the test https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33 <https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33>
>>>>> Le mer. 26 f?vr. 2020 ? 19:53, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a ?crit :
>>>>> In Features XML, is it possible to add a bundle conditionally based on JDK version?
>>>>> 
>>>>> <conditional>
>>>>> 	<condition>???</condition>
>>>>> </conditonal>
>>>>> 
>>>>> BTW, I could not find documentation about what can be put in the condition tag.
>>>>> I looked here https://karaf.apache.org/manual/latest/provisioning <https://karaf.apache.org/manual/latest/provisioning> but there is no mention of this.
>>>>> 
>>>>> Best regards,
>>>>> Alex soto
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> -- 
>>>>> ------------------------
>>>>> Guillaume Nodet
>>>>> 
>>>> 
>>> 
>> 
> 


Re: Features Conditional on JDK version

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Hi,

That’s an issue in the bundle (JAXB is affected AFAIR) itself (already reported). I have to implement a workaround to avoid this with JDK 9+.

About condition, they are evaluated at runtime by the resolver. Thanks to that, if later you install a condition feature, then the inner resources will be installed.

Regards
JB

> Le 27 févr. 2020 à 16:34, Alex Soto <al...@envieta.com> a écrit :
> 
> Thank you JB,
> 
> I have made the changes you suggested, but the behavior is very strange; the first time I run, I get this error:
> 
> java.lang.ArrayIndexOutOfBoundsException: 19
> 	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:576)
> 	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:494)
> 	at aQute.bnd.osgi.Clazz.parseClassFileWithCollector(Clazz.java:483)
> 	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:473)
> 	at aQute.bnd.osgi.Analyzer.analyzeJar(Analyzer.java:2177)
> 	at aQute.bnd.osgi.Analyzer.analyzeBundleClasspath(Analyzer.java:2083)
> 	at aQute.bnd.osgi.Analyzer.analyze(Analyzer.java:138)
> 	at aQute.bnd.osgi.Analyzer.calcManifest(Analyzer.java:616)
> 	at org.ops4j.pax.swissbox.bnd.BndUtils.createBundle(BndUtils.java:161)
> 	at org.ops4j.pax.url.wrap.internal.Connection.getInputStream(Connection.java:83)
> 	at java.net.URL.openStream(URL.java:1045)
> 	at org.apache.karaf.features.internal.download.impl.SimpleDownloadTask.download(SimpleDownloadTask.java:78)
> 	at org.apache.karaf.features.internal.download.impl.AbstractRetryableDownloadTask.run(AbstractRetryableDownloadTask.java:60)
> 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
> 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
> 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
> 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
> 	at java.lang.Thread.run(Thread.java:748)
> java.lang.ArrayIndexOutOfBoundsException: 19
> 	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:576)
> 	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:494)
> 	at aQute.bnd.osgi.Clazz.parseClassFileWithCollector(Clazz.java:483)
> 	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:473)
> 	at aQute.bnd.osgi.Analyzer.analyzeJar(Analyzer.java:2177)
> 	at aQute.bnd.osgi.Analyzer.analyzeBundleClasspath(Analyzer.java:2083)
> 	at aQute.bnd.osgi.Analyzer.analyze(Analyzer.java:138)
> 	at aQute.bnd.osgi.Analyzer.calcManifest(Analyzer.java:616)
> 	at org.ops4j.pax.swissbox.bnd.BndUtils.createBundle(BndUtils.java:161)
> 	at org.ops4j.pax.url.wrap.internal.Connection.getInputStream(Connection.java:83)
> 	at java.net.URL.openStream(URL.java:1045)
> 	at org.apache.karaf.features.internal.download.impl.SimpleDownloadTask.download(SimpleDownloadTask.java:78)
> 	at org.apache.karaf.features.internal.download.impl.AbstractRetryableDownloadTask.run(AbstractRetryableDownloadTask.java:60)
> 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
> 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
> 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
> 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
> 	at java.lang.Thread.run(Thread.java:748)
> 
> Followed by multiple errors of the kind:
> 
> Uses constraint violation. Unable to resolve resource XXXX.  because it is exposed to package 'javax.xml.bind' from resources jakarta.xml.bind-api [jakarta.xml.bind-api [52](R 52.0)] and org.apache.felix.framework [org.apache.felix.framework [0](R 0)] via two dependency chains.
> 
> 
> However, after I exit Karaf and run it again, the errors disappear, and the bundles in the conditional are not deployed as expected.
> All of the above happens when  building the code with Java 13 (although passing —release 1.8 to the compiler).
> 
> I wonder, is the condition evaluated at build time or at runtime?
> 
> Now, when I compile with Java 8,  I still get the Index out of bound errors from BND the first time it runs, but not the uses constraints violation errors.
> 
> 
> Best regards,
> Alex soto
> 
> 
> 
> 
>> On Feb 27, 2020, at 9:46 AM, Jean-Baptiste Onofre <jb@nanthrax.net <ma...@nanthrax.net>> wrote:
>> 
>> Hi Alex,
>> 
>> Can you try this condition:
>> 
>> <condition>req:osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(!(version>=1.8)))"</condition>
>> 
>> And also remove the dependency flag.
>> 
>> Regards
>> JB
>> 
>>> Le 27 févr. 2020 à 15:42, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a écrit :
>>> 
>>> Perhaps I am still doing something wrong, or not understanding how the condition works.
>>> I have this in my features.xml:
>>> 
>>> 
>>> 		<conditional>
>>> 			<!-- From Java 9 and up add JaveEE dependencies -->
>>> 			<condition>req:osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(version>=9))"</condition>
>>> 
>>> 			<bundle dependency="true">mvn:jakarta.xml.bind/jakarta.xml.bind-api/${jaxb.version}</bundle>
>>> 			<bundle dependency="true">mvn:com.sun.activation/javax.activation/1.2.0</bundle>
>>> 			<bundle dependency="true">wrap:mvn:org.glassfish.jaxb/txw2/${jaxb.version}</bundle>
>>> 			<bundle dependency="true">mvn:com.sun.istack/istack-commons-runtime/3.0.8</bundle>
>>> 			<bundle dependency="true">mvn:org.jvnet.staxex/stax-ex/1.8.1</bundle>
>>> 			<bundle dependency="true">mvn:com.sun.xml.fastinfoset/FastInfoset/1.2.16</bundle>
>>> 			<bundle dependency="true">wrap:mvn:org.glassfish.jaxb/jaxb-runtime/${jaxb.version}</bundle>
>>> 		</conditional>
>>> 
>>> 
>>> But when I run on Java 8, the above bundles are deployed, but my intention is the opposite. 
>>> Of course this causes a lot of errors. Please help.
>>> 
>>> Best regards,
>>> Alex soto
>>> 
>>> 
>>> 
>>> 
>>>> On Feb 26, 2020, at 4:21 PM, Jean-Baptiste Onofré <jb@nanthrax.net <ma...@nanthrax.net>> wrote:
>>>> 
>>>> Thanks Guillaume, it?s what I was looking for. 
>>>> 
>>>> Regards 
>>>> JB
>>>> 
>>>> Le mer. 26 f?vr. 2020 ? 21:31, Guillaume Nodet <gnodet@apache.org <ma...@apache.org>> a ?crit :
>>>> This should be doable using something like in the test https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33 <https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33>
>>>> Le mer. 26 f?vr. 2020 ? 19:53, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a ?crit :
>>>> In Features XML, is it possible to add a bundle conditionally based on JDK version?
>>>> 
>>>> <conditional>
>>>> 	<condition>???</condition>
>>>> </conditonal>
>>>> 
>>>> BTW, I could not find documentation about what can be put in the condition tag.
>>>> I looked here https://karaf.apache.org/manual/latest/provisioning <https://karaf.apache.org/manual/latest/provisioning> but there is no mention of this.
>>>> 
>>>> Best regards,
>>>> Alex soto
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> -- 
>>>> ------------------------
>>>> Guillaume Nodet
>>>> 
>>> 
>> 
> 


Re: Features Conditional on JDK version

Posted by Alex Soto <al...@envieta.com>.
Thank you JB,

I have made the changes you suggested, but the behavior is very strange; the first time I run, I get this error:

java.lang.ArrayIndexOutOfBoundsException: 19
	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:576)
	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:494)
	at aQute.bnd.osgi.Clazz.parseClassFileWithCollector(Clazz.java:483)
	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:473)
	at aQute.bnd.osgi.Analyzer.analyzeJar(Analyzer.java:2177)
	at aQute.bnd.osgi.Analyzer.analyzeBundleClasspath(Analyzer.java:2083)
	at aQute.bnd.osgi.Analyzer.analyze(Analyzer.java:138)
	at aQute.bnd.osgi.Analyzer.calcManifest(Analyzer.java:616)
	at org.ops4j.pax.swissbox.bnd.BndUtils.createBundle(BndUtils.java:161)
	at org.ops4j.pax.url.wrap.internal.Connection.getInputStream(Connection.java:83)
	at java.net.URL.openStream(URL.java:1045)
	at org.apache.karaf.features.internal.download.impl.SimpleDownloadTask.download(SimpleDownloadTask.java:78)
	at org.apache.karaf.features.internal.download.impl.AbstractRetryableDownloadTask.run(AbstractRetryableDownloadTask.java:60)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
java.lang.ArrayIndexOutOfBoundsException: 19
	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:576)
	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:494)
	at aQute.bnd.osgi.Clazz.parseClassFileWithCollector(Clazz.java:483)
	at aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:473)
	at aQute.bnd.osgi.Analyzer.analyzeJar(Analyzer.java:2177)
	at aQute.bnd.osgi.Analyzer.analyzeBundleClasspath(Analyzer.java:2083)
	at aQute.bnd.osgi.Analyzer.analyze(Analyzer.java:138)
	at aQute.bnd.osgi.Analyzer.calcManifest(Analyzer.java:616)
	at org.ops4j.pax.swissbox.bnd.BndUtils.createBundle(BndUtils.java:161)
	at org.ops4j.pax.url.wrap.internal.Connection.getInputStream(Connection.java:83)
	at java.net.URL.openStream(URL.java:1045)
	at org.apache.karaf.features.internal.download.impl.SimpleDownloadTask.download(SimpleDownloadTask.java:78)
	at org.apache.karaf.features.internal.download.impl.AbstractRetryableDownloadTask.run(AbstractRetryableDownloadTask.java:60)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Followed by multiple errors of the kind:

Uses constraint violation. Unable to resolve resource XXXX.  because it is exposed to package 'javax.xml.bind' from resources jakarta.xml.bind-api [jakarta.xml.bind-api [52](R 52.0)] and org.apache.felix.framework [org.apache.felix.framework [0](R 0)] via two dependency chains.


However, after I exit Karaf and run it again, the errors disappear, and the bundles in the conditional are not deployed as expected.
All of the above happens when  building the code with Java 13 (although passing —release 1.8 to the compiler).

I wonder, is the condition evaluated at build time or at runtime?

Now, when I compile with Java 8,  I still get the Index out of bound errors from BND the first time it runs, but not the uses constraints violation errors.


Best regards,
Alex soto




> On Feb 27, 2020, at 9:46 AM, Jean-Baptiste Onofre <jb...@nanthrax.net> wrote:
> 
> Hi Alex,
> 
> Can you try this condition:
> 
> <condition>req:osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(!(version>=1.8)))"</condition>
> 
> And also remove the dependency flag.
> 
> Regards
> JB
> 
>> Le 27 févr. 2020 à 15:42, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a écrit :
>> 
>> Perhaps I am still doing something wrong, or not understanding how the condition works.
>> I have this in my features.xml:
>> 
>> 
>> 		<conditional>
>> 			<!-- From Java 9 and up add JaveEE dependencies -->
>> 			<condition>req:osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(version>=9))"</condition>
>> 
>> 			<bundle dependency="true">mvn:jakarta.xml.bind/jakarta.xml.bind-api/${jaxb.version}</bundle>
>> 			<bundle dependency="true">mvn:com.sun.activation/javax.activation/1.2.0</bundle>
>> 			<bundle dependency="true">wrap:mvn:org.glassfish.jaxb/txw2/${jaxb.version}</bundle>
>> 			<bundle dependency="true">mvn:com.sun.istack/istack-commons-runtime/3.0.8</bundle>
>> 			<bundle dependency="true">mvn:org.jvnet.staxex/stax-ex/1.8.1</bundle>
>> 			<bundle dependency="true">mvn:com.sun.xml.fastinfoset/FastInfoset/1.2.16</bundle>
>> 			<bundle dependency="true">wrap:mvn:org.glassfish.jaxb/jaxb-runtime/${jaxb.version}</bundle>
>> 		</conditional>
>> 
>> 
>> But when I run on Java 8, the above bundles are deployed, but my intention is the opposite. 
>> Of course this causes a lot of errors. Please help.
>> 
>> Best regards,
>> Alex soto
>> 
>> 
>> 
>> 
>>> On Feb 26, 2020, at 4:21 PM, Jean-Baptiste Onofré <jb@nanthrax.net <ma...@nanthrax.net>> wrote:
>>> 
>>> Thanks Guillaume, it?s what I was looking for. 
>>> 
>>> Regards 
>>> JB
>>> 
>>> Le mer. 26 f?vr. 2020 ? 21:31, Guillaume Nodet <gnodet@apache.org <ma...@apache.org>> a ?crit :
>>> This should be doable using something like in the test https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33 <https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33>
>>> Le mer. 26 f?vr. 2020 ? 19:53, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a ?crit :
>>> In Features XML, is it possible to add a bundle conditionally based on JDK version?
>>> 
>>> <conditional>
>>> 	<condition>???</condition>
>>> </conditonal>
>>> 
>>> BTW, I could not find documentation about what can be put in the condition tag.
>>> I looked here https://karaf.apache.org/manual/latest/provisioning <https://karaf.apache.org/manual/latest/provisioning> but there is no mention of this.
>>> 
>>> Best regards,
>>> Alex soto
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> -- 
>>> ------------------------
>>> Guillaume Nodet
>>> 
>> 
> 


Re: Features Conditional on JDK version

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Hi Alex,

Can you try this condition:

<condition>req:osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(!(version>=1.8)))"</condition>

And also remove the dependency flag.

Regards
JB

> Le 27 févr. 2020 à 15:42, Alex Soto <al...@envieta.com> a écrit :
> 
> Perhaps I am still doing something wrong, or not understanding how the condition works.
> I have this in my features.xml:
> 
> 
> 		<conditional>
> 			<!-- From Java 9 and up add JaveEE dependencies -->
> 			<condition>req:osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(version>=9))"</condition>
> 
> 			<bundle dependency="true">mvn:jakarta.xml.bind/jakarta.xml.bind-api/${jaxb.version}</bundle>
> 			<bundle dependency="true">mvn:com.sun.activation/javax.activation/1.2.0</bundle>
> 			<bundle dependency="true">wrap:mvn:org.glassfish.jaxb/txw2/${jaxb.version}</bundle>
> 			<bundle dependency="true">mvn:com.sun.istack/istack-commons-runtime/3.0.8</bundle>
> 			<bundle dependency="true">mvn:org.jvnet.staxex/stax-ex/1.8.1</bundle>
> 			<bundle dependency="true">mvn:com.sun.xml.fastinfoset/FastInfoset/1.2.16</bundle>
> 			<bundle dependency="true">wrap:mvn:org.glassfish.jaxb/jaxb-runtime/${jaxb.version}</bundle>
> 		</conditional>
> 
> 
> But when I run on Java 8, the above bundles are deployed, but my intention is the opposite. 
> Of course this causes a lot of errors. Please help.
> 
> Best regards,
> Alex soto
> 
> 
> 
> 
>> On Feb 26, 2020, at 4:21 PM, Jean-Baptiste Onofré <jb@nanthrax.net <ma...@nanthrax.net>> wrote:
>> 
>> Thanks Guillaume, it?s what I was looking for. 
>> 
>> Regards 
>> JB
>> 
>> Le mer. 26 f?vr. 2020 ? 21:31, Guillaume Nodet <gnodet@apache.org <ma...@apache.org>> a ?crit :
>> This should be doable using something like in the test https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33 <https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33>
>> Le mer. 26 f?vr. 2020 ? 19:53, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a ?crit :
>> In Features XML, is it possible to add a bundle conditionally based on JDK version?
>> 
>> <conditional>
>> 	<condition>???</condition>
>> </conditonal>
>> 
>> BTW, I could not find documentation about what can be put in the condition tag.
>> I looked here https://karaf.apache.org/manual/latest/provisioning <https://karaf.apache.org/manual/latest/provisioning> but there is no mention of this.
>> 
>> Best regards,
>> Alex soto
>> 
>> 
>> 
>> 
>> 
>> 
>> -- 
>> ------------------------
>> Guillaume Nodet
>> 
> 


Re: Features Conditional on JDK version

Posted by Alex Soto <al...@envieta.com>.
Perhaps I am still doing something wrong, or not understanding how the condition works.
I have this in my features.xml:


		<conditional>
			<!-- From Java 9 and up add JaveEE dependencies -->
			<condition>req:osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(version>=9))"</condition>

			<bundle dependency="true">mvn:jakarta.xml.bind/jakarta.xml.bind-api/${jaxb.version}</bundle>
			<bundle dependency="true">mvn:com.sun.activation/javax.activation/1.2.0</bundle>
			<bundle dependency="true">wrap:mvn:org.glassfish.jaxb/txw2/${jaxb.version}</bundle>
			<bundle dependency="true">mvn:com.sun.istack/istack-commons-runtime/3.0.8</bundle>
			<bundle dependency="true">mvn:org.jvnet.staxex/stax-ex/1.8.1</bundle>
			<bundle dependency="true">mvn:com.sun.xml.fastinfoset/FastInfoset/1.2.16</bundle>
			<bundle dependency="true">wrap:mvn:org.glassfish.jaxb/jaxb-runtime/${jaxb.version}</bundle>
		</conditional>


But when I run on Java 8, the above bundles are deployed, but my intention is the opposite. 
Of course this causes a lot of errors. Please help.

Best regards,
Alex soto




> On Feb 26, 2020, at 4:21 PM, Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:
> 
> Thanks Guillaume, it?s what I was looking for. 
> 
> Regards 
> JB
> 
> Le mer. 26 f?vr. 2020 ? 21:31, Guillaume Nodet <gn...@apache.org> a ?crit :
> This should be doable using something like in the test https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33 <https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33>
> Le mer. 26 f?vr. 2020 ? 19:53, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a ?crit :
> In Features XML, is it possible to add a bundle conditionally based on JDK version?
> 
> <conditional>
> 	<condition>???</condition>
> </conditonal>
> 
> BTW, I could not find documentation about what can be put in the condition tag.
> I looked here https://karaf.apache.org/manual/latest/provisioning <https://karaf.apache.org/manual/latest/provisioning> but there is no mention of this.
> 
> Best regards,
> Alex soto
> 
> 
> 
> 
> 
> 
> -- 
> ------------------------
> Guillaume Nodet
> 


Re: Features Conditional on JDK version

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Thanks Guillaume, it?s what I was looking for.

  

Regards

JB

  

Le mer. 26 f?vr. 2020 ? 21:31, Guillaume Nodet <gn...@apache.org> a ?crit :  

> This should be doable using something like in the test
[https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33](https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33)

>

>  
>

>

> Le mer. 26 f?vr. 2020 ? 19:53, Alex Soto
<[alex.soto@envieta.com](mailto:alex.soto@envieta.com)> a ?crit :  
>

>

>> In Features XML, is it possible to add a bundle conditionally based on JDK
version?

>>

>>  
>

>>

>> <conditional>  
>  <condition>???</condition>

>>

>> </conditonal>

>>

>>  
>

>>

>> BTW, I could not find documentation about what can be put in the condition
tag.

>>

>> I looked here
[https://karaf.apache.org/manual/latest/provisioning](https://karaf.apache.org/manual/latest/provisioning)
but there is no mention of this.

>>

>>  
>

>>

>> Best regards,  
> Alex soto  
>  
>  
>  
>

>>

>>  
>

>

>  
>

>

>  
>

>

> \--  
>

>

> \------------------------  
> Guillaume Nodet  
>

>

>  
>


Re: Features Conditional on JDK version

Posted by Alex Soto <al...@envieta.com>.
Thank you Guillaume,

I am doing something like this:


		<conditional>
			<!-- From Java 9 and up add JaveEE dependencies -->
			<condition>req:osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(!(version>=9)))"</condition>

			<bundle dependency="true">mvn:jakarta.xml.bind/jakarta.xml.bind-api/${jaxb.version}</bundle>
			<bundle dependency="true">mvn:com.sun.activation/javax.activation/1.2.0</bundle>
			<bundle dependency="true">wrap:mvn:org.glassfish.jaxb/txw2/${jaxb.version}</bundle>
			<bundle dependency="true">mvn:com.sun.istack/istack-commons-runtime/3.0.8</bundle>
			<bundle dependency="true">mvn:org.jvnet.staxex/stax-ex/1.8.1</bundle>
			<bundle dependency="true">mvn:com.sun.xml.fastinfoset/FastInfoset/1.2.16</bundle>
			<bundle dependency="true">wrap:mvn:org.glassfish.jaxb/jaxb-runtime/${jaxb.version}</bundle>
		</conditional>


Not sure yet if it is working correctly. Testing...

Best regards,
Alex soto




> On Feb 26, 2020, at 3:31 PM, Guillaume Nodet <gn...@apache.org> wrote:
> 
> This should be doable using something like in the test https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33 <https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33>
> Le mer. 26 févr. 2020 à 19:53, Alex Soto <alex.soto@envieta.com <ma...@envieta.com>> a écrit :
> In Features XML, is it possible to add a bundle conditionally based on JDK version?
> 
> <conditional>
> 	<condition>???</condition>
> </conditonal>
> 
> BTW, I could not find documentation about what can be put in the condition tag.
> I looked here https://karaf.apache.org/manual/latest/provisioning <https://karaf.apache.org/manual/latest/provisioning> but there is no mention of this.
> 
> Best regards,
> Alex soto
> 
> 
> 
> 
> 
> 
> -- 
> ------------------------
> Guillaume Nodet
> 


Re: Features Conditional on JDK version

Posted by Guillaume Nodet <gn...@apache.org>.
This should be doable using something like in the test
https://github.com/apache/karaf/blob/master/features/core/src/test/resources/org/apache/karaf/features/internal/service/f06.xml#L30-L33

Le mer. 26 févr. 2020 à 19:53, Alex Soto <al...@envieta.com> a écrit :

> In Features XML, is it possible to add a bundle conditionally based on JDK
> version?
>
> <conditional>
> <condition>???</condition>
> </conditonal>
>
> BTW, I could not find documentation about what can be put in the condition
> tag.
> I looked here https://karaf.apache.org/manual/latest/provisioning but
> there is no mention of this.
>
> Best regards,
> Alex soto
>
>
>
>
>

-- 
------------------------
Guillaume Nodet