ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pablo Garralda <PGarra...@amtec.net>
Subject RE: setting properties from a User defined Task.
Date Tue, 01 Aug 2000 20:13:18 GMT



>>where did you set the value of property "ppp" ?

Sorry!! I wasn't clear enough!!

I set that value at the exec method of my (dirListing) task Class:
using setProperty method.

[...]
   project.setProperty(<prop_name> , <prop_value> );
[...]


Here is the entire class code :


import org.apache.tools.ant.*;
import org.apache.tools.ant.taskdefs.*;
import java.io.File;

public class dirListing extends MatchingTask {

   File basedir;
   String property;
   String separator;

   public dirListing(){
      super();
   }
   
   public void init() throws BuildException {
      setSeparator(" "); 
      setDescription("Set a property with a directory listing");
      setTaskName("dirlisting");
   } 

   public void setBasedir(String bd){ 
     basedir = project.resolveFile(bd);
   }

   public void setProperty(String arg){ 
     property = arg;
   }

   public void setSeparator(String arg){ 
     separator = arg;
   }

   public void execute() throws BuildException {

     DirectoryScanner ds = super.getDirectoryScanner(basedir);

     //checks
      if (basedir == null) {
	throw new BuildException("dirlisting: basedir attribute must be set
");
      }
      if (property == null) {
	throw new BuildException("dirlisting: proterty attribute must be set
");
      }

      ds.scan();

      String[] files = ds.getIncludedFiles();
      StringBuffer list = new StringBuffer(files.length * 10);
      if (files.length != 0){
         list.append(files[0]);
      }
      for (int i = 0; i < files.length;i++) {
         list.append(this.separator);
         list.append(files[i]);
      }
  
      project.setProperty(this.property , list.toString());
   }
}





-----Original Message-----
From: Pablo Garralda [mailto:PGarralda@amtec.net]
Sent: Tuesday, August 01, 2000 3:15 PM
To: ant-user@jakarta.apache.org
Subject: setting properties from a User defined Task.



Hi !!

I'm trying to build a user defined Task to store a directory listing into a
Property. 
Someting like this: 

  ...
  <target name="Test" depends="" >
      <dirlisting basedir="." includes="*.java" property="ppp" separator=" "
/>
      <echo message="Java files: ${ppp}" />
  </target>
  ...

This prints:

  Java files: ${ppp}

It don't replace ${ppp} with "ppp" value!!! What's wrong? 

Thanks in advance,
		Pablo.



    

Mime
View raw message