Built In Properties In Phing

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.

<?xml version="1.0"?>
<!-- build xml -->
<project name="myProject" default="main">
 
 <target name="main">
  <echo>application.startdir ${application.startdir}</echo>
  <echo>host.arch ${host.arch}</echo>
  <echo>host.domain ${host.domain}</echo>
  <echo>host.fstype ${host.fstype}</echo>
  <echo>host.name ${host.name}</echo>
  <echo>host.os ${host.os}</echo>
  <echo>host.os.release ${host.os.release}</echo>
  <echo>host.os.version ${host.os.version}</echo>
  <echo>line.separator ${line.separator}</echo>
  <echo>os.name ${os.name}</echo>
  <echo>phing.file ${phing.file}</echo>
  <echo>phing.home ${phing.home}</echo>
  <echo>phing.version ${phing.version}</echo>
  <echo>phing.project.name ${phing.project.name}</echo>
  <echo>php.classpath${php.classpath}</echo>
  <echo>php.version ${php.version}</echo>
  <echo>project.basedir ${project.basedir}</echo>
  <echo>user.home ${user.home}</echo>
 </target>
</project>

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

Automated Build With Phing

Comments

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: host.os.distro ${host.os.distro}Which shows for example: [echo] host.os.distro Ubuntu 10.04.4 LTS \n \l
Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
2 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.