You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Mark Jaffe <mj...@eturn.com> on 2001/05/10 00:14:29 UTC

Cross-platform properties?

I am working with a project that needs to work on both unix and NT. IUs
there an easy way to set properties that will know their platform? I need
something like

<property name="home" value="/home/user" if-os="unix"/>
<property name="home" value="c:\winnt\profiles\user" if-os="windows"/>


Re: Cross-platform properties?

Posted by Mark Jaffe <mj...@eturn.com>.
> > I am working with a project that needs to work on both unix and
> > NT. Is there an easy way to set properties that will know their
> > platform?
>

Thanks all for your suggestions. This seems to be working well for me now,
thought I'd share it back:

<property name="is.${os.name}" value="true"/>

<target name="init.win" if="is.Windows NT" >
  <property name="javahome" value="d:\jdk1.3" />
  <property name="wlhome" value="d:\weblogic" />
</target>

<target name="init.unix" if="is.SunOS" >
  <property name="javahome" value="/usr/local/jdk1.3" />
  <property name="wlhome" value="/usr/local/weblogic" />
</target>

  <target name="init" depends="init.win,init.unix">
  <echo message="Checking environment"/>
  <echo message="   OS = ${os.name}" />
  <echo message="   Home = ${user.home}" />
  <echo message="   Java = ${javahome}" />
  <echo message="   Weblogic = ${wlhome}" />
  </target>



Re: Cross-platform properties?

Posted by Stefan Bodewig <bo...@apache.org>.
Mark Jaffe <mj...@eturn.com> wrote:

> I am working with a project that needs to work on both unix and
> NT. IUs there an easy way to set properties that will know their
> platform?

Yes, use property tasks inside of targets that will only be executed
on the appropriate OS.  Using a very Unix simple heuristic (everything
that doesn't have a C:\config.sys is Unix, everything that does is
Windows) this would look like

<target name="os-check">
  <available property="win" file="C:\config.sys" />
</target>

<target name="set-for-windows" depends="os-check" if="win">
  <property name="home" value="c:\winnt\profiles\user" />
</target>

<target name="set-for-unix" depends="os-check" unless="win">
  <property name="home" value="/home/user" />
</target>

<target name="set" depends="set-for-windows,set-for-unix" />

Stefan

PS: You are not trying to reinvent ${user.home}, are you?