bash - 如何使用 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 着色消失了。
我在 Ubuntu 16.04 的终端上运行它。
解决方案
推荐阅读
- javascript - 我的 JS 字谜图解决方案的时间、空间复杂度
- r - 优化错误:无法在最大似然估计的初始参数处评估函数
- regex - macOS,PyCharm,2.7 python 解释器 - 如何在每次出现给定字符后附加特定字符?
- python - 列表中特定元素的数量
- python - 计算 numpy 数组列的唯一值概率
- angularjs - 如何使用 Angular HttpClient 将地理位置数据作为数组写入 Google Firebase 实时数据库?
- android - Expo - 带有 Google 应用签名和 Expo 签名的 FCM
- java - 将数组作为对象问题的参数传递
- reactjs - 有没有办法从 react-phone-input-2/material-ui-phone-number 中选择的标志中获取国家信息(代码)
- c# - 在 moqu 中作为序列的一部分抛出异常