How to intercept any runner's command line


I'm writing an agent plugin.  Its purpose is to intercept the command line that would be forwarded to any runner and modify it by wrapping it with an outer command line.

For developement only, I've implemented MyCommandLineBuildServiceFactory to return MyCommandLineBuildService from createService().  As well, just for testing purposes, the AgentBuildRunnerInfo within it returns, "Ant" through its getType() method.

MyCommandLineBuildService extends BuildServiceAdapter.  From its makeProgramCommandLine() method, I can create a new SimpleProgramCommandLine that is specific to the runner type ("Ant", in this case).

What I would like to know, is there a mechanism whereby I can be served up a prepared command line, from any runner type?  From my point of view, it feels like I have to implement a CommandLineBuildServiceFactory for each runner type that I would like to intercept.  As well, it feels like I would have to implement a CommandLineBuildService for each run type for which I'd want to modify its command line.  I think that I may have to extend CommandLineBuildService instead of BuildServiceAdapter as the JaveDocs suggest, but I'm not yet sure.  You guys do such a great job of putting together all of those varied command lines, it would be a shame to throw them out and have to re-invent the wheel.

I hope this isn't too abstract without code samples; there really isn't very much to get this up and running; it's just getting it to do what I need.

Cheers & Thanks.

Comment actions Permalink

Hi Nic,

Seems you can use an experimental extension specially designed for modifying invoked comamnds: see as an example (the plugin is related to the issue)

BTW, what kind of functionality you want to add by changing the command line?

Comment actions Permalink

Hi, Yegor,

Your answer and the sample were pretty much exactly what I was looking for.

For future reference, the readme file located a few layers up from the Java sample fills in the blanks.

I need the command line so that I can, in the case of an Ant build, modify it by adding an additional ant listener, and in general, call it from an external tool (At the moment, I don't know what I'll do with Maven, Gradle or any of the other runners; it's still in the poc stage.)  The purpose is to monitor compilation so that the underlying source can be statically analyzed on the fly.

Thank you very much for your accurate and swift reply.



Please sign in to leave a comment.