ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <hol...@yahoo.com>
Subject Re: More Javascript questions
Date Thu, 25 Oct 2001 15:50:36 GMT
--- Robert Seeger <rseeger@nortelnetworks.com> wrote:
> - How can I define a "list of items" in ant?
> I want to be able to say something like
> <this-package-depends-on-the-following-packages name="pkgdepends">
>   <item>PkgDatabase</item>
>   <item>PkgLogger</item>
>   <item>PkgFtp</item>
> </this...package>

I think to do that you'd need to create a new type (eg., <list>) and then
<typedef> it -- but I've not really looked into doing that sort of thing,
so I can't really tell you much about how to do it.

The best I can offer at this point is to suggest you make your
"pkgdepends" a property, and just put the values into it as either a
space- or comma-separated list.

> - How can I iterate over that list in javascript?
> I want to be able to do the following type of thing in javascript...
> classpath="";
> prefix="/usr/lib";
> suffix="src/java";
> foreach pkg ${pkgdepends} {
>   if(classpath == "") {
>     classpath = "$prefix/$pkg/$suffix";
>   } else {
>     classpath = "$classpath:$prefix/$pkg/$suffix";
>   }
> }
> project.setProperty("pkg.classpath", $classpath);

<property name="pkgdepends" value="PkgDatabase,PkgLogger,PkgFTP"/>
or
<property name="pkgdepends" value="PkgDatabase PkgLogger PkgFTP"/>
or
<property name="pkgdepends" value="PkgDatabase, PkgLogger, PkgFTP"/>
or
$ ant -Dpkgdepends="foo, bar, blat" setPkgCP  #you get the idea :)

<target name="setPkgCP">
  <property name="prefix" value="/usr/lib/"/>
  <property name="suffix" value="/src/java"/>
  <script language="javascript"> <![CDATA[
    importClass(java.util.StringTokenizer);
    prefix = projname.getProperty("prefix");
    suffix = projname.getProperty("suffix");
    pkgs = new StringTokenizer(projname.getProperty("pkgdepends"), " ,");
    sep = projname.getProperty("path.separator");
    cp = "";
    while (pkgs.hasMoreTokens()) {
      pkg = pkgs.nextToken();
      if(cp){
        cp = cp + sep + prefix + pkg + suffix;
      }
      else{
        cp = prefix + pkg + suffix;
      }
    }
    projname.setProperty("pkg.classpath", cp);
  ]]> </script>
  <echo message="${pkg.classpath}"/>
</target>

Note: Replace "projname" with the actual name of your project. Also, if
you don't need to allow "prefix" and "suffix" to be overridden, you don't
really need to set them as properties -- just set them as vars in the
script directly.

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

Mime
View raw message