diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java deleted file mode 100644 index 6cbb7614c..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs.optional; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Properties; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; - -/** - * PropertyFile task uses java.util.Properties to modify integer, String and - * Date settings in a property file.

- * - * The following is an example of its usage: - *

- *

- * - * The <propertyfile> task must have:
- * - *

- * Other parameters are:
- * - * - * The <entry> task must have:
- * - * - * Other parameters are:
- * - * - * If type is unspecified, it defaults to string Parameter values:
- * - * - * String property types can only use the "=" operation. Date property types can - * only use the "never" or "now" operations. Int property types can only use the - * "=", "-" or "+" operations.

- * - * The message property is used for the property file header, with "\\" being a - * newline delimiter charater. - * - * @author Thomas Christen chr@active.ch - * @author Jeremy Mawson - * jem@loftinspace.com.au - */ -public class PropertyFile - extends AbstractTask -{ - private ArrayList m_entries = new ArrayList(); - - // Use this to prepend a message to the properties file - private String m_comment; - - private Properties m_properties; - private File m_file; - - public void setComment( final String comment ) - { - m_comment = comment; - } - - public void setFile( final File file ) - { - m_file = file; - } - - public Entry createEntry() - { - final Entry entry = new Entry(); - m_entries.add( entry ); - return entry; - } - - public void execute() - throws TaskException - { - checkParameters(); - readFile(); - executeOperation(); - writeFile(); - } - - /* - * Returns whether the given parameter has been defined. - */ - private boolean checkParam( String param ) - { - return !( ( param == null ) || ( param.equals( "null" ) ) ); - } - - private boolean checkParam( File param ) - { - return !( param == null ); - } - - private void checkParameters() - throws TaskException - { - if( !checkParam( m_file ) ) - { - throw new TaskException( "file token must not be null." ); - } - } - - private void executeOperation() - throws TaskException - { - for( Iterator e = m_entries.iterator(); e.hasNext(); ) - { - Entry entry = (Entry)e.next(); - entry.executeOn( m_properties ); - } - } - - private void readFile() - throws TaskException - { - // Create the PropertyFile - m_properties = new Properties(); - try - { - if( m_file.exists() ) - { - getLogger().info( "Updating property file: " + m_file.getAbsolutePath() ); - FileInputStream fis = null; - try - { - fis = new FileInputStream( m_file ); - BufferedInputStream bis = new BufferedInputStream( fis ); - m_properties.load( bis ); - } - finally - { - if( fis != null ) - { - fis.close(); - } - } - } - else - { - getLogger().info( "Creating new property file: " + - m_file.getAbsolutePath() ); - FileOutputStream out = null; - try - { - out = new FileOutputStream( m_file.getAbsolutePath() ); - out.flush(); - } - finally - { - if( out != null ) - { - out.close(); - } - } - } - } - catch( IOException ioe ) - { - throw new TaskException( ioe.toString() ); - } - } - - private void writeFile() - throws TaskException - { - BufferedOutputStream bos = null; - try - { - bos = new BufferedOutputStream( new FileOutputStream( m_file ) ); - - // Properties.store is not available in JDK 1.1 - Method m = - Properties.class.getMethod( "store", - new Class[]{ - OutputStream.class, - String.class} - ); - m.invoke( m_properties, new Object[]{bos, m_comment} ); - - } - catch( NoSuchMethodException nsme ) - { - m_properties.save( bos, m_comment ); - } - catch( InvocationTargetException ite ) - { - Throwable t = ite.getTargetException(); - throw new TaskException( "Error", t ); - } - catch( IllegalAccessException iae ) - { - // impossible - throw new TaskException( "Error", iae ); - } - catch( IOException ioe ) - { - throw new TaskException( "Error", ioe ); - } - finally - { - if( bos != null ) - { - try - { - bos.close(); - } - catch( IOException ioex ) - { - } - } - } - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/PropertyFile.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/PropertyFile.java deleted file mode 100644 index 6cbb7614c..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/PropertyFile.java +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs.optional; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Properties; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; - -/** - * PropertyFile task uses java.util.Properties to modify integer, String and - * Date settings in a property file.

- * - * The following is an example of its usage: - *

- *

- * - * The <propertyfile> task must have:
- * - *

- * Other parameters are:
- * - * - * The <entry> task must have:
- * - * - * Other parameters are:
- * - * - * If type is unspecified, it defaults to string Parameter values:
- * - * - * String property types can only use the "=" operation. Date property types can - * only use the "never" or "now" operations. Int property types can only use the - * "=", "-" or "+" operations.

- * - * The message property is used for the property file header, with "\\" being a - * newline delimiter charater. - * - * @author Thomas Christen chr@active.ch - * @author Jeremy Mawson - * jem@loftinspace.com.au - */ -public class PropertyFile - extends AbstractTask -{ - private ArrayList m_entries = new ArrayList(); - - // Use this to prepend a message to the properties file - private String m_comment; - - private Properties m_properties; - private File m_file; - - public void setComment( final String comment ) - { - m_comment = comment; - } - - public void setFile( final File file ) - { - m_file = file; - } - - public Entry createEntry() - { - final Entry entry = new Entry(); - m_entries.add( entry ); - return entry; - } - - public void execute() - throws TaskException - { - checkParameters(); - readFile(); - executeOperation(); - writeFile(); - } - - /* - * Returns whether the given parameter has been defined. - */ - private boolean checkParam( String param ) - { - return !( ( param == null ) || ( param.equals( "null" ) ) ); - } - - private boolean checkParam( File param ) - { - return !( param == null ); - } - - private void checkParameters() - throws TaskException - { - if( !checkParam( m_file ) ) - { - throw new TaskException( "file token must not be null." ); - } - } - - private void executeOperation() - throws TaskException - { - for( Iterator e = m_entries.iterator(); e.hasNext(); ) - { - Entry entry = (Entry)e.next(); - entry.executeOn( m_properties ); - } - } - - private void readFile() - throws TaskException - { - // Create the PropertyFile - m_properties = new Properties(); - try - { - if( m_file.exists() ) - { - getLogger().info( "Updating property file: " + m_file.getAbsolutePath() ); - FileInputStream fis = null; - try - { - fis = new FileInputStream( m_file ); - BufferedInputStream bis = new BufferedInputStream( fis ); - m_properties.load( bis ); - } - finally - { - if( fis != null ) - { - fis.close(); - } - } - } - else - { - getLogger().info( "Creating new property file: " + - m_file.getAbsolutePath() ); - FileOutputStream out = null; - try - { - out = new FileOutputStream( m_file.getAbsolutePath() ); - out.flush(); - } - finally - { - if( out != null ) - { - out.close(); - } - } - } - } - catch( IOException ioe ) - { - throw new TaskException( ioe.toString() ); - } - } - - private void writeFile() - throws TaskException - { - BufferedOutputStream bos = null; - try - { - bos = new BufferedOutputStream( new FileOutputStream( m_file ) ); - - // Properties.store is not available in JDK 1.1 - Method m = - Properties.class.getMethod( "store", - new Class[]{ - OutputStream.class, - String.class} - ); - m.invoke( m_properties, new Object[]{bos, m_comment} ); - - } - catch( NoSuchMethodException nsme ) - { - m_properties.save( bos, m_comment ); - } - catch( InvocationTargetException ite ) - { - Throwable t = ite.getTargetException(); - throw new TaskException( "Error", t ); - } - catch( IllegalAccessException iae ) - { - // impossible - throw new TaskException( "Error", iae ); - } - catch( IOException ioe ) - { - throw new TaskException( "Error", ioe ); - } - finally - { - if( bos != null ) - { - try - { - bos.close(); - } - catch( IOException ioex ) - { - } - } - } - } -}