In a previous project we simply used: <property file="${os.name}.properties"/>
The space in the name is not a problem. The os's used were: "Windows 2000", "Windows XP", "Windows NT", "Linux", "HP-UX" and "SunOS". The windows properties were mostly copies of each other, but there were on or two differences.
If you just want a property file for windows like oses and one for the rest you could do. <condition property="iswindows"> <os family="windows"/> </condition>
<target name="init" depends = "windows.init, other.init"/> <target name="windows.init" if="iswindows"> <property file="windows.properties"/> </target> <target name="others.init" unless="iswindows"> <property file="notwindows.properties"/> </target>
or: <condition property="properties.filename" value="windows.properties"> <os family="windows"/> </condition> <property name="properties.filename" value="notwindows.properties">
<property file="${properties.filename}"/>
Using ant-contribs <if/> would make a target/property free control structure: <if> <os family="windows"/> <then> <property file="windows.properties"/> </then> <else> <property file="notwindows.properties"/> </else> </if>
Peter
[EMAIL PROTECTED] wrote:
All,
How can I improve the following code in ant?
Thanks
B.
<target name="all" depends="dist" /> - <target name="set">
- <condition property="isLinux">
<os name="Linux" /> </condition>
- <!-- needs code for testing other windows platforms. --> - <condition property="isWindows">
<os name="Windows XP" /> </condition>
</target>
- <target name="checkwindows" depends="set" if="isWindows">
<echo message="test1: ${isWindows} it is windows" /> <loadproperties srcfile="Windows.properties" /> </target>
- <target name="checklinux" depends="set" if="isLinux">
<echo message="test2: ${isLinux} it is linux" /> <loadproperties srcfile="Linux.properties" /> </target>
<target name="os_check" depends="checklinux, checkwindows" /> - <target name="clean" depends="os_check">
----- Original Message ----- From: "Conor MacNeill" <[EMAIL PROTECTED]>
To: "Ant Users List" <[EMAIL PROTECTED]>
Sent: Thursday, January 15, 2004 6:31 PM
Subject: Re: os.name for windows return "Windows XP"?
On Fri, 16 Jan 2004 12:24 pm, [EMAIL PROTECTED] wrote:
Hi,I've used this approach in the past
There must be someone who is dealing with the same issue. I am trying to take multiplatform builds with different ${os.name}.properties file. Linux is not a problem, Linux.properties. What about Windows? It becomes Windows XP.properties files.
Can someone enlight me the better way to do this with one word .properties name?
<target name="set-conditions"> <condition property="linux"> <os name="linux"/> </condition>
<condition property="solaris"> <os name="SunOS"/> </condition>
<condition property="windows"> <os family="windows"/> </condition> </target>
You could probably use a single property name and different value attributes and load the properties that way. Depends if you want to use if attributes later on.
Conor
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]