1

我已经用 Jenkins 和 Phing 建立了我的第一个 CI 环境,它大部分运行得很完美,尽管我有一些我无法解决的问题。我在确定如何在构建过程的各个部分中引用目录时经常遇到麻烦,感谢您对以下内容的任何想法:

构建.xml

<?xml version="1.0" encoding="UTF-8"?>

<project name="myProject" default="dev" basedir=".">

    <property name="baseDir" value="." />
    <property name="resourceDir" value="${baseDir}/resources" />
    <property name="srcDir" value="${baseDir}/src" />
    <property name="outputDir" value="${baseDir}/build" />
    <property name="logDir" value="${baseDir}/build/logs" />
    <property name="phpmdRulesets" value="${resourceDir}/phpmd/rulesets" />

    <property name="devServer" value="C:\Apache24\htdocs\myProject.com" />

    <target name="init">
        <mkdir dir="${outputDir}" />
        <mkdir dir="${logDir}" />
    </target>

    <target name="clean">
        <delete dir="${devServer}" includeemptydirs="true" verbose="true" failonerror="true" />
        <mkdir dir="${devServer}" />
    </target>

    <target name="test">
        <echo msg="Running unit tests" />
        <exec executable="phpunit" checkreturn="true">
            <arg value="--log-junit=${logDir}/PHPUnit.xml" />
            <arg value="--verbose" />
            <arg value="--debug" />
            <arg value="--coverage-clover=${logDir}/clover.xml" />
            <arg path="${baseDir}" />
        </exec>
    </target>

    <target name="build" depends="phpcs, phpmd, phpcpd, phpDox">
        <echo msg="Running build" />
        <echo msg="Copying files to build directory..." />
        <copy todir="${outputDir}">
            <fileset dir="${baseDir}">
                <include name="**/src/**" />
                <include name="**/resources/**" />
            </fileset>
        </copy>
    </target>

    <target name="phpcs">
        <echo msg="Running phpcs" />
        <exec executable="phpcs"> 
            <arg value="--report=checkstyle" />
            <arg value="--ignore=${srcDir}/php/Test/*,${srcDir}/php/lib/*" />
            <arg value="--report-file=${logDir}/checkstyle.xml" />
            <arg path="${srcDir}" />
        </exec>
    </target>

    <target name="phpmd">
        <echo msg="Running phpmd" />
        <exec executable="phpmd">
            <arg path="${srcDir}" />
            <arg value="xml" />
            <arg value="${phpmdRulesets}/codesize.xml,${phpmdRulesets}/unusedcode.xml,${phpmdRulesets}/naming.xml,${phpmdRulesets}/design.xml" />
            <arg value="--reportfile ${logDir}/messdetector.xml" />
            <arg value="--exclude ${srcDir}/php/Test/,${srcDir}/php/lib/" />
        </exec>
    </target>

    <target name="phpcpd">
        <echo msg="Running phpcpd" />
        <exec executable="phpcpd">
            <arg value="--log-pmd=${logDir}/phpcpd.xml" />
            <arg value="-vvv" />
            <arg value="--exclude=${srcDir}/php/Test/,${srcDir}/php/lib/" />
            <arg path="${srcDir}" />
        </exec>
    </target>

    <target name="phpDox">
        <echo msg="Running phpDox" />
        <exec executable="phpdox">
            <arg value="${resourceDir}" />
        </exec>
    </target>

    <target name="dev" depends="init, clean, test, build">
        <echo msg="Running dev target" />
        <copy file="${outputDir}/src/php/index.php" tofile="${devServer}/index.php" />
        <copy todir="${devServer}/php">
            <fileset dir="${outputDir}/src/php">
                <include name="**" />
                <exclude name="**/index.php" />
            </fileset>
        </copy>
        <copy todir="${devServer}/api">
            <fileset dir="${outputDir}/api/html">
                <include name="**" />
            </fileset>
        </copy>
        <copy file="${outputDir}/src/php/lib/phpLogin/index.php" tofile="${devServer}/php/lib/phpLogin/index.php" />
    </target>
</project>

问题 1: phpmd 不会输出报告文件,但 Jenkins 日志中没有报告错误。相反,它将整个 xml 记录到标准输出并在 Jenkins 日志中报告。

myProject > phpmd:

     [echo] Running phpmd
Property ${srcDir} => ./src
Property ${phpmdRulesets} => ./resources/phpmd/rulesets
Property ${phpmdRulesets} => ./resources/phpmd/rulesets
Property ${phpmdRulesets} => ./resources/phpmd/rulesets
Property ${phpmdRulesets} => ./resources/phpmd/rulesets
Property ${logDir} => ./build/logs
Property ${srcDir} => ./src
Property ${srcDir} => ./src
     [exec] Executing command: phpmd ./src xml ./resources/phpmd/rulesets/codesize.xml,./resources/phpmd/rulesets/unusedcode.xml,./resources/phpmd/rulesets/naming.xml,./resources/phpmd/rulesets/design.xml "--reportfile ./build/logs/messdetector.xml" "--exclude ./src/php/Test/,./src/php/lib/" 2>&1
     [exec] <?xml version="1.0" encoding="UTF-8" ?>
     ...

问题 2:我无法让 phpDox 在我的源代码中排除某些目录。下面是我的 phpdox.xml。

<?xml version="1.0" encoding="utf-8" ?>
<phpdox xmlns="http://phpdox.de/config">
    <project name="myProject.com" source="src/php" workdir="build/api/xml">
        <collector backend="parser" publiconly="false">
            <include mask="*.php" />
            <exclude mask="/lib/**" />
        </collector>
        <generator output="build/api">
            <build engine="html" output="html"/>
        </generator>
    </project>
</phpdox>

请问有谁知道我可以使用的正确排除面罩吗?我的文件结构是:

myProject.com
  /build.xml
  /phpdox.xml
  /src
    /php
      /lib
4

1 回答 1

1

两个问题都解决了。

问题 1:将 phpmd 任务更改为仅使用arg 值而不是arg path。固定如下:

<target name="phpmd">
    <echo msg="Running phpmd" />
    <exec executable="phpmd">
        <arg value="${dir.src}" />
        <arg value="xml" />
        <arg value="${dir.phpmdRulesets}/codesize.xml,${dir.phpmdRulesets}/unusedcode.xml,${dir.phpmdRulesets}/naming.xml,${dir.phpmdRulesets}/design.xml" />
        <arg value="--reportfile" />
        <arg value="${dir.logs}/messdetector.xml" />
        <arg value="--exclude"/>
        <arg value="test,lib" />
    </exec>
</target>

问题 2:终于让排除掩码工作了。固定xml如下:

<?xml version="1.0" encoding="utf-8" ?>
<phpdox xmlns="http://phpdox.de/config">
    <project name="myProject.com" source="src/app" workdir="build/api/xml">
        <collector backend="parser" publiconly="false">
            <include mask="*.php" />
            <exclude mask="**/*lib*" />
            <exclude mask="**/*test*" />
        </collector>
        <generator output="build/api">
            <build engine="html" output="html"/>
        </generator>
    </project>
</phpdox>
于 2013-12-28T05:02:40.567 回答