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 2022/02/09 19:07:05 UTC

[ant] branch master updated (a66dafa -> 90ed3ff)

This is an automated email from the ASF dual-hosted git repository.

mbenson pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git.


    from a66dafa  add java.security.manager=allow while launching against Java 19
     new 6fdb34e  fully migrate pathconvert tests to antunit
     new 43deb9e  test pathconvert features
     new 847dcd9  Resources javadoc
     new a877993  volatile cache property
     new ccde924  use Collections#emptyIterator
     new af035b0  iterate resources directly when !cache
     new 90ed3ff  pathconvert to outputstream so that logging requires no in-memory String accumulation

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/etc/testcases/taskdefs/pathconvert.xml         |  60 --------
 .../org/apache/tools/ant/taskdefs/PathConvert.java | 126 ++++++++--------
 .../tools/ant/types/resources/Resources.java       | 165 ++++++++++-----------
 src/tests/antunit/taskdefs/pathconvert-test.xml    |  71 +++++++++
 .../apache/tools/ant/taskdefs/PathConvertTest.java |  74 ---------
 5 files changed, 206 insertions(+), 290 deletions(-)
 delete mode 100644 src/etc/testcases/taskdefs/pathconvert.xml
 delete mode 100644 src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java

[ant] 02/07: test pathconvert features

Posted by mb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mbenson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git

commit 43deb9e8c825d91c85b90ea13a66150fd9cc0480
Author: Matt Benson <mb...@apache.org>
AuthorDate: Wed Feb 9 10:09:16 2022 -0600

    test pathconvert features
---
 src/tests/antunit/taskdefs/pathconvert-test.xml | 26 +++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/tests/antunit/taskdefs/pathconvert-test.xml b/src/tests/antunit/taskdefs/pathconvert-test.xml
index 7277a05..11bbcb6 100644
--- a/src/tests/antunit/taskdefs/pathconvert-test.xml
+++ b/src/tests/antunit/taskdefs/pathconvert-test.xml
@@ -73,4 +73,30 @@
       <au:assertPropertyEquals name="pc" value="file2.txt" />
   </target>
 
+  <target name="testRef">
+      <pathconvert property="result" refid="testpath" />
+      <au:assertPropertyEquals name="result" value="${ant.file}" />
+  </target>
+
+  <target name="testConsole">
+      <pathconvert refid="testpath" />
+      <au:assertLogContains text="${ant.file}" />
+  </target>
+
+  <target name="testPreserveDuplicates">
+      <pathconvert property="result" pathsep=") " preserveduplicates="true">
+          <resources>
+              <path refid="testpath" />
+              <path refid="testpath" />
+          </resources>
+      </pathconvert>
+      <au:assertPropertyEquals name="result" value="${ant.file}) ${ant.file}" />
+  </target>
+
+  <target name="testDirsep">
+      <pathconvert property="result" dirsep="|">
+          <file file="/foo/bar/baz" />
+      </pathconvert>
+      <au:assertPropertyEquals name="result" value="|foo|bar|baz" />
+  </target>
 </project>

[ant] 07/07: pathconvert to outputstream so that logging requires no in-memory String accumulation

Posted by mb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mbenson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git

commit 90ed3ff6cca8634e38d7c3c82858ce48c9c4be2b
Author: Matt Benson <mb...@apache.org>
AuthorDate: Wed Feb 9 13:00:49 2022 -0600

    pathconvert to outputstream so that logging requires no in-memory String accumulation
---
 .../org/apache/tools/ant/taskdefs/PathConvert.java | 126 ++++++++++-----------
 1 file changed, 60 insertions(+), 66 deletions(-)

diff --git a/src/main/org/apache/tools/ant/taskdefs/PathConvert.java b/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
index fa68c3f..be46bbd 100644
--- a/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
+++ b/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
@@ -18,10 +18,16 @@
 package org.apache.tools.ant.taskdefs;
 
 import java.io.File;
-import java.util.ArrayList;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
 import java.util.List;
-import java.util.StringTokenizer;
+import java.util.Objects;
 import java.util.Vector;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
@@ -31,12 +37,12 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
 import org.apache.tools.ant.types.Mapper;
 import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.types.Reference;
-import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.ResourceCollection;
 import org.apache.tools.ant.types.resources.Resources;
 import org.apache.tools.ant.types.resources.Union;
 import org.apache.tools.ant.util.FileNameMapper;
 import org.apache.tools.ant.util.IdentityMapper;
+import org.apache.tools.ant.util.PropertyOutputStream;
 
 /**
  * Converts path and classpath information to a specific target OS
@@ -195,7 +201,7 @@ public class PathConvert extends Task {
     private synchronized Resources getPath() {
         if (path == null) {
             path = new Resources(getProject());
-            path.setCache(true);
+            path.setCache(false);
         }
         return path;
     }
@@ -344,56 +350,18 @@ public class PathConvert extends Task {
             }
             validateSetup(); // validate our setup
 
-            // Currently, we deal with only two path formats: Unix and Windows
-            // And Unix is everything that is not Windows
-            // (with the exception for NetWare and OS/2 below)
-
-            // for NetWare and OS/2, piggy-back on Windows, since here and
-            // in the apply code, the same assumptions can be made as with
-            // windows - that \\ is an OK separator, and do comparisons
-            // case-insensitive.
-            String fromDirSep = onWindows ? "\\" : "/";
-
-            StringBuilder rslt = new StringBuilder();
-
-            ResourceCollection resources = isPreserveDuplicates() ? path : new Union(path);
-            List<String> ret = new ArrayList<>();
-            FileNameMapper mapperImpl = mapper == null ? new IdentityMapper() : mapper.getImplementation();
-            for (Resource r : resources) {
-                String[] mapped = mapperImpl.mapFileName(String.valueOf(r));
-                for (int m = 0; mapped != null && m < mapped.length; ++m) {
-                    ret.add(mapped[m]);
-                }
-            }
             boolean first = true;
-            for (String string : ret) {
-                String elem = mapElement(string); // Apply the path prefix map
-
-                // Now convert the path and file separator characters from the
-                // current os to the target os.
-
-                if (!first) {
-                    rslt.append(pathSep);
-                }
-                first = false;
-
-                StringTokenizer stDirectory = new StringTokenizer(elem, fromDirSep, true);
-
-                while (stDirectory.hasMoreTokens()) {
-                    String token = stDirectory.nextToken();
-                    rslt.append(fromDirSep.equals(token) ? dirSep : token);
-                }
-            }
-            // Place the result into the specified property,
-            // unless setonempty == false
-            if (setonempty || rslt.length() > 0) {
-                String value = rslt.toString();
-                if (property == null) {
-                    log(value);
-                } else {
-                    log("Set property " + property + " = " + value, Project.MSG_VERBOSE);
-                    getProject().setNewProperty(property, value);
+            try (Writer w = new OutputStreamWriter(createOutputStream())) {
+                for (String s : (Iterable<String>) streamResources()::iterator) {
+                    if (first) {
+                        first = false;
+                    } else {
+                        w.write(pathSep);
+                    }
+                    w.write(s);
                 }
+            } catch (IOException e) {
+                throw new BuildException(e);
             }
         } finally {
             path = savedPath;
@@ -402,6 +370,44 @@ public class PathConvert extends Task {
         }
     }
 
+    private OutputStream createOutputStream() {
+        if (property == null) {
+            return new LogOutputStream(this);
+        }
+        return new PropertyOutputStream(getProject(), property) {
+            @Override
+            public void close() {
+                if (setonempty || size() > 0) {
+                    super.close();
+                    log("Set property " + property + " = " + getProject().getProperty(property), Project.MSG_VERBOSE);
+                }
+            }
+        };
+    }
+
+    private Stream<String> streamResources() {
+        ResourceCollection resources = isPreserveDuplicates() ? path : Union.getInstance(path);
+        FileNameMapper mapperImpl = mapper == null ? new IdentityMapper() : mapper.getImplementation();
+
+        final boolean parallel = false;
+        Stream<String> result = StreamSupport.stream(resources.spliterator(), parallel).map(String::valueOf)
+            .map(mapperImpl::mapFileName).filter(Objects::nonNull).flatMap(Stream::of).map(this::mapElement);
+
+        // Currently, we deal with only two path formats: Unix and Windows
+        // And Unix is everything that is not Windows
+        // (with the exception for NetWare and OS/2 below)
+
+        // for NetWare and OS/2, piggy-back on Windows, since here and
+        // in the apply code, the same assumptions can be made as with
+        // windows - that \\ is an OK separator, and do comparisons
+        // case-insensitive.
+        final String fromDirSep = onWindows ? "\\" : "/";
+        if (fromDirSep.equals(dirSep)) {
+            return result;
+        }
+        return result.map(s -> s.replace(fromDirSep, dirSep));
+    }
+
     /**
      * Apply the configured map to a path element. The map is used to convert
      * between Windows drive letters and Unix paths. If no map is configured,
@@ -411,20 +417,8 @@ public class PathConvert extends Task {
      * @return String Updated element.
      */
     private String mapElement(String elem) {
-        // Iterate over the map entries and apply each one.
-        // Stop when one of the entries actually changes the element.
-
-        for (MapEntry entry : prefixMap) {
-            String newElem = entry.apply(elem);
-
-            // Note I'm using "!=" to see if we got a new object back from
-            // the apply method.
-
-            if (newElem != elem) {
-                return newElem;
-            }
-        }
-        return elem;
+        final Predicate<Object> changed = o -> o != elem;
+        return prefixMap.stream().map(e -> e.apply(elem)).filter(changed).findFirst().orElse(elem);
     }
 
     /**

[ant] 03/07: Resources javadoc

Posted by mb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mbenson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git

commit 847dcd9dbe0a25a8d4cc2d0705a6047132af18d0
Author: Matt Benson <mb...@apache.org>
AuthorDate: Wed Feb 9 11:46:13 2022 -0600

    Resources javadoc
---
 .../tools/ant/types/resources/Resources.java       | 42 +++++++++++-----------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/main/org/apache/tools/ant/types/resources/Resources.java b/src/main/org/apache/tools/ant/types/resources/Resources.java
index a832f63..4e497e2 100644
--- a/src/main/org/apache/tools/ant/types/resources/Resources.java
+++ b/src/main/org/apache/tools/ant/types/resources/Resources.java
@@ -36,12 +36,12 @@ import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.ResourceCollection;
 
 /**
- * Generic ResourceCollection: Either stores nested ResourceCollections,
- * making no attempt to remove duplicates, or references another ResourceCollection.
+ * Generic {@link ResourceCollection}: Either stores nested {@link ResourceCollection}s,
+ * making no attempt to remove duplicates, or references another {@link ResourceCollection}.
  * @since Ant 1.7
  */
 public class Resources extends DataType implements AppendableResourceCollection {
-    /** static empty ResourceCollection */
+    /** {@code static} empty {@link ResourceCollection} */
     public static final ResourceCollection NONE = new ResourceCollection() {
         @Override
         public boolean isFilesystemOnly() {
@@ -57,7 +57,7 @@ public class Resources extends DataType implements AppendableResourceCollection
         }
     };
 
-    /** static empty Iterator */
+    /** {@code static} empty {@link Iterator} */
     public static final Iterator<Resource> EMPTY_ITERATOR = new Iterator<Resource>() {
         @Override
         public Resource next() {
@@ -129,14 +129,14 @@ public class Resources extends DataType implements AppendableResourceCollection
     private boolean cache = false;
 
     /**
-     * Create a new Resources.
+     * Create a new {@link Resources}.
      */
     public Resources() {
     }
 
     /**
-     * Create a new Resources.
-     * @param project Project
+     * Create a new {@link Resources}.
+     * @param project {@link Project}
      * @since Ant 1.8
      */
     public Resources(Project project) {
@@ -145,7 +145,7 @@ public class Resources extends DataType implements AppendableResourceCollection
 
     /**
      * Set whether to cache collections.
-     * @param b boolean cache flag.
+     * @param b {@code boolean} cache flag.
      * @since Ant 1.8.0
      */
     public synchronized void setCache(boolean b) {
@@ -153,8 +153,8 @@ public class Resources extends DataType implements AppendableResourceCollection
     }
 
     /**
-     * Add a ResourceCollection.
-     * @param c the ResourceCollection to add.
+     * Add a {@link ResourceCollection}.
+     * @param c the {@link ResourceCollection} to add.
      */
     @Override
     public synchronized void add(ResourceCollection c) {
@@ -174,8 +174,8 @@ public class Resources extends DataType implements AppendableResourceCollection
     }
 
     /**
-     * Fulfill the ResourceCollection contract.
-     * @return an Iterator of Resources.
+     * Fulfill the {@link ResourceCollection} contract.
+     * @return an {@link Iterator} of {@link Resources}.
      */
     @Override
     public synchronized Iterator<Resource> iterator() {
@@ -187,8 +187,8 @@ public class Resources extends DataType implements AppendableResourceCollection
     }
 
     /**
-     * Fulfill the ResourceCollection contract.
-     * @return number of elements as int.
+     * Fulfill the {@link ResourceCollection} contract.
+     * @return number of elements as {@code int}.
      */
     @Override
     public synchronized int size() {
@@ -200,8 +200,8 @@ public class Resources extends DataType implements AppendableResourceCollection
     }
 
     /**
-     * Fulfill the ResourceCollection contract.
-     * @return true if all Resources represent files.
+     * Fulfill the {@link ResourceCollection} contract.
+     * @return {@code true} if all {@link Resource}s represent files.
      */
     @Override
     public boolean isFilesystemOnly() {
@@ -214,7 +214,7 @@ public class Resources extends DataType implements AppendableResourceCollection
     }
 
     /**
-     * Format this <code>Resources</code> as a String.
+     * Format this <code>Resources</code> as a {@link String}.
      * @return a descriptive <code>String</code>.
      */
     @Override
@@ -231,10 +231,10 @@ public class Resources extends DataType implements AppendableResourceCollection
     }
 
     /**
-     * Overrides the version of DataType to recurse on all DataType
+     * Overrides the base implementation to recurse on all {@link DataType}
      * child elements that may have been added.
      * @param stk the stack of data types to use (recursively).
-     * @param p   the project to use to dereference the references.
+     * @param p   the {@link Project} to use to dereference the references.
      * @throws BuildException on error.
      */
     @Override
@@ -263,8 +263,8 @@ public class Resources extends DataType implements AppendableResourceCollection
     }
 
     /**
-     * Resolves references, allowing any ResourceCollection.
-     * @return the referenced ResourceCollection.
+     * Resolves references, allowing any {@link ResourceCollection}.
+     * @return the referenced {@link ResourceCollection}.
      */
     private ResourceCollection getRef() {
         return getCheckedRef(ResourceCollection.class);

[ant] 04/07: volatile cache property

Posted by mb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mbenson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git

commit a8779939ce44401f7069ef650412b654919feec2
Author: Matt Benson <mb...@apache.org>
AuthorDate: Wed Feb 9 11:49:38 2022 -0600

    volatile cache property
---
 src/main/org/apache/tools/ant/types/resources/Resources.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/org/apache/tools/ant/types/resources/Resources.java b/src/main/org/apache/tools/ant/types/resources/Resources.java
index 4e497e2..15ea73d 100644
--- a/src/main/org/apache/tools/ant/types/resources/Resources.java
+++ b/src/main/org/apache/tools/ant/types/resources/Resources.java
@@ -126,7 +126,7 @@ public class Resources extends DataType implements AppendableResourceCollection
 
     private List<ResourceCollection> rc;
     private Collection<Resource> coll;
-    private boolean cache = false;
+    private volatile boolean cache = false;
 
     /**
      * Create a new {@link Resources}.
@@ -148,7 +148,7 @@ public class Resources extends DataType implements AppendableResourceCollection
      * @param b {@code boolean} cache flag.
      * @since Ant 1.8.0
      */
-    public synchronized void setCache(boolean b) {
+    public void setCache(boolean b) {
         cache = b;
     }
 

[ant] 06/07: iterate resources directly when !cache

Posted by mb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mbenson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git

commit af035b0fc772cff76cd3c5879012cf8c91f7ae4e
Author: Matt Benson <mb...@apache.org>
AuthorDate: Wed Feb 9 12:59:34 2022 -0600

    iterate resources directly when !cache
---
 .../tools/ant/types/resources/Resources.java       | 104 ++++++++++-----------
 1 file changed, 51 insertions(+), 53 deletions(-)

diff --git a/src/main/org/apache/tools/ant/types/resources/Resources.java b/src/main/org/apache/tools/ant/types/resources/Resources.java
index cf6bc03..b00f061 100644
--- a/src/main/org/apache/tools/ant/types/resources/Resources.java
+++ b/src/main/org/apache/tools/ant/types/resources/Resources.java
@@ -26,8 +26,13 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.NoSuchElementException;
+import java.util.Optional;
+import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.Stack;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
@@ -61,10 +66,8 @@ public class Resources extends DataType implements AppendableResourceCollection
     public static final Iterator<Resource> EMPTY_ITERATOR = Collections.emptyIterator();
 
     private class MyCollection extends AbstractCollection<Resource> {
-        private Collection<Resource> cached;
+        private volatile Collection<Resource> cached;
 
-        MyCollection() {
-        }
         @Override
         public int size() {
             return getCache().size();
@@ -74,45 +77,41 @@ public class Resources extends DataType implements AppendableResourceCollection
             return getCache().iterator();
         }
         private synchronized Collection<Resource> getCache() {
-            Collection<Resource> coll = cached;
-            if (coll == null) {
-                coll = new ArrayList<>();
-                new MyIterator().forEachRemaining(coll::add);
-                if (cache) {
-                    cached = coll;
-                }
+            if (cached == null) {
+                cached = internalResources().collect(Collectors.toList());
             }
-            return coll;
+            return cached;
         }
-        private class MyIterator implements Iterator<Resource> {
-            private Iterator<ResourceCollection> rci = getNested().iterator();
-            private Iterator<Resource> ri = null;
+    }
 
-            @Override
-            public boolean hasNext() {
-                boolean result = ri != null && ri.hasNext();
-                while (!result && rci.hasNext()) {
-                    ri = rci.next().iterator();
-                    result = ri.hasNext();
-                }
-                return result;
-            }
-            @Override
-            public Resource next() {
-                if (!hasNext()) {
-                    throw new NoSuchElementException();
-                }
-                return ri.next();
+    private class MyIterator implements Iterator<Resource> {
+        private Iterator<ResourceCollection> rci = getNested().iterator();
+        private Iterator<Resource> ri;
+
+        @Override
+        public boolean hasNext() {
+            boolean result = ri != null && ri.hasNext();
+            while (!result && rci.hasNext()) {
+                ri = rci.next().iterator();
+                result = ri.hasNext();
             }
-            @Override
-            public void remove() {
-                throw new UnsupportedOperationException();
+            return result;
+        }
+        @Override
+        public Resource next() {
+            if (!hasNext()) {
+                throw new NoSuchElementException();
             }
+            return ri.next();
+        }
+        @Override
+        public void remove() {
+            throw new UnsupportedOperationException();
         }
     }
 
     private List<ResourceCollection> rc;
-    private Collection<Resource> coll;
+    private Optional<Collection<Resource>> cacheColl = Optional.empty();
     private volatile boolean cache = false;
 
     /**
@@ -156,7 +155,7 @@ public class Resources extends DataType implements AppendableResourceCollection
         }
         rc.add(c);
         invalidateExistingIterators();
-        coll = null;
+        cacheColl = Optional.empty();
         setChecked(false);
     }
 
@@ -170,7 +169,7 @@ public class Resources extends DataType implements AppendableResourceCollection
             return getRef().iterator();
         }
         validate();
-        return new FailFast(this, coll.iterator());
+        return new FailFast(this, cacheColl.map(Iterable::iterator).orElseGet(MyIterator::new));
     }
 
     /**
@@ -183,7 +182,7 @@ public class Resources extends DataType implements AppendableResourceCollection
             return getRef().size();
         }
         validate();
-        return coll.size();
+        return cacheColl.isPresent() ? cacheColl.get().size() : (int) internalResources().count();
     }
 
     /**
@@ -196,8 +195,7 @@ public class Resources extends DataType implements AppendableResourceCollection
             return getRef().isFilesystemOnly();
         }
         validate();
-        return getNested().stream()
-            .allMatch(ResourceCollection::isFilesystemOnly);
+        return getNested().stream().allMatch(ResourceCollection::isFilesystemOnly);
     }
 
     /**
@@ -210,11 +208,8 @@ public class Resources extends DataType implements AppendableResourceCollection
             return getRef().toString();
         }
         validate();
-        if (coll == null || coll.isEmpty()) {
-            return "";
-        }
-        return coll.stream().map(Object::toString)
-            .collect(Collectors.joining(File.pathSeparator));
+        final Stream<?> stream = cache ? cacheColl.get().stream() : getNested().stream();
+        return stream.map(String::valueOf).collect(Collectors.joining(File.pathSeparator));
     }
 
     /**
@@ -227,17 +222,13 @@ public class Resources extends DataType implements AppendableResourceCollection
     @Override
     protected void dieOnCircularReference(Stack<Object> stk, Project p)
         throws BuildException {
-        if (isChecked()) {
-            return;
-        }
         if (isReference()) {
             super.dieOnCircularReference(stk, p);
-        } else {
-            for (ResourceCollection resourceCollection : getNested()) {
-                if (resourceCollection instanceof DataType) {
-                    pushAndInvokeCircularReferenceCheck((DataType) resourceCollection, stk, p);
-                }
-            }
+            return;
+        }
+        if (!isChecked()) {
+            getNested().stream().filter(DataType.class::isInstance).map(DataType.class::cast)
+                .forEach(dt -> pushAndInvokeCircularReferenceCheck(dt, stk, p));
             setChecked(true);
         }
     }
@@ -259,10 +250,17 @@ public class Resources extends DataType implements AppendableResourceCollection
 
     private synchronized void validate() {
         dieOnCircularReference();
-        coll = (coll == null) ? new MyCollection() : coll;
+        if (cache && !cacheColl.isPresent()) {
+            cacheColl = Optional.of(new MyCollection());
+        }
     }
 
     private synchronized List<ResourceCollection> getNested() {
         return rc == null ? Collections.emptyList() : rc;
     }
+
+    private synchronized Stream<Resource> internalResources() {
+        return StreamSupport.stream(
+            Spliterators.spliteratorUnknownSize(new MyIterator(), Spliterator.NONNULL), false);
+    }
 }

[ant] 01/07: fully migrate pathconvert tests to antunit

Posted by mb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mbenson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git

commit 6fdb34e7351e5fb3090717600e682b82e2553835
Author: Matt Benson <mb...@apache.org>
AuthorDate: Tue Feb 8 18:28:05 2022 -0600

    fully migrate pathconvert tests to antunit
---
 src/etc/testcases/taskdefs/pathconvert.xml         | 60 ------------------
 src/tests/antunit/taskdefs/pathconvert-test.xml    | 45 +++++++++++++
 .../apache/tools/ant/taskdefs/PathConvertTest.java | 74 ----------------------
 3 files changed, 45 insertions(+), 134 deletions(-)

diff --git a/src/etc/testcases/taskdefs/pathconvert.xml b/src/etc/testcases/taskdefs/pathconvert.xml
deleted file mode 100644
index 3ca3102..0000000
--- a/src/etc/testcases/taskdefs/pathconvert.xml
+++ /dev/null
@@ -1,60 +0,0 @@
-<?xml version="1.0"?>
-<!--
-  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
-
-      https://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.
--->
-<project name="pathconvert">
-
-    <import file="../buildfiletest-base.xml"/>
-
-    <path id="testpath">
-        <pathelement path="${ant.file}" />
-    </path>
-
-    <target name="testmap">
-        <pathconvert property="result" dirsep="#">
-            <path refid="testpath" />
-            <map from="${basedir}" to="test" />
-        </pathconvert>
-    </target>
-
-    <target name="testmapper">
-        <pathconvert property="result" dirsep="#">
-            <path refid="testpath" />
-            <mapper type="glob" from="${basedir}*" to="test*" />
-        </pathconvert>
-    </target>
-
-    <target name="testnotargetos">
-        <pathconvert property="result" refid="testpath" />
-    </target>
-
-    <target name="test-nonmatching-mapper" description="test for bug fix bz-62076">
-        <mkdir dir="${output}/mapper-source-dir"/>
-        <!-- create 2 files, one of which will be matched/included by the globmapper
-        later in this target -->
-        <touch file="${output}/mapper-source-dir/file1.txt"/>
-        <touch file="${output}/mapper-source-dir/file2.log"/>
-
-        <pathconvert property="pc">
-            <mappedresources>
-                <fileset dir="${output}/mapper-source-dir"/>
-                <!-- we intentionally exclude one of the files -->
-                <globmapper from="*.log" to="*.txt"/>
-            </mappedresources>
-        </pathconvert>
-    </target>
-
-</project>
diff --git a/src/tests/antunit/taskdefs/pathconvert-test.xml b/src/tests/antunit/taskdefs/pathconvert-test.xml
index 936e257..7277a05 100644
--- a/src/tests/antunit/taskdefs/pathconvert-test.xml
+++ b/src/tests/antunit/taskdefs/pathconvert-test.xml
@@ -28,4 +28,49 @@
     </au:assertTrue>
   </target>
 
+  <path id="testpath">
+      <pathelement path="${ant.file}" />
+  </path>
+
+  <basename property="basename" file="${ant.file}" />
+
+  <target name="testmap">
+      <pathconvert property="result" dirsep="#">
+          <path refid="testpath" />
+          <map from="${basedir}" to="test" />
+      </pathconvert>
+      <au:assertPropertyEquals name="result" value="test#${basename}" />
+  </target>
+
+  <target name="testmapper">
+      <pathconvert property="result" dirsep="#">
+          <path refid="testpath" />
+          <mapper type="glob" from="${basedir}*" to="test*" />
+      </pathconvert>
+      <au:assertPropertyEquals name="result" value="test#${basename}" />
+  </target>
+
+  <target name="testnotargetos">
+      <pathconvert property="result" refid="testpath" />
+      <au:assertPropertyEquals name="result" value="${ant.file}" />
+  </target>
+
+  <target name="test-nonmatching-mapper" description="test for bug fix bz-62076">
+      <mkdir dir="${output}/mapper-source-dir"/>
+      <!-- create 2 files, one of which will be matched/included by the globmapper
+      later in this target -->
+      <touch file="${output}/mapper-source-dir/file1.txt"/>
+      <touch file="${output}/mapper-source-dir/file2.log"/>
+
+      <pathconvert property="pc">
+          <mappedresources>
+              <fileset dir="${output}/mapper-source-dir"/>
+              <!-- we intentionally exclude one of the files -->
+              <globmapper from="*.log" to="*.txt"/>
+          </mappedresources>
+      </pathconvert>
+
+      <au:assertPropertyEquals name="pc" value="file2.txt" />
+  </target>
+
 </project>
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java
deleted file mode 100644
index cf9bb5d..0000000
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- *  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
- *
- *      https://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.taskdefs;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * Unit test for the &lt;pathconvert&gt; task.
- */
-public class PathConvertTest {
-
-    @Rule
-    public final BuildFileRule buildRule = new BuildFileRule();
-
-    private static final String BUILD_FILENAME = "pathconvert.xml";
-
-    @Before
-    public void setUp() {
-        buildRule.configureProject("src/etc/testcases/taskdefs/" + BUILD_FILENAME);
-    }
-
-    @Test
-    public void testMap() {
-        test("testmap");
-    }
-
-    @Test
-    public void testMapper() {
-        test("testmapper");
-    }
-
-    @Test
-    public void testNoTargetOs() {
-        buildRule.executeTarget("testnotargetos");
-    }
-
-    /**
-     * Tests that if a {@code mappedresource}, that excludes certain resources, is used in a {@code pathconvert},
-     * then it doesn't lead to a {@link NullPointerException}.
-     *
-     * @see <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=62076">bz-62076</a> for more details
-     */
-    @Test
-    public void testNonMatchingMapper() {
-        buildRule.executeTarget("test-nonmatching-mapper");
-    }
-
-    private void test(String target) {
-        buildRule.executeTarget(target);
-        assertEquals("test#" + BUILD_FILENAME, buildRule.getProject().getProperty("result"));
-    }
-
-}

[ant] 05/07: use Collections#emptyIterator

Posted by mb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mbenson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git

commit ccde92427d0ab35af64d618e2492d521af1c26e1
Author: Matt Benson <mb...@apache.org>
AuthorDate: Wed Feb 9 11:51:13 2022 -0600

    use Collections#emptyIterator
---
 .../org/apache/tools/ant/types/resources/Resources.java   | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/src/main/org/apache/tools/ant/types/resources/Resources.java b/src/main/org/apache/tools/ant/types/resources/Resources.java
index 15ea73d..cf6bc03 100644
--- a/src/main/org/apache/tools/ant/types/resources/Resources.java
+++ b/src/main/org/apache/tools/ant/types/resources/Resources.java
@@ -58,20 +58,7 @@ public class Resources extends DataType implements AppendableResourceCollection
     };
 
     /** {@code static} empty {@link Iterator} */
-    public static final Iterator<Resource> EMPTY_ITERATOR = new Iterator<Resource>() {
-        @Override
-        public Resource next() {
-            throw new NoSuchElementException();
-        }
-        @Override
-        public boolean hasNext() {
-            return false;
-        }
-        @Override
-        public void remove() {
-            throw new UnsupportedOperationException();
-        }
-    };
+    public static final Iterator<Resource> EMPTY_ITERATOR = Collections.emptyIterator();
 
     private class MyCollection extends AbstractCollection<Resource> {
         private Collection<Resource> cached;