Wondering over toward <scriptdef> which I haven't used before.  I saw <element> 
in there and can't see it described anywhere in the doc.  Can someone give me a 
reference?

Thanks,
Eric




________________________________
From: Eric Fetzer <elstonk...@yahoo.com>
To: Ant Users List <user@ant.apache.org>
Sent: Thu, January 21, 2010 8:38:41 AM
Subject: Re: AppendToProperty MacroDef

And to leverage your \n example:

<project default="main">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="myProp" value="C:\noDog\Hates\Big\Juicy\Bones"/>
<property name="myProp2" value="C:\\noDog\\Hates\\Big\\Juicy\\Bones"/>
<property name="myProp3" value="C:\noDog\\Hates\Big\\Juicy\Bones"/>
  <target name="main">
    <propertyregex property="tmpProp" input="${myProp}" override="true" 
regexp="\\" replace="\\\\" global="true"/>
    <echo message="tmpProp is:  ${tmpProp}"/>
    <propertyregex property="tmpProp2" input="${myProp2}" override="true" 
regexp="\\" replace="\\\\" global="true"/>
    <echo message="tmpProp is:  ${tmpProp2}"/>
    <propertyregex property="tmpProp3" input="${myProp3}" override="true" 
regexp="\\" replace="\\\\" global="true"/>
    <echo message="tmpProp is:  ${tmpProp3}"/>
    <propertyregex property="tmpProp4" input="${myProp}" override="true" 
regexp="\" replace="\\" global="true"/>
    <echo message="tmpProp is:  ${tmpProp4}"/>
  </target>
</project>

Produces:

main:
     [echo] tmpProp is:  C:\noDog\Hates\Big\Juicy\Bones
     [echo] tmpProp is:  C:\\noDog\\Hates\\Big\\Juicy\\Bones
     [echo] tmpProp is:  C:\noDog\\Hates\Big\\Juicy\Bones
BUILD FAILED
java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
\
 ^
        at java.util.regex.Pattern.error(Pattern.java:1650)
        at java.util.regex.Pattern.compile(Pattern.java:1403)
        at java.util.regex.Pattern.<init>(Pattern.java:1124)
        at java.util.regex.Pattern.compile(Pattern.java:840)
        at org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher.getCompiledPatter
n(Jdk14RegexpMatcher.java:67)
        at org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher.matches(Jdk14Rege
xpMatcher.java:94)
        at net.sf.antcontrib.property.RegexTask.doReplace(RegexTask.java:135)
        at net.sf.antcontrib.property.RegexTask.execute(RegexTask.java:192)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
        at org.apache.tools.ant.Main.runBuild(Main.java:758)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Total time: 0 seconds




________________________________
From: Eric Fetzer <elstonk...@yahoo.com>
To: Ant Users List <user@ant.apache.org>
Sent: Thu, January 21, 2010 8:28:07 AM
Subject: Re: AppendToProperty MacroDef

Let me give you a better example Scot.  Substitution seems to ignore escape 
characters entirely.  As the task is written now, I don't imagine there is a 
way to replace \'s.

<project default="main">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="myProp" value="C:\myDog\Loves\Big\Juicy\Bones"/>
<property name="myProp2" value="C:\\myDog\\Loves\\Big\\Juicy\\Bones"/>
<property name="myProp3" value="C:\myDog\\Loves\Big\\Juicy\Bones"/>
  <target name="main">
    <propertyregex property="tmpProp" input="${myProp}" override="true" 
regexp="\\" replace="\\\\" global="true"/>
    <echo message="tmpProp is:  ${tmpProp}"/>
    <propertyregex property="tmpProp2" input="${myProp2}" override="true" 
regexp="\\" replace="\\\\" global="true"/>
    <echo message="tmpProp2 is:  ${tmpProp2}"/>
    <propertyregex property="tmpProp3" input="${myProp3}" override="true" 
regexp="\\" replace="\\\\" global="true"/>
    <echo message="tmpProp3 is:  ${tmpProp3}"/>
    <propertyregex property="tmpProp4" input="${myProp}" override="true" 
regexp="\" replace="\\" global="true"/>
    <echo message="tmpProp4 is:  ${tmpProp4}"/>
  </target>
</project>

Produces:

main:
     [echo] tmpProp is:  C:\myDog\Loves\Big\Juicy\Bones
     [echo] tmpProp2 is:  C:\\myDog\\Loves\\Big\\Juicy\\Bones
     [echo] tmpProp3 is:  C:\myDog\\Loves\Big\\Juicy\Bones
BUILD FAILED
java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
\
 ^
        at java.util.regex.Pattern.error(Pattern.java:1650)
        at java.util.regex.Pattern.compile(Pattern.java:1403)
        at java.util.regex.Pattern.<init>(Pattern.java:1124)
        at java.util.regex.Pattern.compile(Pattern.java:840)
        at org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher.getCompiledPatter
n(Jdk14RegexpMatcher.java:67)
        at org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher.matches(Jdk14Rege
xpMatcher.java:94)
        at net.sf.antcontrib.property.RegexTask.doReplace(RegexTask.java:135)
        at net.sf.antcontrib.property.RegexTask.execute(RegexTask.java:192)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
        at org.apache.tools.ant.Main.runBuild(Main.java:758)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Total time: 0 seconds




________________________________
From: Scot P. Floess <sflo...@nc.rr.com>
To: Ant Users List <user@ant.apache.org>
Sent: Thu, January 21, 2010 8:09:33 AM
Subject: Re: AppendToProperty MacroDef


I might be wrong but I think the output you are seeing is correct - as in 
the \ is escapeed thereby printing only 1 \ not 2...  For example if you 
consider \n it is emitted as a newline...but if you do \\n the output will 
be a literal \n (as in a backslash followed by the letter n)...  Try 
printing out the property when you don't do the regex for \\\\ - for 
example something like:

C:\foo\nbar

I bet the output has a new line in it ;)

On Thu, 21 Jan 2010, Eric Fetzer wrote:

> Yeah, that's what I did.  The small repro just shows that it doesn't affect 
> the string with the \'s whatsoever...  If there were actual instances of \\ 
> in there maybe it would do something, but there are only \'s.  Seems like for 
> the saving down of the property, it uses escape characters, but for the 
> substitution part, it doesn't.  I'd call it a bug I think.
>
>
>
> On Jan 21, 2010, at 7:10 AM, "Scot P. Floess" <sflo...@nc.rr.com> wrote:
>
>
> OK, so in looking more closely, what I meant to say was to do the 
> <propertyregex property="tmpProp"  first and then the one you had initially 
> afterward using the first :)
>
> If I get a free moment today I'll see if I can get it to work...  Little busy 
> at the moment - maybe at lunch today :)
>
> On Wed, 20 Jan 2010, Scot P. Floess wrote:
>
>
> Yeah, I'll give it some thought and see if there is something I can think of 
> tomorrow as well :)
>
> On Wed, 20 Jan 2010, Eric Fetzer wrote:
>
> I tried this Scot, but it didn't do it.  So here's an easy repro:
> <project default="main">
> <taskdef resource="net/sf/antcontrib/antlib.xml"/>
> <property name="myProp" value="C:\myDog\Loves\Big\Juicy\Bones"/>
>  <target name="main">
>    <propertyregex property="tmpProp" input="${myProp}" override="true" 
>regexp="\\" replace="\\\\" global="true"/>
>    <echo message="tmpProp is:  ${tmpProp}"/>
>  </target>
> </project>
> It produces:
> [echo] tmpProp is:  C:\myDog\Loves\Big\Juicy\Bones
> If I change it to:
> <project default="main">
> <taskdef resource="net/sf/antcontrib/antlib.xml"/>
> <property name="myProp" value="C:\myDog\Loves\Big\Juicy\Bones"/>
>  <target name="main">
>    <propertyregex property="tmpProp" input="${myProp}" override="true" 
>regexp="\" replace="\\" global="true"/>
>    <echo message="tmpProp is:  ${tmpProp}"/>
>  </target>
> </project>
> it crashes with:
> java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
> \
> ^
>        at java.util.regex.Pattern.error(Pattern.java:1650)
>        at java.util.regex.Pattern.compile(Pattern.java:1403)
>        at java.util.regex.Pattern.<init>(Pattern.java:1124)
>        at java.util.regex.Pattern.compile(Pattern.java:840)
>        at 
>org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher.getCompiledPatter
> n(Jdk14RegexpMatcher.java:67)
>        at 
>org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher.matches(Jdk14Rege
> xpMatcher.java:94)
>        at net.sf.antcontrib.property.RegexTask.doReplace(RegexTask.java:135)
>        at net.sf.antcontrib.property.RegexTask.execute(RegexTask.java:192)
>        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at 
>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
> java:39)
>        at 
>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
> sorImpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:585)
>        at 
>org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
> a:106)
>        at org.apache.tools.ant.Task.perform(Task.java:348)
>        at org.apache.tools.ant.Target.execute(Target.java:357)
>        at org.apache.tools.ant.Target.performTasks(Target.java:385)
>        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
>        at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
>        at 
>org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
> cutor.java:41)
>        at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
>        at org.apache.tools.ant.Main.runBuild(Main.java:758)
>        at org.apache.tools.ant.Main.startAnt(Main.java:217)
>        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
>        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
> I don't know that what we're trying to do is possible with propertyregex.  It 
> seems it may need some scripting.  All I'm really trying to do is:
> if(property1.indexOf(string1) >= 0) then return true;
> I'll take a look at how to achieve this tomorrow.  Thanks!
> Eric
> ________________________________
> From: Scot P. Floess <sflo...@nc.rr.com>
> To: Ant Users List <user@ant.apache.org>
> Sent: Wed, January 20, 2010 2:21:41 PM
> Subject: Re: AppendToProperty MacroDef
> Mmm - you may need to do this before your first propertyregex
> <propertyregex property="tmpProp" input="${propertyList}" override="true" 
> regexp="\\" replace="\\\\" globale="true"/>
> Basically the above will escape the \
> On Wed, 20 Jan 2010, Eric Fetzer wrote:
> Well, out of that error and on to the next.  It seems that PropertyRegEx has 
> an issue with the "\" as well.  I wrote a different macrodef that works 
> without slashes, but not with slashes.  Anyone see a better way?
>  <macrodef name="md.isInPropList" description="Find if a dir is a subdir of 
>any dir in the list">
>    <attribute name="var.item"/>
>    <attribute name="var.itemList"/>
>    <sequential>
>      <!--First get rid of any values left from previous calls to this md and 
>set to false-->
>      <unset name="isInList"/>
>      <property name="isInList" value="false"/>
>      <!--For loop on each item in itemlist to see if any of them are true-->
>      <for list="@{var.itemList}" param="item">
>        <sequential>
>          <!--Make sure regExResult isn't left over-->
>          <unset name="regExResult"/>
>          <!--Regex expression that will result in the value if it is in 
>there-->
>          <propertyregex property="regExResult"
>            input="${propertyList}"
>            override="true"
>            regexp=".*(@{item})"
>            select="\1"
>            casesensitive="false"
>          />
>          <!--If regExResult is set to the value of the item, we have a 
>match-->
>          <if>
>            <equals arg1="${regExResult}" arg2="${item}"/>
>            <then>
>              <unset name="isInList"/>
>              <property name="isInList" value="true"/>
>            </then>
>          </if>
>        </sequential>
>      </for>
>    </sequential>
>  </macrodef>
> Thanks,
> Eric
> ________________________________
> From: Eric Fetzer <elstonk...@yahoo.com>
> To: Ant Users List <user@ant.apache.org>
> Sent: Wed, January 20, 2010 1:40:34 PM
> Subject: Re: AppendToProperty MacroDef
> Beautiful, thanks Scott!
> On Jan 20, 2010, at 1:18 PM, "Scot P. Floess" <sflo...@nc.rr.com> wrote:
> You could use Ant Contrib's var task - probably be a little easier :)
> <macrodef name="md.AppendProperty">
> <attribute name="var.propertyName"/>
> <attribute name="var.stringAppend"/>
> <sequential>
>  <var name="@{var.propertyName}" 
>value="$...@{var.propertyname}}@{var.stringAppend}"/>
> </sequential>
> </macrodef>
> On Wed, 20 Jan 2010, Eric Fetzer wrote:
> Hi all.  I wrote a MacroDef to append a string to a property.  All works as 
> planned until you slip a "\" in there and then it gets jacked up.  My 
> javascripting has MUCH to be desired.  Any help?
>  <macrodef name="md.AppendProperty">
>    <attribute name="var.propertyName"/>
>    <attribute name="var.stringAppend"/>
>    <sequential>
>      <script language="javascript"> <![CDATA[
>        curVal=project.getProperty("@{var.propertyName}");
>        
>project.setProperty("@{var.propertyName}",curVal+"@{var.stringAppend}");
>        ]]>
>      </script>
>    </sequential>
>  </macrodef>
> Thanks,
> Eric
> Scot P. Floess
> 27 Lake Royale
> Louisburg, NC  27549
> 252-478-8087 (Home)
> 919-890-8117 (Work)
> Chief Architect JPlate  http://sourceforge.net/projects/jplate
> Chief Architect JavaPIM  http://sourceforge.net/projects/javapim
> Architect Keros          http://sourceforge.net/projects/keros
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
> For additional commands, e-mail: user-h...@ant.apache.org
>      ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
> For additional commands, e-mail: user-h...@ant.apache.org
> Scot P. Floess
> 27 Lake Royale
> Louisburg, NC  27549
> 252-478-8087 (Home)
> 919-890-8117 (Work)
> Chief Architect JPlate  http://sourceforge.net/projects/jplate
> Chief Architect JavaPIM  http://sourceforge.net/projects/javapim
> Architect Keros          http://sourceforge.net/projects/keros
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
> For additional commands, e-mail: user-h...@ant.apache.org
>
> Scot P. Floess
> 27 Lake Royale
> Louisburg, NC  27549
>
> 252-478-8087 (Home)
> 919-890-8117 (Work)
>
> Chief Architect JPlate  http://sourceforge.net/projects/jplate
> Chief Architect JavaPIM  http://sourceforge.net/projects/javapim
>
> Architect Keros          http://sourceforge.net/projects/keros
>
>
> Scot P. Floess
> 27 Lake Royale
> Louisburg, NC  27549
>
> 252-478-8087 (Home)
> 919-890-8117 (Work)
>
> Chief Architect JPlate  http://sourceforge.net/projects/jplate
> Chief Architect JavaPIM  http://sourceforge.net/projects/javapim
>
> Architect Keros          http://sourceforge.net/projects/keros
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
> For additional commands, e-mail: user-h...@ant.apache.org
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
> For additional commands, e-mail: user-h...@ant.apache.org
>
>

Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-890-8117 (Work)

Chief Architect JPlate  http://sourceforge.net/projects/jplate
Chief Architect JavaPIM  http://sourceforge.net/projects/javapim

Architect Keros          http://sourceforge.net/projects/keros

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


      

Reply via email to