first part of https://bz.apache.org/bugzilla/show_bug.cgi?id=57834 - allbutlast to followmaster
| @@ -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 | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -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 >= 0"> | |||
| <resourcecount> | |||
| <allbutfirst count="-1"><resources refid="testrc" /></allbutfirst> | |||
| </resourcecount> | |||
| </au:expectfailure> | |||
| </target> | |||
| </project> | |||