bndtools / bnd

Bnd/Bndtools. Tooling to build OSGi bundles including Eclipse, Maven, and Gradle plugins.
https://bndtools.org
Other
527 stars 305 forks source link

bndrun export doesn't process -includeresource instruction in bndtools #2906

Closed amitjoy closed 5 years ago

amitjoy commented 5 years ago

I am currently working on my own bndrun configuration which comprises -includeresource instructions to include some external resources to the exported launcher JAR. But when I manually export the JAR by clicking on Export button in Run Tab, it doesn't include any of the external resources.

On the other hand, if I export using bnd library from command line, it does include all of them to the launcher JAR.

bjhargrave commented 5 years ago

Can you please provide a small github repo which demonstrates the problem? Then we can investigate. Thanks.

amitjoy commented 5 years ago

Here it is: https://github.com/amitjoy/bndtools-issue-2906

It comprises one sample bnd project - com.amitinside.sample.launcher.

Steps to reproduce

bjhargrave commented 5 years ago

I cloned the example repo and when I tried to export the bndrun file, I received the following error. So I don't think the example repo is properly configured. Please fix the example repo.

> Task :com.amitinside.sample.launcher:export.launcher FAILED
warning: The JAR is empty: The instructions for the JAR named bndtools-issue-2906 did not cause any content to be included, this is likely wrong
error  : Cannot find /error/org.apache.felix.framework;version=0 Not found in [bnd-cache [/Users/hargrave/git/tmp/bndtools-issue-2906/cnf/cache/4.2.0/bnd-cache r/w=false], BndPomRepository [name=OSGi R7 API, localRepo=/Users/hargrave/.m2/repository, location=cnf/cache/pom-OSGi R7 API.xml, inited=true], BndPomRepository [name=Enterprise Java APIs, localRepo=/Users/hargrave/.m2/repository, location=cnf/cache/pom-Enterprise Java APIs.xml, inited=true], BndPomRepository [name=OSGi R7 Reference Implementations, localRepo=/Users/hargrave/.m2/repository, location=cnf/cache/pom-OSGi R7 Reference Implementations.xml, inited=true], BndPomRepository [name=Testing Bundles, localRepo=/Users/hargrave/.m2/repository, location=cnf/cache/pom-Testing Bundles.xml, inited=true], BndPomRepository [name=Debug Bundles, localRepo=/Users/hargrave/.m2/repository, location=cnf/cache/pom-Debug Bundles.xml, inited=true], MavenBndRepository [localRepo=/Users/hargrave/.m2/repository, storage=Maven Central, inited=true, redeploy=false], Local, Templates, Release]
error  : org.apache.felix.framework;version=0 Not found in [bnd-cache [/Users/hargrave/git/tmp/bndtools-issue-2906/cnf/cache/4.2.0/bnd-cache r/w=false], BndPomRepository [name=OSGi R7 API, localRepo=/Users/hargrave/.m2/repository, location=cnf/cache/pom-OSGi R7 API.xml, inited=true], BndPomRepository [name=Enterprise Java APIs, localRepo=/Users/hargrave/.m2/repository, location=cnf/cache/pom-Enterprise Java APIs.xml, inited=true], BndPomRepository [name=OSGi R7 Reference Implementations, localRepo=/Users/hargrave/.m2/repository, location=cnf/cache/pom-OSGi R7 Reference Implementations.xml, inited=true], BndPomRepository [name=Testing Bundles, localRepo=/Users/hargrave/.m2/repository, location=cnf/cache/pom-Testing Bundles.xml, inited=true], BndPomRepository [name=Debug Bundles, localRepo=/Users/hargrave/.m2/repository, location=cnf/cache/pom-Debug Bundles.xml, inited=true], MavenBndRepository [localRepo=/Users/hargrave/.m2/repository, storage=Maven Central, inited=true, redeploy=false], Local, Templates, Release]
error  : Input file does not exist: run

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':com.amitinside.sample.launcher:export.launcher'.
> /Users/hargrave/git/tmp/bndtools-issue-2906/com.amitinside.sample.launcher/launcher.bndrun export failure

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 25s
2 actionable tasks: 2 executed
amitjoy commented 5 years ago

I cleaned the repo a bit. I think you found another bug.

I executed the following -

./gradlew :com.amitinside.sample.launcher:export.launcher

It did definitely fail as you mentioned above since it complained about the inexistence of run.sh but it works perfectly if you use bnd to package it.

cd com.amitinside.sample.launcher/
java -jar biz.aQute.bnd.jar package launcher.bndrun
bjhargrave commented 5 years ago

If you use

-includeresource             :  ${.}/run.sh

Then it works fine since the referenced file's location is anchored by the bndrun file's location.

The gradle and maven exported plugins use a temporary directory as the base of the bndrun file which is different than the project directory (generated/tmp/export.launcher in this case for the gradle export). This avoids the export operation from polluting the normal project build output files but it means your file is not in the temp folder.

$ ll generated/tmp/export.launcher/
total 0
drwxr-xr-x  2 hargrave  staff  64 Feb 11 13:17 bin
drwxr-xr-x  2 hargrave  staff  64 Feb 11 17:15 generated
drwxr-xr-x  2 hargrave  staff  64 Feb 11 13:17 src

Since the bnd command is standalone, it is not gradle or maven aware and thus simply defaults the project as the base of the bndrun file. So, it is best to use ${.} to anchor the file references in the bndrun file.

amitjoy commented 5 years ago

Didn't know that we have to use name-inode {.} in bndrun files to include resources. It works perfectly in IDE as well as in Gradle. Thanks BJ 👍