ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umag...@apache.org
Subject cvs commit: jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs LoadFile.java
Date Sat, 16 Feb 2002 00:34:27 GMT
umagesh     02/02/15 16:34:27

  Modified:    proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs
                        LoadFile.java
  Log:
  1.  "final" modifiers introduced in relevant places.
  2.  BuildExceptions thrown only when failonerror is true.
  3.  A few variables renamed.
  
  Revision  Changes    Path
  1.2       +45 -30    jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java
  
  Index: LoadFile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LoadFile.java	15 Feb 2002 21:50:55 -0000	1.1
  +++ LoadFile.java	16 Feb 2002 00:34:27 -0000	1.2
  @@ -60,9 +60,9 @@
   import org.apache.tools.ant.types.FilterReaderSet;
   import org.apache.tools.ant.types.Parameterizable;
   
  +import java.io.*;
   import java.lang.reflect.Constructor;
   import java.lang.reflect.InvocationTargetException;
  -import java.io.*;
   import java.util.Hashtable;
   import java.util.Vector;
   
  @@ -104,7 +104,7 @@
       /**
        * Holds filterReaderSets
        */
  -    private Vector filterReaderSets=new Vector();
  +    private final Vector filterReaderSets = new Vector();
   
       /**
        * Encoding to use for filenames, defaults to the platform's default
  @@ -117,7 +117,7 @@
        * @param encoding The new Encoding value
        */
   
  -    public void setEncoding(String encoding) {
  +    public final void setEncoding(final String encoding) {
           this.encoding = encoding;
       }
   
  @@ -127,7 +127,7 @@
        *
        * @param property The new Property value
        */
  -    public void setProperty(String property) {
  +    public final void setProperty(final String property) {
           this.property = property;
       }
   
  @@ -137,7 +137,7 @@
        *
        * @param srcFile The new SrcFile value
        */
  -    public void setSrcFile(File srcFile) {
  +    public final void setSrcFile(final File srcFile) {
           this.srcFile = srcFile;
       }
   
  @@ -147,7 +147,7 @@
        *
        * @param fail The new Failonerror value
        */
  -    public void setFailonerror(boolean fail) {
  +    public final void setFailonerror(final boolean fail) {
           failOnError = fail;
       }
   
  @@ -156,7 +156,7 @@
        * setter to eval properties.
        * @since 1.6
        */
  -    public void setEvaluateProperties(boolean evaluateProperties) {
  +    public final void setEvaluateProperties(final boolean evaluateProperties) {
           this.evaluateProperties=evaluateProperties;
       }
   
  @@ -166,7 +166,7 @@
        *
        * @exception BuildException if something goes wrong with the build
        */
  -    public void execute()
  +    public final void execute()
           throws BuildException {
           //validation
           if (srcFile == null) {
  @@ -180,13 +180,13 @@
           Reader instream = null;
           log("loading "+srcFile+" into property "+property,Project.MSG_VERBOSE);
           try {
  -            long len = srcFile.length();
  +            final long len = srcFile.length();
               log("file size = "+len,Project.MSG_DEBUG);
               //discard most of really big files
               if (len > Integer.MAX_VALUE) {
                   log("this file is far to big to load completely");
               }
  -            int size=(int) len;
  +            final int size=(int) len;
               //open up the file
               fis = new FileInputStream(srcFile);
               bis = new BufferedInputStream(fis);
  @@ -206,20 +206,28 @@
               log("loaded " + text.length() + " characters",Project.MSG_VERBOSE);
               log(property+" := "+text,Project.MSG_DEBUG);
   
  -        } catch (IOException ioe) {
  -            String message = "Unable to load file: " + ioe.toString();
  +        } catch (final IOException ioe) {
  +            final String message = "Unable to load file: " + ioe.toString();
               if (failOnError) {
                   throw new BuildException(message, ioe, location);
               }
               else {
                   log(message, Project.MSG_ERR);
               }
  +        } catch (final BuildException be) {
  +            if (failOnError) {
  +                throw be;
  +            }
  +            else {
  +                log(be.getMessage(), Project.MSG_ERR);
  +            }
           } finally {
               try {
                   if (fis != null) {
                       fis.close();
                   }
               } catch (IOException ioex) {
  +                //ignore
               }
           }
       }
  @@ -227,20 +235,23 @@
       /**
        * Process the input by passing it through the reader chain.
        */
  -    private final String processStream(Reader instream, final int size)
  -        throws IOException {
  +    private final String processStream(final Reader inputReader, final int size)
  +        throws BuildException, IOException {
   
  +        Reader instream = inputReader;
           final char[] buffer = new char[size];
           final int filterReadersCount = filterReaderSets.size();
           final Vector finalFilters = new Vector();
   
           for (int i = 0; i < filterReadersCount; i++) {
  -            final FilterReaderSet filterset = (FilterReaderSet) filterReaderSets.elementAt(i);
  +            final FilterReaderSet filterset =
  +                (FilterReaderSet) filterReaderSets.elementAt(i);
               final Vector filterReaders = filterset.getFilterReaders();
               final int readerCount = filterReaders.size();
               for (int j = 0; j < readerCount; j++) {
  -                final AntFilterReader fr = (AntFilterReader) filterReaders.elementAt(j);
  -                finalFilters.addElement(fr);
  +                final AntFilterReader afr =
  +                    (AntFilterReader) filterReaders.elementAt(j);
  +                finalFilters.addElement(afr);
               }
           }
   
  @@ -248,28 +259,32 @@
   
           if (filtersCount > 0) {
               for (int i = 0; i < filtersCount; i++) {
  -                final AntFilterReader filter = (AntFilterReader) finalFilters.elementAt(i);
  -                final String clazz = filter.getClassName();
  -                if (clazz != null) {
  +                final AntFilterReader filter =
  +                    (AntFilterReader) finalFilters.elementAt(i);
  +                final String className = filter.getClassName();
  +                if (className != null) {
                       try {
  -                        final Class c = Class.forName(clazz);
  -                        if (c != null) {
  -                            final Constructor[] constructors = c.getConstructors();
  +                        final Class clazz = Class.forName(className);
  +                        if (clazz != null) {
  +                            final Constructor[] constructors =
  +                                clazz.getConstructors();
                               final Reader[] rdr = {instream};
  -                            instream = (Reader) constructors[0].newInstance(rdr);
  -                            if (Parameterizable.class.isAssignableFrom(c)) {
  +                            instream =
  +                                (Reader) constructors[0].newInstance(rdr);
  +                            if (Parameterizable.class.isAssignableFrom(clazz)) {
                                   final Hashtable params = filter.getParams();
  -                                ((Parameterizable) instream).setParameters(params);
  +                                ((Parameterizable)
  +                                    instream).setParameters(params);
                               }
                           }
                       } catch (final ClassNotFoundException cnfe) {
  -                        throw new BuildException(cnfe);
  +                        throw new BuildException(cnfe, location);
                       } catch (final InstantiationException ie) {
  -                        throw new BuildException(ie);
  +                        throw new BuildException(ie, location);
                       } catch (final IllegalAccessException iae) {
  -                        throw new BuildException(iae);
  +                        throw new BuildException(iae, location);
                       } catch (final InvocationTargetException ite) {
  -                        throw new BuildException(ite);
  +                        throw new BuildException(ite, location);
                       }
                   }
               }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message