Property substitution issue

Description

I have a property SHIP_DIR defined as below: (Normally, this property would be read from a properties file).

<properties>
<property name="SHIP_DIR" value="C:\konaware\kilauea_2.1\kmp\build\BUILD_DBG\ship" />
</properties>

I use it in a pack element as follows

<pack name="Docs" required="no">
<description>The documentation</description>
<fileset dir="$SHIP_DIR"
targetdir="$INSTALL_PATH"
defaultexcludes="false"
includes="documentation/" />
</pack>

I get the following error

-> Fatal error :
install.xml:130: C:\cygwin64\home\Andy\IzPack\KMPtrial\.\C:\konaware\kilauea_2.1\kmp\build\BUILD_DBG\ship not found.
com.izforge.izpack.api.exception.CompilerException: install.xml:130: C:\cygwin64\home\Andy\IzPack\KMPtrial\.\C:\konaware\kilauea_2.1\kmp\build\BUILD_DBG\ship not found.

Notice the "\" before the C: in the error message.

If I replace the $SHIP_DIR in the <pack> element with the value of the property SHIP_DIR, there is no error.

I now understand what is happening. I accidentally set the base directory to something other than "." and the resulting path that I got for the fileset dir above was concatenation of the absolute path of the base directory and the substituted value of $SHIP_DIR.

Here's what happens. In the following code:

That line for the "not exists" case looks like it should read something like the following You have no idea what the path in base_dir looks like if it contains variables!

baseDir = FileUtil.getAbsolutePath(variableSubstitutor.substitute(dir_attr), baseDir.getAbsolutePath());

In fact, why isn't variable substitution simply done at the outset? That's got to be faster a simpler than making a file system query and finding out it doesn't exist!

Here's what happens in the case above. The line

computes a basedir via FileUtil which constructs a File object out of the string "$SHIP_DIR" and tests if it is absolute.

"$SHIP_DIR" is not absolute, so FileUtil returns a File object constructed out of the basedir ('.") and the aforementioned File object.

Then basedir is tested for existence, which fails. So an attempt is made to construct a File object with this line.

baseDir = new File(variableSubstitutor.substitute(baseDir.getAbsolutePath()));

but getting the string on which to do the substitution from basedir which is not a valid File does not get back the original string. It has the base dir prepended! You need to start over with the original string as follows:

baseDir = FileUtil.getAbsolutePath(variableSubstitutor.substitute(dir_attr), baseDir.getAbsolutePath());

This error also exists for the "src" attribute

Environment

None

Assignee

Adrien Lesur

Reporter

Andrew Hall

Impact

None

Components

Sprint

None

Fix versions

Affects versions

Priority

High
Configure