How to beautify the output of phing?

旧城冷巷雨未停 提交于 2019-12-23 02:36:33

问题


Phing, by default, or even with any of built-in loggers (phing.listener.NoBannerLogger, phing.listener.AnsiColorLogger, phing.listener.XmlLogger and phing.listener.HtmlColorLogger) has quite verbose output.

My use-case is to use Phing for running tests as a pre-commit hook. Therefore I don't care about all that information in log phing may provide me. I just use it as a multiplatform tool for running tests.

Example:

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

Many of these lines are really redundant and useless for my use case. I actually even don't run "build" in the original meaning.

What I would love to make phing log to look like is simply sth like this:

 ✔ 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

If you think I am using the bad tool for my purpose, tell me that too, I would be happy to know there's something else.


回答1:


What you could try is using phing.listener.XmlLogger and piping it through xsltproc with your own stylesheet.

Given a basic build.xml file that just lints your 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>

Coupled with 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>

Invoked with phing -logger phing.listener.XmlLogger lint | xsltproc parse.xsl - will give you something clean like:

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



回答2:


u have a sytax error on line 2 mytest

it comes basically when inapropriate code is passed or is not properly closed like {}

can you post the line 2 of mytest



来源:https://stackoverflow.com/questions/11709160/how-to-beautify-the-output-of-phing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!