I have a build.xml file for ant, and I want to modify a directory from
<condition property="flex_sdk" value="%cd%/SDK/flex_sdk/">
<os family="windows" />
</condition>
to
<condition property="flex_sdk" value="../SDK/flex_sdk/">
<os family="windows" />
</condition>
The flex_sdk bin directory has .bat files so they are run using cmd /c. I get the error "'..' is not recognized as an internal or external command".
Any help is greatly appreciated.
Thanks.
Maybe you could try this :
<property name="bat.dir" location="${flex_sdk}"/>
The location attribute if specified in a property resolves relative paths based on the ${basedir} which is the directory of your ant build.xml file.
Related
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.
Is it possible to set a property value in Ant property files (as opposed to build.xml) in a conditional way? For example, if apache.root property is set - the my_property will be ${apache.root}/myapp, /var/www/myapp otherwise. If not, what would be the common practice - reusable build.xml files?
Use the condition task:
<project name="demo" default="run">
<condition property="my_property" value="${apache.root}/myapp" else="/var/www/myapp">
<isset property="apache.root"/>
</condition>
<target name="run">
<echo message="my_property=${my_property}"/>
</target>
</project>
You can include different property files based on environments or the conditional variables. For example
<echo>Building ${ant.project.name} on OS: ${os.name}-${os.arch}</echo>
<property file="build-${os.name}.properties" />
this would include a file named 'build-Windows 7.properties' or 'build-Linux.properties' depending on where the build is being run. Of course the property directive looks in the current directory as well as home directory. So the property file could be a part of the build source or in the home directory of the build account.
You can use the condition tag to generate part of the name of the property file as well to select
One of the simplest form of condition you can use is:
<exec executable="hostname" outputproperty="hostname"/>
<condition property="python" value="/usr/bin/python3.4">
<equals arg1="${hostname}" arg2="host0"/>
</condition>
<property name="python" value="/usr/bin/python"/>
to accommodate different python installation path for example. Here, default install path is /usr/bin/python except for host0 where it /usr/bin/python3.4
The OP was asking about a properties file, not within the ant build file. Unfortunately conditionals cannot be done from within the build file. What you can do is have separate property files for each set of dependant properties. For instance:
Build.xml
<condition property="app.name" value="appA">
<equals arg1="${appName}" arg2="A" />
</condition>
<condition property="app.name" value="appB">
<equals arg1="${appName}" arg2="B" />
</condition>
<property file="${app.name}.properties" />
<!-- since properties are immutable, set your defaults here -->
<property name="apache.root" value="/var" />
<property file="restOfProps.properties" />
appA.properties
apache.root=/appA
restOfProps.properties
my_property=${apache.root}/myapp
I want to use resolvers (ssh) which are dependant on ant classpath.
Something like
<resolvers>
...
<ssh ...
...
</resolvers>
To use it I need jsch in ant classpath. Ant script should depends only on common lib (which also includes resolved jsch dependencies) - to use it on any client PC. Scenario is:
task to download lib.
Extract libs (jsch and etc.)
ivy:configure
But ivy:configure does not have any classpathref param, so it is unclear for me how to load jars I extracted.
Is it possible?
Or, probably, somehow run ant again internally with extended classpath?
Ok,
so my comment to question looked good for me but at the end it did not work.
The only way I found (working way I mean) is to to run ant script with
Download common-lib (with ) which includes all jar-libs required for optional ivy processing
Construct new classpath and run exec on same build file with required target:
<target name="call.task" if="wrapped.task.name">
<path id="ant.class.path">
<fileset dir="${tools.lib.dir}" >
<include name="*.jar" />
</fileset>
<pathelement location="${java.class.path}" />
</path>
<condition property="append.dest.dir" value="-Ddest.dir=${dest.dir}" else="">
<isset property="dest.dir"/>
</condition>
<exec executable="ant" failonerror="true">
<arg line="-f ivy-build.xml" />
<arg line='-lib "${toString:ant.class.path}"' />
<arg value="${wrapped.task.name}" />
<arg value="${append.dest.dir}" />
</exec>
</target>
I have an ant target I don't want called unless I am running ant on Linux (Not called on Windows)
<target name="jar.all" depends="clean,compile.nic,jar,jar.resources"/>
The target that I don't want called on Windows is: compile.nic
How can I do this?
Insert an if property to your compile.nic target.
<target name="compile.nic" if="windowsos">
And use this conditions before running your target
<condition property="windowsos">
<os family="windows" />
</condition>
<condition property="linuxos">
<os family="unix" />
</condition>
Here is a real-world example for Windows vs. UNIX commands. The ELSE improves on previous answers.
<condition property="maven.executable" value="mvn.bat" else="mvn">
<os family="windows" />
</condition>
<target name="clean">
<exec executable="${maven.executable}">
<arg value="clean" />
</exec>
</target>
Can I make the Ant copy task OS-specific?
Additionally some tasks support os attribute. for example exec:
<exec executable="cmd" os="windows"/>
You can use the os condition to set a property, and then skip your target by adding either the if or unless attributes (depending on how you define your property)
I have an Ant script that performs a copy operation using the 'copy' task. It was written for Windows, and has a hardcoded C:\ path as the 'todir' argument. I see the 'exec' task has an OS argument, is there a similar way to branch a copy based on OS?
I would recommend putting the path in a property, then setting the property conditionally based on the current OS.
<condition property="foo.path" value="C:\Foo\Dir">
<os family="windows"/>
</condition>
<condition property="foo.path" value="/home/foo/dir">
<os family="unix"/>
</condition>
<fail unless="foo.path">No foo.path set for this OS!</fail>
As a side benefit, once it is in a property you can override it without editing the Ant script.
The previously posted suggestions of an OS specific variable will work, but many times you can simply omit the "C:" prefix and use forward slashes (Unix style) file paths and it will work on both Windows and Unix systems.
So, if you want to copy files to "C:/tmp" on Windows and "/tmp" on Unix, you could use something like:
<copy todir="/tmp" overwrite="true" >
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</copy>
If you do want/need to set a conditional path based on OS, it can be simplified as:
<condition property="root.drive" value="C:/" else="/">
<os family="windows" />
</condition>
<copy todir="${root.drive}tmp" overwrite="true" >
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</copy>
You could use the condition task to branch to different copy tasks... from the ant manual:
<condition property="isMacOsButNotMacOsX">
<and>
<os family="mac"/>
<not>
<os family="unix"/>
</not>
</and>
Declare a variable that is the root folder of your operation. Prefix your folders with that variable, including in the copy task.
Set the variable based on the OS using a conditional, or pass it as an argument to the Ant script.
You can't use a variable and assign it depending on the type? You could put it in a build.properties file. Or you could assign it using a condition.
Ant-contrib has the <osfamily /> task. This will expose the family of the os to a property (that you specify the name of). This could be of some benefit.