3

Imagine an Eclipse plug-in (resp. OSGi bundle) with a package org.acme.foo.bar.

It's possible to export "." e.g. see the following MANIFEST.MF snippet:

Export-Package: .,
 org.acme.foo.bar

Compiler has no problems with that so it seems to be a legit export.

What does it do? What is the difference to the following ("." not exported)?

Export-Package: org.acme.foo.bar
Marteng
  • 1,179
  • 13
  • 31

3 Answers3

6

. is the default package but according to the OSGi Core, Release 6 specification . is not a valid value for Export-Package because a package name must start with a letter:

Export-Package ::= export ( ',' export)*
export ::= package-names ( ';' parameter )*
package-names ::= package-name ( ';' package-name )*
package-name ::= unique-name
unique-name ::= identifier ( '.' identifier )*
identifier ::= jletter jletterordigit *
jletter ::= <see Java Language Specification Third Edition for JavaLetter>
jletterordigit ::= <see Java Language Specification Third Edition for JavaLetterOrDigit>

It would therefore be better to do without a default package:

Export-Package: org.acme.foo.bar
howlger
  • 31,050
  • 11
  • 59
  • 99
  • 1
    Correct except that it does not depend on the OSGi Framework used. Exporting the default package is an error under all spec-compliant framework implementations. – Neil Bartlett Feb 07 '18 at 13:38
  • @NeilBartlett Thank you for clarifying. I edited my answer accordingly. Does this mean that ignoring `.` or non-existing packages and interpreting `.` as a default package violates the spec? Does the spec allow a non-exported default package? – howlger Feb 07 '18 at 14:27
  • `.` is an invalid package name. The default package has no name and, of course, cannot be imported or exported from a bundle. – BJ Hargrave Feb 07 '18 at 18:22
3

Although the Eclipse MANIFEST.MF validation allows '.' it isn't valid according to the OSGi specification. It seems to mean the default package, but this isn't a sensible thing to export.

This appears to be confirmed by Eclipse bug 366800 which reported the use of a '.' like this in the 'org.eclipse.datatools.sqltools.parsers.sql.query' plugin. The bug was accepted as a error and the '.' removed.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • 1
    `.` is the default package (which should be avoided) and in the referenced bug added by mistake to a plug-in/bundle not containing a default package. Are you sure the OSGi specification does not allow to specify the default package as an exported package? – howlger Feb 07 '18 at 11:16
  • OK, so this seems to be Eclipse specific and doesn't really seem to make much sense. – greg-449 Feb 07 '18 at 11:30
  • I don't think `. ` is Eclipse specific (e. g. see [_"default package '.'"_ here](http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html)) but I agree using a default package is ugly and maybe not covered by the OSGi specification. – howlger Feb 07 '18 at 11:48
1

Couldn't find it in the OSGi Spec (V6).

Tried an example in Eclipse (Oygen.2). Created two plug-ins (aka bundles), one "provider", the other "consumer". Provider exports default package and in that package contains a public Class A.

=> It's not possible to access A from plug-in "provider". Eclipse suggests to export package ''. Invoking that option doesn't change anything. Compile error remains.

I would recommend not to use this.

ingo.mohr
  • 117
  • 1
  • 7