Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conditionalpackage should overrule exportcontents #3721

Closed
kwin opened this issue Jan 20, 2020 · 8 comments
Closed

conditionalpackage should overrule exportcontents #3721

kwin opened this issue Jan 20, 2020 · 8 comments
Milestone

Comments

@kwin
Copy link
Contributor

kwin commented Jan 20, 2020

Currently in the global parent pom I use the instruction

# export all versioned packages by default
-exportcontents: ${packages;VERSIONED}

Unfortunately that will lead to also exporting packages being embedded via -conditionalpackage. That is not intended. How can I exclude certain packages from being exported while keeping the global/inherited -exportcontents: ${packages;VERSIONED}?

IMHO all packages being embedded via -conditionalpackage should be excluded from being exported, no matter whether the package is versioned or not.

@kwin kwin changed the title conditionalpackage should overrule Export-Package conditionalpackage should overrule exportcontents Jan 20, 2020
@bjhargrave
Copy link
Member

These instructions are processed at different phases in the build and are orthogonal in purpose. Conditional package is about populating the jar contents (to later avoid importing packages). Export contents is about calculating the manifest's Export-Packages header.

Also, there may be developers who depend upon the current behavior and would break in your requested behavior change.

I am not sure using -exportcontents: ${packages;VERSIONED} is wise when using -conditionalpackage since you depend upon the whether the conditionally added package may or may not be versioned.

Since you know the package pattern for conditionally added packages, you could exclude that pattern from the export contents.

-conditionalpackage: foo.*
-exportcontents: !foo.*, ${packages;VERSIONED}

@kwin
Copy link
Contributor Author

kwin commented Jan 20, 2020

Ok, I see. But since https://bnd.bndtools.org/instructions/conditionalpackage.html explicitly states

The packages that are copied cannot be exported, they must be private. This makes it possible to rely on the exact version that the bundle is compiled against. It also ensures that no information is leaked between bundles when statics are used.

at least a WARNING from bnd would be very helpful in that case.
Since it says "cannot" and not "must not" I was assuming this kind of semantics is enforced by bnd itself. The documentation should be clarified in this regard.

@bjhargrave
Copy link
Member

The doc is giving advice to you, the reader. It is expressing the intent of conditional package which is to replace an import of a package with a private copy of a package. And since the copy of the package is meant to be private to the bundle, the bundle should really not be exporting it. But hey, you are the developer and can do a crazy thing if you want! :-)

I agree the doc should be more precise and helpful here. Can you make a PR?

@bjhargrave bjhargrave added this to the 5.1 milestone Jan 24, 2020
@kwin
Copy link
Contributor Author

kwin commented Jan 27, 2020

@bjhargrave Actually your workaround does not work in bnd 4.3.1

-conditionalpackage: foo.*
-exportcontents: !foo.*, ${packages;VERSIONED}

will still export foo!
Any other idea?

You can reproduce with the slightly more complex example at https://github.com/apache/sling-org-apache-sling-installer-core/tree/feature/new-parent.

@bjhargrave
Copy link
Member

It turns out the correct solution is

-exportcontents: ${removeall;${packages;VERSIONED};${packages;CONDITIONAL}}

This says to export all versioned packages except those which are conditionally added.

(It turns out Bnd already knows which packages are conditionally added. Bnd has so many features I can't sometimes remember them all!)

Also, your bnd.bnd

https://github.com/apache/sling-org-apache-sling-installer-core/blob/b1528bd9e2e59beecac9373a3a0b462f06ccb099/bnd.bnd#L1-L18

file is weird in that it has two backslashes at the end of each line instead of the single backslash used to indicate line continuation. And this line

https://github.com/apache/sling-org-apache-sling-installer-core/blob/b1528bd9e2e59beecac9373a3a0b462f06ccb099/bnd.bnd#L7

has a line continuation (albeit a double backslash again) which adds what you intended to be a comment line to the end of the -conditionalpackage instruction.

So your bnd.bnd file should look like:

-conditionalpackage: org.apache.felix.configurator.impl.*,\
                     org.apache.sling.feature.io.*,\
                     javax.json.*,\
                     org.apache.johnzon.core.*,\
                     org.apache.felix.converter.*,\
                     org.apache.felix.cm.*,\
                     org.apache.sling.commons.osgi.*
-exportcontents:     ${removeall;${packages;VERSIONED};${packages;CONDITIONAL}}
Provide-Capability:  osgi.service;objectClass:List<String>="org.apache.sling.installer.api.OsgiInstaller,org.apache.sling.installer.api.ResourceChangeListener,org.apache.sling.installer.api.info.InfoProvider,org.apache.sling.installer.api.tasks.RetryHandler",\
                     osgi.service;objectClass:List<String>="org.apache.sling.installer.api.event.InstallationListener,org.apache.sling.installer.api.jmx.InstallerMBean"

@kwin
Copy link
Contributor Author

kwin commented Jan 28, 2020

@bjhargrave Thanks a lot. The ${packages;CONDITIONAL} macro works like a charm!

@kwin
Copy link
Contributor Author

kwin commented Jul 8, 2020

@bjhargrave Is there a similar macro to not export packages being embedded via -includeresource: @<my-file-[0-9.]*(-SNAPSHOT)?.jar?

Update: As there is nothing documented in https://bnd.bndtools.org/macros/packages.html I raised #4219.

@kvkoti
Copy link

kvkoti commented May 18, 2022

Hi team I had one problem
I am code deployed in my local but when I run the maven command (mvn clean install -PautoInstallPackage)
it,s showing error ( Child module C:\project maven code\genc-aem-training\ui.frontend of C:\project maven code\genc-aem-training\pom.xml does not exist) like this how to crack this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants