Trying to set some "base" runproperies for all TestOSGi Gradle tasks

Hi,

I have a Gradle convention plugin which creates a TestOSGi task, and I would like to ensure that this task always uses some basic -runproperties. My initial idea was to extend the TestOSGi task and override its worker method:

class BongoTestOSGi extends TestOSGi {
    @Override
    protected void worker(aQute.bnd.build.Project run) {
        // Do things here...

        super.worker(run)
}

However, while the ProjectLauncher object’s runproperties are preserved once created, it turns out that Project.getProjectLauncher() creates a new ProjectLauncher every time it is invoked :man_facepalming:. There is therefore no point invoking run.projectLauncher.runProperties myself, and then modifying the map’s contents.

Is there any other hook I can use to update the runproperties like this please? Otherwise I am will constantly be telling people that they need to add them to their test.bndrun files themselves when their tests fail.

Thanks,
Chris

Overriding worker is not safe since the method is not an API and can be changed in future releases.

Why don’t you just configure any properties needed through the properties property?

Why don’t you just configure any properties needed through the properties property?

I thought those properties were only used for token expansion in the .bndrun file, whereas I am looking to set / modify the -runproperties.

Edit: OK, I see that I can do something like:

properties.put '-runproperties', '...all runproperties as a single string...'

Thanks, that’s something. Although I assume this will be clobbered if the .bndrun contains its own-runproperties?

Cheers,
Chris

You can set any property you want in there. -runproperties.bongo=foo=bar.

It will. So use merged properties to define your properties. -runproperties.bongo

Then what about an -include: common-properties.bndrun where common-properties.bndrun contains your common instructions?

Ah, I see. Thanks. Presumably anyone who now puts

-runproperties: foo=boink

in their .bndrun file will clobber my default value of bar. But I will assume that anyone setting any of these properties themselves will know what they are doing :wink:.

Thanks again,
Cheers,
Chris

Hmm, this is odd… Adding

properties.put '-runproperties.bongo', 'foo=bar'

to my TestOSGi task causes Bnd to ignore any -runproperties inside the .bndrun file :astonished:.

Could this be a bug, please?

I added

	properties.put("-runproperties.bongo", "foo=bar")
	properties.put("-runtrace", "true")

to a TestOSGi task configuration and it worked as expected. The tracing shows a property of foo with a value of bar and all other properties from -runproperties in the bndrun file are present.

If your bndrun file uses the project property to access the Gradle Project object, then you will also need to add

	properties.put("project", "__convention__")

to have the Gradle Project object available since setting any properties value causes the task to not automatically add in the project property.

Thanks again, the loss of the property’s “convention” value was indeed the problem, and

properties.put("project", "__convention__")

has fixed it.

Cheers,
Chris