You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by mb...@apache.org on 2017/04/13 15:16:08 UTC
[08/34] ant git commit: java 5-8
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/FileList.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/FileList.java b/src/main/org/apache/tools/ant/types/FileList.java
index 42e2763..f91059e 100644
--- a/src/main/org/apache/tools/ant/types/FileList.java
+++ b/src/main/org/apache/tools/ant/types/FileList.java
@@ -37,7 +37,7 @@ import org.apache.tools.ant.types.resources.FileResourceIterator;
*/
public class FileList extends DataType implements ResourceCollection {
- private List<String> filenames = new ArrayList<String>();
+ private List<String> filenames = new ArrayList<>();
private File dir;
/**
@@ -68,8 +68,9 @@ public class FileList extends DataType implements ResourceCollection {
* @param r the reference to another filelist.
* @exception BuildException if an error occurs.
*/
+ @Override
public void setRefid(Reference r) throws BuildException {
- if ((dir != null) || (filenames.size() != 0)) {
+ if ((dir != null) || (!filenames.isEmpty())) {
throw tooManyAttributes();
}
super.setRefid(r);
@@ -105,7 +106,7 @@ public class FileList extends DataType implements ResourceCollection {
*/
public void setFiles(String filenames) {
checkAttributesAllowed();
- if (filenames != null && filenames.length() > 0) {
+ if (!(filenames == null || filenames.isEmpty())) {
StringTokenizer tok = new StringTokenizer(
filenames, ", \t\n\r\f", false);
while (tok.hasMoreTokens()) {
@@ -128,7 +129,7 @@ public class FileList extends DataType implements ResourceCollection {
throw new BuildException("No directory specified for filelist.");
}
- if (filenames.size() == 0) {
+ if (filenames.isEmpty()) {
throw new BuildException("No files specified for filelist.");
}
@@ -187,6 +188,7 @@ public class FileList extends DataType implements ResourceCollection {
* @return an Iterator of Resources.
* @since Ant 1.7
*/
+ @Override
public Iterator<Resource> iterator() {
if (isReference()) {
return getRef(getProject()).iterator();
@@ -200,9 +202,10 @@ public class FileList extends DataType implements ResourceCollection {
* @return number of elements as int.
* @since Ant 1.7
*/
+ @Override
public int size() {
if (isReference()) {
- return ((FileList) getRef(getProject())).size();
+ return getRef(getProject()).size();
}
return filenames.size();
}
@@ -212,6 +215,7 @@ public class FileList extends DataType implements ResourceCollection {
* @return true indicating that all elements will be FileResources.
* @since Ant 1.7
*/
+ @Override
public boolean isFilesystemOnly() {
return true;
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/FileSet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/FileSet.java b/src/main/org/apache/tools/ant/types/FileSet.java
index c6d2127..244e204 100644
--- a/src/main/org/apache/tools/ant/types/FileSet.java
+++ b/src/main/org/apache/tools/ant/types/FileSet.java
@@ -49,12 +49,12 @@ public class FileSet extends AbstractFileSet implements ResourceCollection {
* as this one.
* @return the cloned fileset
*/
- public Object clone() {
+ @Override
+ public FileSet clone() {
if (isReference()) {
return ((FileSet) getRef(getProject())).clone();
- } else {
- return super.clone();
}
+ return (FileSet) super.clone();
}
/**
@@ -62,6 +62,7 @@ public class FileSet extends AbstractFileSet implements ResourceCollection {
* @return an Iterator of Resources.
* @since Ant 1.7
*/
+ @Override
public Iterator<Resource> iterator() {
if (isReference()) {
return ((FileSet) getRef(getProject())).iterator();
@@ -75,6 +76,7 @@ public class FileSet extends AbstractFileSet implements ResourceCollection {
* @return number of elements as int.
* @since Ant 1.7
*/
+ @Override
public int size() {
if (isReference()) {
return ((FileSet) getRef(getProject())).size();
@@ -87,6 +89,7 @@ public class FileSet extends AbstractFileSet implements ResourceCollection {
* @return true indicating that all elements will be FileResources.
* @since Ant 1.7
*/
+ @Override
public boolean isFilesystemOnly() {
return true;
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/FilterSet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/FilterSet.java b/src/main/org/apache/tools/ant/types/FilterSet.java
index 4ff3181..a504896 100644
--- a/src/main/org/apache/tools/ant/types/FilterSet.java
+++ b/src/main/org/apache/tools/ant/types/FilterSet.java
@@ -29,7 +29,6 @@ import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
-import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.VectorSet;
/**
@@ -114,12 +113,6 @@ public class FilterSet extends DataType implements Cloneable {
public class FiltersFile {
/**
- * Constructor for the FiltersFile object.
- */
- public FiltersFile() {
- }
-
- /**
* Sets the file from which filters will be read.
*
* @param file the file from which filters will be read.
@@ -187,7 +180,7 @@ public class FilterSet extends DataType implements Cloneable {
private boolean recurse = true;
private Hashtable<String, String> filterHash = null;
- private Vector<File> filtersFiles = new Vector<File>();
+ private Vector<File> filtersFiles = new Vector<>();
private OnMissing onMissingFiltersFile = OnMissing.FAIL;
private boolean readingFiles = false;
@@ -196,7 +189,7 @@ public class FilterSet extends DataType implements Cloneable {
/**
* List of ordered filters and filter files.
*/
- private Vector<Filter> filters = new Vector<Filter>();
+ private Vector<Filter> filters = new Vector<>();
/**
* Default constructor.
@@ -259,7 +252,7 @@ public class FilterSet extends DataType implements Cloneable {
}
dieOnCircularReference();
if (filterHash == null) {
- filterHash = new Hashtable<String, String>(getFilters().size());
+ filterHash = new Hashtable<>(getFilters().size());
for (Enumeration<Filter> e = getFilters().elements(); e.hasMoreElements();) {
Filter filter = e.nextElement();
filterHash.put(filter.getToken(), filter.getValue());
@@ -358,39 +351,28 @@ public class FilterSet extends DataType implements Cloneable {
* @param filtersFile the file from which filters are read.
* @exception BuildException when the file cannot be read.
*/
- public synchronized void readFiltersFromFile(File filtersFile) throws BuildException {
+ public synchronized void readFiltersFromFile(File filtersFile)
+ throws BuildException {
if (isReference()) {
throw tooManyAttributes();
}
if (!filtersFile.exists()) {
- handleMissingFile("Could not read filters from file "
- + filtersFile + " as it doesn't exist.");
+ handleMissingFile("Could not read filters from file " + filtersFile
+ + " as it doesn't exist.");
}
if (filtersFile.isFile()) {
- log("Reading filters from " + filtersFile, Project.MSG_VERBOSE);
- InputStream in = null;
- try {
- Properties props = new Properties();
- in = Files.newInputStream(filtersFile.toPath());
- props.load(in);
-
- Enumeration<?> e = props.propertyNames();
- Vector<Filter> filts = getFilters();
- while (e.hasMoreElements()) {
- String strPropName = (String) e.nextElement();
- String strValue = props.getProperty(strPropName);
- filts.addElement(new Filter(strPropName, strValue));
- }
- } catch (Exception ex) {
- throw new BuildException("Could not read filters from file: "
- + filtersFile, ex);
- } finally {
- FileUtils.close(in);
- }
+ log("Reading filters from " + filtersFile, Project.MSG_VERBOSE);
+ try (InputStream in = Files.newInputStream(filtersFile.toPath())) {
+ Properties props = new Properties();
+ props.load(in);
+ props.forEach((k,v) -> addFilter(new Filter((String) k, (String) v)));
+ } catch (Exception ex) {
+ throw new BuildException(
+ "Could not read filters from file: " + filtersFile, ex);
+ }
} else {
- handleMissingFile(
- "Must specify a file rather than a directory in "
- + "the filtersfile attribute:" + filtersFile);
+ handleMissingFile("Must specify a file rather than a directory in "
+ + "the filtersfile attribute:" + filtersFile);
}
filterHash = null;
}
@@ -471,7 +453,7 @@ public class FilterSet extends DataType implements Cloneable {
throw noChildrenAllowed();
}
Properties p = propertySet.getProperties();
- Set<Map.Entry<Object,Object>> entries = p.entrySet();
+ Set<Map.Entry<Object, Object>> entries = p.entrySet();
for (Map.Entry<Object, Object> entry : entries) {
addFilter(new Filter(String.valueOf(entry.getKey()),
String.valueOf(entry.getValue())));
@@ -484,7 +466,7 @@ public class FilterSet extends DataType implements Cloneable {
* @return Return true if there are filters in this set.
*/
public synchronized boolean hasFilters() {
- return getFilters().size() > 0;
+ return !getFilters().isEmpty();
}
/**
@@ -545,8 +527,6 @@ public class FilterSet extends DataType implements Cloneable {
try {
StringBuilder b = new StringBuilder();
int i = 0;
- String token = null;
- String value = null;
while (index > -1) {
//can't have zero-length token
@@ -555,11 +535,11 @@ public class FilterSet extends DataType implements Cloneable {
if (endIndex == -1) {
break;
}
- token
- = line.substring(index + beginToken.length(), endIndex);
+ String token =
+ line.substring(index + beginToken.length(), endIndex);
b.append(line.substring(i, index));
if (tokens.containsKey(token)) {
- value = tokens.get(token);
+ String value = tokens.get(token);
if (recurse && !value.equals(token)) {
// we have another token, let's parse it.
value = replaceTokens(value, token);
@@ -603,7 +583,7 @@ public class FilterSet extends DataType implements Cloneable {
String beginToken = getBeginToken();
String endToken = getEndToken();
if (recurseDepth == 0) {
- passedTokens = new VectorSet<String>();
+ passedTokens = new VectorSet<>();
}
recurseDepth++;
if (passedTokens.contains(parent) && !duplicateToken) {
@@ -623,14 +603,14 @@ public class FilterSet extends DataType implements Cloneable {
passedTokens = null;
} else if (duplicateToken) {
// should always be the case...
- if (passedTokens.size() > 0) {
+ if (!passedTokens.isEmpty()) {
value = passedTokens.remove(passedTokens.size() - 1);
- if (passedTokens.size() == 0) {
+ if (passedTokens.isEmpty()) {
value = beginToken + value + endToken;
duplicateToken = false;
}
}
- } else if (passedTokens.size() > 0) {
+ } else if (!passedTokens.isEmpty()) {
// remove last seen token when crawling out of recursion
passedTokens.remove(passedTokens.size() - 1);
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/FilterSetCollection.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/FilterSetCollection.java b/src/main/org/apache/tools/ant/types/FilterSetCollection.java
index 8afb963..500f32f 100644
--- a/src/main/org/apache/tools/ant/types/FilterSetCollection.java
+++ b/src/main/org/apache/tools/ant/types/FilterSetCollection.java
@@ -28,7 +28,7 @@ import java.util.List;
*/
public class FilterSetCollection {
- private List<FilterSet> filterSets = new ArrayList<FilterSet>();
+ private List<FilterSet> filterSets = new ArrayList<>();
/**
* Constructor for a FilterSetCollection.
@@ -75,12 +75,7 @@ public class FilterSetCollection {
* @return Return true if there are filter in this set otherwise false.
*/
public boolean hasFilters() {
- for (FilterSet filterSet : filterSets) {
- if (filterSet.hasFilters()) {
- return true;
- }
- }
- return false;
+ return filterSets.stream().anyMatch(FilterSet::hasFilters);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/FlexInteger.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/FlexInteger.java b/src/main/org/apache/tools/ant/types/FlexInteger.java
index d757429..9bce762 100644
--- a/src/main/org/apache/tools/ant/types/FlexInteger.java
+++ b/src/main/org/apache/tools/ant/types/FlexInteger.java
@@ -48,6 +48,7 @@ public class FlexInteger {
* Overridden method to return the decimal value for display
* @return a string version of the integer
*/
+ @Override
public String toString() {
return value.toString();
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/LogLevel.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/LogLevel.java b/src/main/org/apache/tools/ant/types/LogLevel.java
index a02b948..5c66d99 100644
--- a/src/main/org/apache/tools/ant/types/LogLevel.java
+++ b/src/main/org/apache/tools/ant/types/LogLevel.java
@@ -55,6 +55,7 @@ public class LogLevel extends EnumeratedAttribute {
* @see EnumeratedAttribute#getValues
* @return the strings allowed for the level attribute
*/
+ @Override
public String[] getValues() {
return new String[] {
"error",
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/Mapper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/Mapper.java b/src/main/org/apache/tools/ant/types/Mapper.java
index c02e782..6b922a7 100644
--- a/src/main/org/apache/tools/ant/types/Mapper.java
+++ b/src/main/org/apache/tools/ant/types/Mapper.java
@@ -187,6 +187,7 @@ public class Mapper extends DataType {
* @param r the reference to another mapper
* @throws BuildException if other attributes are set
*/
+ @Override
public void setRefid(Reference r) throws BuildException {
if (type != null || from != null || to != null) {
throw tooManyAttributes();
@@ -306,6 +307,7 @@ public class Mapper extends DataType {
/**
* @return the filenamemapper names
*/
+ @Override
public String[] getValues() {
return new String[] {"identity", "flatten", "glob",
"merge", "regexp", "package", "unpackage"};
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/Parameterizable.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/Parameterizable.java b/src/main/org/apache/tools/ant/types/Parameterizable.java
index 7945a9a..188b76b 100644
--- a/src/main/org/apache/tools/ant/types/Parameterizable.java
+++ b/src/main/org/apache/tools/ant/types/Parameterizable.java
@@ -27,5 +27,5 @@ public interface Parameterizable {
*
* @param parameters an array of name/type/value parameters.
*/
- void setParameters(Parameter[] parameters);
+ void setParameters(Parameter... parameters);
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/Path.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/Path.java b/src/main/org/apache/tools/ant/types/Path.java
index 16270e3..3a671fa 100644
--- a/src/main/org/apache/tools/ant/types/Path.java
+++ b/src/main/org/apache/tools/ant/types/Path.java
@@ -20,11 +20,12 @@ package org.apache.tools.ant.types;
import java.io.File;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import java.util.Stack;
-import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.MagicNames;
@@ -71,7 +72,6 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
public static Path systemClasspath = //NOSONAR
new Path(null, System.getProperty("java.class.path"));
-
/**
* The system bootclasspath as a Path object.
*
@@ -94,7 +94,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* @param loc a <code>File</code> value
*/
public void setLocation(File loc) {
- parts = new String[] {translateFile(loc.getAbsolutePath())};
+ parts = new String[] { translateFile(loc.getAbsolutePath()) };
}
/**
@@ -119,6 +119,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* Create an iterator.
* @return an iterator.
*/
+ @Override
public Iterator<Resource> iterator() {
return new FileResourceIterator(getProject(), null, parts);
}
@@ -127,6 +128,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* Check if this resource is only for filesystems.
* @return true.
*/
+ @Override
public boolean isFilesystemOnly() {
return true;
}
@@ -135,6 +137,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* Get the number of resources.
* @return the number of parts.
*/
+ @Override
public int size() {
return parts == null ? 0 : parts.length;
}
@@ -194,6 +197,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* @param r the reference to another Path
* @throws BuildException on error
*/
+ @Override
public void setRefid(Reference r) throws BuildException {
if (union != null) {
throw tooManyAttributes();
@@ -344,9 +348,9 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
} else if (f.getParentFile() != null && f.getParentFile().exists()
&& containsWildcards(f.getName())) {
setLocation(f);
- log("adding " + f + " which contains wildcards and may not"
- + " do what you intend it to do depending on your OS or"
- + " version of Java", Project.MSG_VERBOSE);
+ log("adding " + f
+ + " which contains wildcards and may not do what you intend it to do depending on your OS or version of Java",
+ Project.MSG_VERBOSE);
} else {
log("dropping " + f + " from path as it doesn't exist",
Project.MSG_VERBOSE);
@@ -383,6 +387,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* CLASSPATH or PATH environment variable definition.
* @return a textual representation of the path.
*/
+ @Override
public String toString() {
return isReference() ? getCheckedRef().toString()
: union == null ? "" : union.toString();
@@ -395,13 +400,13 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* @return an array of strings, one for each path element
*/
public static String[] translatePath(Project project, String source) {
- final Vector<String> result = new Vector<String>();
if (source == null) {
return new String[0];
}
+ final List<String> result = new ArrayList<>();
PathTokenizer tok = new PathTokenizer(source);
- StringBuffer element = new StringBuffer();
while (tok.hasMoreTokens()) {
+ StringBuffer element = new StringBuffer();
String pathElement = tok.nextToken();
try {
element.append(resolveFile(project, pathElement).getPath());
@@ -413,8 +418,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
for (int i = 0; i < element.length(); i++) {
translateFileSep(element, i);
}
- result.addElement(element.toString());
- element = new StringBuffer();
+ result.add(element.toString());
}
return result.toArray(new String[result.size()]);
}
@@ -456,6 +460,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* Fulfill the ResourceCollection contract.
* @return number of elements as int.
*/
+ @Override
public synchronized int size() {
if (isReference()) {
return ((Path) getCheckedRef()).size();
@@ -468,6 +473,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* Clone this Path.
* @return Path with shallowly cloned Resource children.
*/
+ @Override
public Object clone() {
try {
Path result = (Path) super.clone();
@@ -485,6 +491,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* @param p the project to use to dereference the references.
* @throws BuildException on error.
*/
+ @Override
protected synchronized void dieOnCircularReference(Stack<Object> stk, Project p)
throws BuildException {
if (isChecked()) {
@@ -697,6 +704,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* are added to this container while the Iterator is in use.
* @return a "fail-fast" Iterator.
*/
+ @Override
public final synchronized Iterator<Resource> iterator() {
if (isReference()) {
return ((Path) getCheckedRef()).iterator();
@@ -713,6 +721,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* Fulfill the ResourceCollection contract.
* @return whether this is a filesystem-only resource collection.
*/
+ @Override
public synchronized boolean isFilesystemOnly() {
if (isReference()) {
return ((Path) getCheckedRef()).isFilesystemOnly();
@@ -730,8 +739,8 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
*/
protected ResourceCollection assertFilesystemOnly(ResourceCollection rc) {
if (rc != null && !(rc.isFilesystemOnly())) {
- throw new BuildException(getDataTypeName()
- + " allows only filesystem resources.");
+ throw new BuildException("%s allows only filesystem resources.",
+ getDataTypeName());
}
return rc;
}
@@ -749,7 +758,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
return false;
}
try {
- Method listMethod = getClass().getMethod("list", (Class[]) null);
+ Method listMethod = getClass().getMethod("list");
return !listMethod.getDeclaringClass().equals(Path.class);
} catch (Exception e) {
//shouldn't happen, but
@@ -770,7 +779,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
*/
private static boolean containsWildcards(String path) {
return path != null
- && (path.indexOf("*") > -1 || path.indexOf("?") > -1);
+ && (path.indexOf('*') > -1 || path.indexOf('?') > -1);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/PatternSet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/PatternSet.java b/src/main/org/apache/tools/ant/types/PatternSet.java
index 9fb9405..c958d8e 100644
--- a/src/main/org/apache/tools/ant/types/PatternSet.java
+++ b/src/main/org/apache/tools/ant/types/PatternSet.java
@@ -23,12 +23,13 @@ import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import java.util.StringTokenizer;
+import java.util.function.Predicate;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.PropertyHelper;
-import org.apache.tools.ant.util.FileUtils;
/**
* Named collection of include/exclude tags.
@@ -38,10 +39,10 @@ import org.apache.tools.ant.util.FileUtils;
*
*/
public class PatternSet extends DataType implements Cloneable {
- private List<NameEntry> includeList = new ArrayList<NameEntry>();
- private List<NameEntry> excludeList = new ArrayList<NameEntry>();
- private List<NameEntry> includesFileList = new ArrayList<NameEntry>();
- private List<NameEntry> excludesFileList = new ArrayList<NameEntry>();
+ private List<NameEntry> includeList = new ArrayList<>();
+ private List<NameEntry> excludeList = new ArrayList<>();
+ private List<NameEntry> includesFileList = new ArrayList<>();
+ private List<NameEntry> excludesFileList = new ArrayList<>();
/**
* inner class to hold a name on list. "If" and "Unless" attributes
@@ -150,8 +151,9 @@ public class PatternSet extends DataType implements Cloneable {
/**
* @return a printable form of this object.
*/
+ @Override
public String toString() {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
if (name == null) {
buf.append("noname");
} else {
@@ -181,9 +183,11 @@ public class PatternSet extends DataType implements Cloneable {
setProject(p.getProject());
addConfiguredPatternset(p);
}
+ @Override
public String[] getIncludePatterns(Project p) {
return super.getExcludePatterns(p);
}
+ @Override
public String[] getExcludePatterns(Project p) {
return super.getIncludePatterns(p);
}
@@ -205,6 +209,7 @@ public class PatternSet extends DataType implements Cloneable {
* @param r the reference to another patternset.
* @throws BuildException on error.
*/
+ @Override
public void setRefid(Reference r) throws BuildException {
if (!includeList.isEmpty() || !excludeList.isEmpty()) {
throw tooManyAttributes();
@@ -290,7 +295,7 @@ public class PatternSet extends DataType implements Cloneable {
if (isReference()) {
throw tooManyAttributes();
}
- if (includes != null && includes.length() > 0) {
+ if (includes != null && !includes.isEmpty()) {
StringTokenizer tok = new StringTokenizer(includes, ", ", false);
while (tok.hasMoreTokens()) {
createInclude().setName(tok.nextToken());
@@ -308,7 +313,7 @@ public class PatternSet extends DataType implements Cloneable {
if (isReference()) {
throw tooManyAttributes();
}
- if (excludes != null && excludes.length() > 0) {
+ if (excludes != null && !excludes.isEmpty()) {
StringTokenizer tok = new StringTokenizer(excludes, ", ", false);
while (tok.hasMoreTokens()) {
createExclude().setName(tok.nextToken());
@@ -358,26 +363,19 @@ public class PatternSet extends DataType implements Cloneable {
private void readPatterns(File patternfile, List<NameEntry> patternlist, Project p)
throws BuildException {
- BufferedReader patternReader = null;
- try {
- // Get a FileReader
- patternReader = new BufferedReader(new FileReader(patternfile));
+ try (BufferedReader patternReader =
+ new BufferedReader(new FileReader(patternfile))) {
// Create one NameEntry in the appropriate pattern list for each
// line in the file.
- String line = patternReader.readLine();
- while (line != null) {
- if (line.length() > 0) {
- line = p.replaceProperties(line);
- addPatternToList(patternlist).setName(line);
- }
- line = patternReader.readLine();
- }
+ patternReader.lines()
+ .filter(((Predicate<String>) String::isEmpty).negate())
+ .map(p::replaceProperties)
+ .forEach(line -> addPatternToList(patternlist).setName(line));
+
} catch (IOException ioe) {
throw new BuildException("An error occurred while reading from pattern file: "
+ patternfile, ioe);
- } finally {
- FileUtils.close(patternReader);
}
}
@@ -444,8 +442,8 @@ public class PatternSet extends DataType implements Cloneable {
return getRef(p).hasPatterns(p);
}
dieOnCircularReference(p);
- return includesFileList.size() > 0 || excludesFileList.size() > 0
- || includeList.size() > 0 || excludeList.size() > 0;
+ return !(includesFileList.isEmpty() && excludesFileList.isEmpty()
+ && includeList.isEmpty() && excludeList.isEmpty());
}
/**
@@ -460,24 +458,18 @@ public class PatternSet extends DataType implements Cloneable {
* Convert a vector of NameEntry elements into an array of Strings.
*/
private String[] makeArray(List<NameEntry> list, Project p) {
- if (list.size() == 0) {
+ if (list.isEmpty()) {
return null;
}
- ArrayList<String> tmpNames = new ArrayList<String>();
- for (NameEntry ne : list) {
- String pattern = ne.evalName(p);
- if (pattern != null && pattern.length() > 0) {
- tmpNames.add(pattern);
- }
- }
- return tmpNames.toArray(new String[tmpNames.size()]);
+ return list.stream().map(ne -> ne.evalName(p)).filter(Objects::nonNull)
+ .filter(pattern -> !pattern.isEmpty()).toArray(String[]::new);
}
/**
* Read includesfile ot excludesfile if not already done so.
*/
private void readFiles(Project p) {
- if (includesFileList.size() > 0) {
+ if (!includesFileList.isEmpty()) {
for (NameEntry ne : includesFileList) {
String fileName = ne.evalName(p);
if (fileName != null) {
@@ -491,7 +483,7 @@ public class PatternSet extends DataType implements Cloneable {
}
includesFileList.clear();
}
- if (excludesFileList.size() > 0) {
+ if (!excludesFileList.isEmpty()) {
for (NameEntry ne : excludesFileList) {
String fileName = ne.evalName(p);
if (fileName != null) {
@@ -510,21 +502,24 @@ public class PatternSet extends DataType implements Cloneable {
/**
* @return a printable form of this object.
*/
+ @Override
public String toString() {
- return "patternSet{ includes: " + includeList + " excludes: " + excludeList + " }";
+ return String.format("patternSet{ includes: %s excludes: %s }",
+ includeList, excludeList);
}
/**
* @since Ant 1.6
* @return a clone of this patternset.
*/
- public Object clone() {
+ @Override
+ public PatternSet clone() {
try {
PatternSet ps = (PatternSet) super.clone();
- ps.includeList = new ArrayList<NameEntry>(includeList);
- ps.excludeList = new ArrayList<NameEntry>(excludeList);
- ps.includesFileList = new ArrayList<NameEntry>(includesFileList);
- ps.excludesFileList = new ArrayList<NameEntry>(excludesFileList);
+ ps.includeList = new ArrayList<>(includeList);
+ ps.excludeList = new ArrayList<>(excludeList);
+ ps.includesFileList = new ArrayList<>(includesFileList);
+ ps.excludesFileList = new ArrayList<>(excludesFileList);
return ps;
} catch (CloneNotSupportedException e) {
throw new BuildException(e);
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/Permissions.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/Permissions.java b/src/main/org/apache/tools/ant/types/Permissions.java
index d0559c7..d476427 100644
--- a/src/main/org/apache/tools/ant/types/Permissions.java
+++ b/src/main/org/apache/tools/ant/types/Permissions.java
@@ -44,8 +44,8 @@ import org.apache.tools.ant.ExitException;
*/
public class Permissions {
- private final List<Permission> grantedPermissions = new LinkedList<Permission>();
- private final List<Permission> revokedPermissions = new LinkedList<Permission>();
+ private final List<Permission> grantedPermissions = new LinkedList<>();
+ private final List<Permission> revokedPermissions = new LinkedList<>();
private java.security.Permissions granted = null;
private SecurityManager origSm = null;
private boolean active = false;
@@ -284,7 +284,7 @@ public class Permissions {
*/
public void setActions(final String actions) {
actionString = actions;
- if (actions.length() > 0) {
+ if (!actions.isEmpty()) {
this.actions = parseActions(actions);
}
}
@@ -310,10 +310,8 @@ public class Permissions {
if (!perm.getName().startsWith(name.substring(0, name.length() - 1))) {
return false;
}
- } else {
- if (!name.equals(perm.getName())) {
- return false;
- }
+ } else if (!name.equals(perm.getName())) {
+ return false;
}
}
if (actions != null) {
@@ -333,11 +331,11 @@ public class Permissions {
* @param actions The actions to be parsed.
*/
private Set<String> parseActions(final String actions) {
- final Set<String> result = new HashSet<String>();
+ final Set<String> result = new HashSet<>();
final StringTokenizer tk = new StringTokenizer(actions, ",");
while (tk.hasMoreTokens()) {
final String item = tk.nextToken().trim();
- if (!item.equals("")) {
+ if (!"".equals(item)) {
result.add(item);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/PropertySet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/PropertySet.java b/src/main/org/apache/tools/ant/types/PropertySet.java
index f599204..85e65d2 100644
--- a/src/main/org/apache/tools/ant/types/PropertySet.java
+++ b/src/main/org/apache/tools/ant/types/PropertySet.java
@@ -22,15 +22,16 @@ import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
+import java.util.stream.Stream;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
@@ -50,8 +51,8 @@ public class PropertySet extends DataType implements ResourceCollection {
private boolean dynamic = true;
private boolean negate = false;
private Set<String> cachedNames;
- private List<PropertyRef> ptyRefs = new ArrayList<PropertyRef>();
- private List<PropertySet> setRefs = new ArrayList<PropertySet>();
+ private List<PropertyRef> ptyRefs = new ArrayList<>();
+ private List<PropertySet> setRefs = new ArrayList<>();
private Mapper mapper;
/**
@@ -118,6 +119,7 @@ public class PropertySet extends DataType implements ResourceCollection {
* A debug toString().
* @return a string version of this object.
*/
+ @Override
public String toString() {
return "name=" + name + ", regex=" + regex + ", prefix=" + prefix
+ ", builtin=" + builtin;
@@ -273,12 +275,12 @@ public class PropertySet extends DataType implements ResourceCollection {
}
/**
- * Convert the system properties to a hashtable.
+ * Convert the system properties to a Map.
* Use propertynames to get the list of properties (including
* default ones).
*/
- private Hashtable<String, Object> getAllSystemProperties() {
- Hashtable<String, Object> ret = new Hashtable<String, Object>();
+ private Map<String, Object> getAllSystemProperties() {
+ Map<String, Object> ret = new HashMap<>();
for (Enumeration<?> e = System.getProperties().propertyNames();
e.hasMoreElements();) {
String name = (String) e.nextElement();
@@ -312,7 +314,7 @@ public class PropertySet extends DataType implements ResourceCollection {
final Map<String, Object> effectiveProperties = getEffectiveProperties();
final Set<String> propertyNames = getPropertyNames(effectiveProperties);
- final Map<String, Object> result = new HashMap<String, Object>();
+ final Map<String, Object> result = new HashMap<>();
//iterate through the names, get the matching values
for (String name : propertyNames) {
@@ -349,7 +351,7 @@ public class PropertySet extends DataType implements ResourceCollection {
private Set<String> getPropertyNames(Map<String, Object> props) {
Set<String> names;
if (getDynamic() || cachedNames == null) {
- names = new HashSet<String>();
+ names = new HashSet<>();
addPropertyNames(names, props);
// Add this PropertySet's nested PropertySets' property names.
for (PropertySet set : setRefs) {
@@ -357,7 +359,7 @@ public class PropertySet extends DataType implements ResourceCollection {
}
if (negate) {
//make a copy...
- HashSet<String> complement = new HashSet<String>(props.keySet());
+ HashSet<String> complement = new HashSet<>(props.keySet());
complement.removeAll(names);
names = complement;
}
@@ -427,7 +429,7 @@ public class PropertySet extends DataType implements ResourceCollection {
* @return the referenced PropertySet.
*/
protected PropertySet getRef() {
- return (PropertySet) getCheckedRef(PropertySet.class, "propertyset");
+ return getCheckedRef(PropertySet.class, "propertyset");
}
/**
@@ -437,6 +439,7 @@ public class PropertySet extends DataType implements ResourceCollection {
* @throws BuildException if another attribute was set, since
* refid and all other attributes are mutually exclusive.
*/
+ @Override
public final void setRefid(Reference r) {
if (!noAttributeSet) {
throw tooManyAttributes();
@@ -475,6 +478,7 @@ public class PropertySet extends DataType implements ResourceCollection {
static final String SYSTEM = "system";
static final String COMMANDLINE = "commandline";
/** {@inheritDoc}. */
+ @Override
public String[] getValues() {
return new String[] {ALL, SYSTEM, COMMANDLINE};
}
@@ -487,13 +491,14 @@ public class PropertySet extends DataType implements ResourceCollection {
* The output order is sorted according to the keys' <i>natural order</i>.
* @return a string rep of this object.
*/
+ @Override
public String toString() {
if (isReference()) {
return getRef().toString();
}
dieOnCircularReference();
StringBuilder b = new StringBuilder();
- TreeMap<String, Object> sorted = new TreeMap<String, Object>(getPropertyMap());
+ TreeMap<String, Object> sorted = new TreeMap<>(getPropertyMap());
for (Entry<String, Object> e : sorted.entrySet()) {
if (b.length() != 0) {
b.append(", ");
@@ -510,35 +515,27 @@ public class PropertySet extends DataType implements ResourceCollection {
* @return an Iterator of Resources.
* @since Ant 1.7
*/
+ @Override
public Iterator<Resource> iterator() {
if (isReference()) {
return getRef().iterator();
}
dieOnCircularReference();
- final Set<String> names = getPropertyNames(getEffectiveProperties());
-
- Mapper myMapper = getMapper();
- final FileNameMapper m = myMapper == null ? null : myMapper.getImplementation();
- final Iterator<String> iter = names.iterator();
-
- return new Iterator<Resource>() {
- public boolean hasNext() {
- return iter.hasNext();
- }
- public Resource next() {
- PropertyResource p = new PropertyResource(getProject(), iter.next());
- return m == null ? (Resource) p : new MappedResource(p, m);
- }
- public void remove() {
- throw new UnsupportedOperationException();
- }
- };
+ Stream<Resource> result = getPropertyNames(getEffectiveProperties())
+ .stream().map(name -> new PropertyResource(getProject(), name));
+ Optional<FileNameMapper> m =
+ Optional.ofNullable(getMapper()).map(Mapper::getImplementation);
+ if (m.isPresent()) {
+ result = result.map(p -> new MappedResource(p, m.get()));
+ }
+ return result.iterator();
}
/**
* Fulfill the ResourceCollection contract.
* @return the size of this ResourceCollection.
*/
+ @Override
public int size() {
return isReference() ? getRef().size() : getProperties().size();
}
@@ -547,6 +544,7 @@ public class PropertySet extends DataType implements ResourceCollection {
* Fulfill the ResourceCollection contract.
* @return whether this is a filesystem-only resource collection.
*/
+ @Override
public boolean isFilesystemOnly() {
if (isReference()) {
return getRef().isFilesystemOnly();
@@ -555,6 +553,7 @@ public class PropertySet extends DataType implements ResourceCollection {
return false;
}
+ @Override
protected synchronized void dieOnCircularReference(Stack<Object> stk, Project p)
throws BuildException {
if (isChecked()) {
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/Quantifier.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/Quantifier.java b/src/main/org/apache/tools/ant/types/Quantifier.java
index ac1b84c..1aedcb6 100644
--- a/src/main/org/apache/tools/ant/types/Quantifier.java
+++ b/src/main/org/apache/tools/ant/types/Quantifier.java
@@ -17,6 +17,12 @@
*/
package org.apache.tools.ant.types;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.stream.Stream;
+
import org.apache.tools.ant.BuildException;
/**
@@ -36,59 +42,82 @@ import org.apache.tools.ant.BuildException;
* @since Ant 1.7
*/
public class Quantifier extends EnumeratedAttribute {
- private static final String[] VALUES
- = new String[] {"all", "each", "every", "any", "some", "one",
- "majority", "most", "none"};
+ private static final String[] VALUES =
+ Stream.of(Predicate.values()).map(Predicate::getNames)
+ .flatMap(Collection::stream).toArray(String[]::new);
/** ALL instance */
- public static final Quantifier ALL = new Quantifier("all");
+ public static final Quantifier ALL = new Quantifier(Predicate.ALL);
+
/** ANY instance */
- public static final Quantifier ANY = new Quantifier("any");
+ public static final Quantifier ANY = new Quantifier(Predicate.ANY);
+
/** ONE instance */
- public static final Quantifier ONE = new Quantifier("one");
+ public static final Quantifier ONE = new Quantifier(Predicate.ONE);
+
/** MAJORITY instance */
- public static final Quantifier MAJORITY = new Quantifier("majority");
+ public static final Quantifier MAJORITY =
+ new Quantifier(Predicate.MAJORITY);
+
/** NONE instance */
- public static final Quantifier NONE = new Quantifier("none");
+ public static final Quantifier NONE = new Quantifier(Predicate.NONE);
- private abstract static class Predicate {
- abstract boolean eval(int t, int f);
- }
+ private enum Predicate {
+ ALL("all", "each", "every") {
+ @Override
+ boolean eval(int t, int f) {
+ return f == 0;
+ }
+ },
+
+ ANY("any", "some") {
+ @Override
+ boolean eval(int t, int f) {
+ return t > 0;
+ }
+ },
+
+ ONE("one") {
+ @Override
+ boolean eval(int t, int f) {
+ return t == 1;
+ }
+ },
+
+ MAJORITY("majority", "most") {
+ @Override
+ boolean eval(int t, int f) {
+ return t > f;
+ }
+ },
+
+ NONE("none") {
+ @Override
+ boolean eval(int t, int f) {
+ return t == 0;
+ }
+ };
- private static final Predicate ALL_PRED = new Predicate() {
- boolean eval(int t, int f) { return f == 0; }
- };
-
- private static final Predicate ANY_PRED = new Predicate() {
- boolean eval(int t, int f) { return t > 0; }
- };
-
- private static final Predicate ONE_PRED = new Predicate() {
- boolean eval(int t, int f) { return t == 1; }
- };
-
- private static final Predicate MAJORITY_PRED = new Predicate() {
- boolean eval(int t, int f) { return t > f; }
- };
-
- private static final Predicate NONE_PRED = new Predicate() {
- boolean eval(int t, int f) { return t == 0; }
- };
-
- private static final Predicate[] PREDS = new Predicate[VALUES.length];
-
- static {
- // CheckStyle:MagicNumber OFF
- PREDS[0] = ALL_PRED;
- PREDS[1] = ALL_PRED;
- PREDS[2] = ALL_PRED;
- PREDS[3] = ANY_PRED;
- PREDS[4] = ANY_PRED;
- PREDS[5] = ONE_PRED;
- PREDS[6] = MAJORITY_PRED;
- PREDS[7] = MAJORITY_PRED;
- PREDS[8] = NONE_PRED;
- // CheckStyle:MagicNumber ON
+ static Predicate get(String name) {
+ return Stream.of(values()).filter(p -> p.names.contains(name))
+ .findFirst()
+ .orElseThrow(() -> new IllegalArgumentException(name));
+ }
+
+ final Set<String> names;
+
+ Predicate(String primaryName, String... additionalNames) {
+ Set<String> names = new LinkedHashSet<>();
+ names.add(primaryName);
+ Collections.addAll(names, additionalNames);
+ this.names = Collections.unmodifiableSet(names);
+ }
+
+ Set<String> getNames() {
+ return names;
+ }
+
+ abstract boolean eval(int t, int f);
}
/**
@@ -105,10 +134,15 @@ public class Quantifier extends EnumeratedAttribute {
setValue(value);
}
+ private Quantifier(Predicate impl) {
+ setValue(impl.getNames().iterator().next());
+ }
+
/**
* Return the possible values.
* @return String[] of EnumeratedAttribute values.
*/
+ @Override
public String[] getValues() {
return VALUES;
}
@@ -139,7 +173,7 @@ public class Quantifier extends EnumeratedAttribute {
if (index == -1) {
throw new BuildException("Quantifier value not set.");
}
- return PREDS[index].eval(t, f);
+ return Predicate.get(VALUES[index]).eval(t, f);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/RedirectorElement.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/RedirectorElement.java b/src/main/org/apache/tools/ant/types/RedirectorElement.java
index d27b199..7f7271a 100644
--- a/src/main/org/apache/tools/ant/types/RedirectorElement.java
+++ b/src/main/org/apache/tools/ant/types/RedirectorElement.java
@@ -84,13 +84,13 @@ public class RedirectorElement extends DataType {
private Mapper errorMapper;
/** input filter chains. */
- private Vector<FilterChain> inputFilterChains = new Vector<FilterChain>();
+ private Vector<FilterChain> inputFilterChains = new Vector<>();
/** output filter chains. */
- private Vector<FilterChain> outputFilterChains = new Vector<FilterChain>();
+ private Vector<FilterChain> outputFilterChains = new Vector<>();
/** error filter chains. */
- private Vector<FilterChain> errorFilterChains = new Vector<FilterChain>();
+ private Vector<FilterChain> errorFilterChains = new Vector<>();
/** The output encoding */
private String outputEncoding;
@@ -527,13 +527,13 @@ public class RedirectorElement extends DataType {
redirector.setError(toFileArray(errorTargets));
}
}
- if (inputFilterChains.size() > 0) {
+ if (!inputFilterChains.isEmpty()) {
redirector.setInputFilterChains(inputFilterChains);
}
- if (outputFilterChains.size() > 0) {
+ if (!outputFilterChains.isEmpty()) {
redirector.setOutputFilterChains(outputFilterChains);
}
- if (errorFilterChains.size() > 0) {
+ if (!errorFilterChains.isEmpty()) {
redirector.setErrorFilterChains(errorFilterChains);
}
if (inputEncoding != null) {
@@ -571,7 +571,7 @@ public class RedirectorElement extends DataType {
return null;
}
//remove any null elements
- ArrayList<File> list = new ArrayList<File>(name.length);
+ ArrayList<File> list = new ArrayList<>(name.length);
for (int i = 0; i < name.length; i++) {
if (name[i] != null) {
list.add(getProject().resolveFile(name[i]));
@@ -587,6 +587,7 @@ public class RedirectorElement extends DataType {
* @param p the project to use to dereference the references.
* @throws BuildException on error.
*/
+ @Override
protected void dieOnCircularReference(Stack<Object> stk, Project p)
throws BuildException {
if (isChecked()) {
@@ -603,7 +604,6 @@ public class RedirectorElement extends DataType {
stk.pop();
}
}
- @SuppressWarnings("unchecked")
final List<? extends List<FilterChain>> filterChainLists = Arrays
.<List<FilterChain>> asList(inputFilterChains, outputFilterChains,
errorFilterChains);
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/RegularExpression.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/RegularExpression.java b/src/main/org/apache/tools/ant/types/RegularExpression.java
index 18ee3f1..e2aafc3 100644
--- a/src/main/org/apache/tools/ant/types/RegularExpression.java
+++ b/src/main/org/apache/tools/ant/types/RegularExpression.java
@@ -69,12 +69,6 @@ public class RegularExpression extends DataType {
private String myPattern;
private boolean setPatternPending = false;
- /**
- * default constructor
- */
- public RegularExpression() {
- }
-
private void init(Project p) {
if (!alreadyInit) {
this.regexp = FACTORY.newRegexp(p);
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/Resource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/Resource.java b/src/main/org/apache/tools/ant/types/Resource.java
index 6cd0e07..31a6d0a 100644
--- a/src/main/org/apache/tools/ant/types/Resource.java
+++ b/src/main/org/apache/tools/ant/types/Resource.java
@@ -21,8 +21,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
+import java.util.Collections;
import java.util.Iterator;
-import java.util.NoSuchElementException;
+import java.util.Optional;
import org.apache.tools.ant.types.resources.FileProvider;
@@ -139,7 +140,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* @return the name of this resource.
*/
public String getName() {
- return isReference() ? ((Resource) getCheckedRef()).getName() : name;
+ return isReference() ? getCheckedRef().getName() : name;
}
/**
@@ -158,7 +159,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
public boolean isExists() {
if (isReference()) {
- return ((Resource) getCheckedRef()).isExists();
+ return getCheckedRef().isExists();
}
//default true:
return exists == null || exists.booleanValue();
@@ -185,7 +186,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
public long getLastModified() {
if (isReference()) {
- return ((Resource) getCheckedRef()).getLastModified();
+ return getCheckedRef().getLastModified();
}
if (!isExists() || lastmodified == null) {
return UNKNOWN_DATETIME;
@@ -209,7 +210,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
public boolean isDirectory() {
if (isReference()) {
- return ((Resource) getCheckedRef()).isDirectory();
+ return getCheckedRef().isDirectory();
}
//default false:
return directory != null && directory.booleanValue();
@@ -242,7 +243,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
public long getSize() {
if (isReference()) {
- return ((Resource) getCheckedRef()).getSize();
+ return getCheckedRef().getSize();
}
return isExists()
? (size != null ? size.longValue() : UNKNOWN_SIZE)
@@ -253,13 +254,13 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* Clone this Resource.
* @return copy of this.
*/
- public Object clone() {
+ @Override
+ public Resource clone() {
try {
- return super.clone();
+ return (Resource) super.clone();
} catch (CloneNotSupportedException e) {
throw new UnsupportedOperationException(
- "CloneNotSupportedException for a Resource caught. "
- + "Derived classes must support cloning.");
+ "CloneNotSupportedException for a Resource caught. Derived classes must support cloning.");
}
}
@@ -270,9 +271,10 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* is less than, equal to, or greater than the specified Resource.
* @since Ant 1.6
*/
+ @Override
public int compareTo(Resource other) {
if (isReference()) {
- return ((Resource) getCheckedRef()).compareTo(other);
+ return getCheckedRef().compareTo(other);
}
return toString().compareTo(other.toString());
}
@@ -283,6 +285,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* @return true if the specified Object is equal to this Resource.
* @since Ant 1.7
*/
+ @Override
public boolean equals(Object other) {
if (this == other) {
return true;
@@ -299,6 +302,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* @return hash code as int.
* @since Ant 1.7
*/
+ @Override
public int hashCode() {
if (isReference()) {
return getCheckedRef().hashCode();
@@ -318,7 +322,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
public InputStream getInputStream() throws IOException {
if (isReference()) {
- return ((Resource) getCheckedRef()).getInputStream();
+ return getCheckedRef().getInputStream();
}
throw new UnsupportedOperationException();
}
@@ -334,7 +338,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
public OutputStream getOutputStream() throws IOException {
if (isReference()) {
- return ((Resource) getCheckedRef()).getOutputStream();
+ return getCheckedRef().getOutputStream();
}
throw new UnsupportedOperationException();
}
@@ -344,24 +348,10 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* @return an Iterator of Resources.
* @since Ant 1.7
*/
+ @Override
public Iterator<Resource> iterator() {
- return isReference() ? ((Resource) getCheckedRef()).iterator()
- : new Iterator<Resource>() {
- private boolean done = false;
- public boolean hasNext() {
- return !done;
- }
- public Resource next() {
- if (done) {
- throw new NoSuchElementException();
- }
- done = true;
- return Resource.this;
- }
- public void remove() {
- throw new UnsupportedOperationException();
- }
- };
+ return isReference() ? getCheckedRef().iterator()
+ : Collections.singleton(this).iterator();
}
/**
@@ -369,8 +359,9 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* @return the size of this ResourceCollection.
* @since Ant 1.7
*/
+ @Override
public int size() {
- return isReference() ? ((Resource) getCheckedRef()).size() : 1;
+ return isReference() ? getCheckedRef().size() : 1;
}
/**
@@ -378,8 +369,9 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* @return whether this Resource is a FileProvider.
* @since Ant 1.7
*/
+ @Override
public boolean isFilesystemOnly() {
- return (isReference() && ((Resource) getCheckedRef()).isFilesystemOnly())
+ return (isReference() && getCheckedRef().isFilesystemOnly())
|| this.as(FileProvider.class) != null;
}
@@ -388,6 +380,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* @return this Resource formatted as a String.
* @since Ant 1.7
*/
+ @Override
public String toString() {
if (isReference()) {
return getCheckedRef().toString();
@@ -404,7 +397,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* @since Ant 1.7
*/
public final String toLongString() {
- return isReference() ? ((Resource) getCheckedRef()).toLongString()
+ return isReference() ? getCheckedRef().toLongString()
: getDataTypeName() + " \"" + toString() + '"';
}
@@ -412,6 +405,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* Overrides the base version.
* @param r the Reference to set.
*/
+ @Override
public void setRefid(Reference r) {
if (name != null
|| exists != null
@@ -434,9 +428,28 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* <p>This implementation of the method will return the current
* instance itself if it can be assigned to the given class.</p>
*
+ * @param <T> desired type
+ * @param clazz
+ * @return <T>
* @since Ant 1.8.0
*/
public <T> T as(Class<T> clazz) {
return clazz.isAssignableFrom(getClass()) ? clazz.cast(this) : null;
}
+
+ /**
+ * Return {@link #as(Class)} as an {@link Optional}.
+ * @param <T> desired type
+ * @param clazz
+ * @return {@link Optional} <T>
+ * @since Ant 1.11
+ */
+ public <T> Optional<T> asOptional(Class<T> clazz) {
+ return Optional.ofNullable(as(clazz));
+ }
+
+ @Override
+ protected Resource getCheckedRef() {
+ return (Resource) super.getCheckedRef();
+ }
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/ResourceCollection.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/ResourceCollection.java b/src/main/org/apache/tools/ant/types/ResourceCollection.java
index a82c8b5..9fd7f58 100644
--- a/src/main/org/apache/tools/ant/types/ResourceCollection.java
+++ b/src/main/org/apache/tools/ant/types/ResourceCollection.java
@@ -1,50 +1,61 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
*/
package org.apache.tools.ant.types;
-import java.util.Iterator;
+import java.util.stream.Stream;
/**
* Interface describing a collection of Resources.
+ *
* @since Ant 1.7
*/
public interface ResourceCollection extends Iterable<Resource> {
- /**
- * Gets the contents of this collection.
- * @return all resources in the collection
- */
- Iterator<Resource> iterator();
+ /**
+ * Learn the number of contained Resources.
+ *
+ * @return number of elements as int.
+ */
+ int size();
- /**
- * Learn the number of contained Resources.
- * @return number of elements as int.
- */
- int size();
+ /**
+ * Indicate whether this ResourceCollection is composed entirely of
+ * Resources accessible via local filesystem conventions. If true, all
+ * resources returned from this collection should respond with a
+ * {@link org.apache.tools.ant.types.resources.FileProvider} when asked via
+ * {@link Resource#as}.
+ *
+ * @return whether this is a filesystem-only resource collection.
+ */
+ boolean isFilesystemOnly();
- /**
- * Indicate whether this ResourceCollection is composed entirely of
- * Resources accessible via local filesystem conventions. If true,
- * all resources returned from this collection should
- * respond with a {@link org.apache.tools.ant.types.resources.FileProvider}
- * when asked via {@link Resource#as}.
- * @return whether this is a filesystem-only resource collection.
- */
- boolean isFilesystemOnly();
+ /**
+ * Return a {@link Stream} over this {@link ResourceCollection}.
+ * @return {@link Stream} of {@link Resource}
+ * @since Ant 1.11
+ */
+ default Stream<? extends Resource> stream() {
+ final Stream.Builder<Resource> b = Stream.builder();
+ forEach(b);
+ return b.build();
+ }
+ /**
+ * Learn whether this {@link ResourceCollection} is empty.
+ * @return boolean
+ */
+ default boolean isEmpty() {
+ return size() == 0;
+ }
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/TarFileSet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/TarFileSet.java b/src/main/org/apache/tools/ant/types/TarFileSet.java
index 6446e9b..49bcaa2 100644
--- a/src/main/org/apache/tools/ant/types/TarFileSet.java
+++ b/src/main/org/apache/tools/ant/types/TarFileSet.java
@@ -178,6 +178,7 @@ public class TarFileSet extends ArchiveFileSet {
* Create a new scanner.
* @return the created scanner.
*/
+ @Override
protected ArchiveScanner newArchiveScanner() {
TarScanner zs = new TarScanner();
zs.setEncoding(getEncoding());
@@ -192,6 +193,7 @@ public class TarFileSet extends ArchiveFileSet {
* @param r the <code>Reference</code> to use.
* @throws BuildException on error
*/
+ @Override
public void setRefid(Reference r) throws BuildException {
if (userNameSet || userIdSet || groupNameSet || groupIdSet) {
throw tooManyAttributes();
@@ -205,19 +207,20 @@ public class TarFileSet extends ArchiveFileSet {
* @param p the project to use
* @return the abstract fileset instance
*/
+ @Override
protected AbstractFileSet getRef(Project p) {
dieOnCircularReference(p);
Object o = getRefid().getReferencedObject(p);
if (o instanceof TarFileSet) {
return (AbstractFileSet) o;
- } else if (o instanceof FileSet) {
+ }
+ if (o instanceof FileSet) {
TarFileSet zfs = new TarFileSet((FileSet) o);
configureFileSet(zfs);
return zfs;
- } else {
- String msg = getRefid().getRefId() + " doesn\'t denote a tarfileset or a fileset";
- throw new BuildException(msg);
}
+ String msg = getRefid().getRefId() + " doesn\'t denote a tarfileset or a fileset";
+ throw new BuildException(msg);
}
/**
@@ -226,6 +229,7 @@ public class TarFileSet extends ArchiveFileSet {
* specific attributes.
* @param zfs the archive fileset to configure.
*/
+ @Override
protected void configureFileSet(ArchiveFileSet zfs) {
super.configureFileSet(zfs);
if (zfs instanceof TarFileSet) {
@@ -242,12 +246,12 @@ public class TarFileSet extends ArchiveFileSet {
* as this one.
* @return the cloned tarFileSet
*/
- public Object clone() {
+ @Override
+ public TarFileSet clone() {
if (isReference()) {
return ((TarFileSet) getRef(getProject())).clone();
- } else {
- return super.clone();
}
+ return (TarFileSet) super.clone();
}
/**
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/TarScanner.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/TarScanner.java b/src/main/org/apache/tools/ant/types/TarScanner.java
index a3c7f6d..f5b3a39 100644
--- a/src/main/org/apache/tools/ant/types/TarScanner.java
+++ b/src/main/org/apache/tools/ant/types/TarScanner.java
@@ -23,7 +23,6 @@ import java.util.Map;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.resources.TarResource;
-import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarInputStream;
@@ -53,35 +52,30 @@ public class TarScanner extends ArchiveScanner {
Map<String, Resource> fileEntries, Map<String, Resource> matchFileEntries,
Map<String, Resource> dirEntries, Map<String, Resource> matchDirEntries) {
- TarEntry entry = null;
- TarInputStream ti = null;
-
- try {
+ try (TarInputStream ti = new TarInputStream(src.getInputStream(), encoding)) {
try {
- ti = new TarInputStream(src.getInputStream(), encoding);
- } catch (IOException ex) {
- throw new BuildException("problem opening " + srcFile, ex);
- }
- while ((entry = ti.getNextEntry()) != null) {
- Resource r = new TarResource(src, entry);
- String name = entry.getName();
- if (entry.isDirectory()) {
- name = trimSeparator(name);
- dirEntries.put(name, r);
- if (match(name)) {
- matchDirEntries.put(name, r);
- }
- } else {
- fileEntries.put(name, r);
- if (match(name)) {
- matchFileEntries.put(name, r);
+ TarEntry entry = null;
+ while ((entry = ti.getNextEntry()) != null) {
+ Resource r = new TarResource(src, entry);
+ String name = entry.getName();
+ if (entry.isDirectory()) {
+ name = trimSeparator(name);
+ dirEntries.put(name, r);
+ if (match(name)) {
+ matchDirEntries.put(name, r);
+ }
+ } else {
+ fileEntries.put(name, r);
+ if (match(name)) {
+ matchFileEntries.put(name, r);
+ }
}
}
+ } catch (IOException ex) {
+ throw new BuildException("problem reading " + srcFile, ex);
}
} catch (IOException ex) {
- throw new BuildException("problem reading " + srcFile, ex);
- } finally {
- FileUtils.close(ti);
+ throw new BuildException("problem opening " + srcFile, ex);
}
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/XMLCatalog.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/XMLCatalog.java b/src/main/org/apache/tools/ant/types/XMLCatalog.java
index 9281d5d..753e533 100644
--- a/src/main/org/apache/tools/ant/types/XMLCatalog.java
+++ b/src/main/org/apache/tools/ant/types/XMLCatalog.java
@@ -356,6 +356,7 @@ public class XMLCatalog extends DataType
* @param r the reference to which this catalog instance is associated
* @exception BuildException if this instance already has been configured.
*/
+ @Override
public void setRefid(Reference r) throws BuildException {
if (!elements.isEmpty()) {
throw tooManyAttributes();
@@ -372,6 +373,7 @@ public class XMLCatalog extends DataType
* @return the resolved entity.
* @see org.xml.sax.EntityResolver#resolveEntity
*/
+ @Override
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
@@ -403,6 +405,7 @@ public class XMLCatalog extends DataType
* @throws TransformerException if an error occurs.
* @see javax.xml.transform.URIResolver#resolve
*/
+ @Override
public Source resolve(String href, String base)
throws TransformerException {
@@ -428,7 +431,7 @@ public class XMLCatalog extends DataType
// setEntityResolver (see setEntityResolver javadoc comment)
//
source = new SAXSource();
- URL baseURL = null;
+ URL baseURL;
try {
if (base == null) {
baseURL = FILE_UTILS.getFileURL(getProject().getBaseDir());
@@ -448,6 +451,7 @@ public class XMLCatalog extends DataType
return source;
}
+ @Override
protected synchronized void dieOnCircularReference(Stack<Object> stk, Project p)
throws BuildException {
if (isChecked()) {
@@ -495,7 +499,7 @@ public class XMLCatalog extends DataType
if (catalogResolver == null) {
- AntClassLoader loader = null;
+ AntClassLoader loader;
// Memory-Leak in line below
loader = getProject().createClassLoader(Path.systemClasspath);
@@ -590,12 +594,9 @@ public class XMLCatalog extends DataType
* of the Resource or null if no such information is available.
*/
private ResourceLocation findMatchingEntry(String publicId) {
- for (ResourceLocation element : getElements()) {
- if (element.getPublicId().equals(publicId)) {
- return element;
- }
- }
- return null;
+ return getElements().stream()
+ .filter(e -> e.getPublicId().equals(publicId)).findFirst()
+ .orElse(null);
}
/**
@@ -628,7 +629,7 @@ public class XMLCatalog extends DataType
String uri = matchingEntry.getLocation();
// the following line seems to be necessary on Windows under JDK 1.2
uri = uri.replace(File.separatorChar, '/');
- URL baseURL = null;
+ URL baseURL;
//
// The ResourceLocation may specify a relative path for its
@@ -645,7 +646,6 @@ public class XMLCatalog extends DataType
}
}
- InputSource source = null;
URL url = null;
try {
url = new URL(baseURL, uri);
@@ -670,7 +670,8 @@ public class XMLCatalog extends DataType
}
}
- if (url != null && url.getProtocol().equals("file")) {
+ InputSource source = null;
+ if (url != null && "file".equals(url.getProtocol())) {
String fileName = FILE_UTILS.fromURI(url.toString());
if (fileName != null) {
log("fileName " + fileName, Project.MSG_DEBUG);
@@ -701,14 +702,13 @@ public class XMLCatalog extends DataType
InputSource source = null;
- AntClassLoader loader = null;
Path cp = classpath;
if (cp != null) {
cp = classpath.concatSystemClasspath("ignore");
} else {
cp = (new Path(getProject())).concatSystemClasspath("last");
}
- loader = getProject().createClassLoader(cp);
+ AntClassLoader loader = getProject().createClassLoader(cp);
//
// for classpath lookup we ignore the base directory
@@ -737,7 +737,7 @@ public class XMLCatalog extends DataType
private InputSource urlLookup(ResourceLocation matchingEntry) {
String uri = matchingEntry.getLocation();
- URL baseURL = null;
+ URL baseURL;
//
// The ResourceLocation may specify a relative url for its
@@ -754,15 +754,15 @@ public class XMLCatalog extends DataType
}
}
- InputSource source = null;
- URL url = null;
+ URL url;
try {
url = new URL(baseURL, uri);
} catch (MalformedURLException ex) {
- // ignore
+ url = null;
}
+ InputSource source = null;
if (url != null) {
try {
InputStream is = null;
@@ -792,10 +792,6 @@ public class XMLCatalog extends DataType
* the ExternalResolver strategy.
*/
private interface CatalogResolver extends URIResolver, EntityResolver {
-
- InputSource resolveEntity(String publicId, String systemId);
-
- Source resolve(String href, String base) throws TransformerException;
}
/**
@@ -812,6 +808,7 @@ public class XMLCatalog extends DataType
Project.MSG_VERBOSE);
}
+ @Override
public InputSource resolveEntity(String publicId,
String systemId) {
InputSource result = null;
@@ -837,6 +834,7 @@ public class XMLCatalog extends DataType
return result;
}
+ @Override
public Source resolve(String href, String base)
throws TransformerException {
@@ -948,14 +946,15 @@ public class XMLCatalog extends DataType
Project.MSG_VERBOSE);
}
+ @Override
public InputSource resolveEntity(String publicId,
String systemId) {
- InputSource result = null;
processExternalCatalogs();
ResourceLocation matchingEntry = findMatchingEntry(publicId);
+ InputSource result;
if (matchingEntry != null) {
log("Matching catalog entry found for publicId: '"
@@ -999,11 +998,12 @@ public class XMLCatalog extends DataType
return result;
}
+ @Override
public Source resolve(String href, String base)
throws TransformerException {
- SAXSource result = null;
- InputSource source = null;
+ SAXSource result;
+ InputSource source;
processExternalCatalogs();
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/ZipFileSet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/ZipFileSet.java b/src/main/org/apache/tools/ant/types/ZipFileSet.java
index 24f0ccd..84362a1 100644
--- a/src/main/org/apache/tools/ant/types/ZipFileSet.java
+++ b/src/main/org/apache/tools/ant/types/ZipFileSet.java
@@ -58,6 +58,7 @@ public class ZipFileSet extends ArchiveFileSet {
* Return a new archive scanner based on this one.
* @return a new ZipScanner with the same encoding as this one.
*/
+ @Override
protected ArchiveScanner newArchiveScanner() {
ZipScanner zs = new ZipScanner();
zs.setEncoding(getEncoding());
@@ -70,19 +71,20 @@ public class ZipFileSet extends ArchiveFileSet {
* @param p the project to use
* @return the abstract fileset instance
*/
+ @Override
protected AbstractFileSet getRef(Project p) {
dieOnCircularReference(p);
Object o = getRefid().getReferencedObject(p);
if (o instanceof ZipFileSet) {
return (AbstractFileSet) o;
- } else if (o instanceof FileSet) {
+ }
+ if (o instanceof FileSet) {
ZipFileSet zfs = new ZipFileSet((FileSet) o);
configureFileSet(zfs);
return zfs;
- } else {
- String msg = getRefid().getRefId() + " doesn\'t denote a zipfileset or a fileset";
- throw new BuildException(msg);
}
+ String msg = getRefid().getRefId() + " doesn\'t denote a zipfileset or a fileset";
+ throw new BuildException(msg);
}
/**
@@ -90,28 +92,12 @@ public class ZipFileSet extends ArchiveFileSet {
* as this one.
* @return the cloned zipFileSet
*/
- public Object clone() {
+ @Override
+ public ZipFileSet clone() {
if (isReference()) {
return ((ZipFileSet) getRef(getProject())).clone();
- } else {
- return super.clone();
- }
- }
-
- /**
- * A check attributes for zipFileSet.
- * If there is a reference, and
- * it is a ZipFileSet, the zip fileset attributes
- * cannot be used.
- */
- private void checkZipFileSetAttributesAllowed() {
- if (getProject() == null
- || (isReference()
- && (getRefid().getReferencedObject(
- getProject())
- instanceof ZipFileSet))) {
- checkAttributesAllowed();
}
+ return (ZipFileSet) super.clone();
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/ZipScanner.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/ZipScanner.java b/src/main/org/apache/tools/ant/types/ZipScanner.java
index 0539222..49f66eb 100644
--- a/src/main/org/apache/tools/ant/types/ZipScanner.java
+++ b/src/main/org/apache/tools/ant/types/ZipScanner.java
@@ -52,31 +52,20 @@ public class ZipScanner extends ArchiveScanner {
* resources found inside the archive that matched all include
* patterns and didn't match any exclude patterns.
*/
+ @Override
protected void fillMapsFromArchive(Resource src, String encoding,
Map<String, Resource> fileEntries, Map<String, Resource> matchFileEntries,
Map<String, Resource> dirEntries, Map<String, Resource> matchDirEntries) {
- ZipEntry entry = null;
- ZipFile zf = null;
- File srcFile = null;
- FileProvider fp = src.as(FileProvider.class);
- if (fp != null) {
- srcFile = fp.getFile();
- } else {
- throw new BuildException("Only file provider resources are supported");
- }
+ File srcFile = src.asOptional(FileProvider.class)
+ .map(FileProvider::getFile).orElseThrow(() -> new BuildException(
+ "Only file provider resources are supported"));
+
+ try (ZipFile zf = new ZipFile(srcFile, encoding)) {
- try {
- try {
- zf = new ZipFile(srcFile, encoding);
- } catch (ZipException ex) {
- throw new BuildException("Problem reading " + srcFile, ex);
- } catch (IOException ex) {
- throw new BuildException("Problem opening " + srcFile, ex);
- }
Enumeration<ZipEntry> e = zf.getEntries();
while (e.hasMoreElements()) {
- entry = e.nextElement();
+ ZipEntry entry = e.nextElement();
Resource r = new ZipResource(srcFile, encoding, entry);
String name = entry.getName();
if (entry.isDirectory()) {
@@ -92,8 +81,10 @@ public class ZipScanner extends ArchiveScanner {
}
}
}
- } finally {
- ZipFile.closeQuietly(zf);
+ } catch (ZipException ex) {
+ throw new BuildException("Problem reading " + srcFile, ex);
+ } catch (IOException ex) {
+ throw new BuildException("Problem opening " + srcFile, ex);
}
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java b/src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java
index b9e7cfb..8f24e92 100644
--- a/src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java
+++ b/src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java
@@ -46,6 +46,7 @@ public class CutDirsMapper implements FileNameMapper {
* Empty implementation.
* @param ignore ignored.
*/
+ @Override
public void setFrom(final String ignore) {
}
@@ -53,10 +54,12 @@ public class CutDirsMapper implements FileNameMapper {
* Empty implementation.
* @param ignore ignored.
*/
+ @Override
public void setTo(final String ignore) {
}
/** {@inheritDoc}. */
+ @Override
public String[] mapFileName(final String sourceFileName) {
if (dirs <= 0) {
throw new BuildException("dirs must be set to a positive number");
@@ -71,6 +74,6 @@ public class CutDirsMapper implements FileNameMapper {
if (nthMatch == -1) {
return null;
}
- return new String[] {sourceFileName.substring(nthMatch + 1)};
+ return new String[] { sourceFileName.substring(nthMatch + 1) };
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/types/mappers/FilterMapper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/mappers/FilterMapper.java b/src/main/org/apache/tools/ant/types/mappers/FilterMapper.java
index 501da50..4eb5813 100644
--- a/src/main/org/apache/tools/ant/types/mappers/FilterMapper.java
+++ b/src/main/org/apache/tools/ant/types/mappers/FilterMapper.java
@@ -41,6 +41,7 @@ public class FilterMapper extends FilterChain implements FileNameMapper {
* @param from a string
* @throws BuildException always
*/
+ @Override
public void setFrom(String from) {
throw new UnsupportedAttributeException(
"filtermapper doesn't support the \"from\" attribute.", "from");
@@ -51,6 +52,7 @@ public class FilterMapper extends FilterChain implements FileNameMapper {
* @param to a string
* @throws BuildException always
*/
+ @Override
public void setTo(String to) {
throw new UnsupportedAttributeException(
"filtermapper doesn't support the \"to\" attribute.", "to");
@@ -62,6 +64,7 @@ public class FilterMapper extends FilterChain implements FileNameMapper {
* @return a one-element array of converted filenames, or null if
* the filterchain returns an empty string.
*/
+ @Override
public String[] mapFileName(String sourceFileName) {
try {
Reader stringReader = new StringReader(sourceFileName);
@@ -69,15 +72,14 @@ public class FilterMapper extends FilterChain implements FileNameMapper {
helper.setBufferSize(BUFFER_SIZE);
helper.setPrimaryReader(stringReader);
helper.setProject(getProject());
- Vector<FilterChain> filterChains = new Vector<FilterChain>();
+ Vector<FilterChain> filterChains = new Vector<>();
filterChains.add(this);
helper.setFilterChains(filterChains);
String result = FileUtils.safeReadFully(helper.getAssembledReader());
- if (result.length() == 0) {
+ if (result.isEmpty()) {
return null;
- } else {
- return new String[] {result};
}
+ return new String[] { result };
} catch (BuildException ex) {
throw ex;
} catch (Exception ex) {