如何美化phing的输出?

时间:2012-07-29 12:14:01

标签: php phing pre-commit-hook

默认情况下,

Phing,或者甚至使用任何内置记录器(phing.listener.NoBannerLogger,phing.listener.AnsiColorLogger,phing.listener.XmlLogger和phing.listener.HtmlColorLogger)都有相当详细的输出

我的用例是使用Phing作为预提交钩子运行测试。因此,我并不关心日志中可能提供的所有信息。 我只是将它用作运行测试的多平台工具。

示例:

Buildfile: /private/var/workspace/www/me_com/build.xml

SBKSWWW > main:

   [delete] Deleting /private/var/workspace/www/me_com/temp/pre-commit-hook/changed_files
   [delete] Deleting directory /private/var/workspace/www/me_com/temp/pre-commit-hook
    [mkdir] Created dir: /private/var/workspace/www/me_com/temp/pre-commit-hook
  [phplint] Parse error: parse error in ./www/MyTest.php on line 2
[phpcodesniffer] 2 files where checked
[phpcodesniffer] No syntax errors detected

BUILD FINISHED

Total time: 0.3430 seconds

这些行中有许多对我的用例来说真的是多余的而且毫无用处。我实际上甚至没有以原来的意思运行“构建”。

我希望让phing log看起来像是这样的:

 ✔ Commited code matches coding standards
 ✘ Commited code has syntax errors!
   Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE in MyTest.php on line 2

如果您认为我正在使用这个坏工具,请告诉我,我也很高兴知道还有别的东西。

3 个答案:

答案 0 :(得分:0)

您可以尝试使用phing.listener.XmlLogger并通过xsltproc使用您自己的样式表进行管道传输。

给出一个基本的build.xml文件,它只会让你的PHP发现:

<?xml version="1.0" ?>
<project name="Example" basedir=".">

    <target name="lint" description="PHP syntax check">
        <phplint>
            <fileset dir="src">
                <include name="**/*.php"/>
            </fileset>
        </phplint>
    </target>

</project>

加上parse.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="text"
        omit-xml-declaration="yes"/>

    <xsl:template match="/build">
        <xsl:variable name="newline"><xsl:text>
</xsl:text></xsl:variable>

        <xsl:for-each select="target">
            <xsl:text>Task: </xsl:text>
            <xsl:value-of select="concat(@name, $newline)" />

            <xsl:choose>
                <xsl:when test="task/message[@priority = 'error']">
                    <xsl:value-of select="concat(task/message[@priority = 'error'], $newline)"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>No errors</xsl:text>
                    <xsl:value-of select="$newline" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

使用phing -logger phing.listener.XmlLogger lint | xsltproc parse.xsl -调用会给你一些干净的东西,如:

Task: lint
Fatal error: Only variables can be passed by reference in Request.class.php on line 128

答案 1 :(得分:0)

从Phing 2.11.0开始,您将使用phing.listener.SilentLogger

答案 2 :(得分:-3)

你在第2行mytest上有语法错误

它基本上是在传递不适当的代码或未正确关闭时{}

你可以发布mytest的第2行

相关问题