#153 'shellscript' task in the same target cannot be run twice

v1.0 (example)
platform (5)
Dirk Krummacker

If a target contains the 'shellscript' task, and if
during one invocation of Ant this target is executed
twice, the second invocation fails with something along
the lines of

[shellscript] /bin/sh: /tmp/script2023260757null:
Datei oder Verzeichnis nicht gefunden

(the error message translates to "file not found")

Steps to reproduce:

1) create a build.xml with a target "foo" containing a
'shellscript' task
2) run "ant foo foo"

I also think I have found the reason for this behaviour:

In the execute() method of the 'ShellScriptTask' (which
inherits from 'ExecTask'), the super class method
createArg() is being called and the name of the
temporary shell script file is set. To my
understanding, Ant creates one instance of the
'ShellScriptTask' class per occurrence in the build.xml
file. Thus, if execute() is being called the second
time, yet *another* Arg gets created and added. The
first Arg which still exists however points to a temp
file which is already deleted. Consequently, the next
invocation of super.execute() then fails due to a 'file
not found' error.

I haven't tested this since I wasn't able to get the
source distribution of 'ant-contrib' to compile, but I
would suggest a bugfix along the following lines:

1) invoke super.createArg() only once (through lazy
init maybe) and assign it to an instance field
2) in the execute() method, call setValue() on the
instance field

This should make sure that there is only one command
line arg that always contains the proper file name.

BTW: We here find 'ant-contrib' really helpful. Keep up
the good work :-)




    • status: open --> closed-duplicate