开发者

How to get propery from scriptdef using Flex Ant Tasks

I have a working build.xml file that I'm using for various tasks like building a swc etc. One of the things I want to do is parse a version number from a class and append it to the swc filename.

I am using scriptd开发者_如何学Pythonef to parse the version number, but I can't work out how to access the result from outside of the scriptdef call.

<target name="output_version">
     <loadfile property="version" srcFile="src/Main.as"/>
     <script_test str="${version}"/>    
    <echo>${str}</echo>
</target>

<scriptdef name="script_test" language="javascript">
                <attribute name="str"/>
                <attribute name="result"/>
                <element name="fileset" type="fileset"/>
                <element name="path" type="path"/>
                <![CDATA[

                  var txt = attributes.get("str");
                  var patt = /VERSION:String = "(.+)?"/;
                  var result = patt.exec(txt);
                  self.log("Hello from script: " + result[1]);

                 self.project.setProperty( attributes.get("str"), result[1]);
                ]]>
</scriptdef>


It looks like you're trying to set the str property (as you're echoing it). One option is to, in the javascript, just assign directly to it:

self.project.setProperty( "str", result[1] );

In your posted code the value of

attributes.get("str")

will be the contents of the file src/Main.as, which is not ideal as a property name.

If you want to pass the name of the property to hold the found info in to the scriptdef via the result attribute, use this in the script:

self.project.setProperty( attributes.get("result"), result[1] );

And then in the caller, e.g.:

<script_test str="${version}" result="res" />
<echo>${res}</echo>

Note that Ant properties are immutable - they are not variables - once set the value cannot be changed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜