Forum Discussion

Usha_Kodali's avatar
Usha_Kodali
Frequent Contributor
16 years ago

searching for a word in properties

Hi,

I have following code
filename = context.expand( '${projectDir}\\scheduledatetime.properties' )
file = new java.io.File( filename )
def props
// if the file exists,read the file and set the endpoint according to the environment entered and finally close the file
if( file.exists() )
{
FileReader r = null;
r = new java.io.FileReader( file )

props = new java.util.Properties()
//loading the properties
props.load(r)
log.info("Properties is:"+" "+props)
r.close()
}

The Output for log.info("Properties are:+" "+props) is Tue Jun 22 16:21:51 EDT 2010:INFO:Properties are: [BTH_StartDateTime:2010-06-23T21:00:00.000-04:00, LM_StartDateTime:2010-06-23T21:30:00.000-04:00, LM_EndDateTime:2010-06-23T22:30:00.000-04:00, BTH_EndDateTime:2010-06-23T21:30:00.000-04:00]

Now I want to check of props contains BTH.
How to achive this?
I tried props.contains('BTH') and props.grep('BTH') but both failed.
I want to say if(props.contains('BTH'))
{
do something
}
else log.info("Property doesnt exist")

1 Reply

  • Usha_Kodali's avatar
    Usha_Kodali
    Frequent Contributor
    I handled the following way...may be there is better...please suggest

    propsmatchmaker = ~/${testSuiteName}/
    def propsmatchmaker = propsmatchmaker.matcher("${props}");
    if(propsmatchmaker.find())
    {
    ..............
    }
    else
    {log.info("Did not find the right property")
    }