Can someone tell from where the build script is taking $env variable value?. Dont find anything in the ant build script.
<if>
<or>
<equals arg1="${env}" arg2="test"/>
<equals arg1="${env}" arg2="dev"/>
</or>
<then>
Probably the script is designed to run with additional properties. From the command line for example, like:
ant -Denv=test
Related
I am new to Ant and any help will be appreciated.
What I want to do is:
<target name="run-tenantManagement" depends="jar"
description="Running TestNG Tests">
<if> ... SIMV3.1 env variable set
<property name="output.dir.name" value="tenantManagementV3"/>
<else>
<property name="output.dir.name" value="tenantManagement"/>
</if>
</target>
Basically I am setting one env variable
setenv SIMV3.1 true
I want to put a check in the Ant target if this variable is set and has value=true, then set output.dir.name to a particular value, else set it to another value.
Kindly help. I have googled through many Ant tutorials but everything seems ambiguous.
There's a few ways to do this, for example using an Ant <condition> task:
<property environment="env" />
<condition property="output.dir.name" value="tenantManagementV3"
else="tenantManagement">
<istrue value="${env.SIMV3.1}" />
</condition>
There are a number of other tests you can use and combine in the task, see Conditions for the list.
Also: I'd avoid using an environment variable name with an embedded dot - it won't work in all shells.
my app-builder ant task is like that:
<target name="build.app" depends="eval.dev.params, prepare.app, install.plugin.pay">
<exec executable="/usr/sbin/ipconfig" outputproperty="ip.addr" osfamily="mac">
<arg value="getifaddr"/>
<arg value="en0"/>
</exec>
<condition property="current.ip" value="${server.path}">
<not>
<equals arg1="${build.env}" arg2="dev"/>
</not>
</condition>
<condition property="current.ip" value="http://${ip.addr}:${server.port}">
<equals arg1="${build.env}" arg2="dev"/>
</condition>
<echo message="${current.ip}"/>
<app-builder applicationFolder="${build.path}/${context.root}"
nativeProjectPrefix="${context.root}" outputFolder="${build.path}"
worklightserverhost="${worklight.server.host}"/>
</target>
The problem is that after this step I get two xcodeprojects instead of one and the ios build then fails and I don't know how to inspect "app-builder" work.
The two resulting xcode projects are named this way:
/workspace/kWallet/build/myAppEnv/iphone/native/myAppMyAppIphone.xcodeproj
/workspace/kWallet/build/myAppEnv/iphone/native/myAppEnvMyAppIphone.xcodeproj
Are you sure that they both are being build by ant???
The myAppMyAppIphone.xcodeproj, by looking at name format, is the one built by the ant utility and the other myAppEnvMyAppIphone.xcodeproj was built by eclipse.
When you use eclipse to build the ios env it uses the format
<project><app><env>.xcodeproj
where as ant uses the format
<app><app><env>.xcodeproj
<app-builder applicationFolder="${build.path}/${context.root}"
nativeProjectPrefix="${context.root}" outputFolder="${build.path}"
worklightserverhost="${worklight.server.host}"/>
If you provide the nativeProjectPrefix to be the projectname then we get the xcode file name as same.
I have an ANT build file which has the line-
<java classname="arq.sparql" fork="true" outputproperty="javaresult" errorproperty="javaerror">
Now I want add the condition to fail the build of the property 'javaerror' is not empty.
So I have the condition written like this :
<fail message="${javaerror}">
<condition>
<not>
<equals javaerror=""/>
</not>
</condition>
</fail>
But this did not work, can you please help.
Kind regards
Som
Your equals condition has the wrong syntax, it will work like that :
<fail message="${javaerror}">
<condition>
<not>
<equals arg1="${javaerror}" arg2=""/>
</not>
</condition>
</fail>
see Ant manual conditions for details
-- EDIT --
Alternatively you could use the new if/unless feature introduced with Ant 1.9.1 but you should use Ant 1.9.3 because of bugs in Ant 1.9.1 see this answer for details
<project xmlns:if="ant:if" xmlns:unless="ant:unless">
<property name="javaerror" value="whatever"/>
<fail message="${javaerror}" unless:blank="${javaerror}"/>
</project>
You're looking for
<fail message="failed" if="javaerror"/>
Fail ant task doc
I would like my Ant task to fail if a variable it uses is not defined. E.g. currently
<mkdir dir="${some.dir}"/>
always succeeds, if some.dir is defined, it creates a directory under the variable's value, if not it creates a directory named literally ${some.dir}.
Is there a way and how to switch between the currently lenient and a more strict mode of resolving variables in Ant? I am running this in Eclipse.
<fail unless="some.dir"/>
<mkdir dir="${some.dir}"/>
or
<fail>
<condition>
<not>
<isset property="some.dir"/>
</not>
</condition>
</fail>
<mkdir dir="${some.dir}"/>
I am a newbie in Ant. My ant script receives a user input variable named "env" from command line:
e.g. ant doIt -Denv=test
The user input value could be "test","dev" or "prod".
I also have the "doIt" target:
<target name="doIt">
//What to do here?
</target>
In my target, I would like to create the following if else condition for my ant script:
if(env == "test")
echo "test"
else if(env == "prod")
echo "prod"
else if(env == "dev")
echo "dev"
else
echo "You have to input env"
That's to check which value user has inputted from command line, then, print a message accordingly.
I know with ant-Contrib, I can write ant script with <if> <else> . But for my project, I would like to use pure Ant to implement if else condition. Probably, I should use <condition> ?? But I am not sure how to use <condition> for my logic. Could some one help me please?
You can create few targets and use if/unless tags.
<project name="if.test" default="doIt">
<target name="doIt" depends="-doIt.init, -test, -prod, -dev, -else"></target>
<target name="-doIt.init">
<condition property="do.test">
<equals arg1="${env}" arg2="test" />
</condition>
<condition property="do.prod">
<equals arg1="${env}" arg2="prod" />
</condition>
<condition property="do.dev">
<equals arg1="${env}" arg2="dev" />
</condition>
<condition property="do.else">
<not>
<or>
<equals arg1="${env}" arg2="test" />
<equals arg1="${env}" arg2="prod" />
<equals arg1="${env}" arg2="dev" />
</or>
</not>
</condition>
</target>
<target name="-test" if="do.test">
<echo>this target will be called only when property $${do.test} is set</echo>
</target>
<target name="-prod" if="do.prod">
<echo>this target will be called only when property $${do.prod} is set</echo>
</target>
<target name="-dev" if="do.dev">
<echo>this target will be called only when property $${do.dev} is set</echo>
</target>
<target name="-else" if="do.else">
<echo>this target will be called only when property $${env} does not equal test/prod/dev</echo>
</target>
</project>
Targets with - prefix are private so user won't be able to run them from command line.
If any of you require a plain if/else condition (without elseif); then use the below:
Here I am dependent on a env variable DMAPM_BUILD_VER, but it may happen that this variable is not set in the env. So I need to have mechanism to default to a local value.
<!-- Read build.version value from env variable DMAPM_BUILD_VER. If it is not set, take default.build.version. -->
<property name="default.build.version" value="0.1.0.0" />
<condition property="build.version" value="${env.DMAPM_BUILD_VER}" else="${default.build.version}">
<isset property="env.DMAPM_BUILD_VER"/>
</condition>