Browse Source

fmt/refac

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@556982 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 18 years ago
parent
commit
7da091a46f
1 changed files with 19 additions and 40 deletions
  1. +19
    -40
      src/main/org/apache/tools/ant/types/PatternSet.java

+ 19
- 40
src/main/org/apache/tools/ant/types/PatternSet.java View File

@@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */

package org.apache.tools.ant.types; package org.apache.tools.ant.types;


import java.io.BufferedReader; import java.io.BufferedReader;
@@ -27,6 +26,7 @@ import java.util.StringTokenizer;
import java.util.Vector; import java.util.Vector;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.FileUtils;


/** /**
* Named collection of include/exclude tags. * Named collection of include/exclude tags.
@@ -107,7 +107,8 @@ public class PatternSet extends DataType implements Cloneable {
private boolean valid(Project p) { private boolean valid(Project p) {
if (ifCond != null && p.getProperty(ifCond) == null) { if (ifCond != null && p.getProperty(ifCond) == null) {
return false; return false;
} else if (unlessCond != null && p.getProperty(unlessCond) != null) {
}
if (unlessCond != null && p.getProperty(unlessCond) != null) {
return false; return false;
} }
return true; return true;
@@ -138,7 +139,6 @@ public class PatternSet extends DataType implements Cloneable {
buf.append(unlessCond); buf.append(unlessCond);
} }
} }

return buf.toString(); return buf.toString();
} }
} }
@@ -188,7 +188,6 @@ public class PatternSet extends DataType implements Cloneable {
if (isReference()) { if (isReference()) {
throw noChildrenAllowed(); throw noChildrenAllowed();
} }

String[] nestedIncludes = p.getIncludePatterns(getProject()); String[] nestedIncludes = p.getIncludePatterns(getProject());
String[] nestedExcludes = p.getExcludePatterns(getProject()); String[] nestedExcludes = p.getExcludePatterns(getProject());


@@ -197,7 +196,6 @@ public class PatternSet extends DataType implements Cloneable {
createInclude().setName(nestedIncludes[i]); createInclude().setName(nestedIncludes[i]);
} }
} }

if (nestedExcludes != null) { if (nestedExcludes != null) {
for (int i = 0; i < nestedExcludes.length; i++) { for (int i = 0; i < nestedExcludes.length; i++) {
createExclude().setName(nestedExcludes[i]); createExclude().setName(nestedExcludes[i]);
@@ -325,13 +323,12 @@ public class PatternSet extends DataType implements Cloneable {
* includes or excludes list (as appropriate). * includes or excludes list (as appropriate).
*/ */
private void readPatterns(File patternfile, Vector patternlist, Project p) private void readPatterns(File patternfile, Vector patternlist, Project p)
throws BuildException {
throws BuildException {


BufferedReader patternReader = null; BufferedReader patternReader = null;
try { try {
// Get a FileReader // Get a FileReader
patternReader =
new BufferedReader(new FileReader(patternfile));
patternReader = new BufferedReader(new FileReader(patternfile));


// Create one NameEntry in the appropriate pattern list for each // Create one NameEntry in the appropriate pattern list for each
// line in the file. // line in the file.
@@ -344,17 +341,10 @@ public class PatternSet extends DataType implements Cloneable {
line = patternReader.readLine(); line = patternReader.readLine();
} }
} catch (IOException ioe) { } catch (IOException ioe) {
String msg = "An error occurred while reading from pattern file: "
+ patternfile;
throw new BuildException(msg, ioe);
throw new BuildException("An error occurred while reading from pattern file: "
+ patternfile, ioe);
} finally { } finally {
if (null != patternReader) {
try {
patternReader.close();
} catch (IOException ioe) {
//Ignore exception
}
}
FileUtils.close(patternReader);
} }
} }


@@ -367,14 +357,12 @@ public class PatternSet extends DataType implements Cloneable {
if (isReference()) { if (isReference()) {
throw new BuildException("Cannot append to a reference"); throw new BuildException("Cannot append to a reference");
} }

String[] incl = other.getIncludePatterns(p); String[] incl = other.getIncludePatterns(p);
if (incl != null) { if (incl != null) {
for (int i = 0; i < incl.length; i++) { for (int i = 0; i < incl.length; i++) {
createInclude().setName(incl[i]); createInclude().setName(incl[i]);
} }
} }

String[] excl = other.getExcludePatterns(p); String[] excl = other.getExcludePatterns(p);
if (excl != null) { if (excl != null) {
for (int i = 0; i < excl.length; i++) { for (int i = 0; i < excl.length; i++) {
@@ -391,10 +379,9 @@ public class PatternSet extends DataType implements Cloneable {
public String[] getIncludePatterns(Project p) { public String[] getIncludePatterns(Project p) {
if (isReference()) { if (isReference()) {
return getRef(p).getIncludePatterns(p); return getRef(p).getIncludePatterns(p);
} else {
readFiles(p);
return makeArray(includeList, p);
} }
readFiles(p);
return makeArray(includeList, p);
} }


/** /**
@@ -405,10 +392,9 @@ public class PatternSet extends DataType implements Cloneable {
public String[] getExcludePatterns(Project p) { public String[] getExcludePatterns(Project p) {
if (isReference()) { if (isReference()) {
return getRef(p).getExcludePatterns(p); return getRef(p).getExcludePatterns(p);
} else {
readFiles(p);
return makeArray(excludeList, p);
} }
readFiles(p);
return makeArray(excludeList, p);
} }


/** /**
@@ -420,10 +406,9 @@ public class PatternSet extends DataType implements Cloneable {
public boolean hasPatterns(Project p) { public boolean hasPatterns(Project p) {
if (isReference()) { if (isReference()) {
return getRef(p).hasPatterns(p); return getRef(p).hasPatterns(p);
} else {
return includesFileList.size() > 0 || excludesFileList.size() > 0
|| includeList.size() > 0 || excludeList.size() > 0;
} }
return includesFileList.size() > 0 || excludesFileList.size() > 0
|| includeList.size() > 0 || excludeList.size() > 0;
} }


/** /**
@@ -441,7 +426,6 @@ public class PatternSet extends DataType implements Cloneable {
if (list.size() == 0) { if (list.size() == 0) {
return null; return null;
} }

Vector tmpNames = new Vector(); Vector tmpNames = new Vector();
for (Enumeration e = list.elements(); e.hasMoreElements();) { for (Enumeration e = list.elements(); e.hasMoreElements();) {
NameEntry ne = (NameEntry) e.nextElement(); NameEntry ne = (NameEntry) e.nextElement();
@@ -450,7 +434,6 @@ public class PatternSet extends DataType implements Cloneable {
tmpNames.addElement(pattern); tmpNames.addElement(pattern);
} }
} }

String[] result = new String[tmpNames.size()]; String[] result = new String[tmpNames.size()];
tmpNames.copyInto(result); tmpNames.copyInto(result);
return result; return result;
@@ -468,16 +451,14 @@ public class PatternSet extends DataType implements Cloneable {
if (fileName != null) { if (fileName != null) {
File inclFile = p.resolveFile(fileName); File inclFile = p.resolveFile(fileName);
if (!inclFile.exists()) { if (!inclFile.exists()) {
throw new BuildException("Includesfile "
+ inclFile.getAbsolutePath()
+ " not found.");
throw new BuildException("Includesfile " + inclFile.getAbsolutePath()
+ " not found.");
} }
readPatterns(inclFile, includeList, p); readPatterns(inclFile, includeList, p);
} }
} }
includesFileList.removeAllElements(); includesFileList.removeAllElements();
} }

if (excludesFileList.size() > 0) { if (excludesFileList.size() > 0) {
Enumeration e = excludesFileList.elements(); Enumeration e = excludesFileList.elements();
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
@@ -486,9 +467,8 @@ public class PatternSet extends DataType implements Cloneable {
if (fileName != null) { if (fileName != null) {
File exclFile = p.resolveFile(fileName); File exclFile = p.resolveFile(fileName);
if (!exclFile.exists()) { if (!exclFile.exists()) {
throw new BuildException("Excludesfile "
+ exclFile.getAbsolutePath()
+ " not found.");
throw new BuildException("Excludesfile " + exclFile.getAbsolutePath()
+ " not found.");
} }
readPatterns(exclFile, excludeList, p); readPatterns(exclFile, excludeList, p);
} }
@@ -501,8 +481,7 @@ public class PatternSet extends DataType implements Cloneable {
* @return a printable form of this object. * @return a printable form of this object.
*/ */
public String toString() { public String toString() {
return "patternSet{ includes: " + includeList
+ " excludes: " + excludeList + " }";
return "patternSet{ includes: " + includeList + " excludes: " + excludeList + " }";
} }


/** /**


Loading…
Cancel
Save