Menu

#43 unset file

open
nobody
None
5
2006-07-20
2006-07-20
Omry Yadan
No

Added functionality to unset a properties file keys.
this is useful when you want to undo a load of a
properties file.

Discussion

  • Omry Yadan

    Omry Yadan - 2006-08-02

    Logged In: YES
    user_id=126268

    OOPS, forgot to include patch.

    106,107c106,117
    < if ( name == null || name.equals( "" ) ) {
    < throw new BuildException( "The 'name'
    attribute is required with 'unset'." );
    ---
    > if ( (name == null || name.equals( "" )) && (file
    == null) ) {
    > throw new BuildException( "The 'name' or
    'file' attribute are required with 'unset'." );
    > }
    >
    > if (file != null)
    > {
    > unloadFile(file);
    > }
    >
    > if (name == null || name.equals( "" ))
    > {
    > removeProperty( name );
    109d118
    < removeProperty( name );
    280a290,324
    >
    > private void unloadFile( File file ) throws
    BuildException {
    > Properties props = new Properties();
    > try {
    > if ( file.exists() ) {
    > FileInputStream fis = new FileInputStream(
    file );
    > try {
    > props.load( fis );
    > }
    > finally {
    > if ( fis != null ) {
    > fis.close();
    > }
    > }
    >
    > Enumeration keys = props.keys();
    > log( "Unloading file : " + file
    ,Project.MSG_VERBOSE );
    >
    > while (keys.hasMoreElements())
    > {
    > String key = (String) keys.nextElement();
    > log( "Unloading " + key + " = " +
    getProject().getProperty(key) ,Project.MSG_VERBOSE );
    > removeProperty(key);
    > }
    > }
    > else {
    > log( "Unable to find property file: " +
    file.getAbsolutePath(),
    > Project.MSG_VERBOSE );
    > }
    > }
    > catch ( IOException ex ) {
    > throw new BuildException( ex, location );
    > }
    > }
    >

     
  • Omry Yadan

    Omry Yadan - 2006-08-02

    diff file

     

Log in to post a comment.