You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by gi...@apache.org on 2018/05/20 15:00:47 UTC
[1/3] ant git commit: More Streams (less StreamUtils)
Repository: ant
Updated Branches:
refs/heads/master c069b5007 -> e6b203006
More Streams (less StreamUtils)
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/70da75c5
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/70da75c5
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/70da75c5
Branch: refs/heads/master
Commit: 70da75c5053a3f2e5f7905e2d8bfeb4e998edcec
Parents: c069b50
Author: Gintas Grigelionis <gi...@apache.org>
Authored: Sun May 20 15:53:04 2018 +0200
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Sun May 20 15:56:02 2018 +0200
----------------------------------------------------------------------
.../org/apache/tools/ant/ComponentHelper.java | 44 ++++-----
.../apache/tools/ant/RuntimeConfigurable.java | 7 +-
src/main/org/apache/tools/ant/XmlLogger.java | 11 +--
.../tools/ant/attribute/BaseIfAttribute.java | 20 ++--
.../org/apache/tools/ant/taskdefs/Recorder.java | 8 +-
.../optional/ejb/BorlandDeploymentTool.java | 8 +-
.../optional/ejb/DescriptorHandler.java | 3 +-
.../optional/ejb/WeblogicDeploymentTool.java | 99 +++++++++-----------
.../optional/ejb/WebsphereDeploymentTool.java | 16 ++--
9 files changed, 88 insertions(+), 128 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/70da75c5/src/main/org/apache/tools/ant/ComponentHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/ComponentHelper.java b/src/main/org/apache/tools/ant/ComponentHelper.java
index 0011079..28fa824 100644
--- a/src/main/org/apache/tools/ant/ComponentHelper.java
+++ b/src/main/org/apache/tools/ant/ComponentHelper.java
@@ -34,6 +34,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Stack;
+import java.util.stream.Collectors;
import org.apache.tools.ant.launch.Launcher;
import org.apache.tools.ant.taskdefs.Definer;
@@ -228,7 +229,8 @@ public class ComponentHelper {
public void initSubProject(ComponentHelper helper) {
// add the types of the parent project
@SuppressWarnings("unchecked")
- final Hashtable<String, AntTypeDefinition> typeTable = (Hashtable<String, AntTypeDefinition>) helper.antTypeTable.clone();
+ final Hashtable<String, AntTypeDefinition> typeTable
+ = (Hashtable<String, AntTypeDefinition>) helper.antTypeTable.clone();
synchronized (antTypeTable) {
for (AntTypeDefinition def : typeTable.values()) {
antTypeTable.put(def.getName(), def);
@@ -239,7 +241,8 @@ public class ComponentHelper {
synchronized (this) {
checkedNamespaces.addAll(inheritedCheckedNamespace);
}
- Map<String, List<AntTypeDefinition>> inheritedRestrictedDef = helper.getRestrictedDefinition();
+ Map<String, List<AntTypeDefinition>> inheritedRestrictedDef
+ = helper.getRestrictedDefinition();
synchronized (restrictedDefinitions) {
restrictedDefinitions.putAll(inheritedRestrictedDef);
}
@@ -398,15 +401,11 @@ public class ComponentHelper {
synchronized (antTypeTable) {
if (rebuildTaskClassDefinitions) {
taskClassDefinitions.clear();
- for (Map.Entry<String, AntTypeDefinition> e : antTypeTable.entrySet()) {
- final Class<?> clazz = e.getValue().getExposedClass(project);
- if (clazz == null) {
- continue;
- }
- if (Task.class.isAssignableFrom(clazz)) {
- taskClassDefinitions.put(e.getKey(), e.getValue().getTypeClass(project));
- }
- }
+ antTypeTable.entrySet().stream()
+ .filter(e -> e.getValue().getExposedClass(project) != null
+ && Task.class.isAssignableFrom(e.getValue().getExposedClass(project)))
+ .forEach(e -> taskClassDefinitions.put(e.getKey(),
+ e.getValue().getTypeClass(project)));
rebuildTaskClassDefinitions = false;
}
}
@@ -426,15 +425,11 @@ public class ComponentHelper {
synchronized (antTypeTable) {
if (rebuildTypeClassDefinitions) {
typeClassDefinitions.clear();
- for (Map.Entry<String, AntTypeDefinition> e : antTypeTable.entrySet()) {
- final Class<?> clazz = e.getValue().getExposedClass(project);
- if (clazz == null) {
- continue;
- }
- if (!Task.class.isAssignableFrom(clazz)) {
- typeClassDefinitions.put(e.getKey(), e.getValue().getTypeClass(project));
- }
- }
+ antTypeTable.entrySet().stream()
+ .filter(e -> e.getValue().getExposedClass(project) != null
+ && !Task.class.isAssignableFrom(e.getValue().getExposedClass(project)))
+ .forEach(e -> typeClassDefinitions.put(e.getKey(),
+ e.getValue().getTypeClass(project)));
rebuildTypeClassDefinitions = false;
}
}
@@ -1077,14 +1072,9 @@ public class ComponentHelper {
* @return the (possibly empty) list of definitions
*/
private List<AntTypeDefinition> findTypeMatches(String prefix) {
- final List<AntTypeDefinition> result = new ArrayList<>();
synchronized (antTypeTable) {
- for (AntTypeDefinition def : antTypeTable.values()) {
- if (def.getName().startsWith(prefix)) {
- result.add(def);
- }
- }
+ return antTypeTable.values().stream().filter(def -> def.getName().startsWith(prefix))
+ .collect(Collectors.toList());
}
- return result;
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/70da75c5/src/main/org/apache/tools/ant/RuntimeConfigurable.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/RuntimeConfigurable.java b/src/main/org/apache/tools/ant/RuntimeConfigurable.java
index d996409..90c34a2 100644
--- a/src/main/org/apache/tools/ant/RuntimeConfigurable.java
+++ b/src/main/org/apache/tools/ant/RuntimeConfigurable.java
@@ -43,10 +43,6 @@ public class RuntimeConfigurable implements Serializable {
/** Serialization version */
private static final long serialVersionUID = 1L;
- /** Empty Hashtable. */
- private static final Hashtable<String, Object> EMPTY_HASHTABLE =
- new Hashtable<>(0);
-
/** Name of the element to configure. */
private String elementTag = null;
@@ -336,8 +332,7 @@ public class RuntimeConfigurable implements Serializable {
* @since Ant 1.6
*/
public synchronized Hashtable<String, Object> getAttributeMap() {
- return (attributeMap == null)
- ? EMPTY_HASHTABLE : new Hashtable<>(attributeMap);
+ return new Hashtable<>(attributeMap == null ? Collections.emptyMap() : attributeMap);
}
/**
http://git-wip-us.apache.org/repos/asf/ant/blob/70da75c5/src/main/org/apache/tools/ant/XmlLogger.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/XmlLogger.java b/src/main/org/apache/tools/ant/XmlLogger.java
index 96cfc68..5adce14 100644
--- a/src/main/org/apache/tools/ant/XmlLogger.java
+++ b/src/main/org/apache/tools/ant/XmlLogger.java
@@ -25,13 +25,13 @@ import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Hashtable;
+import java.util.Map;
import java.util.Stack;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.tools.ant.util.DOMElementWriter;
-import org.apache.tools.ant.util.StreamUtils;
import org.apache.tools.ant.util.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -108,16 +108,16 @@ public class XmlLogger implements BuildLogger {
private Document doc = builder.newDocument();
/** Mapping for when tasks started (Task to TimedElement). */
- private Hashtable<Task, TimedElement> tasks = new Hashtable<>();
+ private Map<Task, TimedElement> tasks = new Hashtable<>();
/** Mapping for when targets started (Target to TimedElement). */
- private Hashtable<Target, TimedElement> targets = new Hashtable<>();
+ private Map<Target, TimedElement> targets = new Hashtable<>();
/**
* Mapping of threads to stacks of elements
* (Thread to Stack of TimedElement).
*/
- private Hashtable<Thread, Stack<TimedElement>> threadStacks = new Hashtable<>();
+ private Map<Thread, Stack<TimedElement>> threadStacks = new Hashtable<>();
/**
* When the build started.
@@ -345,8 +345,7 @@ public class XmlLogger implements BuildLogger {
if (element != null) {
return element;
}
- return StreamUtils.enumerationAsStream(tasks.keys())
- .filter(UnknownElement.class::isInstance)
+ return tasks.keySet().stream().filter(UnknownElement.class::isInstance)
.filter(key -> ((UnknownElement) key).getTask() == task).findFirst()
.map(key -> tasks.get(key)).orElse(null);
}
http://git-wip-us.apache.org/repos/asf/ant/blob/70da75c5/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java b/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java
index 14c22a5..fc861e1 100644
--- a/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java
+++ b/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java
@@ -19,11 +19,10 @@
package org.apache.tools.ant.attribute;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.Map;
+import java.util.stream.Collectors;
import org.apache.tools.ant.ProjectComponent;
-import org.apache.tools.ant.RuntimeConfigurable;
import org.apache.tools.ant.UnknownElement;
@@ -68,17 +67,10 @@ public abstract class BaseIfAttribute
* @return a map of attributes.
*/
protected Map<String, String> getParams(UnknownElement el) {
- Map<String, String> ret = new HashMap<>();
- RuntimeConfigurable rc = el.getWrapper();
- Hashtable<String, Object> attributes = rc.getAttributeMap(); // This does a copy!
- for (Map.Entry<String, Object> entry : attributes.entrySet()) {
- String key = entry.getKey();
- if (key.startsWith("ant-attribute:param")) {
- int pos = key.lastIndexOf(':');
- ret.put(key.substring(pos + 1),
- el.getProject().replaceProperties((String) entry.getValue()));
- }
- }
- return ret;
+ // this makes a copy!
+ return el.getWrapper().getAttributeMap().entrySet().stream()
+ .filter(e -> e.getKey().startsWith("ant-attribute:param"))
+ .collect(Collectors.toMap(e -> e.getKey().substring(e.getKey().lastIndexOf(':') + 1),
+ e -> el.getProject().replaceProperties((String) e.getValue()), (a, b) -> b));
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/70da75c5/src/main/org/apache/tools/ant/taskdefs/Recorder.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Recorder.java b/src/main/org/apache/tools/ant/taskdefs/Recorder.java
index 66152d3..90410b6 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Recorder.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Recorder.java
@@ -18,6 +18,7 @@
package org.apache.tools.ant.taskdefs;
import java.util.Hashtable;
+import java.util.Map;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildException;
@@ -66,7 +67,7 @@ public class Recorder extends Task implements SubBuildListener {
/** Strip task banners if true. */
private boolean emacsMode = false;
/** The list of recorder entries. */
- private static Hashtable<String, RecorderEntry> recorderEntries = new Hashtable<>();
+ private static Map<String, RecorderEntry> recorderEntries = new Hashtable<>();
//////////////////////////////////////////////////////////////////////
// CONSTRUCTORS / INITIALIZERS
@@ -304,11 +305,8 @@ public class Recorder extends Task implements SubBuildListener {
*
* @since Ant 1.7
*/
- @SuppressWarnings("unchecked")
private void cleanup() {
- ((Hashtable<String, RecorderEntry>) recorderEntries.clone()).entrySet().stream()
- .filter(entry -> entry.getValue().getProject() == getProject())
- .forEach(entry -> recorderEntries.remove(entry.getKey()));
+ recorderEntries.entrySet().removeIf(e -> e.getValue().getProject() == getProject());
getProject().removeBuildListener(this);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/70da75c5/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java
index 8894045..3db3d56 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java
@@ -16,10 +16,8 @@
*
*/
-
package org.apache.tools.ant.taskdefs.optional.ejb;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
@@ -31,6 +29,7 @@ import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.ExecTask;
@@ -41,7 +40,6 @@ import org.apache.tools.ant.taskdefs.optional.ejb.EjbJar.DTDLocation;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Path;
-
/**
* BorlandDeploymentTool is dedicated to the Borland Application Server 4.5 and 4.5.1
* This task generates and compiles the stubs and skeletons for all ejb described into the
@@ -60,7 +58,7 @@ import org.apache.tools.ant.types.Path;
* <li>version (int) : tell what is the Borland appserver version 4 or 5 </li>
* </ul>
*
- *<PRE>
+ *<pre>
*
* <ejbjar srcdir="${build.classes}"
* basejarname="vsmp"
@@ -74,7 +72,7 @@ import org.apache.tools.ant.types.Path;
* <include name="demo\helper\*.class"/>
* </support>
* </ejbjar>
- *</PRE>
+ *</pre>
*
*/
public class BorlandDeploymentTool extends GenericDeploymentTool
http://git-wip-us.apache.org/repos/asf/ant/blob/70da75c5/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java
index eaef78c..4c3ea49 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
+import java.util.Collections;
import java.util.Hashtable;
import java.util.Map;
@@ -233,7 +234,7 @@ public class DescriptorHandler extends HandlerBase {
* @return the map of files
*/
public Hashtable<String, File> getFiles() {
- return ejbFiles == null ? new Hashtable<>() : ejbFiles;
+ return new Hashtable<>(ejbFiles == null ? Collections.emptyMap() : ejbFiles);
}
/**
http://git-wip-us.apache.org/repos/asf/ant/blob/70da75c5/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
index c44aea4..5961eca 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
@@ -21,13 +21,16 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
-import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Vector;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
+import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
@@ -36,7 +39,6 @@ import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Java;
-import org.apache.tools.ant.taskdefs.optional.ejb.EjbJar.DTDLocation;
import org.apache.tools.ant.types.Environment;
import org.apache.tools.ant.types.Environment.Variable;
import org.apache.tools.ant.types.Path;
@@ -424,9 +426,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
handler.registerDTD(PUBLICID_WEBLOGIC_EJB510, weblogicDTD);
handler.registerDTD(PUBLICID_WEBLOGIC_EJB600, weblogicDTD);
- for (DTDLocation dtdLocation : getConfig().dtdLocations) {
- handler.registerDTD(dtdLocation.getPublicId(), dtdLocation.getLocation());
- }
+ getConfig().dtdLocations.forEach(l -> handler.registerDTD(l.getPublicId(), l.getLocation()));
return handler;
}
@@ -685,73 +685,62 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
genericJar = new JarFile(genericJarFile);
wlJar = new JarFile(weblogicJarFile);
- Hashtable<String, JarEntry> genericEntries = new Hashtable<>();
- Hashtable<String, JarEntry> wlEntries = new Hashtable<>();
- Hashtable<String, JarEntry> replaceEntries = new Hashtable<>();
+ Map<String, JarEntry> replaceEntries = new HashMap<>();
//get the list of generic jar entries
- for (Enumeration<JarEntry> e = genericJar.entries(); e.hasMoreElements();) {
- JarEntry je = e.nextElement();
- genericEntries.put(je.getName().replace('\\', '/'), je);
- }
+ Map<String, JarEntry> genericEntries = genericJar.stream()
+ .collect(Collectors.toMap(je -> je.getName().replace('\\', '/'),
+ je -> je, (a, b) -> b));
// get the list of WebLogic jar entries
- for (Enumeration<JarEntry> e = wlJar.entries(); e.hasMoreElements();) {
- JarEntry je = e.nextElement();
- wlEntries.put(je.getName(), je);
- }
+ Map<String, JarEntry> wlEntries = wlJar.stream().collect(Collectors.toMap(ZipEntry::getName,
+ je -> je, (a, b) -> b));
// Cycle through generic and make sure its in WebLogic
genericLoader = getClassLoaderFromJar(genericJarFile);
- for (Enumeration<String> e = genericEntries.keys(); e.hasMoreElements();) {
- String filepath = e.nextElement();
-
- if (wlEntries.containsKey(filepath)) {
- // File name/path match
-
- // Check files see if same
- JarEntry genericEntry = genericEntries.get(filepath);
- JarEntry wlEntry = wlEntries.get(filepath);
+ for (String filepath : genericEntries.keySet()) {
+ if (!wlEntries.containsKey(filepath)) {
+ // a file doesn't exist rebuild
+ log("File " + filepath + " not present in weblogic jar",
+ Project.MSG_VERBOSE);
+ rebuild = true;
+ break;
+ }
+ // File name/path match
+ // Check files see if same
+ JarEntry genericEntry = genericEntries.get(filepath);
+ JarEntry wlEntry = wlEntries.get(filepath);
- if (genericEntry.getCrc() != wlEntry.getCrc()
- || genericEntry.getSize() != wlEntry.getSize()) {
+ if (genericEntry.getCrc() != wlEntry.getCrc()
+ || genericEntry.getSize() != wlEntry.getSize()) {
- if (genericEntry.getName().endsWith(".class")) {
- //File are different see if its an object or an interface
- String classname
- = genericEntry.getName()
+ if (genericEntry.getName().endsWith(".class")) {
+ //File are different see if its an object or an interface
+ String classname = genericEntry.getName()
.replace(File.separatorChar, '.')
.replace('/', '.');
- classname = classname.substring(0, classname.lastIndexOf(".class"));
-
- Class<?> genclass = genericLoader.loadClass(classname);
-
- if (genclass.isInterface()) {
- //Interface changed rebuild jar.
- log("Interface " + genclass.getName()
- + " has changed", Project.MSG_VERBOSE);
- rebuild = true;
- break;
- }
- //Object class Changed update it.
- replaceEntries.put(filepath, genericEntry);
- } else if (!"META-INF/MANIFEST.MF".equals(genericEntry.getName())) {
- // it is not the manifest, otherwise we'd ignore it
- // File other then class changed rebuild
- log("Non class file " + genericEntry.getName()
+ classname = classname.substring(0, classname.lastIndexOf(".class"));
+
+ Class<?> genclass = genericLoader.loadClass(classname);
+
+ if (genclass.isInterface()) {
+ //Interface changed rebuild jar.
+ log("Interface " + genclass.getName()
+ " has changed", Project.MSG_VERBOSE);
rebuild = true;
break;
}
+ //Object class Changed update it.
+ replaceEntries.put(filepath, genericEntry);
+ } else if (!genericEntry.getName().equals("META-INF/MANIFEST.MF")) {
+ // it is not the manifest, otherwise we'd ignore it
+ // File other then class changed rebuild
+ log("Non class file " + genericEntry.getName()
+ + " has changed", Project.MSG_VERBOSE);
+ rebuild = true;
+ break;
}
- } else {
- // a file doesn't exist rebuild
-
- log("File " + filepath + " not present in weblogic jar",
- Project.MSG_VERBOSE);
- rebuild = true;
- break;
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/70da75c5/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
index cca7716..4a94007 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
@@ -22,6 +22,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
@@ -35,7 +37,6 @@ import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.types.Environment;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.FileUtils;
-import org.apache.tools.ant.util.StreamUtils;
/**
* WebSphere deployment tool that augments the ejbjar task.
@@ -667,21 +668,18 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool {
wasJar = new JarFile(websphereJarFile);
//get the list of generic jar entries
- Hashtable<String, JarEntry> genericEntries
- = StreamUtils.enumerationAsStream(genericJar.entries())
+ Map<String, JarEntry> genericEntries = genericJar.stream()
.collect(Collectors.toMap(je -> je.getName().replace('\\', '/'),
- je -> je, (a, b) -> b, Hashtable::new));
+ je -> je, (a, b) -> b));
// get the list of WebSphere jar entries
- Hashtable<String, JarEntry> wasEntries
- = StreamUtils.enumerationAsStream(wasJar.entries())
- .collect(Collectors.toMap(ZipEntry::getName,
- je -> je, (a, b) -> b, Hashtable::new));
+ Map<String, JarEntry> wasEntries = wasJar.stream()
+ .collect(Collectors.toMap(ZipEntry::getName, je -> je, (a, b) -> b));
// Cycle through generic and make sure its in WebSphere
genericLoader = getClassLoaderFromJar(genericJarFile);
- Hashtable<String, JarEntry> replaceEntries = new Hashtable<>();
+ Map<String, JarEntry> replaceEntries = new HashMap<>();
for (String filepath : genericEntries.keySet()) {
if (!wasEntries.containsKey(filepath)) {
// a file doesn't exist rebuild
[2/3] ant git commit: Bz 22370: posixGroup and posixPermissions
selectors
Posted by gi...@apache.org.
Bz 22370: posixGroup and posixPermissions selectors
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/748e9172
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/748e9172
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/748e9172
Branch: refs/heads/master
Commit: 748e917268bccf914530827b89d45f4e52b185a2
Parents: 70da75c
Author: Gintas Grigelionis <gi...@apache.org>
Authored: Sun May 20 15:57:06 2018 +0200
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Sun May 20 16:45:12 2018 +0200
----------------------------------------------------------------------
manual/Types/selectors.html | 48 ++++++++++++
.../apache/tools/ant/types/AbstractFileSet.java | 20 ++++-
.../selectors/AbstractSelectorContainer.java | 16 ++++
.../types/selectors/BaseSelectorContainer.java | 16 ++++
.../ant/types/selectors/PosixGroupSelector.java | 66 +++++++++++++++++
.../selectors/PosixPermissionsSelector.java | 76 +++++++++++++++++++
.../types/selectors/PosixGroupSelectorTest.java | 64 ++++++++++++++++
.../selectors/PosixPermissionsSelectorTest.java | 78 ++++++++++++++++++++
8 files changed, 383 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/748e9172/manual/Types/selectors.html
----------------------------------------------------------------------
diff --git a/manual/Types/selectors.html b/manual/Types/selectors.html
index f12e2da..955a1b2 100644
--- a/manual/Types/selectors.html
+++ b/manual/Types/selectors.html
@@ -84,6 +84,10 @@
symlinks.</li>
<li><a href="#ownedBy"><code><ownedBy></code></a>—Select files if they are owned
by a given user.</li>
+ <li><a href="#posixGroup"><code><posixGroup></code>—Select
+ files if they have a given POSIX group.</li>
+ <li><a href="#posixPermissions"><code><posixPermissions></code>—Select
+ files if they have given POSIX permissions.</li>
</ul>
<h4 id="containsselect">Contains Selector</h4>
@@ -923,6 +927,50 @@
</tr>
</table>
+ <h4 id="posixGroup">PosixGroup Selector</h4>
+
+ <p>The <code><posixGroup></code> selector selects only files that are owned by the given
+ POSIX group. Ant only invokes <code class="code">java.nio.file.Files#readAttributes</code> so
+ if a file system doesn't support the operation or POSIX attributes this selector will not
+ select the file.</p>
+
+ <p><em>Since Ant 1.10.4</em></p>
+
+ <table class="attr">
+ <tr>
+ <th scope="col">Attribute</th>
+ <th scope="col">Description</th>
+ <th scope="col">Required</th>
+ </tr>
+ <tr>
+ <td>group</td>
+ <td>POSIX group name</td>
+ <td>Yes</td>
+ </tr>
+ </table>
+
+ <h4 id="posixPermissions">PosixPermissions Selector</h4>
+
+ <p>The <code><posixPermissions></code> selector selects only files that have the given
+ POSIX permissions. Ant only
+ invokes <code class="code">java.nio.file.Files#getPosixFilePermissions</code> so if a file
+ system doesn't support the operation this selector will not select the file.</p>
+
+ <p><em>Since Ant 1.10.4</em></p>
+
+ <table class="attr">
+ <tr>
+ <th scope="col">Attribute</th>
+ <th scope="col">Description</th>
+ <th scope="col">Required</th>
+ </tr>
+ <tr>
+ <td>permissions</td>
+ <td>POSIX permissions in string (<q>rwxrwxrwx</q>) or octal (<q>777</q>) format</td>
+ <td>Yes</td>
+ </tr>
+ </table>
+
<h4 id="scriptselector">Script Selector</h4>
<p>The <code><scriptselector></code> element enables you to write a complex selection
http://git-wip-us.apache.org/repos/asf/ant/blob/748e9172/src/main/org/apache/tools/ant/types/AbstractFileSet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/AbstractFileSet.java b/src/main/org/apache/tools/ant/types/AbstractFileSet.java
index 7c0651a..482fef4 100644
--- a/src/main/org/apache/tools/ant/types/AbstractFileSet.java
+++ b/src/main/org/apache/tools/ant/types/AbstractFileSet.java
@@ -46,6 +46,8 @@ import org.apache.tools.ant.types.selectors.NoneSelector;
import org.apache.tools.ant.types.selectors.NotSelector;
import org.apache.tools.ant.types.selectors.OrSelector;
import org.apache.tools.ant.types.selectors.OwnedBySelector;
+import org.apache.tools.ant.types.selectors.PosixGroupSelector;
+import org.apache.tools.ant.types.selectors.PosixPermissionsSelector;
import org.apache.tools.ant.types.selectors.PresentSelector;
import org.apache.tools.ant.types.selectors.ReadableSelector;
import org.apache.tools.ant.types.selectors.SelectSelector;
@@ -824,7 +826,7 @@ public abstract class AbstractFileSet extends DataType
/**
* Add the modified selector.
* @param selector the <code>ModifiedSelector</code> to add.
- * @since ant 1.6
+ * @since Ant 1.6
*/
@Override
public void addModified(ModifiedSelector selector) {
@@ -864,6 +866,22 @@ public abstract class AbstractFileSet extends DataType
}
/**
+ * @param o PosixGroupSelector
+ * @since 1.10.4
+ */
+ public void addPosixGroup(PosixGroupSelector o) {
+ appendSelector(o);
+ }
+
+ /**
+ * @param o PosixPermissionsSelector
+ * @since 1.10.4
+ */
+ public void addPosixPermissions(PosixPermissionsSelector o) {
+ appendSelector(o);
+ }
+
+ /**
* Add an arbitrary selector.
* @param selector the <code>FileSelector</code> to add.
* @since Ant 1.6
http://git-wip-us.apache.org/repos/asf/ant/blob/748e9172/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java b/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
index 27fa157..f8f9b19 100644
--- a/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
+++ b/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
@@ -325,6 +325,22 @@ public abstract class AbstractSelectorContainer extends DataType
}
/**
+ * @param o PosixGroupSelector
+ * @since 1.10.4
+ */
+ public void addPosixGroup(PosixGroupSelector o) {
+ appendSelector(o);
+ }
+
+ /**
+ * @param o PosixPermissionsSelector
+ * @since 1.10.4
+ */
+ public void addPosixPermissions(PosixPermissionsSelector o) {
+ appendSelector(o);
+ }
+
+ /**
* add an arbitrary selector
* @param selector the selector to add
* @since Ant 1.6
http://git-wip-us.apache.org/repos/asf/ant/blob/748e9172/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java b/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
index fe90b38..7703ea6 100644
--- a/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
+++ b/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
@@ -321,6 +321,22 @@ public abstract class BaseSelectorContainer extends BaseSelector
}
/**
+ * @param o PosixGroupSelector
+ * @since 1.10.4
+ */
+ public void addPosixGroup(PosixGroupSelector o) {
+ appendSelector(o);
+ }
+
+ /**
+ * @param o PosixPermissionsSelector
+ * @since 1.10.4
+ */
+ public void addPosixPermissions(PosixPermissionsSelector o) {
+ appendSelector(o);
+ }
+
+ /**
* add an arbitrary selector
* @param selector the selector to add
* @since Ant 1.6
http://git-wip-us.apache.org/repos/asf/ant/blob/748e9172/src/main/org/apache/tools/ant/types/selectors/PosixGroupSelector.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/PosixGroupSelector.java b/src/main/org/apache/tools/ant/types/selectors/PosixGroupSelector.java
new file mode 100644
index 0000000..9c74985
--- /dev/null
+++ b/src/main/org/apache/tools/ant/types/selectors/PosixGroupSelector.java
@@ -0,0 +1,66 @@
+/*
+ * 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.selectors;
+
+import org.apache.tools.ant.BuildException;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.attribute.GroupPrincipal;
+import java.nio.file.attribute.PosixFileAttributes;
+
+/**
+ * A selector that selects files based on their POSIX group.
+ *
+ * <p>Group is defined in terms of {@link java.nio.file.Files#readAttributes}
+ * group attribute as provided by {@link java.nio.file.attribute.PosixFileAttributes},
+ * this means the selector will accept any file that exists and has the given
+ * group attribute.</p>
+ *
+ * @since Ant 1.10.4
+ */
+public class PosixGroupSelector implements FileSelector {
+
+ private String group;
+
+ /**
+ * Sets the group name to look for.
+ * @param group the group name
+ */
+ public void setGroup(String group) {
+ this.group = group;
+ }
+
+ @Override
+ public boolean isSelected(File basedir, String filename, File file) {
+ if (group == null) {
+ throw new BuildException("the group attribute is required");
+ }
+ try {
+ GroupPrincipal actualGroup = Files.readAttributes(file.toPath(),
+ PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS).group();
+ return actualGroup != null && actualGroup.getName().equals(group);
+ } catch (IOException e) {
+ // => not the expected group
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/748e9172/src/main/org/apache/tools/ant/types/selectors/PosixPermissionsSelector.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/PosixPermissionsSelector.java b/src/main/org/apache/tools/ant/types/selectors/PosixPermissionsSelector.java
new file mode 100644
index 0000000..8cd60ab
--- /dev/null
+++ b/src/main/org/apache/tools/ant/types/selectors/PosixPermissionsSelector.java
@@ -0,0 +1,76 @@
+/*
+ * 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.selectors;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.util.PermissionUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.attribute.PosixFilePermissions;
+
+/**
+ * A selector that selects files based on their POSIX permissions.
+ *
+ * <p>Permissions are defined in terms of {@link
+ * java.nio.file.Files#getPosixFilePermissions}, this means the selector will accept
+ * any file that exists and has given POSIX permissions.</p>
+ *
+ * @since Ant 1.10.4
+ */
+public class PosixPermissionsSelector implements FileSelector {
+
+ private String permissions;
+
+ /**
+ * Sets the permissions to look for.
+ * @param permissions the permissions string (rwxrwxrwx or octal)
+ */
+ public void setPermissions(String permissions) {
+ if (permissions.length() == 3 && permissions.matches("^[0-7]+$")) {
+ this.permissions = PosixFilePermissions.toString(
+ PermissionUtils.permissionsFromMode(Integer.parseInt(permissions, 8)));
+ return;
+ }
+
+ try {
+ this.permissions = PosixFilePermissions.toString(PosixFilePermissions.fromString(permissions));
+ } catch (IllegalArgumentException ex) {
+ throw new BuildException("the permissions attribute " + permissions
+ + " is invalid", ex);
+ }
+ }
+
+ @Override
+ public boolean isSelected(File basedir, String filename, File file) {
+ if (permissions == null) {
+ throw new BuildException("the permissions attribute is required");
+ }
+ try {
+ return PosixFilePermissions.toString(
+ Files.getPosixFilePermissions(file.toPath(), LinkOption.NOFOLLOW_LINKS))
+ .equals(permissions);
+ } catch (IOException e) {
+ // => not the expected permissions
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/748e9172/src/tests/junit/org/apache/tools/ant/types/selectors/PosixGroupSelectorTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/PosixGroupSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/PosixGroupSelectorTest.java
new file mode 100644
index 0000000..8d4e28f
--- /dev/null
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/PosixGroupSelectorTest.java
@@ -0,0 +1,64 @@
+package org.apache.tools.ant.types.selectors;
+
+import org.apache.tools.ant.taskdefs.condition.Os;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.attribute.GroupPrincipal;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeNoException;
+import static org.junit.Assume.assumeTrue;
+
+public class PosixGroupSelectorTest {
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+
+ private final String GROUP_GETTER = "getGid";
+
+ private Class<?> jaasProviderClass;
+
+ private PosixGroupSelector s;
+
+ @Before
+ public void setUp() {
+ assumeTrue(Os.isFamily("unix"));
+ String osName = System.getProperty("os.name", "unknown").toLowerCase();
+ String jaasProviderClassName = osName.contains("sunos")
+ ? "com.sun.security.auth.module.SolarisSystem"
+ : "com.sun.security.auth.module.UnixSystem";
+
+ try {
+ jaasProviderClass = Class.forName(jaasProviderClassName);
+ } catch (Throwable e) {
+ assumeNoException("Cannot obtain OS-specific JAAS information", e);
+ }
+
+ s = new PosixGroupSelector();
+ }
+
+ @Test
+ public void PosixGroupIsTrueForSelf() throws Exception {
+ long gid = (long) jaasProviderClass.getMethod(GROUP_GETTER)
+ .invoke(jaasProviderClass.newInstance());
+
+ File file = folder.newFile("f.txt");
+ Map<String, Object> fileAttributes = Files.readAttributes(file.toPath(),
+ "unix:group,gid", LinkOption.NOFOLLOW_LINKS);
+ long actualGid = (int) fileAttributes.get("gid");
+ assertEquals("Different GIDs", gid, actualGid);
+
+ GroupPrincipal actualGroup = (GroupPrincipal) fileAttributes.get("group");
+ s.setGroup(actualGroup.getName());
+ assertTrue(s.isSelected(null, null, file));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/748e9172/src/tests/junit/org/apache/tools/ant/types/selectors/PosixPermissionsSelectorTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/PosixPermissionsSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/PosixPermissionsSelectorTest.java
new file mode 100644
index 0000000..c72b61ae
--- /dev/null
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/PosixPermissionsSelectorTest.java
@@ -0,0 +1,78 @@
+package org.apache.tools.ant.types.selectors;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.condition.Os;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+@RunWith(Enclosed.class)
+public class PosixPermissionsSelectorTest {
+
+ @RunWith(Parameterized.class)
+ public static class IllegalArgumentTest {
+
+ private PosixPermissionsSelector s;
+
+ // requires JUnit 4.12
+ @Parameterized.Parameters(name = "illegal argument: |{0}|")
+ public static Collection<String> data() {
+ return Arrays.asList("855", "4555", "-rwxr-xr-x", "xrwr-xr-x");
+ }
+
+ @Parameterized.Parameter
+ public String argument;
+
+ @Before
+ public void setUp() {
+ assumeTrue("no POSIX", Os.isFamily("unix"));
+ s = new PosixPermissionsSelector();
+ }
+
+ @Test(expected = BuildException.class)
+ public void test() {
+ s.setPermissions(argument);
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class LegalArgumentTest {
+
+ private PosixPermissionsSelector s;
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+
+ // requires JUnit 4.12
+ @Parameterized.Parameters(name = "legal argument: |{0}|")
+ public static Collection<String> data() {
+ return Arrays.asList("755", "rwxr-xr-x");
+ }
+
+ @Parameterized.Parameter
+ public String argument;
+
+ @Before
+ public void setUp() {
+ assumeTrue("No POSIX", Os.isFamily("unix"));
+ s = new PosixPermissionsSelector();
+ }
+
+ @Test
+ public void PosixPermissionsIsTrueForSelf() throws Exception {
+ s.setPermissions(argument);
+ assertTrue(s.isSelected(null, null, folder.newFolder()));
+ }
+ }
+
+}
[3/3] ant git commit: Tidy up the code
Posted by gi...@apache.org.
Tidy up the code
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/e6b20300
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/e6b20300
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/e6b20300
Branch: refs/heads/master
Commit: e6b2030060df21679cae372a8948a5aa4a42d155
Parents: 748e917
Author: Gintas Grigelionis <gi...@apache.org>
Authored: Sun May 20 17:00:02 2018 +0200
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Sun May 20 17:00:02 2018 +0200
----------------------------------------------------------------------
src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java | 1 -
src/main/org/apache/tools/ant/taskdefs/Replace.java | 2 +-
.../apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java | 2 +-
3 files changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/e6b20300/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java b/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java
index fc861e1..00b595b 100644
--- a/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java
+++ b/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java
@@ -18,7 +18,6 @@
package org.apache.tools.ant.attribute;
-import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
http://git-wip-us.apache.org/repos/asf/ant/blob/e6b20300/src/main/org/apache/tools/ant/taskdefs/Replace.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Replace.java b/src/main/org/apache/tools/ant/taskdefs/Replace.java
index b32b4b8..0129fbf 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Replace.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Replace.java
@@ -936,7 +936,7 @@ public class Replace extends MatchingTask {
*/
private Iterator<String> getOrderedIterator(Properties props) {
List<String> keys = new ArrayList<>(props.stringPropertyNames());
- keys.sort(Comparator.<String>comparingInt(String::length).reversed());
+ keys.sort(Comparator.comparingInt(String::length).reversed());
return keys.iterator();
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/e6b20300/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
index e82af1d..83d3f0a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
@@ -150,7 +150,7 @@ public class FailureRecorder extends ProjectComponent implements JUnitResultForm
super.setProject(project);
// check if already registered
// register if needed
- if (!project.getBuildListeners().stream().anyMatch(FailureRecorder.class::isInstance)) {
+ if (project.getBuildListeners().stream().noneMatch(FailureRecorder.class::isInstance)) {
verbose("Register FailureRecorder (@" + this.hashCode() + ") as BuildListener");
project.addBuildListener(this);
}