教父的告白
一切都是紙老虎 |
在AX3+SP3中有一個工具Code Profiler,近來發現是非常好用的工具,可以檢查代碼運行的軌跡,以及代碼運行的時間,對于跟蹤代碼是非常有效的。
C++代碼度量工具-cccc
軟件度量多個指標依賴于代碼行統計,如每千行代碼發現bug等,所以代碼行是一個基礎數據。CCCC度量數據可結合測試風險完善測試計劃。
CodeStatistics
一個小的命令行工具。我主要用它來做兩件事情,一者是代碼統計功能;另一者是刪除空白行功能。在某此時候,我覺得對于整理代碼和了解代碼情況還是有一定的幫助作用的。明天我會將代碼的行結束符格式加上的,當然,還有分析代碼元素,如有多少個函數,多少個類,也在我確定要添加的功能之內。當然,能整理代碼就更棒了。
靜態代碼分析工具Cppcheck
Cppcheck是一款開源c++靜態代碼分析工具,在檢測源碼時可根據規則就能挖掘出疑似缺陷, 幫開源項目發現的bug有:
http://sourceforge.net/apps/mediawiki/cppcheck/index.php?title=Found_bugs
功能比較強大,使用很簡單
轉自http://blog.csdn.net/summerfang/archive/2006/05/20/746216.aspx
聰明的Web開發人員會告訴你,越快找到代碼的錯誤,你就能越快修正它,長期而言,項目成本越低。好了,能最有效的檢測PHP代碼中的錯誤的工具是PHPUnit,一個開發源代碼的框架,它在你不在的時候,自動進行成套的單元測試。使用PHPUnit的好處是顯而易見的:
l 減少用于測試代碼的工作量
l 減少總體軟件缺陷
l 增加對代碼的信心
l 改善你和開發源代碼的團隊伙伴的關系
直到現在,這個流行工具唯一的問題是缺乏文檔。為了解決這個問題,O’Reilly直接找到了源頭,PHPUnit口袋書指南的作者,也是PHPUnit的創造者,Sebastian Bergmann,來解決這個問題。這本書把很多難以記憶的信息,語法,PHPUnit工作的原則,統一到一起。它也帶來了只有技術創造者才能提供的洞察力和睿智忠告。而且,本書也談到了敏捷方法和極限編程中關于測試的內容。
在O’Reilly口袋書指南最近的系列中,這本快速參考書把所有的答案都帶到了你的指尖。那些對測試PHP代碼感興趣的Web應用程序開發者,會覺得本書是一個無價的伴侶。
--------------------------------------------------------------------------------------------------------------
原文:
Overview
Smart web developers will tell you that the sooner you detect your code mistakes, the quicker you can fix them, and the less the project will cost in the long run. Well, the most efficient way to detect your mistakes in PHP is with PHPUnit, an open source framework that automates unit testing by running a battery of tests as you go. The benefits of PHPUnit are significant:
a reduction in the effort required to frequently test code
fewer overall defects
added confidence in your code
improved relations with your open source teammates
The only problem with this popular testing tool was its lack of documentation-until now, that is. For this, O'Reilly went right to the source, as Sebastian Bergmann, the author of PHPUnit Pocket Guide, also happens to be PHPUnit's creator. This little book brings together hard-to-remember information, syntax, and rules for working with PHPUnit. It also delivers the insight and sage advice that can only come from the technology's creator. Coverage of testing under agile methodologies and Extreme Programming (XP) is also included.
The latest in O'Reilly's series of handy Pocket Guides, this quick-reference book puts all the answers are right at your fingertips. It's an invaluable companion for anyone interested in testing the PHP code they write for web applications.
一、簡介:
現在我們安裝Linux的時候通常考慮到安全因素(默認情況下)是不打開telnet服務的,而ssh服務是有的,ant很早就支持telnet,但要求我們在Linux下要安裝telnet-server,并要啟用該服務。
還好自Ant1.60開始支持了SSH 及SCP 操作了,早在Ant之前若要支持SSH、SCP、SFTP等任務就必須下載j2ssh的j2ssh-ant.jar和j2ssh-core.jar(在http://www.sourceforge.net的j2ssh下有下載)。現在可以使用Ant提供的Sshexec和scp任務,由$ANT_HOME/lib/ant-jsch.jar提供支持,但是同樣你也要在http://www.jcraft.com/jsch/index.html下載一個依賴包jsch-0.1.24.jar(文件名因版本而不同),jsch同樣也是http://www.sourceforge.net下的一個項目。
你需要把下載的jsch-0.1.24拷貝到$ANT_HOME/lib下,如果是Eclipse下的Ant環境必須在Window->Preferences->Ant->Runtime->Classpath中加入jsch-0.1.24。
JSch是一個SSH2的純Java實現
JSch允許你連接到sshd server并采用端口映射, X11 映射; Scp文件傳輸等,你可以把集成JSch提供的功能到你自己的Java項目中,JSch 的授權方式為 BSD形式。
二、簡單例子:
下面是用JSch完成Sshexec和scp兩個任務的最簡單例子,如果需要更詳細的內容,請參考Ant用戶手冊
[Sshexec任務]
<BR><target name="sshexec">
<sshexec host="192.168.122.180" username="root" password="123456"
trust="true" command="cd /;ls"/>
</target>
注意上面的trust屬性一般設置為true, 如果為默認值false時,那么就要求你所連接的host必須存在于你的knownhosts文件中,并且這個文件也必須是存在的,否則會出現 com.jcraft.jsch.JSchException: reject HostKey: 192.168.122.180異常。執行Linux下的命令時可以用分號";"把多個命令隔開,它們將會依次執行,而不需要寫多個sshexec進行多次連接,每次連接只執行一個命令。
該任務的執行后輸出結果如下:
sshexec:
[sshexec] Connecting to 192.168.122.180:22
[sshexec] backup
[sshexec] bin
[sshexec] boot
[sshexec] dev
[sshexec] etc
...................
[scp任務]
1.拷貝單個文件到遠端服務器
<scp file="c:/cmd.txt" todir="root:123456@192.168.122.180:/tmp" trust="true"/>
或
<scp file="c:/cmd.txt" todir="root@192.168.122.180:/tmp" password="123456" trust="true"/>
2.拷貝遠端文件本地
<scp file="root:123456@192.168.122.180:/tmp/cmd.txt" todir="D:/my-app" trust="true"/>
3.拷貝遠端目錄到本地,將以遞歸形式操作
<scp file="root:123456@192.168.122.180:/tmp/*" todir="d:/my-app" trust="true"/>
4.拷貝本地目錄中的內容到遠端,遞歸形式,但不在服務器上建立my-app目錄
<scp todir="root:123456@192.168.122.180:/tmp/" trust="true">
<fileset dir="d:/my-app"/>
</scp>
5.拷貝一系列的文件到遠端,會建立相應的層次目錄,不建立my-app目錄
<scp todir="root:123456@192.168.122.180:/tmp" trust="true">
<fileset dir="d:/my-app">
<include name="**/*.java" />
</fileset>
</scp>
或
<scp todir="root:123456@192.168.122.180:/tmp" trust="true">
<fileset dir="d:/my-app" excludes="**/*.java"/>
</scp>
最后一個任務的執行輸出結果如下(其他略):
scp:
[scp]Connecting to 192.168.122.180:22
[scp] Sending: cmd.txt : 0
[scp] File transfer time: 0.0 Average Rate: ? B/s
[scp] Sending: pom.xml : 852
[scp] File transfer time: 0.0 Average Rate: ∞ B/s
[scp] Sending: application.properties : 142
[scp] File transfer time: 0.0 Average Rate: ∞ B/s
[scp] Sending: application.properties : 45
[scp] File transfer time: 0.0 Average Rate: ∞ B/s
[scp] Sending: test.properties : 0
[scp] File transfer time: 0.02 Average Rate: 0.0 B/s
[scp] Sending: application.properties : 153
[scp] File transfer time: 0.0 Average Rate: ∞ B/s
[scp] Sending: application.properties : 45
[scp] File transfer time: 0.0 Average Rate: ∞ B/s
[scp] done.
三、其他例子:
例子1: 例子2: |
這段ant腳本主要作用就是:自動從SVN庫拉最新的代碼,編譯、并自動部署到測試服務器。
其中用到了“antsvn” ,有3個jar包需要配置進去
<?xml version="1.0" encoding="UTF-8"?> <!-- wei.songw 2008.3.19 --> <project basedir="." name="smmail" default="auto"> <!-- all properties are in build.properties --> <property file="build.properties" /> <!--svn本身需要的運行庫 --> <path id="svnant.lib"> <pathelement location="${svnjavahl.jar}" /> <pathelement location="${svnant.jar}" /> <pathelement location="${svnClientAdapter.jar}" /> </path> <!--java EE 1.4 庫 --> <path id="javaEE1.4"> <fileset dir="${javaEE1.4.lib}"> <include name="**/*.jar" /> </fileset> </path> <!--項目的classpath庫 --> <path id="project.classpath"> <pathelement location="${build.dir}" /> <fileset dir="${lib.dir}" /> </path> <!--清理項目任務(干掉下載目錄,tomcat原來的部署文件) --> <target name="clear"> <delete dir="${work.space}" /> <delete dir="${tomcat.home}/work/Catalina/localhost/${ant.project.name}" /> <delete dir="${tomcat.home}/webapps/${ant.project.name}" /> <delete dir="${tomcat.home}/webapps/${ant.project.name}.war" /> </target> <!-- load the svn task --> <taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpathref="svnant.lib" /> <!--svn同步任務--> <target name="svn" depends="clear"> <mkdir dir="${work.space}"/> <svn username="SongWei" password="Song" javahl="false"> <checkout url="${urlRepos}" destPath="${work.space}" /> </svn> </target> <!--編譯--> <target name="compile" depends="svn" description="======compile project======"> <echo message="compile==========>${ant.project.name}: ${ant.file}" /> <mkdir dir="${build.dir}" /> <copy includeemptydirs="false" todir="${build.dir}"> <fileset dir="${java.source}" excludes="**/*.launch, **/*.java, config/*.*"/> </copy> <copy includeemptydirs="false" todir="${build.dir}"> <fileset dir="${java.config}" excludes="**/*.launch, **/*.java"/> </copy> <javac includejavaruntime="true" debug="true" debuglevel="${debuglevel}" destdir="${build.dir}" source="${source}" target="${target}" encoding="utf-8"> <src path="${java.source}" /> <exclude name="config/"/> <classpath> <path refid="project.classpath"> </path> <path refid="javaEE1.4"> </path> </classpath> </javac> <javac debug="true" debuglevel="${debuglevel}" destdir="${build.dir}" source="${source}" target="${target}" encoding="utf-8"> <src path="${java.config}" /> </javac> </target> <!--壓縮,打包--> <target name="war" depends="compile" description="======compress j2ee war file======"> <mkdir dir="${dist.dir}" /> <!--compress j2ee war file--> <war destfile="${war.file}" webxml="${web.dir}/WEB-INF/web.xml"> <fileset dir="${web.dir}" /> <classes dir="${build.dir}" /> <lib dir="${lib.dir}" /> </war> </target> <!--shutdowntomcat--> <target name="shutdowntomcat" description="========shutdowntomcat==========="> <exec executable="${tomcat.home}/bin/shutdown.sh" failonerror="false"></exec> <sleep seconds="10"/> </target> <!--startuptomcat--> <target name="startuptomcat" description="========startuptomcat==========="> <sleep seconds="5"/> <exec executable="${tomcat.home}/bin/startup.sh" failonerror="false"></exec> </target> <!--部署到tomcat下面克--> <target name="deploy" depends="war"> <copy file="${war.file}" todir="${tomcat.home}/webapps" /> </target> <!--全自動無敵部署,啟動關閉tomcat--> <target name="auto" depends="shutdowntomcat,deploy,startuptomcat"> <echo message="DONE!!!!" /> </target> </project>
下面是build.xml指定的properties文件,需要和build.xml放在同一個目錄下面 需要指定work.space(svn拉下來代碼的存放,已經編譯,打包用的臨時目錄) tomcat.home(tomcat服務器的根目錄,如果是其他服務器,需要修改對應項) =============================================== build.version=1.0.0 svnant.jar=/usr/java/svn/svnant.jar debuglevel=source,lines work.space=/home/gmail/workspace build.dir=${work.space}/WebRoot/WEB-INF/classes java.source=${work.space}/src web.dir=${work.space}/WebRoot tomcat.home=/home/gmail/tomcat6 urlRepos=svn://192.168.1.100/product/SMMAIL/Develop
svnClientAdapter.jar=/usr/java/svn/svnClientAdapter.jar
svnjavahl.jar=/usr/java/svn/svnjavahl.jar
javaEE1.4.lib=/usr/javaEE-1.4
target=1.6
source=1.6
dist.dir=${work.space}
lib.dir=${work.space}/WebRoot/WEB-INF/lib
java.config=${work.space}/src/config
resource.dir=${work.space}/resources
war.file=${dist.dir}/${ant.project.name}.war
| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
30 | 31 | 1 | 2 | 3 | 4 | 5 | |||
6 | 7 | 8 | 9 | 10 | 11 | 12 | |||
13 | 14 | 15 | 16 | 17 | 18 | 19 | |||
20 | 21 | 22 | 23 | 24 | 25 | 26 | |||
27 | 28 | 29 | 30 | 1 | 2 | 3 | |||
4 | 5 | 6 | 7 | 8 | 9 | 10 |