You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2015/05/17 11:53:04 UTC

ant git commit: new resource collection "allbutfirst"

Repository: ant
Updated Branches:
  refs/heads/master 6a7a62835 -> 989ca3b78


new resource collection "allbutfirst"

first part of https://bz.apache.org/bugzilla/show_bug.cgi?id=57834 -
allbutlast to follow


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/989ca3b7
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/989ca3b7
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/989ca3b7

Branch: refs/heads/master
Commit: 989ca3b7879d23abc16ce6b48335c2e7b59a1ca8
Parents: 6a7a628
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun May 17 11:51:57 2015 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun May 17 11:51:57 2015 +0200

----------------------------------------------------------------------
 .../apache/tools/ant/types/defaults.properties  |  1 +
 .../tools/ant/types/resources/AllButFirst.java  | 60 +++++++++++++++++
 .../antunit/types/resources/first-last-test.xml | 69 +++++++++++++++++++-
 3 files changed, 129 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/989ca3b7/src/main/org/apache/tools/ant/types/defaults.properties
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/defaults.properties b/src/main/org/apache/tools/ant/types/defaults.properties
index 903f5f0..63c589d 100644
--- a/src/main/org/apache/tools/ant/types/defaults.properties
+++ b/src/main/org/apache/tools/ant/types/defaults.properties
@@ -71,6 +71,7 @@ difference=org.apache.tools.ant.types.resources.Difference
 intersect=org.apache.tools.ant.types.resources.Intersect
 sort=org.apache.tools.ant.types.resources.Sort
 resources=org.apache.tools.ant.types.resources.Resources
+allbutfirst=org.apache.tools.ant.types.resources.AllButFirst
 first=org.apache.tools.ant.types.resources.First
 last=org.apache.tools.ant.types.resources.Last
 tarfileset=org.apache.tools.ant.types.TarFileSet

http://git-wip-us.apache.org/repos/asf/ant/blob/989ca3b7/src/main/org/apache/tools/ant/types/resources/AllButFirst.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/AllButFirst.java b/src/main/org/apache/tools/ant/types/resources/AllButFirst.java
new file mode 100644
index 0000000..d9ea506
--- /dev/null
+++ b/src/main/org/apache/tools/ant/types/resources/AllButFirst.java
@@ -0,0 +1,60 @@
+/*
+ *  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.resources;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.tools.ant.types.Resource;
+
+/**
+ * ResourceCollection that contains all resources of another
+ * collection except for the first <code>count</code> elements, a la
+ * the UNIX tail command with parameter <code>-n +count</code>.
+ * @since Ant 1.9.5
+ */
+public class AllButFirst extends SizeLimitCollection {
+
+    /**
+     * Take the first <code>count</code> elements.
+     * @return a Collection of Resources.
+     */
+    protected Collection<Resource> getCollection() {
+        int ct = getValidCount();
+        Iterator<Resource> iter = getResourceCollection().iterator();
+        List<Resource> al = new ArrayList<Resource>();
+        for (int i = 0; i < ct && iter.hasNext(); i++) {
+            // discard
+            iter.next();
+        }
+        while (iter.hasNext()) {
+            al.add(iter.next());
+        }
+        return al;
+    }
+
+    @Override
+    public synchronized int size() {
+        int sz = getResourceCollection().size();
+        int ct = getValidCount();
+        return sz > ct ? sz - ct : 0;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ant/blob/989ca3b7/src/tests/antunit/types/resources/first-last-test.xml
----------------------------------------------------------------------
diff --git a/src/tests/antunit/types/resources/first-last-test.xml b/src/tests/antunit/types/resources/first-last-test.xml
index dc3304b..46273c1 100644
--- a/src/tests/antunit/types/resources/first-last-test.xml
+++ b/src/tests/antunit/types/resources/first-last-test.xml
@@ -15,7 +15,9 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<project xmlns:au="antlib:org.apache.ant.antunit">
+<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit">
+
+  <import file="../../antunit-base.xml" />
 
   <tokens id="testrc">
     <string value="1,2,3,4,5" />
@@ -154,4 +156,69 @@
     </au:expectfailure>
   </target>
 
+  <target name="testallbutfirst5">
+    <au:assertTrue>
+      <resourcecount count="0">
+        <allbutfirst count="5"><resources refid="testrc" /></allbutfirst>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testallbutfirst4">
+    <au:assertTrue>
+      <resourcecount count="0">
+        <difference>
+          <allbutfirst count="4"><resources refid="testrc" /></allbutfirst>
+          <string value="5" />
+        </difference>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testallbutfirst3">
+    <au:assertTrue>
+      <resourcecount count="0">
+        <difference>
+          <allbutfirst count="3"><resources refid="testrc" /></allbutfirst>
+          <resources>
+            <string value="4" />
+            <string value="5" />
+          </resources>
+        </difference>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testallbutfirst">
+    <au:assertTrue>
+      <resourcecount count="0">
+        <difference>
+          <allbutfirst><resources refid="testrc" /></allbutfirst>
+          <resources>
+            <string value="2" />
+            <string value="3" />
+            <string value="4" />
+            <string value="5" />
+          </resources>
+        </difference>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testallbutfirst6">
+    <au:assertTrue>
+      <resourcecount count="0">
+        <allbutfirst count="6"><resources refid="testrc" /></allbutfirst>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testallbutfirst-1">
+    <au:expectfailure expectedmessage="size-limited collection count should be set to an int &gt;= 0">
+      <resourcecount>
+        <allbutfirst count="-1"><resources refid="testrc" /></allbutfirst>
+      </resourcecount>
+    </au:expectfailure>
+  </target>
+
 </project>