0

寻求一些帮助,试图找到一种方法让 Maven antrun 插件对我的 php 模块中的所有文件进行交互,对它们全部执行 php -l (lint 检查)。

如果我使用设置为 true 的 failonerror 属性,它会在遇到一个坏文件时立即失败。如果我将 result 属性与文件集(当前实现)一起使用,那么它会解析所有文件,但返回代码来自 php lint 的第一次执行,因此只有在第一个文件坏的情况下才会失败。

<apply executable="php" failonerror="false" resultproperty="myresult">
  <arg value="-l" />
  <fileset dir="${basedir}">
    <include name="**/*.php" />
  </fileset>
</apply>

我尝试使用另一种调用 php -l 的方法,使用 find (来自http://kamisama.me/2012/07/02/faster-php-lint/),但它似乎仍然在第一次退出损坏的文件。

<target name="lint" description="Perform syntax check of sourcecode files">
  <exec executable="bash" failonerror="true">
    <arg value="-c" />
    <arg value="find -L ${basedir}/src -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l" />
  </exec>
</target>

可以使用 antrun 语法或检查所有文件的方法的帮助,但如果一个或多个文件未能通过 lint 检查,则在最后退出。

我也考虑过 githooks,但我不负责那个系统。

任何提示表示赞赏!

4

1 回答 1

1

最后使用 AntRun 插件解决了这个问题,从“resultproperty”转移到使用带有附加的“errorproperty”。如果有任何错误,它将继续检查所有文件,并附加更多错误,直到检查完所有文件。

在进行了几次其他检查之后,它会进入报告阶段,在此阶段它将吐出目前发现的所有错误,如果“errorproperty”不为空,它将导致构建失败。(这将错误放在输出的末尾,并且不必在 jenkins / maven 日志中滚动很长一段路以查找 lint 错误)

希望这对某人有帮助!

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>lint-php</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target name="lint-php" unless="skipExecution">

                            <echo>Execution of the php linter</echo>
                            <echo></echo>
                            <apply executable="php" failonerror="false" errorproperty="lint-errors" append="true">
                                <arg value="-l" />
                                <fileset dir="${basedir}">
                                    <include name="**/*.php" />
                                </fileset>
                            </apply>

                        </target>
                        <exportAntProperties>true</exportAntProperties>
                    </configuration>
                </execution>
...
                <execution>
                    <id>report-status</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target name="exit" unless="skipExecution">
                            <echo message="PHP lint check warnings:" />
                            <echoproperties regex="lint-errors" format="xml"/>
                            <echo message="----------" />
                            <fail message="PHP linter found linting errors">
                                <condition>
                                    <not>
                                        <equals arg1="${lint-errors}" arg2="" />
                                    </not>
                                </condition>
                            </fail>
                        </target>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
于 2014-11-25T10:20:39.533 回答