首页 > 解决方案 > 如何使用 sed 为 Gradle 输出着色?

问题描述

我正在尝试使用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" \

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

未处理的输出

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

处理后的输出

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

如果我选择LIFECYCLE而不是,ERROR那么脚本会起作用。那里也丢失了一些行!Gradle 着色消失了。

处理后的输出:LIFECYCLE

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

标签: bashshellgradlesedcolorize

解决方案


推荐阅读