ant task supporting non string properties in gradle context

Description

While converting a very old ANT task using IzPackTask into a gradle build environment I got strange class cast exceptions. I found this happens when using inheritAll: 'true' to configure and inherit ant properties.

While within ANT such properties are generally strings, the internal representation however uses a Hashmap<String, Object> of objects.

In contrast to ANT, gradle uses project properties of various types. Those are commonly groovy.lang.GString instead of java.lang.String or even i.E. Integer objects. When using inheritAll: 'true' those will end up as ANT properties.

This happens to me using an ancient izpack 4.2. The problem arises while casting the value to String , which is still a relic of Java 1.1 I think. The problem can be solved easily by calling projectProps.get(name).toString(); instead.

I tried a big jump to izpack 5.1.4 but I got the same problem here.
Interestingly the cause is not that obvious here:

Some code moved to IzpackAntRunnable. Here a Hashtable<String, String> is used and thus no casting seems necessary any more. Unfortunately it does not work as intended:

While the IzpackAntRunnable constructor requires a Hashtable<String, String> it is initialized by reflection using a newInstance() call. Unfortunately getProject().getProperties() still provides a Hashtable<String, Object>. This fault is hidden since reflective calls are not typesafe.

I'm about to prepare a pull request.

Environment

ant task within gradle context

Status

Assignee

Unassigned

Reporter

Dieter Stüken

Impact

Functional - non-breaking and safe in existing environments

Components

Fix versions

Affects versions

Priority

Medium
Configure