Wednesday, August 19, 2009

Executing maven test with the ant run plugin--A Real experiance.

Few days back i got a unexpected result with using the maven ant run task with a patch i submitted for the unit tests for the SMS Transport(which is my GSoC project).So i thought it would be useful if i blog my experiance and how i solved that issue.

So i'll start with my xml segment in the pom.

<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-antrun-plugin</artifactid>
<executions>
<execution>
<id>build-repo</id>
<phase>test-compile</phase>
<configuration>
<tasks>
<mkdir dir="target/test-resources/samples/conf">
<mkdir dir="target/test-resources/samples/repository/modules">
<mkdir dir="target/test-resources/samples/repository/services">
<mkdir dir="target/test-resources/samples/repository/services/SampleService/org/apache/axis2/transport/sms">
<mkdir dir="target/test-resources/samples/repository/services/SampleService/META-INF">
<copy file="${settings.localRepository}/org/apache/axis2/addressing/${axis2.version}/addressing-${axis2.version}.mar" tofile="target/test-resources/samples/repository/modules/addressing.mar">
<copy file="target/test-classes/org/apache/axis2/transport/sms/SimpleInOutMessageReceiver.class" tofile="target/test-resources/samples/repository/services/SampleService/org/apache/axis2/transport/sms/SimpleInOutMessageReceiver.class">
<copy file="conf/axis2.xml" tofile="target/test-resources/samples/conf/axis2.xml">
<copy file="repository/services/SampleService/META-INF/MANIFEST.MF" tofile="target/test-resources/samples/repository/services/SampleService/META-INF/MANIFEST.MF">
<copy file="repository/services/SampleService/META-INF/services.xml" tofile="target/test-resources/samples/repository/services/SampleService/META-INF/services.xml">
</copy>
</copy>
<goals>
<goal>run</goal>
</goals>
</copy>
</copy>
</copy>

</mkdir></mkdir></mkdir></mkdir></mkdir></tasks></configuration></execution></executions></plugin>
As you see there is only some mkdir and copy tasks listed in the test-compile phase

So When I run the tests test where executed successfully(mvn clean install / mvn test)
And also when i skip the tests with mvn clean install -Dtest=false the build was successful.

The problem comes when i try to skip the test with mvn clean install -Dmaven.test.skip=true
when i do that follwing error appiers

[ERROR] BUILD ERROR
[INFO] ------------------------------
------------------------------------------
[INFO] An Ant BuildException has occured: Warning: Could not find file /home/charith/projects/transport/modules/sms/target/test-classes/org/apache/axis2/transport/sms/SimpleInOutMessageReceiver.class to copy.

So If you look in to the ant run plugin the copy tasks are listed in the "test-compile" phase so its seems correct to assume that those tasks will not execute when we skip the tests.And it seems that assumption is correct when we use the -Dtest=false.But that assumption fails with we run with -Dmaven.test.skip=true

The reason for this error is the .class file that the copy task trying to copy created after compiling the test sources.but when we use -Dmaven.test.skip=true to skip the tests it will execute the tesks that are listed in the test-compile phase .So it reports the Error.

to overcome that case i had to add the system variable check to the task.Now it will check for the maven.test.skip variable before executing the test.So if it is true it will not execute the tasks in the test-compile phase.Following this the modified pom which resolved the issue.




<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-antrun-plugin</artifactid>
<executions>
<execution>
<id>build-repo</id>
<phase>test-compile</phase>
<configuration>
<tasks unless="maven.test.skip">
<mkdir dir="target/test-resources/samples/conf">
<mkdir dir="target/test-resources/samples/repository/modules">
<mkdir dir="target/test-resources/samples/repository/services">
<mkdir dir="target/test-resources/samples/repository/services/SampleService/org/apache/axis2/transport/sms">
<mkdir dir="target/test-resources/samples/repository/services/SampleService/META-INF">
<copy file="${settings.localRepository}/org/apache/axis2/addressing/${axis2.version}/addressing-${axis2.version}.mar" tofile="target/test-resources/samples/repository/modules/addressing.mar">
<copy file="target/test-classes/org/apache/axis2/transport/sms/SimpleInOutMessageReceiver.class" tofile="target/test-resources/samples/repository/services/SampleService/org/apache/axis2/transport/sms/SimpleInOutMessageReceiver.class">
<copy file="conf/axis2.xml" tofile="target/test-resources/samples/conf/axis2.xml">
<copy file="repository/services/SampleService/META-INF/MANIFEST.MF" tofile="target/test-resources/samples/repository/services/SampleService/META-INF/MANIFEST.MF">
<copy file="repository/services/SampleService/META-INF/services.xml" tofile="target/test-resources/samples/repository/services/SampleService/META-INF/services.xml">
</copy>
</copy>
<goals>
<goal>run</goal>
</goals>
</copy>
</copy>
</copy>

</mkdir></mkdir></mkdir></mkdir></mkdir></tasks></configuration></execution></executions></plugin>
As you see the only change is tasks unless="maven.test.skip" in the task element which check !(maven.test.skip)

the follwing xml segment is logically equal to

if(!(maven.test.skip)) {
//execute task
}


<tasks unless="maven.test.skip">
After this system variable check I was successful with running the tests with -Dtest=false , -Dmaven.test.skip=true.

Monday, August 17, 2009

Chandi jaisa rang hai tera- My favorite Gazal

Gazal is a beautiful Hindustan music style which have lot of great songs.the most important thing about gazal style is most of the songs can be enjoyed even without having a classical music background.Most of the gazals are written about romance.It carries "Srungara Rasa" with it.

The Gazal song Chandi jaisa rang hai thera is a gazal that admire the beauty the girl that he loves.

Chandi jaisa rang hai tera, sone jaise baal
Ek tuhi dhanvaan hai gori, baaki sub kangaal
Chandi jaisa rang hai tera, sone jaise baal
Ek tuhi dhanvaan hai gori, baaki sub kangaal
Ek tuhi dhanvaan hai gori, baaki sub kangaal

Jis reste se tu gujre, voh phoolon se bhar jaye
Jis reste se tu gujre, voh phoolon se bhar jaye
Tere pair ki komal aahat sote bhaag jagaye
Jo patthar choo le gori tu voh heera ban jaye
Tu jisko mil jaye voh, tu jisko mil jaye
Vo ho jaye malamal
Ek tuhi dhanvaan hai gori, baaki sub kangaal
Chandi jaisa rang hai tera, sone jaise baal
Ek tuhi dhanvaan hai gori, baaki sub kangaal

Jo be-rang ho us par kya kya rang jamate log
Jo be-rang ho us par kya kya rang jamate log
Tu naadaan na jane kaise roop churate log
Nazaren bhar bhar dekhen tujhko aate jaate log
Chail chabeeli rani thoda, Chail chabeeli rani thoda
ghoonghat aur nikaal
Ek tuhi dhanvaan hai gori, baaki sub kangaal
Chandi jaisa rang hai tera, sone jaise baal
Ek tuhi dhanvaan hai gori, baaki sub kangaal

Dhanak ghata kaliyan aur tare sub hain tere roop
Dhanak ghata kaliyan aur tare sub hain tera roop
Ghazalen hon ya geet hon mere sub mein tera roop
Yunhi chamakti rahe hamesha tere husn ki dhoop
Tujhe nazar na lage kisi ki
Tujhe nazar na lage kisi ki
Jiye hazaron saal
Ek tuhi dhanvaan hai gori, baaki sub kangaal
Chandi jaisa rang hai tera, sone jaise baal
Ek tuhi dhanvaan hai gori, baaki sub kangaal
Chandi jaisa rang hai tera, sone jaise baal
Ek tuhi dhanvaan hai gori, baaki sub kangaal
Ek tuhi dhanvaan hai gori, baaki sub kangaal
Ek tuhi dhanvaan hai gori, baaki sub kangaal