Ant 1.4.1, i'm calling ProjectHelper.replaceProperties(...) on a string like 
the following:

$foo = ${build.top.dir};
print "$foo\n";

The property expansion works fine, but it also strips the $ from '$foo', so i 
end up with:

foo = "/some/path;
print "foo\n";

i'm attaching a small class which tests the xml code below, showing the 
behaviour:

<taskdef name="propexpand" 
classname="net.sf.antcontrib.logic.PropExpansionTest"/>

<property name="whattodrink" value="milk"/>
<propexpand replaceproperties="true">
        $foo = "${whattodrink}";
        print "foo=$foo\n";
</propexpand>

<propexpand replaceproperties="false">
        $foo = "${whattodrink}";
        print "foo=$foo\n";        
</propexpand>

It produces this output:
property expansion = [true]
text=
        foo = "milk";
        print "foo=foo\n";

property expansion = [false]
text=
        $foo = "${whattodrink}";
        print "foo=$foo\n";


Note all the missing dollar signs in the first one.

----- stephan
[EMAIL PROTECTED] - http://www.einsurance.de
Office: +49 (89)  552 92 862 Handy:  +49 (179) 211 97 67
"I didn't give in to the Nazis and I won't give in to the bladder." 
- The Queen Mum
/*
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2002 Ant-Contrib project.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer. 
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 *    any, must include the following acknowlegement:  
 *       "This product includes software developed by the 
 *        Ant-Contrib project (http://sourceforge.net/projects/ant-contrib)."
 *    Alternately, this acknowlegement may appear in the software itself,
 *    if and wherever such third-party acknowlegements normally appear.
 *
 * 4. The name Ant-Contrib must not be used to endorse or promote products 
 *    derived from this software without prior written permission. For
 *    written permission, please contact
 *    [EMAIL PROTECTED]
 *
 * 5. Products derived from this software may not be called "Ant-Contrib"
 *    nor may "Ant-Contrib" appear in their names without prior written
 *    permission of the Ant-Contrib project.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE ANT-CONTRIB PROJECT OR ITS
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 */

package net.sf.antcontrib.logic;

import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.ExecTask;
import java.lang.StringBuffer;
import java.io.*;

/**
Quick test of a prop expansion bug?
*/
public class PropExpansionTest extends org.apache.tools.ant.taskdefs.ExecTask {

    private StringBuffer script = new StringBuffer();
    private boolean replaceproperties = false;

    public PropExpansionTest()
    {
        super();
    }


    public void execute() throws BuildException {
	String scr = this.getReplaceproperties() ? ProjectHelper.replaceProperties( this.getProject(), this.getText(), this.getProject().getProperties() ) : this.getText();
        log( "property expansion = ["+this.getReplaceproperties()+"]" );
        log( "text="+scr );
    }

    /**
       Adds s to the lines of script code.
    */
    public void addText( String s ) {
	script.append( s );
    }

    /**
       Sets script code to s.
    */
    public void setText( String s ) {
	script = new StringBuffer( s );
    }

    /**
       Returns the script code.
    */
    public String getText() {
	return this.script.toString();
    }

    /**
       If set to true then all ${property}-format strings in getText() will be replaced with
       their Ant values. Use with care, since ${foo} is a valid construct in bash code.
    */
    public void setReplaceproperties( boolean b ) {
	this.replaceproperties = b;
    }

    public boolean getReplaceproperties() {
	return this.replaceproperties;
    }
    

} // end class PropExpansionTest org.apache.tools.ant.Task

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to