I currently have this in my Ant build script:
<exec dir="${basedir}" executable="perl">
<arg line="${basedir}/version.pl -major"/>
</exec>
However, when that runs, I get this error message:
[exec] Could not open -major
[exec] Result: 2
To me, that says that what I have is trying to run a file called -major, which doesn't exist. The file is version.pl which takes an argument of -major.
How can I alter this to run version.pl with the argument -major?
Note that I am running the ant script on a Solaris machine, however cross-platform or solutions for other OSes are welcome for posterity.
I made a quick little Perl script that didn't do a whole lot and ran it just fine passing command line arguments to it using Ant 1.5 on a Solaris box.
<project name="perly" basedir="." default="run">
<target name="run">
<exec executable="perl" dir="${basedir}">
<arg value="version.pl"/>
<arg value="-major"/>
</exec>
</target>
</project>
$ ant run
What I can't quite understand is how you are getting "Could not open -major". Is this a custom die message or something? Is there supposed to be a filename passed instead of major?
You can try this:
<exec executable="perl" dir="${basedir}">
<arg value="version.pl"/>
<arg value="-major"/>
</exec>
On windows that is
Try this if it works:
<exec dir="${basedir}" executable="./test.pl">
<arg line="-major"/>
</exec>
From the ant exec doc:
dir: the directory in which the command should be executed.
So i guess it does a cd to the $dir and exec the $executable (shebang set)
Related
We have a project that we compile through Ant, we had some issues people wrote code that's only compilable by eclipse compiler, not through the regular javac, so we changed the compiler by passing in the ecj* jar file when calling ant on the commend-line.
We currently decide to use Project Lombok, it looks good, and it works great on local eclipse IDE's, when it comes to compile on server through a build script, it doesn't encounter in any exception, but at run-time he could not find the getter method etc.
The lomboc.jar file is in our lib folder we specify in build.xml.
Does any body have experience with this scenario?
Thanks
UPDATE
I found a link http://projectlombok.org/setup/ecj.html that explains how to use it with ecj, but i don't understand how i could use it, because we call ant and pass in the ecj jar file in the lib argument.
Finally i figured it out.
I have to use <exec executable="java"> to compile, instead of the javac tag.
Hare is my example:
<exec executable="${env.JAVA_HOME}/bin/java">
<arg value="-javaagent:${lombok_jar}=ECJ"/>
<arg value="-cp"/>
<arg pathref="compile.classpath"/>
<arg value="-jar"/>
<arg value="${ecj_jar}"/>
<arg value="-cp"/>
<arg pathref="compile.classpath"/>
<arg value="-d"/>
<arg value="${classes}"/>
<arg value="${src}"/>
</exec>
I am writing a batch file to install features on eclipse from a local repository.
eclipse.exe -application org.eclipse.equinox.p2.director
-repository C:/repo,http://download.eclipse.org/releases/indigo/
-installIU com.app.feature.feature.group
but i am not able to detect if the operation failed or succeeded from the batch script. It seems eclipse does not set error level? Any possible workarounds?
One workaround that i found is running the command through ant exec instead of calling directly from batch file. It reports all the errors.
<exec executable="eclipse.exe" failonerror="true">
<arg value="-noSplash"/>
<arg value="-application"/>
<arg value="org.eclipse.equinox.p2.director"/>
<arg value="-repository"/>
<arg value="file:C:/repo,http://download.eclipse.org/releases/indigo/"/>
<arg value="-installIU"/>
<arg value="com.app.feature.feature.group"/>
</exec>
There was a bug in Equinox 3.6.0 (which was fixed in 3.6.1) that caused failing applications to return an exit code 0. Unless you are using that Equinox version, the p2 director application has a correct exit code.
I suppose the problem lies in how you checked the exit code in the batch script. You can check for non-zero exit codes with IF ERRORLEVEL 1 GOTO LabelOfErrorHandling.
I was trying to set PATH enviroment variable on an ant build.xml through this answer.
It works on cygwin but not on cmd or PowerShell.
Some information:
Apache Ant 1.6.5 (I know there is a newer version (1.8.4), but for internal reasons I have to use this older version)
Powershell v2.0
cmd v6.1.7601
cygwin 2.774
Windows 7
You may need to use the exec task a little differently on Windows/cmd environments.
Let's use the windows command set as an example. set will print environment variables. A normal exec task running a set command might look like:
<exec executable="set" outputproperty="set.output">
<env key="MY_VAR" value="MY_VAL"/>
<echo message="${set.output}"/>
</exec>
But using this form of the exec task should throw an IOException: The system cannont find the file specified.
When running ant under windows cmd shell, the exec task can also be invoked via cmd, like this:
<exec executable="cmd" outputproperty="set.output">
<arg line="/c set"/>
<env key="MY_VAR" value="MY_VAL"/>
<echo message="${set.output}"/>
</exec>
This is the equivalent command; the actual command executed is cmd /c set, which is running set in a cmd sub-process.
The reason why this is necessary is only a little complicated and is due to the way that the commands are located by Win32 ::CreateProcess. The ant exec docs briefly explain this.
Note that I haven't tried either of these using PowerShell, so I have no experience which, if either, will work.
In my own ant build scripts I typically have two versions of each target that require special handling for windows platforms, with an isWindows test that looks like this:
<target name="check-windows">
<condition property="isWindows">
<os family="windows"/>
</condition>
</target>
Then I can switch between versions of the same task using:
<target name="my-target-notwindows" depends="check-windows" unless="isWindows>
...
</target>
<target name="my-target-windows" depends="check-windows" if="isWindows>
...
</target>
<target name="my-target" depends="my-target-notwindows,my-target-windows">
...
</target>
Unfortunatelly was an ant bug related to 1.6.5 version. I was able to update to 1.8.4 and everything works fine.
I'm currently trying to create a Nant task for our TeamCity setup so that our UnitTests are ran through Gallio and covered by PartCover. The task looks like this:
<!-- UnitTest Configuration -->
<!-- ====================== -->
<!-- This configuration runs the tests through Gallio with MbUnit together with
PartCover to get the results of the test together with the coverage results
-->
<target name="unitTest">
<echo message="Unittesting ${AssemblyToTest}"/>
<exec program="${Paths.Tools}\PartCover\Partcover.exe" failonerror="true">
<arg line="--target "${Paths.Tools}\Gallio\Gallio.Echo.exe"" />
<arg line="--target-work-dir ${AssemblyToTestLocation}"/>
<arg line="--target-args /r:Local "${AssemblyToTest}"" />
<arg line="--include "[${Tests.TestedAssemblyName}]*"" />
<arg line="--output ${Paths.Output}\Coverage.xml" />
</exec>
</target>
The tests are running, we can see this in TeamCity, and a Coverage.xml file is generated, but empty. There's only a single line in it.
Output of the variables:-
${Paths.Tools} : C:\Robinson\Trunk\
${Tests.TestedAssemblyName} : Name of the DLL
${AssemblyToTestLocation} : Path to the DLL
Am I missing something?
EDIT
The TeamCity application is running on a Windows Server 2003 R2 Server, and all the build-agents performing the work are currently running on Windows XP Systems, all 32bit installations.
I believe we covered this issue in https://github.com/sawilde/partcover.net4/issues/46
and the solution was along the lines of
--include [${Tests.TestedAssemblyName}*]* ?
I am using following command in NAnt build file
<msbuild project="${appsdest}\${targetname}\${targetname}.sln"/>
appsdest and targetname are variable contain application project path and targetname is the variable contain project name to be rebuild.
but when using this command it build the solution but the time stamp of dlls are not updated.
I need to rebuild the solution and the latest dlls need to be place in debug folder.
can anyone tell me how to rebuild the solution using the msbuild command as written above?
Thanks
I don't use the MSBUILD tasks in NAnt, I just call the msbuild executable directly and it has worked well for me.
<target name="build">
<exec program="${MSBuildPath}">
<arg line='"${SolutionFile}"' />
<arg line="/property:Configuration=${SolutionConfiguration}" />
<arg value="/target:Rebuild" />
<arg value="/verbosity:normal" />
<arg value="/nologo" />
<arg line='/logger:"C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll"'/>
</exec>
</target>
I write more about it here: http://enterpriseyness.com/2009/12/continuous-integration-with-cruise-control-net-nant
You need to use the 'Rebuild' target:
<msbuild project="${appsdest}\${targetname}\${targetname}.sln" target="Rebuild"/>