You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bu...@apache.org on 2009/04/15 14:20:39 UTC

DO NOT REPLY [Bug 47035] New: Property expansion in macro attributes and elements

https://issues.apache.org/bugzilla/show_bug.cgi?id=47035

           Summary: Property expansion in macro attributes and elements
           Product: Ant
           Version: 1.7.1
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Core
        AssignedTo: notifications@ant.apache.org
        ReportedBy: csaba.juhos@gmail.com


Hi,

I'm using Launch4j to wrap a JAR into a windows executable:

<launch4j>
    <config>
        <jre>
            <opt>-Xms${java.initial.memory}m</opt>
        </jre>
    </config>
</launch4j>

The problem is that the "opt" element doesn't expand properties.
It seems that the developers didn't take care to expand them explicitly.
(http://ant.apache.org/ant_task_guidelines.html)

I wrapped the task into a macro like this:

<macrodef name="create-exe">
    <attribute name="java-initial-memory"/>
    <sequential>
        <launch4j>
            <config>
                <jre>
                    <opt>-Xms@{java.initial.memory}m</opt>
                </jre>
            </config>
        </launch4j>
    </sequential>
</macrodef>

And called it like:

<create-exe java-initial-memory="${java.initial.memory}"/>

in hope that the property will be expanded before being passed to the template.
It wasn't :(



I know that this is the expected behavior. What I'm asking for here is an
option to expand macro arguments before passing them to the template.



After some consideration I came to the conclusion that the best solution would
be to add an optional attribute "expand" to the "element" and "attribute" child
elements of macrodef.

Modified example:

<macrodef name="create-exe">
    <attribute name="java-initial-memory" expand="true"/>
    <attribute name="java-maximum-memory" expand="true"/>
    <element name="vm-options" optional="true" expand="true"/>
    <sequential>
        <launch4j>
            <config>
                <jre>
                    <opt>-Xms@{java.initial.memory}m</opt>
                </jre>
            </config>
        </launch4j>
    </sequential>
</macrodef>

<create-exe java-initial-memory="${java.initial.memory}"
            java-maximum-memory="${java.maximum.memory}">

    <vm-options>
        <opt>${another.vm.option}</opt>
    </vm-options>
</create-exe>

"expand" should be a boolean variable with a default value of "false". This
wouldn't break any existing code.

Another use case I'm seeing is the following:

<macrodef name="create-exe">
    <attribute name="expand-options" default="true"/>
    <attribute name="java-initial-memory" expand="@{expand-options}"/>
    <attribute name="java-maximum-memory" expand="@{expand-options}"/>
    <element name="vm-options" optional="true" expand="@{expand-options}"/>
...

This would make the macro more flexible.



In case this isn't possible to implement, I'm sorry for my ignorance, I'm not
familiar with Ant's internals at all.

Thank you,
Csabi

P.S.: I filed a bug against Launch4j:

   
https://sourceforge.net/tracker/?func=detail&aid=2764888&group_id=95944&atid=613100

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 47035] Property expansion in macro attributes and elements

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=47035


Juhos Csaba-Zsolt <cs...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |csaba.juhos@gmail.com




-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 47035] Property expansion in macro attributes and elements

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=47035


Juhos Csaba-Zsolt <cs...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |




--- Comment #2 from Juhos Csaba-Zsolt <cs...@gmail.com>  2009-04-16 20:56:20 PST ---
Hi,

It's a typo. In my real code I have used the attribute correctly.

What happens is that "@{java-initial-memory}" gets expanded to
"${java.initial.memory}", which doesn't get expanded by the "opt" element,
because it doesn't expand properties in its text.

What I'm asking for is an option for the expansion of "${java.initial.memory}"
when calling the macro, like this:

<property name="java.initial.memory" value="128"/>
<create-exe java-initial-memory="${java.initial.memory}"/>
...
@{java-initial-memory} should expand to "-Xms128m"

Cheers,
Csabi

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 47035] Property expansion in macro attributes and elements

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=47035


Matt Benson <gu...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




--- Comment #1 from Matt Benson <gu...@yahoo.com>  2009-04-16 08:04:08 PST ---
Uh... Red herring alert:  I think the reason your attribute is not expanded is
because you're not using it:

<macrodef name="create-exe">
    <attribute name="java-initial-memory"/>
    <sequential>
        <launch4j>
            <config>
                <jre>
                    <opt>-Xms@{java.initial.memory}m</opt>
                </jre>
            </config>
        </launch4j>
    </sequential>
</macrodef>

This should be:

<macrodef name="create-exe">
    <attribute name="java-initial-memory"/>
    <sequential>
        <launch4j>
            <config>
                <jre>
                    <opt>-Xms@{java-initial-memory}m</opt>
                </jre>
            </config>
        </launch4j>
    </sequential>
</macrodef>

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.