You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Thomas GILLET <th...@consultant.volvo.com> on 2012/01/25 11:31:13 UTC

maven-bundle-plugin : no import version for packages being both imported and exported after a clean build

Hello,

I'm using the maven-bundle-plugin to develop a bundle containing a package
which is exported AND imported (i.e it is a public package which is used by
private code, so BND adds the import statement in the manifest as it is
considered a good practice).

I'm not using package versioning, so, from my understanding of the BND
documentation, the export statement should use the bundle version, and the
import statement should use the version from the export statement. It was
all working fine until I run a "mvn clean" before my "mvn package" and end
up with no version on my import statement.

My guess was that after a clean there is no manifest file, so there is no
export statement to get the package version from.
As a workaround I added the "bundle:manifest" goal just before the
"bundle:bundle" goal so the manifest is generated a first time before the
bundle creation. It's now working fine.

But I wonder if this is "normal" behavior or not. Did I do something wrong ?
Is it a bug ? Should I add an issue about that in the Felix Jira ?

Not a very big problem but, if someone knows something about it, I would
like to understand.

Thomas GILLET
-- 
View this message in context: http://old.nabble.com/maven-bundle-plugin-%3A-no-import-version-for-packages-being-both-imported-and-exported-after-a-clean-build-tp33200339p33200339.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: maven-bundle-plugin : no import version for packages being both imported and exported after a clean build

Posted by Thomas GILLET <th...@consultant.volvo.com>.
Ok now I see it.
I sum it up to help me understand (and maybe help other readers if any):

1.
BND uses the bundle version as default value for the export of packages
without packageinfo.
But BND doesn't allow itself to narrow an import version based only on this
default version.

2.
BND uses all manifests found on the class-path to extract information about
imported packages without packageinfo and use it to narrow their version.
Because of the default value of the "manifestLocation" parameter, the
generated manifest is on the class-path.

3.
Therefore, when a package is exported without explicit version (i.e without
packageinfo nor export directive), the only source of information available
to compute its import version is a possible manifest on the class-path.
Hence the "mvn package" / "mvn clean package" inconsistency.

Workaround 1.
<Export-Package>{local-packages};version=${project.version}</Export-Package>
Explicit export version so no problem to compute the import.
Beware, will override any version from packageinfo files.

Workaround 2.
Execute the bundle:manifest goal just before the bundle:bundle goal.
Generating the manifest a first time allow bundle:bundle to scan it and get
the version from the export statement.
Beware, works only with "manifestLocation" pointing to a directory in the
class-path.


I'll think about opening a "clean / no clean" issue, but as you said, this
is a very specific case (and happens only when using not OSGi friendly
versioning).

Thanks again for digging into code and old issues.
/Thomas
-- 
View this message in context: http://old.nabble.com/maven-bundle-plugin-%3A-no-import-version-for-packages-being-both-imported-and-exported-after-a-clean-build-tp33200339p33209064.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: maven-bundle-plugin : no import version for packages being both imported and exported after a clean build

Posted by Stuart McCulloch <mc...@gmail.com>.
On 26 Jan 2012, at 10:56, Thomas GILLET wrote:
> Hello Stuart, thanks for all the info. Unfortunately I cannot reproduce the
> behaviors you are describing.
> 
> Stuart McCulloch wrote:
>> 
>> The behaviour for the "bundle:bundle" goal follows bnd by not using any
>> version for exported packages unless you supply a version
> 
> Well with versions 2.3.5 and 2.3.6, without any configuration (no
> bundle:manifest goal), my non-versioned packages are all exported with the
> bundle version.

You're right, and it turns out this was actually a change in bnd - the bundleplugin doesn't set any version on the export instruction passed to bnd (you can confirm this with "mvn -X package")

The change was in bnd's Builder.java where it uses the bundle version as the default if the export package instruction does not have any version set:

   https://github.com/bndtools/bnd/commit/19612e8fcba2035e83bbe2639f5fb927d48fd709

The difference between this and setting the version explicitly is that it doesn't narrow the import range using the versionpolicy (whereas it does narrow it if you set the export package version)

Apologies for any confusion

> Stuart McCulloch wrote:
>> 
>> You can make the "bundle:manifest" goal behave more like "bundle:bundle"
>> by setting <rebuildBundle>true</rebuildBundle>
>> [...]
>> The bug where the "bundle:bundle" goal could pick up an existing manifest
>> from the target directory and merge its headers into the final result
>> [...] is fixed in 2.3.6.
>> 
> 
> Again I tried with version 2.3.5 and 2.3.6, with and without the
> "rebuildBundle" parameter, and there isn't any change: export always has a
> version, import has a version only with the extra bundle:manifest goal.
> Also is there an issue about the merging of an existing manifest ? I don't
> find one.

The change was: http://mail-archives.apache.org/mod_mbox/felix-commits/201110.mbox/%3C20111017172809.C31F323888FD@eris.apache.org%3E

It's related to https://issues.apache.org/jira/browse/FELIX-3142 - but this change only covers the manifest in target/classes so the main issue is still open.

But it turns out that this particular difference wrt. import versions is not related to the merging issue in the bundleplugin, because the Maven debug (-X) shows no merging is happening on the bundleplugin side.

The difference is actually because bnd scans the project classpath for existing manifests so it can scrape them for versioning information, and target/classes is on the project classpath.

You can confirm this by adding the following configuration setting:

   <configuration>
      <manifestLocation>target/classes/FOO</manifestLocation>
      <instructions>
         ...
      </instructions>
   </configuration>

The bundle manifest will then be unpacked to target/classes/FOO/META-INF/MANIFEST.MF instead of target/classes/META-INF/MANIFEST.MF and will not be seen by bnd in the second execution.

Note that the unpacking of the manifest to target/classes/META-INF/MANIFEST.MF is a convenience - the manifestLocation setting does not alter it's position in the actual bundle.

So this behaviour is expected (because the target location wasn't cleaned between the two executions) - most people never encounter it because they use the bundle lifecycle rather than repeated executions inside the pom.xml, and in most cases it won't be an issue because it just means the import version is narrowed to match the bundle version. And if you explicitly set your export versions in the pom then you also won't encounter it.

However it is an inconsistency, so feel free to open an issue (and provide a patch if you have time).

> Meanwhile I discovered an other strange thing. If I add
> <Export-Package>{local-packages};version=${project.version}</Export-Package>
> in my instructions, the import statements for exported packages have always
> the correct version, even without the bundle:manifest goal.
> An other workaround for my original problem, but not very good because it
> would override any packageinfo version (which I'm not using but still).

This is expected - when you set the export version explicitly, bnd uses it to narrow the version range on the imports (using the versionpolicy) - without an export version bnd uses the bundle version as the default export version, but does not narrow the imports (because it picked the default export version itself, so it can't know if you expect to match lower bound imports).

Anyway, if you set the version yourself then you're in control - otherwise the tools will do their best to provide reasonable defaults, but they may not match your intention (because it's impossible to infer that in all cases)

> I join the maven project I used to make those tests (using "mvn clean
> package" for each test):
> http://old.nabble.com/file/p33206685/test.zip test.zip 
> -- 
> View this message in context: http://old.nabble.com/maven-bundle-plugin-%3A-no-import-version-for-packages-being-both-imported-and-exported-after-a-clean-build-tp33200339p33206685.html
> Sent from the Apache Felix - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: maven-bundle-plugin : no import version for packages being both imported and exported after a clean build

Posted by Thomas GILLET <th...@consultant.volvo.com>.
Hello Stuart, thanks for all the info. Unfortunately I cannot reproduce the
behaviors you are describing.


Stuart McCulloch wrote:
> 
> The behaviour for the "bundle:bundle" goal follows bnd by not using any
> version for exported packages unless you supply a version
> 

Well with versions 2.3.5 and 2.3.6, without any configuration (no
bundle:manifest goal), my non-versioned packages are all exported with the
bundle version.


Stuart McCulloch wrote:
> 
> You can make the "bundle:manifest" goal behave more like "bundle:bundle"
> by setting <rebuildBundle>true</rebuildBundle>
> [...]
> The bug where the "bundle:bundle" goal could pick up an existing manifest
> from the target directory and merge its headers into the final result
> [...] is fixed in 2.3.6.
> 

Again I tried with version 2.3.5 and 2.3.6, with and without the
"rebuildBundle" parameter, and there isn't any change: export always has a
version, import has a version only with the extra bundle:manifest goal.
Also is there an issue about the merging of an existing manifest ? I don't
find one.


Meanwhile I discovered an other strange thing. If I add
<Export-Package>{local-packages};version=${project.version}</Export-Package>
in my instructions, the import statements for exported packages have always
the correct version, even without the bundle:manifest goal.
An other workaround for my original problem, but not very good because it
would override any packageinfo version (which I'm not using but still).


I join the maven project I used to make those tests (using "mvn clean
package" for each test):
http://old.nabble.com/file/p33206685/test.zip test.zip 
-- 
View this message in context: http://old.nabble.com/maven-bundle-plugin-%3A-no-import-version-for-packages-being-both-imported-and-exported-after-a-clean-build-tp33200339p33206685.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: maven-bundle-plugin : no import version for packages being both imported and exported after a clean build

Posted by Stuart McCulloch <mc...@gmail.com>.
On 25 Jan 2012, at 10:31, Thomas GILLET wrote:

> Hello,
> 
> I'm using the maven-bundle-plugin to develop a bundle containing a package
> which is exported AND imported (i.e it is a public package which is used by
> private code, so BND adds the import statement in the manifest as it is
> considered a good practice).
> 
> I'm not using package versioning, so, from my understanding of the BND
> documentation, the export statement should use the bundle version, and the
> import statement should use the version from the export statement. It was
> all working fine until I run a "mvn clean" before my "mvn package" and end
> up with no version on my import statement.
> 
> My guess was that after a clean there is no manifest file, so there is no
> export statement to get the package version from.
> As a workaround I added the "bundle:manifest" goal just before the
> "bundle:bundle" goal so the manifest is generated a first time before the
> bundle creation. It's now working fine.

The behaviour for the "bundle:bundle" goal follows bnd by not using any version for exported packages unless you supply a version, either in the configuration or via packageinfo.

The legacy behaviour for "bundle:manifest", when creating a manifest for an existing/attached artifact, is to use the bundle version as the exported package version (see the PackageVersionAnalyzer).
You can make the "bundle:manifest" goal behave more like "bundle:bundle" by setting <rebuildBundle>true</rebuildBundle> in the bundle <configuration> section, ie. outside of the bnd <instructions>.

The reason for this inconsistency is because these goals were originally developed by different people, and changing the legacy manifest behaviour now will break old builds - hence the new flag to switch the behaviour: https://issues.apache.org/jira/browse/FELIX-3206. Also the bug where the "bundle:bundle" goal could pick up an existing manifest from the target directory and merge its headers into the final result (which is why you see the different results using "bundle:manifest" followed by "bundle:bundle" without a clean) is fixed in 2.3.6.

Personally, I recommend explicitly setting the versions of exported packages rather than rely on defaults.

> But I wonder if this is "normal" behavior or not. Did I do something wrong ?
> Is it a bug ? Should I add an issue about that in the Felix Jira ?
> 
> Not a very big problem but, if someone knows something about it, I would
> like to understand.
> 
> Thomas GILLET
> -- 
> View this message in context: http://old.nabble.com/maven-bundle-plugin-%3A-no-import-version-for-packages-being-both-imported-and-exported-after-a-clean-build-tp33200339p33200339.html
> Sent from the Apache Felix - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: maven-bundle-plugin : no import version for packages being both imported and exported after a clean build

Posted by Thomas GILLET <th...@consultant.volvo.com>.
Hello Neil, thanks for your quick answer.

I agree that versioning should be done on packages rather than bundles, as
the OSGi spec recommand it.
However for now switching to package versioning would just not worth it, so
I wanted to keep maintaining bundle versions only, and use this version for
all exported packages.


Neil Bartlett wrote:
> 
> I don't believe that bnd has ever used Bundle-Version to set the version
> of an exported package
> 

Well actually I was wondering about that as well. Starting from
maven-bundle-plugin 2.3.5, my export statements have the version of the
containing bundle. But I don't find anything about that in the BND
documentation nor in the Felix JIRA. So I just assumed there was a new
fallback behavior for exports without version.

Thomas

-- 
View this message in context: http://old.nabble.com/maven-bundle-plugin-%3A-no-import-version-for-packages-being-both-imported-and-exported-after-a-clean-build-tp33200339p33201072.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: maven-bundle-plugin : no import version for packages being both imported and exported after a clean build

Posted by Neil Bartlett <nj...@gmail.com>.
Thomas, 

I don't believe that bnd has ever used Bundle-Version to set the version of an exported package, indeed I would consider it bad practice to do so.

If versioning matters to you (and it apparently matters enough for you to write this email!) then I would encourage you to do it properly with package versions. Probably the best way is to create a "packageinfo" file inside the source package, as described in the bnd docs.

Regards,
Neil


On Wednesday, 25 January 2012 at 10:31, Thomas GILLET wrote:

> 
> Hello,
> 
> I'm using the maven-bundle-plugin to develop a bundle containing a package
> which is exported AND imported (i.e it is a public package which is used by
> private code, so BND adds the import statement in the manifest as it is
> considered a good practice).
> 
> I'm not using package versioning, so, from my understanding of the BND
> documentation, the export statement should use the bundle version, and the
> import statement should use the version from the export statement. It was
> all working fine until I run a "mvn clean" before my "mvn package" and end
> up with no version on my import statement.
> 
> My guess was that after a clean there is no manifest file, so there is no
> export statement to get the package version from.
> As a workaround I added the "bundle:manifest" goal just before the
> "bundle:bundle" goal so the manifest is generated a first time before the
> bundle creation. It's now working fine.
> 
> But I wonder if this is "normal" behavior or not. Did I do something wrong ?
> Is it a bug ? Should I add an issue about that in the Felix Jira ?
> 
> Not a very big problem but, if someone knows something about it, I would
> like to understand.
> 
> Thomas GILLET
> -- 
> View this message in context: http://old.nabble.com/maven-bundle-plugin-%3A-no-import-version-for-packages-being-both-imported-and-exported-after-a-clean-build-tp33200339p33200339.html
> Sent from the Apache Felix - Users mailing list archive at Nabble.com (http://Nabble.com).
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org (mailto:users-unsubscribe@felix.apache.org)
> For additional commands, e-mail: users-help@felix.apache.org (mailto:users-help@felix.apache.org)




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org