如何使用sed为Gradle输出着色?

时间:2018-10-09 21:40:10

标签: bash shell gradle sed colorize

我正在尝试使用 sed 处理 Gradle 的以下shell输出,以识别严重性级别并为其着色:

23:06:28.686 [LIFECYCLE] [system.out] 
23:06:28.686 [QUIET] [system.out] Note: the configuration keeps the entry point 'androidx.core.graphics.drawable.IconCompatParcelizer { android.support.v4.graphics.drawable.IconCompat read(androidx.versionedparcelable.VersionedParcel); }', but not the descriptor class 'androidx.versionedparcelable.VersionedParcel'
23:06:28.686 [QUIET] [system.out] Note: the configuration keeps the entry point 'androidx.core.graphics.drawable.IconCompatParcelizer { void write(android.support.v4.graphics.drawable.IconCompat,androidx.versionedparcelable.VersionedParcel); }', but not the descriptor class 'androidx.versionedparcelable.VersionedParcel'
23:06:28.710 [QUIET] [system.out] Note: there were 5 references to unknown classes.
23:06:28.711 [QUIET] [system.out]       You should check your configuration for typos.
23:06:28.711 [QUIET] [system.out]       (http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
23:06:28.711 [QUIET] [system.out] Note: there were 2 unkept descriptor classes in kept class members.
23:06:28.711 [QUIET] [system.out]       You should consider explicitly keeping the mentioned classes
23:06:28.711 [QUIET] [system.out]       (using '-keep').
23:06:28.711 [QUIET] [system.out]       (http://proguard.sourceforge.net/manual/troubleshooting.html#descriptorclass)
23:06:28.711 [QUIET] [system.out] Note: there were 12 unresolved dynamic references to classes or interfaces.
23:06:28.711 [QUIET] [system.out]       You should check if you need to specify additional program jars.
23:06:28.711 [QUIET] [system.out]       (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
23:06:28.711 [ERROR] [system.err] Warning: there were 11 unresolved references to classes or interfaces.
23:06:28.711 [ERROR] [system.err]          You may need to add missing library jars or update their versions.
23:06:28.711 [ERROR] [system.err]          If your code works fine without the missing classes, you can suppress
23:06:28.711 [ERROR] [system.err]          the warnings with '-dontwarn' options.
23:06:28.711 [ERROR] [system.err]          (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
23:06:28.711 [QUIET] [system.out] Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.
23:06:28.585 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] 

我使用以下shell脚本:

#!/bin/sh

c_red=`tput setaf 1`
c_end=`tput sgr0`
./gradlew --info --debug assemble | sed -E -e "s/(\[ERROR\])/${c_red}\1${c_end}/g" \

这是未处理输出的屏幕截图:

Unprocessed output

这是处理后的输出的屏幕截图:

Processed output

除了缺少的颜色,我还注意到输出的某些行在处理后的输出中丢失。此外,正如在未处理的输出中可以看到的那样,Gradle本身似乎为某些单词着色。 Gradle中的控制字符以及我在 sed 命令中使用的控制字符可能会干扰

如果我选择LIFECYCLE而不是ERROR,那么脚本会有所工作。有些行在那里也丢失了!而且Gradle的颜色消失了。

Processed output: LIFECYCLE

我正在Ubuntu 16.04的终端上运行它。

0 个答案:

没有答案