ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wascally Wabbit <wascallywab...@earthling.net>
Subject Re: recursive expansion of property names
Date Wed, 23 Jun 2004 23:21:12 GMT
I rejiggered some of my own code that does this. Try something
like below (seem like a lot of work for what you want though):

--- [ snip ]----

public class MyPropertyHelperInstaller extends Task
{
     public void execute()
     {
         MyPropertyHelper mph= new MyPropertyHelper();
         mph.install(getProject());
         ...// keep mph or not to uninstall.
     }
}

public class MyPropertyHelper extends PropertyHelper
{
     private static final String ANT_HELPER_REFID = "ant.PropertyHelper";
     ...

     /**
      * Installs this helper as the given project's property helper.
      * @param project this net's associated project
      * @return <i>true</i> if helper installed first time
      **/
     public boolean install(Project project)
     {
         PropertyHelper current = PropertyHelper.getPropertyHelper(project);

         verifyNotInChain_(current);

         log("Installing...",Project.MSG_VERBOSE);

         m_defImpl = current;
         project.addReference(ANT_HELPER_REFID,this);

         return true;
     }


     /**
      * Uninstalls this helper as its project's property helper.
      * Will reinstall the helper that was there when this helper
      * was installed.
      * @throws BuildException if this helper is not currently installed
      **/
     public void uninstall(Project project)
     {
         PropertyHelper current = PropertyHelper.getPropertyHelper(project);

         if (current==this) {
             log("Uninstalling...",Project.MSG_VERBOSE);

             project.addReference(ANT_HELPER_REFID,m_defImpl);
             m_defImpl = null;

         } else if (current!=null) {
             throw new BuildException("Not installed (or better message)");
         }
     }


     /**
      * Ensure this helper is not already installed in the given project's
      * property helper (or hook chain). Prevents infinite (circular) lookups.
      **/
     private void verifyNotInChain_(PropertyHelper ph)
     {
         do {
            if (ph==this) {
                 throw new BuildException("Already installed (or better 
message)");
            }
            ph = ph.getNext();
         }while (ph!=null);
     }
     ...
     private PropertyHelper m_defImpl;
}

--- [ end snip ] ---



At 06:46 PM 6/23/2004, you wrote:
>cool, I see in the dev archives "Jose Alberto Fernandez" says:
>=========
>As a matter of fact, we already have the PropertyHelper chain framework. 
>Take a look at how velocity properties(for example) get activated. What 
>you need is:
>
>1) Your own implementation of PropertyHelper that does recursive property 
>expansion.
>2) Provide a task that adds your property helper to the property expansion 
>chain.
>=========
>
>Does anyone know, offhand, how to do (2)?
>
>--
>Jeffrey Bacon
>jbacon@magmic.com
>Creative Developer
>http://www.magmic.com
>
>
>Matt Benson wrote:
>>The code is easy enough... maintaining
>>backwards-compatibility is something else.  Hence my
>>comment about doing it right.  You can search the dev
>>archives around 6/3 or 6/4 for a post originated by
>>Jack G. Woehr on this subject for more detail (I'm
>>going home :)  ).
>>-Matt
>>--- Jeffrey Bacon <jbacon@magmic.com> wrote:
>>
>>>looking at the Ant source code, I think all I have
>>>to do is add one line and it should do tiered property replacements.  Not
>>>sure if it breaks anything but since current behavior in this case
>>>would be to return "${...}" a the string, which is probably not what
>>>people were looking for if they used "${${propname}}" anyway, I think it
>>>_should_ be safe.
>>>
>>>line: 276 (in Ant 1.6.1 code)
>>org.apache.tools.ant.PropertyHelper#replaceProperties(String,
>>
>>>ns, String value, Hashtable keys)
>>>....
>>>                 if (replacement == null) {
>>>                     project.log("Property ${" +
>>>propertyName
>>>                             + "} has not been set",
>>>Project.MSG_VERBOSE);
>>>                 }
>>>....
>>>
>>>if I just add this before that line it should do it:
>>>
>>>   if (replacement == null) {
>>>     replacement = replaceProperties(ns,
>>>propertyName, keys);
>>>   }
>>>
>>>
>>>this is probably more a dev forum type issue though.
>>>--
>>>Jeffrey Bacon
>>>jbacon@magmic.com
>>>Creative Developer
>>>http://www.magmic.com
>>>
>>>
>>>Matt Benson wrote:
>>>
>>>>About three weeks ago there was a discussion on
>>>
>>>the
>>>
>>>>dev list about how to allow recursive property
>>>>expansion without breaking everything.  So it's on
>>>
>>>the
>>>
>>>>radar, but it's not necessarily easy to do
>>>
>>>(right).
>>>
>>>>-Matt
>>>>--- Jeffrey Bacon <jbacon@magmic.com> wrote:
>>>>
>>>>
>>>>>I know I can merge the 2 properties into a 3rd
>>>>>property to get the final value but I was hoping that I would be able

>>>>>to do
>>>
>>>it
>>>
>>>>>without increasing the number of properties I use by 50%.  With the
>>>>>property copy thing, I have to create a new property name for each pair
>>>
>>>of
>>>
>>>>>properties I want to reference this way.
>>>>>--
>>>>>Jeffrey Bacon
>>>>>jbacon@magmic.com
>>>>>Creative Developer
>>>>>http://www.magmic.com
>>>>>
>>>>>
>>>>>Matt Benson wrote:
>>>>>
>>>>>
>>>>>>See
>>http://ant.apache.org/faq.html#propertyvalue-as-name-for-property
>>
>>>>>>-Matt
>>>>>>
>>>>>>--- Jeffrey Bacon <jbacon@magmic.com> wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>sorry, I should be more specific:
>>>>>>>
>>>>>>>I have a properties file:
>>>>>>>
>>>>>>>projects = com.magmic
>>>>>>>com.magmic.name = APIs
>>>>>>>
>>>>>>>and I load that in Ant.
>>>>>>>
>>>>>>>I want to access com.magmic.name by using the
>>>>>>>projects property:
>>>>>>>
>>>>>>><echo>${${projects}.name}</echo>
>>>>>>>
>>>>>>>I want that to print "APIs".  Is there some way
>>>
>>>to
>>>
>>>>>>>effect that?
>>>>>>>
>>>>>>>--
>>>>>>>Jeffrey Bacon
>>>>>>>jbacon@magmic.com
>>>>>>>Creative Developer
>>>>>>>http://www.magmic.com
>>>>>>>
>>>>>>>
>>>>>>>Jeffrey Bacon wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>Can I effect the below behavior somehow to get
>>>
>>>it
>>>
>>>>>>>to print 'hello'?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>><property name="prop1" value="prop2" />
>>>>>>>><property name="prop2" value="hello" />
>>>>>>>><echo>${{prop1}}</echo>
>>>>>>>
>>---------------------------------------------------------------------
>>
>>>>>>>To unsubscribe, e-mail:
>>>>>>>user-unsubscribe@ant.apache.org
>>>>>>>For additional commands, e-mail:
>>>>>>>user-help@ant.apache.org
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>__________________________________
>>>>>>Do you Yahoo!?
>>>>>>Yahoo! Mail - 50x more storage than other
>>>>>
>>>>>providers!
>>>>>
>>>>>
>>>>>>http://promotions.yahoo.com/new_mail
>>>>>>
>>---------------------------------------------------------------------
>>
>>>>>>To unsubscribe, e-mail:
>>>>>
>>>>>user-unsubscribe@ant.apache.org
>>>>>
>>>>>
>>>>>>For additional commands, e-mail:
>>>>>
>>>>>user-help@ant.apache.org
>>>>>
>>---------------------------------------------------------------------
>>
>>>>>To unsubscribe, e-mail:
>>>>>user-unsubscribe@ant.apache.org
>>>>>For additional commands, e-mail:
>>>>>user-help@ant.apache.org
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>__________________________________
>>>>Do you Yahoo!?
>>>>New and Improved Yahoo! Mail - Send 10MB messages!
>>>>http://promotions.yahoo.com/new_mail
>>---------------------------------------------------------------------
>>
>>>>To unsubscribe, e-mail:
>>>
>>>user-unsubscribe@ant.apache.org
>>>
>>>>For additional commands, e-mail:
>>>
>>>user-help@ant.apache.org
>>>
>>---------------------------------------------------------------------
>>
>>>To unsubscribe, e-mail:
>>>user-unsubscribe@ant.apache.org
>>>For additional commands, e-mail:
>>>user-help@ant.apache.org
>>>
>>
>>
>>
>>__________________________________
>>Do you Yahoo!?
>>New and Improved Yahoo! Mail - Send 10MB messages!
>>http://promotions.yahoo.com/new_mail
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>For additional commands, e-mail: user-help@ant.apache.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org

The Wabbit 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message