felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stuart McCulloch" <stuart.mccull...@jayway.net>
Subject Re: Problems with bundle plugin [Fwd: Re: Support for OSGi]
Date Thu, 10 Jan 2008 17:51:11 GMT
On 10/01/2008, Niall Pemberton <niall.pemberton@gmail.com> wrote:
>
> On Jan 10, 2008 2:56 AM, Stuart McCulloch <stuart.mcculloch@jayway.net>
> wrote:
> > On 10/01/2008, Niall Pemberton <niall.pemberton@gmail.com> wrote:
> > >
> > > On Jan 9, 2008 5:35 PM, Stuart McCulloch <stuart.mcculloch@jayway.net>
> > > wrote:
> > > > On 09/01/2008, Niall Pemberton <niall.pemberton@gmail.com> wrote:
> > > >
> > > > > On Jan 9, 2008 6:11 AM, Stuart McCulloch <
> stuart.mcculloch@jayway.net>
> > > > wrote:
> > > > > > Hi Carsten / Niall,
> > > > > >
> > > > > > I've mocked up a quick patch and attached it to
> > > > > > http://issues.apache.org/jira/browse/FELIX-449
> > > > > > could you give it a spin and see if it resolves the problem?
> (see
> > > below
> > > > for
> > > > > > the new config option)
> > > > >
> > > > > Hey, thanks for the quick response - I'll give it a spin and put
> > > > > feedback on the Jira ticket FELIX-449
> > > >
> > > > thanks, I've made some improvements based on your feedback - can you
> > > build
> > > > the plugin from svn and try it out?
> > >
> > > Looks good from the "non-OSGi" manifest entries PoV (using
> > > excludeDependencies=false) - its picked up a couple of entries from
> > > BeanUtils (e.g. Extension-Name)
> >
> >
> > if you use Carsten's original suggestion of a global wildcard export:
> >
> >    <Export-Package>*;version="${pom.version}"</Export-Package>
> >
> > then you must set excludeDependencies to _true_ otherwise you will pull
> > in all sorts of other packages and classes from your dependencies - and
> > your final jarfile will be much larger than the pre-bundle one.
> >
> > - but I could sort those out now by
> > > specifying them explicitly.
> >
> >
> > FYI, you can always use the:
> >
> >    <_removeheaders>comma,separated,list,of,headers</_removeheaders>
> >
> > instruction to remove unwanted headers - but setting Export-Package to
> > an explicit package list (or excludeDependencies to true) means that you
> > shouldn't get the beanutils stuff to begin with...
> >
> > The one thing that strikes me though are
> > > the version numbers are all the same - I don't really know how OSGi
> > > works, but for example (if I use excludeDependencies=false) I would
> > > have expected to see the dependencies version numbers somewhere in the
> > > export/import statements - for example Validator 1.4-SNAPSHOT depends
> > > on BeanUtils 1.7 - but all the version numbers spcify 1.4.0.SNAPSHOT -
> > > is this correct?
> >
> >
> > all _exported_ packages will be marked with the same version, because
> > you've told Bnd to do this in the above Export-Package instruction (and
> > where the same package is also imported, the import will then use the
> > same version).
>
> Using "excludeDependencies=false" that makes sense - but for
> "excludeDependencies=true" I would have thought the import statements
> for dependencies would be specified - which they currently don't seem
> to be.


Bnd does not see the excludeDependencies option - all this option does is
change how much of the Maven classpath the bundleplugin passes to Bnd.
The excludeDependencies option is only there to ease the migration to the
bundleplugin, so you can start with <Export-Package>*</Export-Package>

If you want the full benefits of the bundleplugin you need to understand how
Bnd works - it doesn't zip the contents of target/classes, it pulls classes
and
resources from the classpath into a bundle.

Setting <Export-Package>*</Export-Package> says to Bnd: put the whole
classpath into the bundle, which would normally include dependencies such
as the beanutils. With excludeDependencies set to true we only give Bnd the
local classpath, so you get the bundle you'd expect (ie. just
target/classes).

However because Bnd works primarily from the classpath, cutting it down to
the local project means it has no version information about dependencies,
although you are free to add this detail yourself using <Import-Package>

To get the true power of Bnd you need to tell it exactly which packages you
want to export and which to keep private - you can then pass the complete
classpath to Bnd and it will add versioned imports where possible.

> also note when you set excludeDependencies to true you are not giving
> > Bnd any information about dependencies, so it can't detect the versions.
>
> OK but can't the maven plugin pass the dependency versions to Bnd?


Yes - and the way the plugin does this is by passing the complete classpath.
But then you're back to having to tell Bnd exactly what you want to export
and what you want to keep private...

Niall
>
> > so to sum up, for basic OSGi manifest entries with minimum of fuss use:
> >
> >    <configuration>
> >       <excludeDependencies>true</excludeDependencies>
> >       <instructions>
> >          <Export-Package>*;version=${pom.version}</Export-Package>
> >       </instructions>
> >    </configuration>
> >
> > but if you want better OSGi manifest entries consider something like:
> >
> >    <configuration>
> >       <instructions>
> >          <Export-Package>
> >             some.public.pkg;version=${pom.version},
> >             wildcard.public.pkg.*;version=${pom.version}
> >          </Export-Package>
> >          <Private-Package>
> >             some.internal.pkg,
> >             wildcard.internal.pkg.*
> >          </Private-Package>
> >       </instructions>
> >    </configuration>
> >
> > note you have to be a bit more careful here, because any packages
> > that aren't covered by Export-Package or Private-Package will _not_
> > be pulled into the final bundle.
> >
> > the bundleplugin and Bnd are documented at:
> >
> >    http://felix.apache.org/site/maven-bundle-plugin-bnd.html
> >    http://aqute.biz/Code/Bnd  (has full list of Bnd instructions)
> >
> > HTH
> >
> >
> > Niall
> > >
> > > > > Niall
> > > > >
> > > > > > --
> > > > > > Cheers, Stuart
> > > > > >
> > > > > > ---------- Forwarded message ----------
> > > > > > From: Stuart McCulloch (JIRA) <jira@apache.org >
> > > > > > Date: 9 Jan 2008 13:59
> > > > > > Subject: [jira] Updated: (FELIX-449) Add option to limit the
> > > classpath
> > > > > > passed to BND to just the local project (ie. target/classes)
> > > > > > To: dev@felix.apache.org
> > > > > >
> > > > > >
> > > > > >      [
> > > > > >
> > > >
> > >
> https://issues.apache.org/jira/browse/FELIX-449?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
> > > > > > ]
> > > > > >
> > > > > > Stuart McCulloch updated FELIX-449:
> > > > > > -----------------------------------
> > > > > >
> > > > > >     Attachment: FELIX_449_20080109.txt
> > > > > >
> > > > > > Suggested patch - when applied to trunk, you can use:
> > > > > >
> > > > > >
> > > > > >       <plugin>
> > > > > >         <groupId>org.apache.felix</groupId>
> > > > > >         <artifactId>maven-bundle-plugin</artifactId>
> > > > > >         <extensions>true</extensions>
> > > > > >         <configuration>
> > > > > >           <excludeDependencies>true</excludeDependencies>
> > > > > >
> > > > > >           <instructions>
> > > > > >             <Export-Package>*;version=${pom.version
> > > }</Export-Package>
> > > > > >           </instructions>
> > > > > >         </configuration>
> > > > > >       </plugin>
> > > > > >
> > > > > >  to bundle the project classpath, excluding dependencies.
> > > > > >
> > > > > > PS: feel free to suggest alternative names for this option!
> > > > > >
> > > > > > > Add option to limit the classpath passed to BND to just
the
> local
> > > > project
> > > > > > (ie. target/classes)
> > > > > > >
> > > > > >
> > > >
> > >
> ----------------------------------------------------------------------------------------------
> > > > > > >
> > > > > > >                 Key: FELIX-449
> > > > > > >                 URL:
> > > https://issues.apache.org/jira/browse/FELIX-449
> > > > > > >             Project: Felix
> > > > > > >          Issue Type: Improvement
> > > > > > >          Components: Maven Bundle Plugin
> > > > > > >    Affects Versions: 1.0.0
> > > > > > >            Reporter: Stuart McCulloch
> > > > > > >            Assignee: Stuart McCulloch
> > > > > > >         Attachments: FELIX_449_20080109.txt
> > > > > > >
> > > > > > >
> > > > > > > Email thread from Apache Commons:
> > > > > >
> > > > > >
> > > > > > > On Dec 28, 2007 12:35 PM, Carsten Ziegeler <
> cziegeler@apache.org>
> > > > wrote:
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > in the meantime Stuart fixed the problem with the
maven
> > > > bundleplugin, so
> > > > > > > > I think we can give it a test drive :)
> > > > > > > >
> > > > > > > > Attached is a patch for the parent pom of commons
and one to
> > > > demonstrate
> > > > > > > > how to add support for OSGi to commons-lang.
> > > > > > > >
> > > > > > > > The changes to the parent pom are minimal: it just
adds the
> > > maven
> > > > > > > > bundleplugin from the Apache Felix project. We currently
> need to
> > > use
> > > > a
> > > > > > > > snapshot version, but a release is comming soon.
> > > > > > > > Besides adding the plugin, the patch also configures
the
> bundle
> > > > symbolic
> > > > > > > > name for all modules. The symbolic name is the unique
> identifier
> > > > which
> > > > > > > > should follow java package naming. The best value
is to use
> > > > something
> > > > > > > > like "org.apache.commons.{artifactId}" where artifact
id is
> > > > commons-lang
> > > > > > > > or commons-collections etc.
> > > > > >  > >
> > > > > > > > The patch to commons lang is also very simple. It
changes
> the
> > > parent
> > > > pom
> > > > > > > > to the current snapshot (which includes the changes
from
> above)
> > > and
> > > > sets
> > > > > > > > the packaging to bundle - this ensures that the bundleplugin
> > > runs
> > > > and
> > > > > > > > creates the resulting jar file. So the bundleplugin
replaces
> the
> > > > maven
> > > > > > > > jar plugin. If you leave the packaging as "jar" the
> bundleplugin
> > > > will
> > > > > > > > not run.
> > > > > > > > The last part of the patch adds the configuration
to the
> > > > bundleplugin.
> > > > > > > > The export "*" exports all packages definied in this
module
> for
> > > > other
> > > > > > > > bundles, so all classes are public. All packages are
marked
> with
> > > the
> > > > > > > > current version which allows to run different versions
in
> > > parallel.
> > > > > > > > The imports are not specified as they are calculated
> > > automatically
> > > > by
> > > > > > > > the bundleplugin.
> > > > > > > >
> > > > > > > > And that's it :)
> > > > > > > >
> > > > > > > > The changes to the other projects should be similar.
> > > > > > > I tried using the bundle plugin (I checked out and built
the
> > > latest
> > > > > > > from svn) with Commons Validator and it produced the following
> > > > > > > MANIFEST.MF:
> > > > > > >
> > > > > >
> > > >
> > >
> http://people.apache.org/~niallp/commons-osgi/commons-validator-MANIFEST.MF
> > > > > > > It seems to have picked up some Manifest entries from
> BeanUtils  -
> > > for
> > > > > > example:
> > > > > > > Extension-Name: org.apache.commons.beanutils
> > > > > >  > Implementation-Version: 1.6
> > > > > > > Specification-Title: Jakarta Commons Beanutils
> > > > > > > Implementation-Title: org.apache.commons.beanutils
> > > > > >
> > > > > > > Niall
> > > > > > > (N.B. The BeanUtils 1.7.0 jar has version incorectly
> specifying
> > > 1.6 in
> > > > > > > its manifest.
> > > > > > > > Carsten
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Carsten Ziegeler
> > > > > > > > cziegeler@apache.org
> > > > > > > >
> > > > > > > > Index:
> > > > > >
> > > >
> > >
> /Users/cziegeler/Developer/workspaces/default/commons-proper/commons-parent/pom.xml
> > > > > > > >
> > > ===================================================================
> > > > > > > > ---
> > > > > >
> > > >
> > >
> /Users/cziegeler/Developer/workspaces/default/commons-proper/commons-parent/pom.xml
> > > > > > (revision 605909)
> > > > > > > > +++
> > > > > >
> > > >
> > >
> /Users/cziegeler/Developer/workspaces/default/commons-proper/commons-parent/pom.xml
> > > > > > (working copy)
> > > > > > > > @@ -159,6 +159,12 @@
> > > > > > > >            <artifactId>maven-release-plugin</artifactId>
> > > > > > > >            <version>2.0-beta-7</version>
> > > > > > > >          </plugin>
> > > > > >  > > +        <plugin>
> > > > > > > > +          <groupId>org.apache.felix</groupId>
> > > > > > > > +          <artifactId>maven-bundle-plugin</artifactId>
> > > > > > > > +          <version> 1.1.0-SNAPSHOT</version>
> > > > > > > > +          <inherited>true</inherited>
> > > > > > > > +        </plugin>
> > > > > > > >        </plugins>
> > > > > > > >      </pluginManagement>
> > > > > > > >      <plugins>
> > > > > > > > @@ -194,6 +200,15 @@
> > > > > > > >            <jdkLevel>${maven.compile.source}</jdkLevel>
> > > > > > > >          </configuration>
> > > > > > > >        </plugin>
> > > > > > > > +      <plugin>
> > > > > > > > +        <groupId>org.apache.felix</groupId>
> > > > > > > > +        <artifactId>maven-bundle-plugin</artifactId>
> > > > > > > > +        <configuration>
> > > > > > > > +          <instructions>
> > > > > > > > +
> > > > > >
> > > > <Bundle-SymbolicName>org.apache.commons.${pom.artifactId}
> > > </Bundle-SymbolicName>
> > > > > > > > +          </instructions>
> > > > > > > > +        </configuration>
> > > > > > > > +      </plugin>
> > > > > > > >      </plugins>
> > > > > > > >    </build>
> > > > > > > >
> > > > > > > >
> > > > > > > > Index:
> > > > > >
> > > >
> > >
> /Users/cziegeler/Developer/workspaces/default/commons-proper/lang/pom.xml
> > > > > > > >
> > > ===================================================================
> > > > > > > > ---
> > > > > >
> > > >
> > >
> /Users/cziegeler/Developer/workspaces/default/commons-proper/lang/pom.xml
> > > > > > (revision 605909)
> > > > > > > > +++
> > > > > >
> > > >
> > >
> /Users/cziegeler/Developer/workspaces/default/commons-proper/lang/pom.xml
> > > > > > (working copy)
> > > > > >  > > @@ -22,13 +22,14 @@
> > > > > > > >    <parent>
> > > > > > > >      <groupId>org.apache.commons</groupId>
> > > > > > > >      <artifactId>commons-parent</artifactId>
> > > > > > > > -    <version>5</version>
> > > > > > > > +    <version>6-SNAPSHOT</version>
> > > > > > > >    </parent>
> > > > > > > >    <modelVersion>4.0.0</modelVersion>
> > > > > > > >    <groupId>commons-lang</groupId>
> > > > > > > >    <artifactId>commons-lang</artifactId>
> > > > > > > >    <version>2.4-SNAPSHOT</version>
> > > > > > > >    <name>Commons Lang</name>
> > > > > > > > +  <packaging>bundle</packaging>
> > > > > > > >
> > > > > > > >    <inceptionYear>2001</inceptionYear>
> > > > > > > >      <description>
> > > > > > > > @@ -401,6 +402,16 @@
> > > > > > > >            <tarLongFileMode>gnu</tarLongFileMode>
> > > > > > > >          </configuration>
> > > > > > > >        </plugin>
> > > > > > > > +      <plugin>
> > > > > > > > +        <groupId> org.apache.felix</groupId>
> > > > > > > > +        <artifactId>maven-bundle-plugin</artifactId>
> > > > > > > > +        <extensions>true</extensions>
> > > > > > > > +        <configuration>
> > > > > > > > +          <instructions>
> > > > > > > > +
> > > > <Export-Package>*;version=${pom.version}</Export-Package>
> > > > > > > > +          </instructions>
> > > > > > > > +        </configuration>
> > > > > > > > +      </plugin>
> > > > > > > >      </plugins>
> > > > > > > >    </build>
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > >
> ---------------------------------------------------------------------
> > > > > > > > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > > > > > > > For additional commands, e-mail: dev-help@commons.apache.org
> > > > > > > >
> > > > > > >
> > > ---------------------------------------------------------------------
> > > > > > > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > > > > >  > For additional commands, e-mail: dev-help@commons.apache.org
> > > > > >
> > > > > > --
> > > > > > This message is automatically generated by JIRA.
> > > > > > -
> > > > > > You can reply to this email to add a comment to the issue
> online.
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Cheers, Stuart
> > >
> >
> >
> >
> > --
> > Cheers, Stuart
> >
>

-- 
Cheers, Stuart

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message