ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject AW: set property values using my own task
Date Tue, 18 Oct 2005 11:20:09 GMT
Shouldnt be a problem - have you tried that?
- properties are immutable, once set they cant change
- setNewProperty() knows that
- props are set in order of their appearance
  -- command line
  -- time of load (doesnt matter if property-name/value, property-file or mytask.getProject.setNewProperty)


So a 
$ ant 
should give you the values from the file and a 
$ ant -Dprod.product_number=DEV-20051018
should override that (dont forget your prefix!)

Jan


>-----Urspr√ľngliche Nachricht-----
>Von: Mikael Petterson (KI/EAB) [mailto:mikael.petterson@ericsson.com] 
>Gesendet: Dienstag, 18. Oktober 2005 13:09
>An: Ant Users List
>Betreff: RE: set property values using my own task
>
>Hi,
>
>That works but I need to set the  property values ( as you can 
>do on the command line with -D) for 
>
><property name="arch"                         value="jvm"/>
><property name="product_number"         value="BAD000"/>
><property name="product_revision"         value="P0"/>
>
>so the default values will be overridden( read from 
>product.attributes file).
>Then I will use the properties in target called prepare-product-info.
>Was I more clear this time?
>
>cheers,
>
>//mikael
>
>
>-----Original Message-----
>From: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de]
>Sent: den 18 oktober 2005 13:02
>To: user@ant.apache.org
>Subject: AW: set property values using my own task
>
>
>Where is the problem?
>
><project>
>    <taskdef/>
>    <propertyread/>
>    <target>
>        <echoproperties/>
>    </target>
></project>
>
>in that order should work.
>
>
>Jan
>
>
>>-----Urspr√ľngliche Nachricht-----
>>Von: Mikael Petterson (KI/EAB) [mailto:mikael.petterson@ericsson.com]
>>Gesendet: Dienstag, 18. Oktober 2005 12:50
>>An: user@ant.apache.org
>>Betreff: set property values using my own task
>>
>>Hi,
>>
>>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?
>>
>>cheers,
>>
>>//mikael
>>
>>
>>This is the content of product.attributes:
>>
>>TARGET:PRODUCT_NUMBER:PRODUCT_REVISION
>>jvm:CXC1327714/22:R1A01
>>default:BAD_TARGET:R1A01
>>
>>
>>build.xml
>>=======
>>
>><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" 
>>	    classname="se.mycompany.PropertyReadTask"/>
>>	    <propertyread prefix="prod" 
>>file="product.attributes" delimiter=":"/>
>>   <echoproperties prefix="prod"/>
>>  </target>
>>
>> <target name="prepare-product-info" 
>>	depends="propertyread"
>>	description="Prepare product information.">
>>  <echo>Product name   : ${name}</echo>
>>  <echo>Product number : ${product_number}</echo>
>>  <echo>Product rev    : ${product_revision}</echo>
>>  <exec executable="cleartool"
>>        outputproperty="view">
>>    <arg line="pwv -short"/>
>>  </exec>
>>  <tstamp>
>>    <format property="datetime"
>>            pattern="yyyy-MM-dd HH:mm:ss z"/>
>>  </tstamp>
>>
>>  <property name="product.attrs.line1"
>>            value="${user.dir} ${name} ${arch} ${view}"/>
>>  <property name="product.attrs.line2"
>>            value="${product_number} ${product_revision} ${datetime} 
>>${identifier}"/> </target>
>>
>></project>
>>
>>PropertyReadTask file
>>================
>>public class PropertyReadTask extends org.apache.tools.ant.Task{
>>    
>>    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");
>>        }
>>        try{
>>        // read the file
>>        Reader rdr = new java.io.FileReader(file);
>>        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: user-unsubscribe@ant.apache.org For 
>additional 
>>commands, e-mail: user-help@ant.apache.org
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
>additional commands, e-mail: user-help@ant.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
>additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message