java - What requirements does Ant place on attribute names? -


i can scriptdef run if use names attributes. apparently names "property" , "prop1", "prop2", etc. ok, other names (including "propn") not ok. ones ok , why?

this works (using attribute name prop2):

<project name="ant weird">   <property name="hostname" value="abc-de-fghijk0.lmn.opqr.stu"/>    <scriptdef name="hostsubstring" language="javascript">     <attribute name="text" />     <attribute name="prop1" />     <attribute name="prop2" />     <![cdata[       var hn = attributes.get("text");       project.setproperty(attributes.get("prop1"), hn.replace(/[^0-9]/g,""));       project.setproperty(attributes.get("prop2"), hn.replace(/[^0-9]/g,""));       ]]>   </scriptdef>    <target name="test" description="helps me learn scriptdef">     <echo message="hostname ${hostname}"/>     <hostsubstring text="${hostname}" prop1="firstprop" prop2="secondprop"/>     <echo message="firstprop ${firstprop}" />     <echo message="secondprop ${secondprop}" />   </target> </project> 

output:

$ ant test buildfile: /apps/anttest/build.xml  test:      [echo] hostname abc-de-fghijk0.lmn.opqr.stu      [echo] firstprop 0      [echo] secondprop 0  build successful total time: 0 seconds 

but fails (using attribute name propn):

<project name="ant weird">   <property name="hostname" value="abc-de-fghijk0.lmn.opqr.stu"/>    <scriptdef name="hostsubstring" language="javascript">     <attribute name="text" />     <attribute name="prop1" />     <attribute name="propn" />     <![cdata[       var hn = attributes.get("text");       project.setproperty(attributes.get("prop1"), hn.replace(/[^0-9]/g,""));       project.setproperty(attributes.get("propn"), hn.replace(/[^0-9]/g,""));       ]]>   </scriptdef>    <target name="test" description="helps me learn scriptdef">     <echo message="hostname ${hostname}"/>     <hostsubstring text="${hostname}" prop1="firstprop" propn="secondprop"/>     <echo message="firstprop ${firstprop}" />     <echo message="secondprop ${secondprop}" />   </target> </project> 

output:

$ ant test buildfile: /apps/anttest/build.xml  test:      [echo] hostname abc-de-fghijk0.lmn.opqr.stu  build failed /apps/anttest/build.xml:17: java.lang.nullpointerexception         @ java.util.hashtable.containskey(hashtable.java:335)         @ org.apache.tools.ant.propertyhelper.setproperty(propertyhelper.java:640)         @ org.apache.tools.ant.project.setproperty(project.java:538)         @ jdk.nashorn.internal.scripts.script$\^eval\_.:program(<eval>:8)         @ jdk.nashorn.internal.runtime.scriptfunctiondata.invoke(scriptfunctiondata.java:637)         @ jdk.nashorn.internal.runtime.scriptfunction.invoke(scriptfunction.java:494)         @ jdk.nashorn.internal.runtime.scriptruntime.apply(scriptruntime.java:393)         @ jdk.nashorn.api.scripting.nashornscriptengine.evalimpl(nashornscriptengine.java:446)         @ jdk.nashorn.api.scripting.nashornscriptengine.evalimpl(nashornscriptengine.java:403)         @ jdk.nashorn.api.scripting.nashornscriptengine.evalimpl(nashornscriptengine.java:399)         @ jdk.nashorn.api.scripting.nashornscriptengine.eval(nashornscriptengine.java:155)         @ javax.script.abstractscriptengine.eval(abstractscriptengine.java:264)         @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)         @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)         @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)         @ java.lang.reflect.method.invoke(method.java:498)         @ org.apache.tools.ant.util.reflectutil.invoke(reflectutil.java:108)         @ org.apache.tools.ant.util.reflectwrapper.invoke(reflectwrapper.java:81)         @ org.apache.tools.ant.util.optional.javaxscriptrunner.evaluatescript(javaxscriptrunner.java:103)         @ org.apache.tools.ant.util.optional.javaxscriptrunner.executescript(javaxscriptrunner.java:67)         @ org.apache.tools.ant.taskdefs.optional.script.scriptdef.executescript(scriptdef.java:350)         @ org.apache.tools.ant.taskdefs.optional.script.scriptdefbase.execute(scriptdefbase.java:50)         @ org.apache.tools.ant.unknownelement.execute(unknownelement.java:291)         @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)         @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)         @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)         @ java.lang.reflect.method.invoke(method.java:498)         @ org.apache.tools.ant.dispatch.dispatchutils.execute(dispatchutils.java:106)         @ org.apache.tools.ant.task.perform(task.java:348)         @ org.apache.tools.ant.target.execute(target.java:390)         @ org.apache.tools.ant.target.performtasks(target.java:411)         @ org.apache.tools.ant.project.executesortedtargets(project.java:1399)         @ org.apache.tools.ant.project.executetarget(project.java:1368)         @ org.apache.tools.ant.helper.defaultexecutor.executetargets(defaultexecutor.java:41)         @ org.apache.tools.ant.project.executetargets(project.java:1251)         @ org.apache.tools.ant.main.runbuild(main.java:809)         @ org.apache.tools.ant.main.startant(main.java:217)         @ org.apache.tools.ant.launch.launcher.run(launcher.java:280)         @ org.apache.tools.ant.launch.launcher.main(launcher.java:109)  total time: 0 seconds 

in case matters:

$ cat /etc/redhat-release red hat enterprise linux server release 6.8 (santiago) $ ant -version apache ant(tm) version 1.8.2 compiled on december 20 2010 

the attributes lower-cased automatically. found out putting

self.log(attributes); 

into script.

so if change script use propn instead of propn works:

project.setproperty(attributes.get("propn"), hn.replace(/[^0-9]/g,"")); 

this documented in scriptdef task documentation:

note: ant turn attribute , element names lowercase names, if use name="someattribute", you'll have use "someattribute" retrieve attribute's value attributes collection.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -