Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 329314 - Equinox always prefers system bundle even though there exists another resolved exprter with higher version
Summary: Equinox always prefers system bundle even though there exists another resolve...
Status: CLOSED DUPLICATE of bug 312731
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Framework (show other bugs)
Version: unspecified   Edit
Hardware: All Linux
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: equinox.framework-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-02 23:29 EDT by Sahoo CLA
Modified: 2010-11-04 10:13 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sahoo CLA 2010-11-02 23:29:55 EDT
Build Identifier: 3.6.1.R36x_v20100806

I am trying to find out how to ensure Equinox will prefer my bundle as opposed to system bundle while selecting an exporter for a package requirement that's satisfied by both system bundle and my bundle. As per the spec, the following list defines the preferences, if multiple choices are possible, in order of decreasing priority:
•   A resolved exporter must be preferred over an unresolved exporter.
•   An exporter with a higher version is preferred over an exporter with a
    lower version.
•   An exporter with a lower bundle ID is preferred over a bundle with a
    higher ID.

So, this is what I am doing:
java -jar equinox.jar

telnet localhost 6667

osgi> ss

Framework is launched.

id    State       Bundle
0    ACTIVE      org.eclipse.osgi_3.6.1.R36x_v20100806

osgi> install file:javax.annotation.jar
Bundle id is 1

osgi> install file:d.jar
Bundle id is 2

osgi> start 2

osgi> bundle 2
dummy_0.0.0 [2]
  Imported packages
    javax.annotation; version="1.1.0"<org.glassfish.javax.annotation_3.1.0.SNAPSHOT [1]>
  Required bundles
    org.glassfish.javax.annotation; bundle-version="3.1.0.SNAPSHOT"<org.glassfish.javax.annotation_3.1.0.SNAPSHOT [1]>

osgi> install file:a1.jar
Bundle id is 3

osgi> start 3

osgi> bundle 3
a1_0.0.0 [3]
  Imported packages
    javax.annotation; version="0.0.0"<org.eclipse.osgi_3.6.1.R36x_v20100806 [0]>
  No required bundles

osgi> headers 1
Bundle headers:
Bundle-SymbolicName = org.glassfish.javax.annotation
Export-Package = javax.annotation;version="1.1"
 Import-Package = javax.annotation;version="1.1"

osgi> headers 2
Bundle headers:
 Bundle-ManifestVersion = 2
 Bundle-SymbolicName = dummy
Require-Bundle = org.glassfish.javax.annotation


osgi> headers 3
Bundle headers:
 Bundle-ManifestVersion = 2
 Bundle-SymbolicName = a1
Import-Package = javax.annotation
-------------------

As you can see, before bundle #3 comes into picture, bundle #2 has been resolved. Since it has a Require-Bundle dependency on bundle #1, all of the exported packages of #1 are wired to #2, which means #1 must go into resolved state. Then when bundle #3 is resolved, there exists two resolved exporters for javax.annotation package, viz: #0, which exports with version 0.0.0 and #1, which exports with version 1.1.0. Even though #1 exports an higher version, #0 is selected. 

I will be happy to be proven wrong and/or given an alternate way to achieve my objective.

Reproducible: Always
Comment 1 Simon Kaegi CLA 2010-11-03 01:51:55 EDT
I noticed bundle 1 (javax.annotation.jar) does not have a Bundle-ManifestVersion  header and so will default to 1 (and use the R3 resolution rules). I'm not sure that is the problem here but worth fixing.
Comment 2 Sahoo CLA 2010-11-03 03:04:50 EDT
(In reply to comment #1)
> I noticed bundle 1 (javax.annotation.jar) does not have a
> Bundle-ManifestVersion  header and so will default to 1 (and use the R3
> resolution rules). I'm not sure that is the problem here but worth fixing.

That was a mistake. In the process of filtering out unnecessary entries appearing in the report, I removed Bundle-ManifestVersion entry as well. In reality, javax.annotation.jar is a R4 bundle as it has "Bundle-ManifestVersion: 2"
Comment 3 Thomas Watson CLA 2010-11-04 09:37:30 EDT
Setting the system property osgi.resolver.preferSystemPackages=false will get you the behavior you want.

*** This bug has been marked as a duplicate of bug 312731 ***
Comment 4 Sahoo CLA 2010-11-04 10:13:47 EDT
(In reply to comment #3)
> Setting the system property osgi.resolver.preferSystemPackages=false will get
> you the behavior you want.
> 
> *** This bug has been marked as a duplicate of bug 312731 ***

Thanks for looking into it and telling me how to work around the issue. I am definitely not specifying that property in the configuration object passed to initialize the framework when I use R4.2 framework launcher API. Should the default value for that property not be false? Or am I misreading the spec about selection of provider? It's probably OK to set it to true in Eclipse configuration, but not in  a vanilla use case.