Subclass DefaultExecAction

plugins

(Basil Peace) #1

I want to rewrite Gradle Cross-Platform Exec plugin (com.github.jlouns.cpe) to overcome its problems and also to provide crossPlatformExec method for Project class.
In order to do that I plan to subclass DefaultExecAction and override AbstractExecHandleBuilder.build method. Into that method I want to embed code to substitute correct cross-platform command - see WIP here.

But I have a problem that some methods in Gradle classes are private and therefore are not available to my chilld class. For now the problem is AbstractExecHandleBuilder.getEffectiveStreamsHandler.
Could Gradle team change that method visibility to protected?

Or maybe I’m doing something wrong and there is another way to achieve that?


(Schalk Cronjé) #2

You might be better off wrapping up the project.exec iunto something else rather than fiddling with internal APIs.

The Grolifant library already contains some of this functionality you are mentioning (except for the searching for .bat, ,exe etc,). You can take inspiration from there if you do not want to rely on the library itself.

To add your crossPlatformExec have a look at how it was done in org.ysb33r.gradle.olifant.ExtensionUtils. That implementation relies on the fact that your must define a new kind of execution specification type which must derive from AbstractToolExecSpec. Maybe that is an overkill for your case, but you should be able to get an idea of what can be achived without resorting to internal APIs.

Finally you can also look at https://gitlab.com/ysb33rOrg/grolifant/blob/master/src/main/groovy/org/ysb33r/gradle/olifant/exec/AbstractExecTask.groovy#L280, which will give you an idea on how to wrap up the ExecSpec that is required by project.exec inside another execution specification and then execute it.


(Basil Peace) #3

Thanks for the tip about Grolifant library!
I like this nice library, I will definitely use it instead of home-made solution.

Would you accept pull-requests adding cross-platform process execution?


(Schalk Cronjé) #4

Yes, definitely. As this is a library full of building blocks, we’ll need to keep your submission in the same spirit. Raise an issue on GitLab and we can discuss the details.