Browse Source

1. "final" modifiers introduced in relevant places.

2.  BuildExceptions thrown only when failonerror is true.
3.  A few variables renamed.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271374 13f79535-47bb-0310-9956-ffa450edef68
master
Magesh Umasankar 23 years ago
parent
commit
e886871506
1 changed files with 45 additions and 30 deletions
  1. +45
    -30
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java

+ 45
- 30
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java View File

@@ -60,9 +60,9 @@ import org.apache.tools.ant.types.AntFilterReader;
import org.apache.tools.ant.types.FilterReaderSet; import org.apache.tools.ant.types.FilterReaderSet;
import org.apache.tools.ant.types.Parameterizable; import org.apache.tools.ant.types.Parameterizable;


import java.io.*;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.io.*;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;


@@ -104,7 +104,7 @@ public class LoadFile extends Task {
/** /**
* Holds filterReaderSets * Holds filterReaderSets
*/ */
private Vector filterReaderSets=new Vector();
private final Vector filterReaderSets = new Vector();


/** /**
* Encoding to use for filenames, defaults to the platform's default * Encoding to use for filenames, defaults to the platform's default
@@ -117,7 +117,7 @@ public class LoadFile extends Task {
* @param encoding The new Encoding value * @param encoding The new Encoding value
*/ */


public void setEncoding(String encoding) {
public final void setEncoding(final String encoding) {
this.encoding = encoding; this.encoding = encoding;
} }


@@ -127,7 +127,7 @@ public class LoadFile extends Task {
* *
* @param property The new Property value * @param property The new Property value
*/ */
public void setProperty(String property) {
public final void setProperty(final String property) {
this.property = property; this.property = property;
} }


@@ -137,7 +137,7 @@ public class LoadFile extends Task {
* *
* @param srcFile The new SrcFile value * @param srcFile The new SrcFile value
*/ */
public void setSrcFile(File srcFile) {
public final void setSrcFile(final File srcFile) {
this.srcFile = srcFile; this.srcFile = srcFile;
} }


@@ -147,7 +147,7 @@ public class LoadFile extends Task {
* *
* @param fail The new Failonerror value * @param fail The new Failonerror value
*/ */
public void setFailonerror(boolean fail) {
public final void setFailonerror(final boolean fail) {
failOnError = fail; failOnError = fail;
} }


@@ -156,7 +156,7 @@ public class LoadFile extends Task {
* setter to eval properties. * setter to eval properties.
* @since 1.6 * @since 1.6
*/ */
public void setEvaluateProperties(boolean evaluateProperties) {
public final void setEvaluateProperties(final boolean evaluateProperties) {
this.evaluateProperties=evaluateProperties; this.evaluateProperties=evaluateProperties;
} }


@@ -166,7 +166,7 @@ public class LoadFile extends Task {
* *
* @exception BuildException if something goes wrong with the build * @exception BuildException if something goes wrong with the build
*/ */
public void execute()
public final void execute()
throws BuildException { throws BuildException {
//validation //validation
if (srcFile == null) { if (srcFile == null) {
@@ -180,13 +180,13 @@ public class LoadFile extends Task {
Reader instream = null; Reader instream = null;
log("loading "+srcFile+" into property "+property,Project.MSG_VERBOSE); log("loading "+srcFile+" into property "+property,Project.MSG_VERBOSE);
try { try {
long len = srcFile.length();
final long len = srcFile.length();
log("file size = "+len,Project.MSG_DEBUG); log("file size = "+len,Project.MSG_DEBUG);
//discard most of really big files //discard most of really big files
if (len > Integer.MAX_VALUE) { if (len > Integer.MAX_VALUE) {
log("this file is far to big to load completely"); log("this file is far to big to load completely");
} }
int size=(int) len;
final int size=(int) len;
//open up the file //open up the file
fis = new FileInputStream(srcFile); fis = new FileInputStream(srcFile);
bis = new BufferedInputStream(fis); bis = new BufferedInputStream(fis);
@@ -206,20 +206,28 @@ public class LoadFile extends Task {
log("loaded " + text.length() + " characters",Project.MSG_VERBOSE); log("loaded " + text.length() + " characters",Project.MSG_VERBOSE);
log(property+" := "+text,Project.MSG_DEBUG); 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) { if (failOnError) {
throw new BuildException(message, ioe, location); throw new BuildException(message, ioe, location);
} }
else { else {
log(message, Project.MSG_ERR); log(message, Project.MSG_ERR);
} }
} catch (final BuildException be) {
if (failOnError) {
throw be;
}
else {
log(be.getMessage(), Project.MSG_ERR);
}
} finally { } finally {
try { try {
if (fis != null) { if (fis != null) {
fis.close(); fis.close();
} }
} catch (IOException ioex) { } catch (IOException ioex) {
//ignore
} }
} }
} }
@@ -227,20 +235,23 @@ public class LoadFile extends Task {
/** /**
* Process the input by passing it through the reader chain. * 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 char[] buffer = new char[size];
final int filterReadersCount = filterReaderSets.size(); final int filterReadersCount = filterReaderSets.size();
final Vector finalFilters = new Vector(); final Vector finalFilters = new Vector();


for (int i = 0; i < filterReadersCount; i++) { 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 Vector filterReaders = filterset.getFilterReaders();
final int readerCount = filterReaders.size(); final int readerCount = filterReaders.size();
for (int j = 0; j < readerCount; j++) { 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 @@ public class LoadFile extends Task {


if (filtersCount > 0) { if (filtersCount > 0) {
for (int i = 0; i < filtersCount; i++) { 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 { 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}; 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(); final Hashtable params = filter.getParams();
((Parameterizable) instream).setParameters(params);
((Parameterizable)
instream).setParameters(params);
} }
} }
} catch (final ClassNotFoundException cnfe) { } catch (final ClassNotFoundException cnfe) {
throw new BuildException(cnfe);
throw new BuildException(cnfe, location);
} catch (final InstantiationException ie) { } catch (final InstantiationException ie) {
throw new BuildException(ie);
throw new BuildException(ie, location);
} catch (final IllegalAccessException iae) { } catch (final IllegalAccessException iae) {
throw new BuildException(iae);
throw new BuildException(iae, location);
} catch (final InvocationTargetException ite) { } catch (final InvocationTargetException ite) {
throw new BuildException(ite);
throw new BuildException(ite, location);
} }
} }
} }


Loading…
Cancel
Save