You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@karaf.apache.org by SapnaB <sa...@gmail.com> on 2014/08/06 11:29:40 UTC

List User installed bundles in Karaf from Java

Hi,

When I execute the osgi:list command on Karaf 2.3.2, it lists down the
bundles which I (user) have installed.
I want a similar result through java code.

But when I do context.getBundles() and filter ACTIVE bundles, I get the
complete list installed in Karaf. 
Is there a way to get only user installed bundles through Java?

Thanks,
Sapna



--
View this message in context: http://karaf.922171.n3.nabble.com/List-User-installed-bundles-in-Karaf-from-Java-tp4034602.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: List User installed bundles in Karaf from Java

Posted by SapnaB <sa...@gmail.com>.
Hi Timothy,

Thanks for the tips. What I have done now is alter the bundle symbolic name
to include Project Group and Artifact IDs, which are standard across all
plugins developed by the team. Then filtering for specific plugins using
symbolic names.
But I guess Bundle-Vendor is another field I can use.

-Sapna



--
View this message in context: http://karaf.922171.n3.nabble.com/List-User-installed-bundles-in-Karaf-from-Java-tp4034602p4035162.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: List User installed bundles in Karaf from Java

Posted by Timothy Stewart <ti...@gmail.com>.
There might be a better answer for you, but the only way I was able to set
bundle-specific start levels was to deploy them within a features file.

One thing you could possibly use is the Bundle-Vendor.  If you are using the
maven-bnd-plugin, it defaults to the value of organization name within the
POM, which is often set by an organizational parent POM that all projects
are derived from.  If it is being set, you could use the Bundle.getHeaders()
method to check it for each bundle and verify that it belongs to your
company.

You might also use Bundle-Category somehow, since it can be free text, but
I'm not sure maven-bnd-plugin can set it, and it is more difficult to ensure
you get a category into every project.

Just a couple thoughts.



--
View this message in context: http://karaf.922171.n3.nabble.com/List-User-installed-bundles-in-Karaf-from-Java-tp4034602p4035021.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: List User installed bundles in Karaf from Java

Posted by SapnaB <sa...@gmail.com>.
Hi JB,

I now have a requirement to print only installed application specific
bundles, and not the dependent bundles. 

Ex: im using jersey jars in my bundle com.osgi.test/Test/0.0.1-SNAPSHOT, so
Iv installed jersey jars on Karaf using the wrap command. Both jersey bundle
and Test bundle have a start level=80. If I filter on startLevel>=80, i get
jersey as well. Whereas I want only Test bundle to be printed.

One way is that I filter based on bundle name, but I don not want to use
this approach, since I cannot force all bundle developers to follow some
naming convention.

Is there a way in pom/manifest, where I can specify the StartLevel which I
want my bundle to have when it is installed in Karaf(ex: 100)? Im not using
spring.

Thanks,
Sapna



--
View this message in context: http://karaf.922171.n3.nabble.com/List-User-installed-bundles-in-Karaf-from-Java-tp4034602p4034934.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: List User installed bundles in Karaf from Java

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Sapna,

for OSGi > 4.3, you have to do:

org.osgi.framework.startlevel.BundleStartLevel bsl = 
bundle.adapt(BundleStartLevel.class);
int startLevel = bsl.getStartLevel();

where bundle is org.osgi.framework.Bundle.

Regards
JB

On 08/12/2014 09:12 AM, SapnaB wrote:
> Hi JB
>
> StartLevel is deprecated in OSGi 4.3. Is there any equivalent service
> available which I can use?
> I tried BundleStartLevel, but that doesnt give me the desired results.
>
> Thanks,
> Sapna
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/List-User-installed-bundles-in-Karaf-from-Java-tp4034602p4034702.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: List User installed bundles in Karaf from Java

Posted by SapnaB <sa...@gmail.com>.
Hi JB

StartLevel is deprecated in OSGi 4.3. Is there any equivalent service
available which I can use?
I tried BundleStartLevel, but that doesnt give me the desired results.

Thanks,
Sapna



--
View this message in context: http://karaf.922171.n3.nabble.com/List-User-installed-bundles-in-Karaf-from-Java-tp4034602p4034702.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: List User installed bundles in Karaf from Java

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Sapna,

StartLevel is available as service:

StartLevel sl = 
bundleContext.getService(org.osgi.service.startlevel.StartLevel.class.getName();

sl.getStartLevel() gives the default start level.

sl.getStartLevel(bundleId) gives the bundle start level.

Regards
JB

On 08/06/2014 06:26 PM, SapnaB wrote:
> Hi JB,
>
> Thanks.. this clarifies a lot.
> Is there any straight forward way to query the bundle level? I could not
> find any API available in the com.osgi.framework.Bundle class.
>
> Thanks,
> Sapna
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/List-User-installed-bundles-in-Karaf-from-Java-tp4034602p4034609.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: List User installed bundles in Karaf from Java

Posted by SapnaB <sa...@gmail.com>.
Hi JB,

Thanks.. this clarifies a lot. 
Is there any straight forward way to query the bundle level? I could not
find any API available in the com.osgi.framework.Bundle class.

Thanks,
Sapna



--
View this message in context: http://karaf.922171.n3.nabble.com/List-User-installed-bundles-in-Karaf-from-Java-tp4034602p4034609.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: List User installed bundles in Karaf from Java

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Sapna,

it's because the osgi:list by default display only the bundle with a 
level greater than the system one (so the user bundles).
If you do osgi:list -t 0 (or la which is an alias to osgi:list -t 0), 
you will have the list of all bundles (both system and user).

If you want to do it programmatically, you have to check the bundle 
level and only display bundles with level greater than 50.

Regards
JB

On 08/06/2014 11:29 AM, SapnaB wrote:
> Hi,
>
> When I execute the osgi:list command on Karaf 2.3.2, it lists down the
> bundles which I (user) have installed.
> I want a similar result through java code.
>
> But when I do context.getBundles() and filter ACTIVE bundles, I get the
> complete list installed in Karaf.
> Is there a way to get only user installed bundles through Java?
>
> Thanks,
> Sapna
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/List-User-installed-bundles-in-Karaf-from-Java-tp4034602.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com