2011-08-05 49 views
18

在我的項目中有某些目錄和某些php文件的大小非常大,因此我的構建失敗,我想排除它們在我的build.xml排除某些目錄和文件在pdepend,phpmd,phpcpd,phpcs,phpdoc,phploc

Ques1-是否必須爲項目中的每個php文件編寫--ignore="path/filename"

Ques2-某些文件不是php,但是.dat所以我應該在--ignore中提及這些文件嗎?

Ques3-我可以指定排除基於文件大小的文件,以便排除大於500kb的所有文件嗎?

我當前XML文件是這樣的:

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

<project name="name-of-project" default="build" basedir="."> 
    <property name="root.dir" value="${basedir}/.."/> 
    <property name="source" value="${root.dir}"/> 

<target name="clean" 
     description="Clean up and create artifact directories"> 
    <delete dir="${basedir}/build/api"/> 
    <delete dir="${basedir}/build/code-browser"/> 
    <delete dir="${basedir}/build/coverage"/> 
    <delete dir="${basedir}/build/logs"/> 
    <delete dir="${basedir}/build/pdepend"/> 

    <mkdir dir="${basedir}/build/api"/> 
    <mkdir dir="${basedir}/build/code-browser"/> 
    <mkdir dir="${basedir}/build/coverage"/> 
    <mkdir dir="${basedir}/build/logs"/> 
    <mkdir dir="${basedir}/build/pdepend"/> 
</target> 

<target name="phpunit" 
     description="Run unit tests using PHPUnit and generates junit.xml and clover.xml"> 
    <exec executable="phpunit" failonerror="true"> 
    <env key="DOCUMENT_ROOT" value="${source}/api"/> 
    <env key="MODEL_ROOT" value="${source}/model"/> 
    </exec> 
</target> 

<target name="parallelTasks" 
     description="Run the pdepend, phpmd, phpcpd, phpcs, phpdoc and phploc tasks in parallel using a maximum of 2 threads."> 
    <parallel threadCount="2"> 
    <sequential> 
    <antcall target="pdepend"/> 
    <antcall target="phpmd"/> 
    </sequential> 
    <antcall target="phpcpd"/> 
    <antcall target="phpcs"/> 
    <antcall target="phpdoc"/> 
    <antcall target="phploc"/> 
    </parallel> 
</target> 

<target name="pdepend" 
     description="Generate jdepend.xml and software metrics charts using PHP_Depend"> 
    <exec executable="pdepend"> 
    <arg value="--jdepend-xml=${basedir}/build/logs/jdepend.xml" /> 
    <arg value="--jdepend-chart=${basedir}/build/pdepend/dependencies.svg" /> 
    <arg value="--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg" /> 
    <arg value="--ignore=${source}/web" /> 
    <arg path="${source}" /> 
    </exec> 
</target> 

<target name="phpmd" 
     description="Generate pmd.xml using PHPMD"> 
    <exec executable="phpmd"> 
    <arg path="${source}" /> 
    <arg value="xml" /> 
    <arg value="${basedir}/build/phpmd.xml" /> 
    <arg value="--reportfile" /> 
    <arg value="${basedir}/build/logs/pmd.xml" /> 
    <arg value="--exclude" /> 
    <arg value="${basedir}/web" /> 
    </exec> 
</target> 

<target name="phpcpd" 
     description="Generate pmd-cpd.xml using PHPCPD"> 
    <exec executable="phpcpd"> 
    <arg value="--log-pmd" /> 
    <arg value="${basedir}/build/logs/pmd-cpd.xml" /> 
    <arg value="--exclude" /> 
    <arg value="${basedir}/web" /> 
    <arg path="${source}" /> 
    </exec> 
</target> 

<target name="phploc" 
     description="Generate phploc.csv"> 
    <exec executable="phploc"> 
    <arg value="--log-csv" /> 
    <arg value="${basedir}/build/logs/phploc.csv" /> 
    <arg value="--exclude" /> 
    <arg value="${basedir}/web" /> 
    <arg path="${source}" /> 
    </exec> 
</target> 

<target name="phpcs" 
     description="Generate checkstyle.xml using PHP_CodeSniffer"> 
    <exec executable="phpcs" output="/dev/null"> 
    <arg value="--report=checkstyle" /> 
    <arg value="--report-file=${basedir}/build/logs/checkstyle.xml" /> 
    <arg value="--standard=${basedir}/build/phpcs.xml" /> 
    <arg value="--ignore=${source}/web" /> 
    <arg path="${source}" /> 
    </exec> 
</target> 

<target name="phpdoc" 
     description="Generate API documentation using PHPDocumentor"> 
    <exec executable="phpdoc"> 
    <arg value="--directory" /> 
    <arg path="${source}" /> 
    <arg value="--target" /> 
    <arg path="${basedir}/build/api" /> 
    <arg value="--ignore" /> 
    <arg path="${basedir}/web" /> 
    </exec> 
</target> 

<target name="phpcb" 
     description="Aggregate tool output with PHP_CodeBrowser"> 
    <exec executable="phpcb"> 
    <arg value="--log" /> 
    <arg path="${basedir}/build/logs" /> 
    <arg value="--source" /> 
    <arg path="${source}" /> 
    <arg value="--ignore" /> 
    <arg path="${basedir}/web" /> 
    <arg value="--output" /> 
    <arg path="${basedir}/build/code-browser" /> 
    </exec> 
</target> 

<target name="build" depends="clean,parallelTasks,phpunit,phpcb"/> 
</project> 

而且我越來越喜歡這些

pdepend: 
    [exec] PHP_Depend 0.10.5 by Manuel Pichler 

    [exec] Parsing source files: 
    [exec] phpcpd 1.3.2 by Sebastian Bergmann. 

    [exec] PHP Fatal error: Allowed memory size of 262144000 bytes exhausted (tried to allocate 71 bytes) in /usr/share/pear/PHPCPD/Detector.php on line 115 
    [exec] PHP Stack trace: 
    [exec] PHP 1. {main}() /usr/bin/phpcpd:0 
    [exec] PHP 2. PHPCPD_TextUI_Command::main() /usr/bin/phpcpd:51 
    [exec] PHP 3. PHPCPD_Detector->copyPasteDetection() /usr/share/pear/PHPCPD/TextUI/Command.php:216 
    [exec] PHP 4. token_get_all() /usr/share/pear/PHPCPD/Detector.php:115 
    [exec] Result: 255 

phploc: 
    [exec] phploc 1.6.1 by Sebastian Bergmann. 

    [exec] PHP Fatal error: Allowed memory size of 262144000 bytes exhausted (tried to allocate 71 bytes) in /usr/share/pear/PHPLOC/Analyser.php on line 279 
    [exec] PHP Stack trace: 
    [exec] PHP 1. {main}() /usr/bin/phploc:0 
    [exec] PHP 2. PHPLOC_TextUI_Command::main() /usr/bin/phploc:51 
    [exec] PHP 3. PHPLOC_Analyser->countFiles() /usr/share/pear/PHPLOC/TextUI/Command.php:215 
    [exec] PHP 4. PHPLOC_Analyser->countFile() /usr/share/pear/PHPLOC/Analyser.php:170 
    [exec] PHP 5. token_get_all() /usr/share/pear/PHPLOC/Analyser.php:279 
    [exec] Result: 255 

我應該怎麼做來解決它的錯誤?如果我手動從目錄中刪除大文件,那麼構建只是通過,但我希望構建自動運行從svn檢查代碼庫,這將有這些大文件。

Ques4-我可以配置我的結帳嗎?這些文件不會檢出嗎?

回答

27

對於每一個目標,你可以使用文件集屬性或添加排除目錄手動

<target name="phploc" description="Measure project size using PHPLOC"> 
    <exec executable="phploc"> 
     <arg value="--log-csv"/> 
     <arg value="${basedir}/build/logs/phploc.csv"/> 
     <arg value="--exclude"/> 
     <arg value="${src}/api/"/> 
     <arg value="--exclude"/> 
     <arg value="${src}/external/"/> 
     <arg path="${src}"/> 
    </exec> 
</target> 

<target name="pdepend" 
     description="Calculate software metrics using PHP_Depend"> 
    <exec executable="pdepend"> 
     <arg value="--jdepend-xml=${basedir}/build/logs/jdepend.xml"/> 
     <arg value="--jdepend-chart=${basedir}/build/pdepend/dependencies.svg"/> 
     <arg value="--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg"/> 
     <arg value="--ignore=/dir/one/,/dir/two/"/> 
     <arg path="${src}"/> 
    </exec> 
</target> 

<target name="phpcpd" description="Find duplicate code using PHPCPD"> 
    <exec executable="phpcpd"> 
     <arg value="--log-pmd"/> 
     <arg value="${basedir}/build/logs/pmd-cpd.xml"/> 
     <arg value="--exclude"/> 
     <arg value="${src}/api/"/> 
     <arg value="--exclude"/> 
     <arg value="${src}/exclude/"/><arg path="${src}"/> 
    </exec> 
</target> 

希望我的回答將是一個人幫助。

+6

-1你的示例代碼中沒有'fileset'的例子! – Ben

+1

如果您需要排除文件(不是目錄),請使用選項--names-exclude Select0r

1

In my project there are certain directories and certain php files which are very large in size due to which my build is failing and I want to exclude them in my build.xml

There are certain files which are not php but .dat so should I mention these files in the --ignore too?

我在這種情況下做的是做一個需要的文件的副本,並從那裏工作。要麼複製整個目錄並刪除某些文件,要麼複製所需的文件。在前一種情況下,find程序會做:

cp /my/large/project /tmp/work 
find /tmp/work -name "*.dat" -delete 
find /tmp/work -size 500k -delete 

在後者中,我使用ant's <copy> task

<copy todir="${dir.source.our}" includeEmptyDirs="true"> 
    <fileset dir="${dir.source}/ext" includes="${glob.source.our}"/> 
</copy> 

PHP Fatal error: Allowed memory size of 262144000 bytes exhausted

你必須增加PHP PHP內存大小.ini。 搜索memory_limit並將該值設置爲512 MB等。

memory_limit = 512M 
+1

你也可以使用ini_set('memory_limit','512M'),只要把它放在一個配置文件中幷包含它。 –

+1

這種感覺不正確... – Ben

+0

唯一的其他課程是分析失敗。選一個。 – demonkoryu

相關問題