Question

I have a problem using build.xml in jenkins. I have to exlude some directories when i exec phpmd, phpcs phpcpd, phpdoc, pdepend, phploc... For each of these above, my --exclude or --ignore params is not working.... and my build on jenkins is so long. I have to ignore some folder like (vendor(zend framework), js(for Jquery and jquery plugin), and some others like tests(for PHPunit)) This is my XML :

See my XML on Pastie

When i create this XML, i check on google some help and i found this :

No luck tutorial

Was it helpful?

Solution

Here is the solution after a lot of headhache :

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

<fileset id="php-files" dir="${basedir}">
    <include name="**/*.php"/>
    <exclude name="vendor/**"/>
    <exclude name="build/**"/>
    <exclude name="tests/**"/>
</fileset>

<target name="main" description="Start analyzing our application">
    <echo msg="Start Build" />

    <phingCall target="clean" />
    <phingCall target="prepare" />
    <phingCall target="phpunit" />
    <phingCall target="pdepend" />
    <phingCall target="phpmd-ci" />
    <phingCall target="phpcpd" />
    <phingCall target="phpdoc" />
    <phingCall target="phpcs-ci" />
    <phingCall target="phploc" />
    <phingCall target="phpcb" />

    <echo msg="Finished Build" />
</target>



<target name="clean" description="Delete old stuff">
    <delete dir="${basedir}/build/api"/>
    <delete dir="${basedir}/build/coverage"/>
    <delete dir="${basedir}/build/code-browser"/>
    <delete dir="${basedir}/build/logs"/>
    <delete dir="${basedir}/build/pdepend"/>
</target>

<target name="prepare" depends="clean" description="prepare new build">
    <mkdir dir="${basedir}/build/api"/>
    <mkdir dir="${basedir}/build/coverage"/>
    <mkdir dir="${basedir}/build/code-browser"/>
    <mkdir dir="${basedir}/build/logs"/>
    <mkdir dir="${basedir}/build/pdepend"/>
</target>

<!-- works perfectly -->
<target name="phploc" description="your project is too heavy loose weight fat boy">
    <exec executable="phploc.bat">
        <arg path="${basedir}/module" />
        <arg value="--log-csv" />
        <arg value="${basedir}/build/logs/phploc.csv" />
    </exec>
</target>
<!-- works perfectly -->
<target name="pdepend" description="more metrics chart please">
    <exec command="pdepend --jdepend-xml=${basedir}/build/logs/jdepend.xml 
       --jdepend-chart=${basedir}/build/pdepend/dependencies.svg 
       --overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg 
       --suffix=php
       --ignore=vendor,tests,build,public/js
       ${basedir}" 
    escape="false" />
</target>
<!-- works perfectly -->
<target name="phpmd-ci" description="Generate pmd.xml using PHPMD">
    <phpmd rulesets="codesize,design,naming,unusedcode">
        <fileset refid="php-files"/>
        <formatter type="xml" outfile="${basedir}/build/logs/pmd.xml"/>
    </phpmd>
</target>  
<!-- works perfectly -->
<target name="phpcs-ci" description="coding with checkstyle">
    <exec passthru="false" command="phpcs 
        --report=checkstyle
        --report-file=${basedir}/build/logs/checkstyle.xml
        --standard=Zend
        --ignore=vendor,tests,public/js,build
        --extensions=php
        ${basedir}"/>
</target>
<!-- Ne marche pas non plus en raison de : pas de test unitaire encore -->
<target name="phpcpd" description="repeat yourself is killing you">
    <exec executable="phpcpd">
        <arg line="--log-pmd ${basedir}/build/logs/pmd-cpd.xml
            --exclude ${basedir}/vendor
            --exclude ${basedir}/tests
            --exclude ${basedir}/build
            --exclude ${basedir}/js
            --suffixes php
            ${basedir}" />
        </exec>
</target>

<target name="phpdoc" description="Generate API documentation using PHPDocumentor">
    <phpdoc title="MyLink API Documentation"
          destdir="${basedir}/build/api"
          sourcecode="false"
          output="HTML:Smarty:PHP"
          quiet="true">
        <fileset refid="php-files"/>
    </phpdoc>
</target>

<target name="phpunit" description="test your code">
    <exec command="phpunit.bat 
    --bootstrap=${basedir}/tests/Bootstrap.php
    --configuration=${basedir}/tests/phpunit.xml
    --log-junit ${basedir}/build/logs/junit.xml
    --coverage-clover ${basedir}/build/logs/clover.xml
    --coverage-html ${basedir}/build/coverage/"/>
</target>

<!-- works perfectly -->
<target name="phpcb" description="are you coding properly">
    <exec executable="phpcb.bat">
        <arg value="--log" />
        <arg path="${basedir}/build/logs" />
        <arg value="--source" />
        <arg path="${basedir}" />
        <arg value="--output" />
        <arg path="${basedir}/build/code-browser" />
        <arg value="--ignore"/>
        <arg path="${basedir}/vendor/,${basedir}/tests/,${basedir}/build/,${basedir}/public/js/"/>
    </exec>
</target>

The solution was to do some syntax adjustment, and use phing syntax either, especially phings call.

This Phing build.xml was so usefull for this problem !!

Hope this help someone, and convince others to work with Jenkins for Continuous Integration, in Zend Framework projects !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top