Ant can't find a executable in the Windows path - ant

I got a simple ant target :
<target name="doxygen">
<exec executable="doxygen" dir="${basedir}/doxygen">
<arg value="Doxyfile" />
</exec>
</target>
I'm on Windows Seven.
When i try the same command line ( doxygen Doxyfile ) in the Windows console, it works perfectly. The doxygen executable can by found because i added the good path in my PATH environment variable.
But ANT juste can't find the doxygen executable and i get the following error :
build.xml:83: Execute failed: java.io.IOException: Cannot run program "doxygen.exe" : CreateProcess error=2
How can i make ANT to use the Windows PATH environment variable ?
I already tried the searchpath property, but i don't works.

You want to find where Doxygen is currently installed on your system. Then make a property with that value, so it can be overridden by people that installed doxygen somewhere else.
<property name="doxygen.path" location="C:\Program Files\Doxygen"/>
<target name="doxygen">
<exec executable="${doxygen.path}/doxygen" dir="${basedir}/doxygen">
<arg value="Doxyfile" />
</exec>
</target>

Related

Jenkins cannot execute webpack from ant script

I am trying to execute an Ant script through jenkins but it fails when it attempts to use webpack...
The ant script's execution task is the following:
<exec executable="webpack.cmd" failonerror="true">
<env key="PROD_ENV" value="true"/>
</exec>
where webpack.cmd has been installed as a global npm module. The module directory has been included in the Path variable and I have even made sure that Jenkins is actually able to see it by doing a trial run inside a Execute windows batch command build step. However when it attempts to execute it via Ant it fails. Could it be a problem with the Ant plugin and its version?
The error i'm getting is the following:
Execute failed: java.io.IOException: Cannot run program "webpack.cmd": CreateProcess error=2, The system cannot find the file specified
webpack.cmd needs to run in a command shell. Try...
<exec executable="cmd" failonerror="true">
<env key="PROD_ENV" value="true"/>
<arg value="/c"/>
<arg value="webpack.cmd"/>
</exec>
You may need to provide the full absolute path to webpack.cmd so cmd.exe can find it.

Terminal command works, but not when I run it in Ant

I can run the following terminal command just fine:
security cms -D -i ../MyMobileProvision.mobileprovision > provision.plist
However, when I run it in Ant, from an ant script in the exact same directory, terminal claims the provisioning file doesn't exist and it creates an empty file for provision.plist, which screws up the next step in my process. The ant code looks like this:
<exec executable="security">
<arg line="cms -D -i ../MyMobileProvision.mobileprovision > provision.plist" />
</exec>
Am I missing something about how ant works? I'm no expert at build scripts but I can use ../ syntax to import properties files just fine, so I'm confused why a relative path isn't working for a terminal command that otherwise would work fine with it.
In your terminal command example, the snippet...
> provision.plist
...is interpreted by your shell as a redirect command.
The <exec> task of Ant doesn't use a shell to execute commands. Instead, the > provision.plist is passed unmodified to the security program.
To get what you want, use the output attribute of <exec>. output is the name of a file where <exec> will write the output:
<exec executable="security" output="provision.plist">
<arg value="cms" />
<arg value="-D" />
<arg value="-i" />
<arg value="../MyMobileProvision.mobileprovision" />
</exec>
In the above example, I've replaced the <arg line="..."> with several <arg value="..."> elements. The reasoning from the Ant documentation on Command-line Arguments:
It is highly recommended to avoid the line version when possible. Ant will try to split the command line in a way similar to what a (Unix) shell would do, but may create something that is very different from what you expect under some circumstances.

Apache Ant: Unable to call Composer's vendor/bin scripts

I am using Apache Ant for my builds. I have some composer scripts belonging to several vendors in vendor/bin folder. I have added this folder to the system path and if I run the commands on my command window in works but in the build file i get an error.
Is there anything I should be doing differently? Before is an example:
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProject" default="build" basedir=".">
<target name="phpcpd" description="Find duplicate code using PHPCPD">
<exec executable="phpcpd">
<arg value="--version" />
</exec>
</target>
</project>'
I get this when I run ant phpcpd
phpcpd:
BUILD FAILED
C:\xxxxxx\xxxxxxx\build.xml:96: Execute failed: java.io.IO Exce
ption: Cannot run program "phpcpd": CreateProcess error=2, The system
cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Jav
a13CommandLauncher.java:41)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:428)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:442)
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:628)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:669)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:495)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
...
But phpcpd --version works on command prompt
ANT is not aware where phpcpd is as it doesn't share path with your Command Promt.
One way around it is to create a .bat file to run phpcpd
Create a phpcpd.bat with the following:
#echo off
phpcpd --version
Your build scripts to be updated from :
<exec executable="phpcpd">
<arg value="--version" />
</exec>
To: <exec executable="phpcpd.bat"/>
Above assumed with Windows Command Promt
My solution was to use the .phar files of the scripts. That way, the build file became platform independent to a large extent. So
<target name="phpcpd" description="Find duplicate code using PHPCPD">
<exec executable="phpcpd">
<arg value="--version" />
</exec>
</target>
Became:
<target name="phpcpd" description="Find duplicate code using PHPCPD">
<exec executable="php">
<arg value="${phpcpd}" />
<arg value="--version" />
</exec>
</target>
Where ${phpcpd} is the path to the phar file
I'm using absolute paths and a configurable executable.properties like this:
build.xml
<project name="build">
<property file="executable.properties" />
<target name="run-phpcd" unless="${phpcpd.skip}">
<exec executable="${phpcpd.executable}"><!-- .. --></exec>
</target>
</project>
executable.dist.properties
phpcpd.skip = no
#phpcpd.executable = C:\path\to\phpcpd.bat
phpcpd.executable = /path/to/phpcpd.sh
Both files can be committed to your VCS, for usage copy the template file (*.dist.properties) and rename it to executable.properties. Add this file to the ignore list of your VCS.

Can ANT parametrize InnoSetup script?

The final step of building our java application (using ANT script) involves Inno Setup to package everything in a nice windows installer.
We are now upgrading our ANT script to generate both a 32-bit and a 64-bit version of our application. Our question is thus: how can we parametrize our Inno Setup config file so that it can generate both a x86 and a x64 version (it would thus be called 2x by the ANT script, with a parameter indicating the x86/x64).
In the Inno Setup config file, there is only 1 line that needs to be changed based on this parameter:
ArchitecturesInstallIn64BitMode=x64
And this is how we call Inno Setup command line from ANT:
<exec executable="C:\Program Files (x86)\Inno Setup 5\iscc.exe">
<arg value="/cc" />
<arg value="${dir.create_setup}/CreateSetup.iss" />
</exec>
Any help / hint on how to do this would be greatly appreciated !
Thanks,
Thomas
Use copy task with filtering, may be used for other dynamic values also.
your iss configfile template has :
ArchitecturesInstallIn64BitMode=#32or64#
your build.xml has :
<filter token="32or64" value="${32or64}"/>
<copy file="foobar.iss" tofile="foobaz.iss" filtering="true" overwrite="true"/>
<exec executable="C:\Program Files (x86)\Inno Setup 5\iscc.exe">
<arg value="/cc" />
<arg value="foobaz.iss" />
</exec>
then start your ant file with userproperty 32or64 like that :
ant -f build.xml -D32or64=x64
or
ant -f build.xml -D32or64=x86
copy task with filtering will replace the token #32or64# with the value of userproperty 32or64, so foobaz.iss has either :
ArchitecturesInstallIn64BitMode=x64
or
ArchitecturesInstallIn64BitMode=x86

Ant build using thrift fails with Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

What I want to do is:
<exec executable="thrift" dir="${thriftsrc}">
<arg value="--gen java"/>
<arg value="-out ${src}"/>
<arg value="mqlServer.idl"/>
</exec>
I have copied thrift.exe in C:\Windows\System32\ so the file is definitely in the PATH. I have tried several executable Arguments, full path, with and without .exe but it is not working in any variant.
But this is working very well:
<exec executable="perl" dir="${generators}">
<arg value="compactTalib.pl"/>
<arg value="${talibsrc}"/>
</exec>
Any Ideas how I can get my thirft compiler invoked in my ant build?
First, go to a DOS prompt and type in "thrift". Does it "work"? I'd expect it to give you an error, but at least find the exe. If it doesn't find the exe, solve that problem before going back to Ant.
Second, echo ${thriftsrc} in Ant. Is that C:\Windows\System32? If not, omit the dir argument. It's optional so you might remove it anyway and just use the path.
Finally, I see another problem that you haven't hit yet. This is going to get passed in as a single parameter "--gen java".
<arg value="--gen java"/>
The relevant part of the doc is:
is a single command-line argument containing a
space character, not separate commands "-l" and "-a".
This is likely how the thrift command should be called:
<exec executable="thrift" dir="${thriftsrc}">
<arg value="--gen"/>
<arg value="java"/>
<arg value="-out"/>
<arg value="${src}"/>
<arg value="mqlServer.idl"/>
</exec>
Also, consider adding failonerror to your <exec> task:
<exec executable="thrift" dir="${thriftsrc}" failonerror="yes">
This will cause the Ant script to end with an error message which will help with troubleshooting.

Resources