Terminal command works, but not when I run it in Ant - 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.

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.

What does the "-c" mean in an ant exec task?

These are two ant tasks:
<target name="hg.add" >
<exec dir="." executable="hg">
<arg line="add ${reports-summary}" />
</exec>
</target>
<target name="hg.add">
<exec executable="/bin/sh">
<arg value="-c"/>
<arg value="hg add ${reports-summary}"/>
</exec>
</target>
This two tasks seem to have the same function. But why the second one needs to write"/bin/sh" and "-c"?
The -c is just an argument to the executable it does not mean anything special to the ant exec task.
The first target is running the hg executable directly.
The second target is running the Linux/Unix shell command (/bin/sh) and passing it the -c argument which tells the shell to execute a command given in the next argument. So this will run the same command as the first target, but the shell command may set up things like environment variables before running the command.

Ant can't find a executable in the Windows path

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>

blackberry build using hudson signing automation not at configure page but inside the build

I know the automation of signature for blackberry app, as "java -jar ..signaturetool.jar....",
when I am building using hudson, i have to give at project config page by calling execute windows batch command ant task.
But am writing a build which is common for different clients, that time i want to include
this automation of signing within the build,as my app name will be changed according to the client's name and the path will be changed, so i want to execute this command line within the build, i tried this, but not working, its not executing the exec ant task.
Can anyone help me where am missing, this is the code:
<property name="signpath" location="C:/Program Files/Research In Motion/BlackBerry JDE 5.0.0/bin/SignatureTool.jar"/>
<exec executable ="cmd" os="Windows XP" >
<arg line="java -jar ${signpath} -a -c -p pswd ${codfilepath}/${uid}/${uName}_${version}_${server}.cod"/>
</exec>
I use the following ANT target for signing. It requires the use of bb_ant_tools (which seems to be an industry standard, at least among stackoverflow users).
<target name="sign" depends=""
description="Signs the final COD file by calling the BlackBerry signing server. The password is stored in the common.properties file." >
<sigtool
codfile="${cod.output.dir}/${project.output}.cod"
jdehome="${sigtool.jde}"
password="${sigtool.password}"
/>
</target>
All the parameters are stored in various properties files (I recommend keeping your signature password in a separate properties file to the rest of your project settings).
I would recommend this approach, since bb_ant_tools offers many useful features.
As to why the exec isn't working, I have had problems with exec when putting all parameters in one tag.
Try something like:
<exec executable="java" >
<arg value="-jar" />
<arg value="${signpath}" />
<arg value="-a" />
<arg value="-c" />
<arg value="-p" />
<arg value="pswd " />
<arg value="${codfilepath}/${uid}/${uName}_${version}_${server}.cod" />
</exec>
In my experience, each "space" character in the command line means you need to add a new <arg value="...." /> line to the script. ymmv.

Sourcing a shell profile in an ant build file?

I am using cruisecontrol and ant to build some legacy executables that also depend on a shell profile to setup env vars properly. Is there a way to exec this profile using ant in the current process so the makefiles ant calls get the env vars correctly?
Another solution would be if there is a way to add the profile sourcing to the sub make files I'm calling.
Edit: I guess I wasn't clear in my question. I know what env varibles need to be passed to make using the exec/env tasks. However, I don't know how to have ant grab the values from a shell profile that is usually sourced via: . /usr/local/profile/foo.profile
I figured out how to do it based off of how ant itself sources env variables.
<exec executable="ksh" dir="${foo.dir}"
failonerror="true" output="${foo.dir}/env.properties">
<arg value="-c" />
<arg value=". /usr/local/profiles/profile.foo; set" />
</exec>
<property file="${foo.dir}/env.properties" prefix="env"/>
Further down I can then pass them to sub make calls using the exec tags. For example:
<exec executable="make" dir="${bar.dir}" failonerror="true">
<env key="ORACLE_HOME" value="${env.ORACLE_HOME}" />
</exec>
You will not be able to execute make in the current process.
Take a look at the ant <exec> task, use this to execute your make build. The environment variables will still be available for the make process, in fact you can turn this off explicitly with the newenvironment attribute. The following simple exec should retain all environment variables in make:
<exec executable="make" />
If you need extra environment variables, or want to maintain them through your ant build you can use them in the exec task by adding <env> elements like so:
<exec executable="make" >
<env key="ENV_KEY" value="ENV_VALUE"/>
</exec>

Resources