A better test for detecting Unix operating systems in an Ant build script

In several previous tutorials (see my references below) about testing for operating systems within Ant build scripts, and then conditionally executing targets based on the results of those tests, I noted that Mac OS X operating systems respond to both Mac and Unix test conditions based on the Ant "os family" test. I mentioned that I thought this behavior was probably correct, because Mac OS X is built an a Unix base (BSD, to be specific).

I just dug through some Ant documentation, and I believe this assertion is correct (if not helpful).

Specifically, this Ant condition link shows the following sample Ant source code:

<condition property="isMacOsButNotMacOsX">
  <and>
    <os family="mac"/>

    <not>
      <os family="unix"/>
    </not>

  </and>
</condition>

As you can tell from the name, this test condition detects whether the build script is running on a Mac OS, but specifically not Mac OS X. (If it helps to know it, Mac OS X is based on BSD Unix, where prior versions of the Mac OS were not.)

Writing a better "Is Unix but is not Mac" test

The reason I mention any of this is that I think you can easily get into a situation when writing Java programs on Mac OS X where your Ant build script will run both a Mac-specific test and a Unix-specific test, when all you really want to do is run a Mac-specific test. To combat this problem, I think my previous Unix tests need to be changed to look more like the test I showed above.

Specifically, I think this Unix test is better than my previous tests:

<condition property="isUnixButNotMacOsX">
  <and>
    <os family="unix"/>

    <not>
      <os family="mac"/>
    </not>

  </and>
</condition>

I just tested this on my Mac OS X 10.5.7 system using Ant 1.7.0, and it worked fine, but unfortunately I don't have a Unix system to test this on these days. If you run this on a Unix system and find that it's wrong, please let me know, and I'll correct it here.

References: My complete Ant operating system specific build scripts

For your reference, here are two links to my previous discussions on creating Ant build scripts that have operating system tests in them:

As mentioned, those scripts run a test for Unix platforms, and I think the test I've shown above is an improvement on those more basic tests.