Menu

[r294]: / wiki / UsingWithANT.wiki  Maximize  Restore  History

Download this file

90 lines (67 with data), 2.1 kB

#labels Featured

= Running PHPCheckstyle with ANT =

To run PHPCheckstyle with ANT we need to launch a PHP cli.

This can be done using the "exec" task of ANT.

Sample ANT file :
{{{
<project name="PHPCheckstyle" default="phpcheckstyle" basedir=".">

	<description>
            Static Analysis tool for PHP.
    </description>


        <!-- Test the environment -->
	<target name="targetCheck">
		<condition property="isUnix">
			<and>
				<os family="unix" />
			</and>
		</condition>
		<condition property="isWindows">
			<and>
				<os family="windows" />
			</and>
		</condition>
	</target>

        <!-- Launch PHP CheckStyle on Windows -->
	<target name="_phpcheckstylewindows" depends="targetCheck" if="isWindows">
		<echo>Windows</echo>
		<exec executable="./phpcheckstyle.cmd" dir=".">
		</exec>
	</target>

	<!-- Launch PHP CheckStyle on Unix -->
	<target name="_phpcheckstyleunix" depends="targetCheck" if="isUnix">
		<echo>Unix</echo>
		<chmod file="./phpcheckstyle.sh" perm="ugo+rx" />
		<exec executable="./phpcheckstyle.sh" dir=".">
		</exec>
	</target>

	<!-- Launch PHP CheckStyle-->
	<target name="phpcheckstyle" description="Launch PHP CheckStyle" depends="_phpcheckstylewindows, _phpcheckstyleunix">
	</target>

</project>

}}}


The script files can look like this :

phpcheckstyle.cmd
{{{
echo "PHP Checkstyle script"
php run.php --src ./test --outdir ./checkstyle_result --config default.cfg.xml --format html,xml --linecount
pause
}}}

phpcheckstyle.sh
{{{
#!/bin/sh
echo "PHP CheckStyle script"
php run.php --src ./test --outdir ./checkstyle_result --config default.cfg.xml --format html,xml --linecount
}}}



= PHP Syntax Check =

You can also use ANT to launch a syntax check using the CLI command "php -l". 
Thanks to Manuel Pichler : http://manuel-pichler.de/archives/25-integrate-php-lint-syntax-checks-in-your-build-process.html

{{{

 <target name="checkphp">
    <apply executable="php" failonerror="true">
      <arg value="-l" />
      <fileset dir="source/src">
        <include name="**/*.php" />
      </fileset>
    </apply>
  </target>

}}}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.