How should plugins handle ConsoleOutput.Auto


(Steve Ramage) #1

I noticed an issue with a plugin when running Gradle with IntelliJ, and it outputting ASCII control codes inappropriately. I decided to be a good egg and try and fix it but I’m honestly not sure what the best fix is.

It seems that the plugin is using the value of org.gradle.StartParameter.getConsoleOutput() , however if this returns ConsoleOutput.Auto which has documentation which says:

Enable color and rich output when the current process is attached to a console, disable when not attached to a console.

No guidance is given on how to determine whether we are in fact “attached to a console”. System.console() is probably the plain old Java way, but I believe it is unreliable and is in fact not what Gradle uses. I dug a bit into what Gradle is doing and it turned up: ConsoleConfigureAction.getConsoleMetaData() line 73 returns the console if it’s detected, and the code for that is here in NativePlatformConsoleDetector.getConsole(). This is very deep into gradle’s internals, and so probably isn’t to be emulated.

My question is ultimately, if a plugin receives a ConsoleOutput of Auto, how is it expected to make the determination whether to actually treat the console as rich or plain? How should it be consistent with the choice Gradle makes?