Built In Properties In Phing

9th January 2009 - 4 minutes read time

Aside from assigning and using your own properties Phing also comes with a set of built in properties that can be used to find out all sorts of information regarding the system that Phing is run on.

As an example, let's say you wanted to found out the operating system that phing is being run on. In this case you would use the variable host.os, which on a Windows XP system would print out WINNT.

There are a lot of different properties available, so I have included the table from the phing website at the bottom of this post as a reference. However, there is one special variable called env that needs further explanation. The env variable references any environment variables that have been set. For example, if you set an environment variable using the following shell command (on UNIX based systems only).

export TESTVAR=mytestvar

You can now reference this in your build.xml file by using the following.

${env.TESTVAR}

Here is a table of the built in properties available.

PropertyContents
application.startdirCurrent work directory
env.*Environment variables, extracted from $_SERVER.
host.archSystem architecture, i.e. i586. Not available on Windows machines.
host.domainDNS domain name, i.e. php.net. Not available on Windows machines.
host.fstypeThe type of the filesystem. Possible values are UNIX, WINNT and WIN32
host.nameOperating System hostname as returned by posix_uname(). Not available on Windows machines.
host.osOperating System description as set in PHP_OS variable (see PHP Manual).
host.os.releaseOperating version release, i.e. 2.2.10. Not available on Windows machines.
host.os.versionOperating system version, i.e. #4 Tue Jul 20 17:01:36 MEST 1999. Not available on Windows machines.
line.separatorCharacter(s) that signal the end of a line, "\n" for Linux, "\r\n" for Windows system, "\r" for Macintosh.
os.nameOperating System description as set in PHP_OS variable.
phing.fileFull path to current buildfile.
phing.homePhing installation directory, not set in PEAR installations.
phing.versionCurrent Phing version.
phing.project.nameName of the currently processed project.
php.classpathThe value of the environment variable PHP_CLASSPATH.
php.versionVersion of the PHP interpreter. Same as PHP constant PHP_VERSION (see PHP Manual).
project.basedirThe current project basedir.
user.homeValue of the environment variable HOME.

This list can also be found on the Phing website.

I have found that even though some of variables specifically say "not available on Windows" most of them will produce some sort of output, even on Windows machines. Here is a test build.xml file that you can use to see what the different variables print out on your system.

  1. <?xml version="1.0"?>
  2. <!-- build xml -->
  3. <project name="myProject" default="main">
  4.  
  5. <target name="main">
  6. <echo>application.startdir ${application.startdir}</echo>
  7. <echo>host.arch ${host.arch}</echo>
  8. <echo>host.domain ${host.domain}</echo>
  9. <echo>host.fstype ${host.fstype}</echo>
  10. <echo>host.name ${host.name}</echo>
  11. <echo>host.os ${host.os}</echo>
  12. <echo>host.os.release ${host.os.release}</echo>
  13. <echo>host.os.version ${host.os.version}</echo>
  14. <echo>line.separator ${line.separator}</echo>
  15. <echo>os.name ${os.name}</echo>
  16. <echo>phing.file ${phing.file}</echo>
  17. <echo>phing.home ${phing.home}</echo>
  18. <echo>phing.version ${phing.version}</echo>
  19. <echo>phing.project.name ${phing.project.name}</echo>
  20. <echo>php.classpath${php.classpath}</echo>
  21. <echo>php.version ${php.version}</echo>
  22. <echo>project.basedir ${project.basedir}</echo>
  23. <echo>user.home ${user.home}</echo>
  24. </target>
  25. </project>

This file misses out the env property as this is a custom property.

Automated Build With Phing

Comments

Permalink
Thanks, that was very useful. I was looking for a variable to find what OS version you are running and solved by simple creating my own property value from the output of a Linux command:
  1. <exec command="cat /etc/issue" outputproperty="host.os.distro"></exec>
  2. <echo>host.os.distro ${host.os.distro}</echo>
Which shows for example: [echo] host.os.distro Ubuntu 10.04.4 LTS \n \l

Angel Abad (Wed, 02/05/2014 - 13:03)

Add new comment

The content of this field is kept private and will not be shown publicly.