dqyitt2954 2014-11-20 14:28
浏览 67
已采纳

尝试使用maven antrun插件进行php lint检查

Looking for some help, trying to find a way to make Maven antrun plugin interate over ALL files in my php module, executing php -l (lint check) on them all.

If I use failonerror property set to true, it will fail as soon as it hits one bad file. If I use the resultproperty with a fileset (current implementation) then it parses all files, but the return code is from the first execution of php lint, so it only fails if the first file is bad.

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

I've tried to use a different method of calling php -l, using find (from http://kamisama.me/2012/07/02/faster-php-lint/ ), but it still seems to quit on the first broken file.

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

Could use some help with antrun syntax or a method which will check all files, but exit at the end IF one or more files fail the lint check.

I've also considered githooks, but am not in charge of that system.

Any tips appreciated!

  • 写回答

1条回答 默认 最新

  • dongxing7318 2014-11-25 10:20
    关注

    Solved it using AntRun plugin in the end, moved away from 'resultproperty' to using 'errorproperty' with append. If there are any errors, it will continue checking all files, appending further errors until all the files have been checked.

    After a few other checks, it then reaches a report phase where it will spit out all the errors found so far, and if the 'errorproperty' was not empty, it will fail the build. (This puts the errors right at the end of the output, and saves having to scroll a long way up through the jenkins / maven logs to find the lint errors)

    Hope this helps someone!

    <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序哪有错误怎么改?
  • ¥15 交换机和交换机之间的链路带宽以及主机带宽的理解
  • ¥15 ai创想家对战模式代码
  • ¥15 集合A由3个2行4列二维数组构成,从集合A中任意取一个二维数组元素、如果该二维数组元素的对应列位置的上、下两数都是奇数,而且仅有2个列是奇数/奇数,则该数组有意义,并放入集合B中打印输出。
  • ¥15 电信IPV6 无法外网访问吗
  • ¥15 有偿求效果比较好的遥感影像匹配的c++代码
  • ¥15 博主,你好,我下载了你的智能网联汽车辅助驾驶安全信息检测系统,现在不会运行,可以教我吗,
  • ¥15 怎么在excle输入下列公式
  • ¥15 Arduino,利用modbus的RS485协议,进行对外置的温湿度传感器进行数据读取
  • ¥15 vhdl+MODELSIM