You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Robert Seeger <rs...@nortelnetworks.com> on 2001/10/23 20:39:19 UTC

More Javascript questions

Heya folks. Thanks to all the great help I received from ym previous
questions, I've gotten almost all the way to where I want to be. If you
missed the "where I want to be, and what I'm try to do" part, don't worry
about it... doesn't really matter all that much.

Anyways, I've gotten to the point where I need to ask another pair of
questions:

- 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>

- 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);


Any ideas on this? Keep in mind, I'm not fluent in javascript, but I'm
quite willing to learn more.

Robert Seeger
========================================
Robert Seeger
Network Engineer
Nortel Networks

Telephone:	(518)237-2087
Pager:		(800)SKY-8888  Pin#1264792
Fax:		(518)237-4190
Email:		rseeger@nortelnetworks.com
Address:	224 5th Ave, Apt#2
		Lansingburgh, NY 12182
========================================

Re: More Javascript questions

Posted by Diane Holt <ho...@yahoo.com>.
--- Robert Seeger <rs...@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