You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Carlos Sanchez <ca...@apache.org> on 2007/02/09 00:45:54 UTC

How to reexport packages when using import-package

I know about visibility:=reexport with Require-Bundle, but how can I
reexport packages imported with Import-Package?

-- 
I could give you my word as a Spaniard.
No good. I've known too many Spaniards.
                             -- The Princess Bride

Re: How to reexport packages when using import-package

Posted by Carlos Sanchez <ca...@apache.org>.
On 2/9/07, Niclas Hedhman <ni...@hedhman.org> wrote:
> On Friday 09 February 2007 08:05, Carlos Sanchez wrote:
> > ok, so there's no "transitive dependency" thing like Maven has,
>
>
> Speaking of that; IMHO If artifact A dependsOn artifact B which dependsOn
> artifact C, then the transitive dependency should not provide C's classes to
> A at compile time. Reason; If A uses anything directly in C, it would mean
> that if a later version of B stop using C, A becomes 'unusable'.
>
> Fast forward to OSGi; If you had the somewhat broken way of Maven allowing B
> to automagically supply classes to A, then if one replaces B with another
> implementation then A breaks. Therefor, A imports the C packages explicitly,
> if they are needed, but if it is only internal use of C in B then it would
> not require A to know about C.
>
> > basically I have to reference all the bundles I need.
>
> Try to stop thinking "bundles" and start thinking "packages". Bundles are
> typically not referenced at all, especially not the generic case for the
> maven-jar-plugin, which is what I am hoping you are working on.

I got it, I got it ;)  just wrote the wrong word

>
>
>
> Cheers
> Niclas
>


-- 
I could give you my word as a Spaniard.
No good. I've known too many Spaniards.
                             -- The Princess Bride

Re: How to reexport packages when using import-package

Posted by "Richard S. Hall" <he...@ungoverned.org>.
Niclas Hedhman wrote:
> On Friday 09 February 2007 08:05, Carlos Sanchez wrote:
>   
>> ok, so there's no "transitive dependency" thing like Maven has,
>>     
>
>
> Speaking of that; IMHO If artifact A dependsOn artifact B which dependsOn 
> artifact C, then the transitive dependency should not provide C's classes to 
> A at compile time. Reason; If A uses anything directly in C, it would mean 
> that if a later version of B stop using C, A becomes 'unusable'.
>
> Fast forward to OSGi; If you had the somewhat broken way of Maven allowing B 
> to automagically supply classes to A, then if one replaces B with another 
> implementation then A breaks. Therefor, A imports the C packages explicitly, 
> if they are needed, but if it is only internal use of C in B then it would 
> not require A to know about C.
>   

Correct. The transitive type of dependency in OSGi is captured by "uses" 
constraints, but this is still done in terms of packages. For example, 
bundle A can export package 'foo' and export (or import) package 'bar' 
and can declare that 'foo' uses 'bar'. This tells the framework that if 
bundle B imports 'foo' and is wired to bundle A's 'foo', then if bundle 
B imports 'bar' it must also get that from bundle A (or from the same 
place as bundle A if a imports 'bar').

Thus, bundle A can inform the framework about transitive dependencies so 
that it can resolve package dependencies in a consistent way for a set 
of bundles. But, as Niclas points out, even then this does not 
automagically give bundle B access to these "used" packages, bundle B 
must still explicitly import them to have access to them.

-> richard

> Try to stop thinking "bundles" and start thinking "packages". Bundles are 
> typically not referenced at all, especially not the generic case for the 
> maven-jar-plugin, which is what I am hoping you are working on.
>
>
>
> Cheers
> Niclas
>   

Re: How to reexport packages when using import-package

Posted by Niclas Hedhman <ni...@hedhman.org>.
On Friday 09 February 2007 08:05, Carlos Sanchez wrote:
> ok, so there's no "transitive dependency" thing like Maven has,


Speaking of that; IMHO If artifact A dependsOn artifact B which dependsOn 
artifact C, then the transitive dependency should not provide C's classes to 
A at compile time. Reason; If A uses anything directly in C, it would mean 
that if a later version of B stop using C, A becomes 'unusable'.

Fast forward to OSGi; If you had the somewhat broken way of Maven allowing B 
to automagically supply classes to A, then if one replaces B with another 
implementation then A breaks. Therefor, A imports the C packages explicitly, 
if they are needed, but if it is only internal use of C in B then it would 
not require A to know about C.

> basically I have to reference all the bundles I need.

Try to stop thinking "bundles" and start thinking "packages". Bundles are 
typically not referenced at all, especially not the generic case for the 
maven-jar-plugin, which is what I am hoping you are working on.



Cheers
Niclas

Re: How to reexport packages when using import-package

Posted by Carlos Sanchez <ca...@apache.org>.
ok, so the framework is the one to take care of resolving all packages needed.
Thanks!

On 2/9/07, Felix Meschberger <Fe...@day.com> wrote:
> Hi
>
> On 2/9/07, Carlos Sanchez <ca...@apache.org> wrote:
> >
> > ok, so there's no "transitive dependency" thing like Maven has,
> > basically I have to reference all the bundles I need.
>
>
> Maybe there is some confusion here... By listing Java packages your bundle
> needs in the Import-Package header you place an order to the framework for
> these packages and have the framework resolve the bundles providing those
> packages in their Export-Package headers.
>
> So, the nice thing here is, that you do not need to care as much for finding
> the right libraries/bundles as you do in Maven, where you declare the
> providers of the packages and not the packages themselves.
>
> Consequently, there is no such thing as transitive imports for packages
> because either your bundle needs a package, in which case it is imported, or
> your bundle does not need it and then you don't care. And the list of
> packages required by a bundle may be automatically generated by the BND
> tool.
>
> Hope this helps.
>
> Regards
> Felix
>
> On 2/8/07, Richard S. Hall <he...@ungoverned.org> wrote:
> > > On Feb 8, 2007, at 6:45 PM, Carlos Sanchez wrote:
> > >
> > > > I know about visibility:=reexport with Require-Bundle, but how can I
> > > > reexport packages imported with Import-Package?
> > >
> > > You cannot do so.
> > >
> > > This issue is a little confusing, especially given the terminology that
> > > was adopted, but even require-bundle with "reexport" does not re-export
> > > the packages as I think you are imagining.
> > >
> > > Consider A requires B requires C. If B requires C with "reexport" then
> > > A will see C's packages too. If B requires C privately, then A will not
> > > see C's packages.
> > >
> > > The only form of re-export available in OSGi R4 is if a bundle requires
> > > several bundles and then declares an Export-Package for some of the
> > > packages in the required bundles. This use case was only intended to be
> > > used for cases where you wanted to split a package into multiple
> > > bundles (using mandatory directives to avoid accidental importation)
> > > and then the split packages could be recombined into a whole package
> > > using require-bundle + Export-Package.
> > >
> > > -> richard
> > >
> > > >
> > > > --
> > > > I could give you my word as a Spaniard.
> > > > No good. I've known too many Spaniards.
> > > >                             -- The Princess Bride
> > >
> > >
> >
> >
> > --
> > I could give you my word as a Spaniard.
> > No good. I've known too many Spaniards.
> >                              -- The Princess Bride
> >
>


-- 
I could give you my word as a Spaniard.
No good. I've known too many Spaniards.
                             -- The Princess Bride

Re: How to reexport packages when using import-package

Posted by Felix Meschberger <Fe...@day.com>.
Hi

On 2/9/07, Carlos Sanchez <ca...@apache.org> wrote:
>
> ok, so there's no "transitive dependency" thing like Maven has,
> basically I have to reference all the bundles I need.


Maybe there is some confusion here... By listing Java packages your bundle
needs in the Import-Package header you place an order to the framework for
these packages and have the framework resolve the bundles providing those
packages in their Export-Package headers.

So, the nice thing here is, that you do not need to care as much for finding
the right libraries/bundles as you do in Maven, where you declare the
providers of the packages and not the packages themselves.

Consequently, there is no such thing as transitive imports for packages
because either your bundle needs a package, in which case it is imported, or
your bundle does not need it and then you don't care. And the list of
packages required by a bundle may be automatically generated by the BND
tool.

Hope this helps.

Regards
Felix

On 2/8/07, Richard S. Hall <he...@ungoverned.org> wrote:
> > On Feb 8, 2007, at 6:45 PM, Carlos Sanchez wrote:
> >
> > > I know about visibility:=reexport with Require-Bundle, but how can I
> > > reexport packages imported with Import-Package?
> >
> > You cannot do so.
> >
> > This issue is a little confusing, especially given the terminology that
> > was adopted, but even require-bundle with "reexport" does not re-export
> > the packages as I think you are imagining.
> >
> > Consider A requires B requires C. If B requires C with "reexport" then
> > A will see C's packages too. If B requires C privately, then A will not
> > see C's packages.
> >
> > The only form of re-export available in OSGi R4 is if a bundle requires
> > several bundles and then declares an Export-Package for some of the
> > packages in the required bundles. This use case was only intended to be
> > used for cases where you wanted to split a package into multiple
> > bundles (using mandatory directives to avoid accidental importation)
> > and then the split packages could be recombined into a whole package
> > using require-bundle + Export-Package.
> >
> > -> richard
> >
> > >
> > > --
> > > I could give you my word as a Spaniard.
> > > No good. I've known too many Spaniards.
> > >                             -- The Princess Bride
> >
> >
>
>
> --
> I could give you my word as a Spaniard.
> No good. I've known too many Spaniards.
>                              -- The Princess Bride
>

Re: How to reexport packages when using import-package

Posted by Carlos Sanchez <ca...@apache.org>.
ok, so there's no "transitive dependency" thing like Maven has,
basically I have to reference all the bundles I need.

On 2/8/07, Richard S. Hall <he...@ungoverned.org> wrote:
> On Feb 8, 2007, at 6:45 PM, Carlos Sanchez wrote:
>
> > I know about visibility:=reexport with Require-Bundle, but how can I
> > reexport packages imported with Import-Package?
>
> You cannot do so.
>
> This issue is a little confusing, especially given the terminology that
> was adopted, but even require-bundle with "reexport" does not re-export
> the packages as I think you are imagining.
>
> Consider A requires B requires C. If B requires C with "reexport" then
> A will see C's packages too. If B requires C privately, then A will not
> see C's packages.
>
> The only form of re-export available in OSGi R4 is if a bundle requires
> several bundles and then declares an Export-Package for some of the
> packages in the required bundles. This use case was only intended to be
> used for cases where you wanted to split a package into multiple
> bundles (using mandatory directives to avoid accidental importation)
> and then the split packages could be recombined into a whole package
> using require-bundle + Export-Package.
>
> -> richard
>
> >
> > --
> > I could give you my word as a Spaniard.
> > No good. I've known too many Spaniards.
> >                             -- The Princess Bride
>
>


-- 
I could give you my word as a Spaniard.
No good. I've known too many Spaniards.
                             -- The Princess Bride

Re: How to reexport packages when using import-package

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On Feb 8, 2007, at 6:45 PM, Carlos Sanchez wrote:

> I know about visibility:=reexport with Require-Bundle, but how can I
> reexport packages imported with Import-Package?

You cannot do so.

This issue is a little confusing, especially given the terminology that 
was adopted, but even require-bundle with "reexport" does not re-export 
the packages as I think you are imagining.

Consider A requires B requires C. If B requires C with "reexport" then 
A will see C's packages too. If B requires C privately, then A will not 
see C's packages.

The only form of re-export available in OSGi R4 is if a bundle requires 
several bundles and then declares an Export-Package for some of the 
packages in the required bundles. This use case was only intended to be 
used for cases where you wanted to split a package into multiple 
bundles (using mandatory directives to avoid accidental importation) 
and then the split packages could be recombined into a whole package 
using require-bundle + Export-Package.

-> richard

>
> -- 
> I could give you my word as a Spaniard.
> No good. I've known too many Spaniards.
>                             -- The Princess Bride


Re: How to reexport packages when using import-package

Posted by Dale Peakall <d....@oclcpica.org>.
Alessandro Mottadelli wrote:
> BJ Hargrave wrote:
>> You can't. You can only export packages that your bundle contains. If 
>> your bundle imports a package, then your bundle cannot also export it.
>>
>> BJ Hargrave
>>   
> mmmmm..... why this limitation? It would be very useful to reexport a 
> package if the dependencies between bundles are expressed via 
> require-bundle (the "normal" eclipse way).
> If I have a plugin A that requires plugin B and I decide to take some 
> package out of B to be able to distribute them independently it would 
> be nice not to change the plugin A and simply reexport from B packages 
> that are now elsewhere.
>
> Am I missing something?
Yes!  Bundles import packages.  There is no dependency of Bundle A on 
Bundle B.  Bundle A has dependencies on packages (say X, Y and Z).  
Bundle B may initially provide all 3 of these packages.  However, if 
Bundle B is refactored so that it only provides packages X and Y and 
Bundle C provides package Z, Bundle A doesn't need to change - but you 
will need to change the set of deployed bundles to include Bundle C.

Re: How to reexport packages when using import-package

Posted by Niclas Hedhman <ni...@hedhman.org>.
On Thursday 15 February 2007 22:14, Alessandro Mottadelli wrote:
> BJ Hargrave wrote:
> > You can't. You can only export packages that your bundle contains. If
> > your bundle imports a package, then your bundle cannot also export it.
> >
> > BJ Hargrave
>
> mmmmm..... why this limitation? It would be very useful to reexport a
> package if the dependencies between bundles are expressed via
> require-bundle (the "normal" eclipse way).
> If I have a plugin A that requires plugin B and I decide to take some
> package out of B to be able to distribute them independently it would be
> nice not to change the plugin A and simply reexport from B packages that
> are now elsewhere.
>
> Am I missing something?

Yeah; Skip the Require-Bundle system, and use Import-Package, and you get what 
you are looking for ;o)
Just another argument for only using Require-Bundle in the originally quoted 
use-cases from Eclipse community.


Cheers
Niclas

Re: How to reexport packages when using import-package

Posted by BJ Hargrave <ha...@us.ibm.com>.
Alessandro Mottadelli <am...@tele2.it> wrote on 02/15/2007 09:14:53 
AM:

> BJ Hargrave wrote:
> > You can't. You can only export packages that your bundle contains. If 
your 
> > bundle imports a package, then your bundle cannot also export it.
> >
> > BJ Hargrave
> > 
> mmmmm..... why this limitation? It would be very useful to reexport a 
> package if the dependencies between bundles are expressed via 
> require-bundle (the "normal" eclipse way).
> If I have a plugin A that requires plugin B and I decide to take some 
> package out of B to be able to distribute them independently it would be 

> nice not to change the plugin A and simply reexport from B packages that 

> are now elsewhere.
> 
> Am I missing something?

Well if you are using Require-Bundle and not Import-Package, then it is a 
different game.

When you use Import-Package, you are dependent upon the pakcage and not 
some bundle that might provide it. So the importing bundle will wire 
directly to the exporting bundle for that package. So reexport is of no 
value, since the importer can directly wire to the other bundle exporting 
the package.

If however your are using Require-Bundle, then your bundle A only knows 
about bundle B and is dependent on bundle B to provide all the packages 
bundle A needs. So if bundle B is refactores and no longer contains some 
package the bundle A needs, then either bundle A must change to obtain the 
package from elsewhere or bundle B must change to obtain and reexport that 
package (this means bundle B will need to require bundle C and reexport). 
This is the brittleness of Require-Bundle and why it should only be used 
with great care.

Bundle A should not really care what bundle provides the packages it 
needs. It should only care that somebody does provide them. 

Require-Bundle may be the "normal" Eclipse way but only because (a), that 
was all they had prior to moving to OSGi in 3.0 and (b) it is much easier 
for developers to use then import-package. This is a tooling issue and PDE 
has been steadily improving in this area since 3.0.

> 
> regards,
> A.Mottadelli

BJ Hargrave
Senior Technical Staff Member, IBM
OSGi Fellow and CTO of the OSGi Alliance
hargrave@us.ibm.com

office: +1 386 848 1781
mobile: +1 386 848 3788


Re: How to reexport packages when using import-package

Posted by Alessandro Mottadelli <am...@tele2.it>.
BJ Hargrave wrote:
> You can't. You can only export packages that your bundle contains. If your 
> bundle imports a package, then your bundle cannot also export it.
>
> BJ Hargrave
>   
mmmmm..... why this limitation? It would be very useful to reexport a 
package if the dependencies between bundles are expressed via 
require-bundle (the "normal" eclipse way).
If I have a plugin A that requires plugin B and I decide to take some 
package out of B to be able to distribute them independently it would be 
nice not to change the plugin A and simply reexport from B packages that 
are now elsewhere.

Am I missing something?

regards,
A.Mottadelli





Re: How to reexport packages when using import-package

Posted by BJ Hargrave <ha...@us.ibm.com>.
You can't. You can only export packages that your bundle contains. If your 
bundle imports a package, then your bundle cannot also export it.

BJ Hargrave
Senior Technical Staff Member, IBM
OSGi Fellow and CTO of the OSGi Alliance
hargrave@us.ibm.com

office: +1 386 848 3788
mobile: +1 386 848 3788




"Carlos Sanchez" <ca...@apache.org> 
Sent by: carlossg@gmail.com
02/08/2007 06:45 PM
Please respond to
felix-dev@incubator.apache.org


To
felix-dev@incubator.apache.org
cc

Subject
How to reexport packages when using import-package






I know about visibility:=reexport with Require-Bundle, but how can I
reexport packages imported with Import-Package?

-- 
I could give you my word as a Spaniard.
No good. I've known too many Spaniards.
                             -- The Princess Bride