Bug 37688 - script task confuses Ant references
Summary: script task confuses Ant references
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.6.5
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-29 11:54 UTC by vidl
Modified: 2008-02-22 12:18 UTC (History)
0 users



Attachments
Ant build file to reproduce the bug (1.16 KB, text/plain)
2005-11-29 11:56 UTC, vidl
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vidl 2005-11-29 11:54:32 UTC
When using a beanshell script, Ant shows a special behavior together with
references.
To have beanshell, I used bsf-2.3.0.jar and bsh-2.0b4.jar in the ${ant.home}/lib
directory.


<?xml version="1.0"?>
<project name="antbug">

  <macrodef name="compileMapper" >
    <attribute name="objDir" />
    <attribute name="id" default="compileMapperID" />
    <sequential>
      <mapper id="@{id}">
        <chainedmapper  >
          <flattenmapper/>
          <globmapper from="*" to="@{objDir}/*.o"/>
        </chainedmapper>
      </mapper>
    </sequential>
  </macrodef>

  <target name="failes">
      <script language="beanshell"><![CDATA[
      // nothing
      ]]></script>
      <!-- throws java.lang.ClassCastException:
org.apache.tools.ant.types.Mapper -->
      <compileMapper objDir="." />
  </target>

  <target name="works">
      <compileMapper objDir="." />
  </target>

  <target name="override" >
      <script language="beanshell"><![CDATA[
      // nothing
      ]]></script>
      <!-- Overriding previous definition of reference to anID -->
      <path id="anID">
        <fileset dir="." includes="*.ant" />
      </path>
  </target>

  <target name="noOverride" >
      <path id="anID">
        <fileset dir="." includes="*.ant" />
      </path>
  </target>

</project>
Comment 1 vidl 2005-11-29 11:56:08 UTC
Created attachment 17074 [details]
Ant build file to reproduce the bug
Comment 2 Peter Reilly 2005-12-02 10:50:07 UTC
Just changing the name of bug as it is a general script/reference problem.
It is most likely related to the way references are processed - they are
looked at both at xml parse time (when they are unknown elements) and
at run time where they get resolved.

There are a large number of bugs associated with this behaviour - some
get fixed by hacks but a large number remain.

Personally I think that the way refernces are handled should be looked
at - so that they are processed at runtime. However I cannot see any way to
do this in a backward compatible fashion.
Comment 3 Peter Reilly 2006-09-02 23:06:48 UTC
I have added a workaround in ant 1.7.
A new attribute "setbeans" has been added to the 
<script> task. This is by default "true". However
if is set to false, only the "project" and "self"
variables will be set.
Comment 4 Peter Reilly 2006-10-06 14:22:50 UTC
A proper fix has been done, there
is now no need for the setbeans attribute.
I am leaving it in to allow <script> to be
used without populating it with lots of properties, references
and targets.