ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikael Petterson (KI/EAB)" <>
Subject set property values using my own task
Date Tue, 18 Oct 2005 10:49:48 GMT

The purose of my task is to set the values for properties arch, product_number and product_revision.
The information is stored in a file called 'product.attributes'. I need to assign the properties
the values ( line two)
in the product.attributes file and then use the property values in target, prepare-product-info.
Is it possible ?
Any suggestions?



This is the content of product.attributes:



<project ........>
<property name="arch"                         value="jvm"/>
<property name="product_number"         value="BAD000"/>
<property name="product_revision"         value="P0"/>


  <target name="product.attributes">
   <taskdef name="propertyread" 
	    <propertyread prefix="prod" file="product.attributes" delimiter=":"/>
   <echoproperties prefix="prod"/>

 <target name="prepare-product-info" 
	description="Prepare product information.">
  <echo>Product name   : ${name}</echo>
  <echo>Product number : ${product_number}</echo>
  <echo>Product rev    : ${product_revision}</echo>
  <exec executable="cleartool"
    <arg line="pwv -short"/>
    <format property="datetime"
            pattern="yyyy-MM-dd HH:mm:ss z"/>

  <property name="product.attrs.line1"
            value="${user.dir} ${name} ${arch} ${view}"/>
  <property name="product.attrs.line2"
            value="${product_number} ${product_revision} ${datetime} ${identifier}"/>


PropertyReadTask file
public class PropertyReadTask extends{
    private String prefix;
    private String file;
    private String delimiter;
    public void execute() throws BuildException {
      if (prefix==null || file==null) {
            throw new BuildException("prefix and file must be set");
        // read the file
        Reader rdr = new;
        String content = FileUtils.readFully(rdr);
         // split into metadata and content data
        String lines[] = content.split( getProject().getProperty("line.separator") );
        String h1eader = lines[0];
        String body = lines[1];

        // get the metadata
        String metaData[] = header.split(delimiter);

        // get the content data and save as Ant properties
        String contentData[] = body.split(delimiter);
        for (int i=0; i<contentData.length; i++) {
            getProject().setNewProperty(prefix + "." + metaData[i], contentData[i]);
        }catch(Exception e){
            throw new BuildException("Something happened");
    public void setDelimiter(String delimiter){
        this.delimiter = delimiter;
    public void setFile(String file){
        this.file = file;
    public void setPrefix(String prefix){
         this.prefix = prefix;


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message