How to do a workspace build programmatically? (with bndlib)

134 views
Skip to first unread message

Thomas Driessen

unread,
Aug 16, 2018, 7:58:17 AM8/16/18
to bndtools-users
Hi,

I'm trying to build my project programmatically via the API provided by biz.aQute.bndlib.

So far I've created a bnd-workspace with cnf folder and everything else.

Now when I try to build it via  the following code (Xtend, but I think it's readable)

val workspace = Workspace.getWorkspace(workspaceLoc.toFile)
workspace.allProjects.forEach[clean]
workspace.allProjects.forEach[prepare]
workspace.allProjects.forEach[build]

I end up with errors complaining about missing libraries that are on the buildpath of my project and can not be found in the bnd cache during the build. 
It seems I currently  do not pick up the Maven repositories defined in the ext folder of cnf, but I couldn't find any method to add those repositories so that they are used  when building my projects. 
Can anyone give me a hint in the right direction?

Kind regards,
Thomas

BJ Hargrave

unread,
Aug 16, 2018, 8:31:01 AM8/16/18
to bndtool...@googlegroups.com
You may want to look at how the Bnd Gradle plugins works.

Also, you will want to get the build order of the projects and build them in that order since one project can depend upon the build output of another project.

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
BJ

Thomas Driessen

unread,
Aug 16, 2018, 10:51:23 AM8/16/18
to bndtools-users
Thanks BJ

I was missing biz.aQute.repository on the classpath, but got no exception when trying to run my code. 
All exceptions were collected in workspace.errors. Is there a specific reason for this?

Regarding build order: Is it sufficient if I use workspace.getBuildOrder()? Or do I have to calculate the build order myself?

Aside from the build order, are there any special properties I need to set for the workspace if I stick to the default layout?
In the gradle plugins only the setOffline() method is called but otherwise only gradle specific parts are set as far as I can see.  The bndWorkspace itself is not configured any further?

Kind regards,
Thomas

Peter Kriens

unread,
Aug 16, 2018, 10:54:15 AM8/16/18
to via bndtools-users
On 16 Aug 2018, at 16:51, Thomas Driessen <thomas.dr...@gmail.com> wrote:
Thanks BJ
I was missing biz.aQute.repository on the classpath, but got no exception when trying to run my code. 
All exceptions were collected in workspace.errors. Is there a specific reason for this?

For these things it is better to use biz.aQute.bnd instead of biz.aQute.bndlib since it contains also the important extra dependencies

All errors are put in the workspace so you need to check this after you ran your code. This is really the only place since we need to be able to be used by the Eclipse and gradle reporting mechanisms.

Kind regards,

Peter Kriens

Thomas Driessen

unread,
Aug 16, 2018, 12:05:17 PM8/16/18
to bndtools-users
Right now I can call build without getting any errors afterwards, but I end up with Jars that only contain the manifest.

The code looks like this:

// get workspace
val workspace = Workspace.getWorkspace(workspaceLoc.toFile)
// clean each project and then prepare it
workspace.allProjects.forEach[clean prepare]
// compile and build each project according to the build order
workspace.buildOrder.forEach[compile build]

Can you give me a hint, what I'm missing?

Kind regards,
Thomas

BJ Hargrave

unread,
Aug 16, 2018, 12:28:48 PM8/16/18
to bndtool...@googlegroups.com
Your clean call will clean the bin folders. and then you don't seem to call your compilers to compile the source code back into bin. Bnd does not invoke compilers. In gradle/maven/eclipse the compiler is invoked buy the build tool.

Thomas Driessen

unread,
Aug 17, 2018, 7:09:04 AM8/17/18
to bndtools-users
I assumed project.compile() would do that, but I now got it working by compiling the sources myself. Thanks a lot for your help!
Just as a quick summary of my findings:

To do a workspace build programmatically you have to 

- add the current biz.aQute.bnd.jar to your classpath
- create a workspace by calling Workspace.getWorkspace(new File(pathToyourworkspace))
- optionally clean all projects by calling workspace.getAllProjects().forEach(Project it -> it.clean())
- prepare all projects by calling workspace.getAllProjects().forEach(Project it -> it.prepare())
- compile all source files into the project's bin folder (respect build order by using workspace.getBuildOrder())
- build all projects via worspace.getBuildOrder().forEach(Project it -> it.build())

One last question though: When I call the method project.prepare(), then this calls BndPomRepository.version(bsn) which somehow creates a non-background thread that keeps my program alive even after it finishes.
Is this intended? If so, is there a way to stop this plugin? Right now I'm using System.exit(0) at the end of my program.

Kind regards,
Thomas

BJ Hargrave

unread,
Aug 17, 2018, 8:49:05 AM8/17/18
to bndtool...@googlegroups.com
The Processor class has an executor (in  static field) which uses Executor.defaultThreadFactory() to make threads. These threads are non-daemon. These should probably be daemon. I will look at changing this.

Thomas Driessen

unread,
Aug 17, 2018, 8:51:12 AM8/17/18
to bndtool...@googlegroups.com
Thank you :)

------ Originalnachricht ------
Von: "BJ Hargrave" <b...@bjhargrave.com>
Gesendet: 17.08.2018 14:48:51
Betreff: Re: How to do a workspace build programmatically? (with bndlib)

You received this message because you are subscribed to a topic in the Google Groups "bndtools-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bndtools-users/hdXxi6TcwUI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bndtools-user...@googlegroups.com.

BJ Hargrave

unread,
Aug 20, 2018, 10:27:55 AM8/20/18
to bndtool...@googlegroups.com
I have released a change [1] to Bnd to mark the executor threads as daemon. So you can try the latest Bnd builds.

Thomas Driessen

unread,
Aug 21, 2018, 4:43:15 AM8/21/18
to bndtools-users
Thanks BJ. Works perfectly!
Reply all
Reply to author
Forward
0 new messages