Return-Path: Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org Received: (qmail 12400 invoked from network); 18 Sep 2009 04:27:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Sep 2009 04:27:38 -0000 Received: (qmail 31044 invoked by uid 500); 18 Sep 2009 04:27:38 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 30971 invoked by uid 500); 18 Sep 2009 04:27:37 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 30962 invoked by uid 99); 18 Sep 2009 04:27:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Sep 2009 04:27:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Sep 2009 04:27:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2AE8023888CD; Fri, 18 Sep 2009 04:27:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r816468 - /ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java Date: Fri, 18 Sep 2009 04:27:12 -0000 To: notifications@ant.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090918042712.2AE8023888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bodewig Date: Fri Sep 18 04:27:11 2009 New Revision: 816468 URL: http://svn.apache.org/viewvc?rev=816468&view=rev Log: Use Collections consistently Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java?rev=816468&r1=816467&r2=816468&view=diff ============================================================================== --- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java (original) +++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java Fri Sep 18 04:27:11 2009 @@ -23,7 +23,7 @@ import java.io.InputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; @@ -264,13 +264,13 @@ mode = new Mode(); mode.setValue(Mode.FORCE_CREATE); } - ResourceWithFlags[] sourceResources; + Collection sourceResources; try { sourceResources = findSources(); } catch (IOException ioex) { throw new BuildException("Failed to read sources", ioex); } - if (sourceResources.length == 0) { + if (sourceResources.size() == 0) { if (WhenEmpty.SKIP.equals(emptyBehavior.getValue())) { log(NO_SOURCES_MSG, Project.MSG_WARN); } else { @@ -288,7 +288,7 @@ List/**/ toAdd = new ArrayList/**/(); - toAdd.addAll(Arrays.asList(sourceResources)); + toAdd.addAll(sourceResources); if (checkAndLogUpToDate(sourceResources, targetArchive, existingEntries)) { @@ -299,8 +299,7 @@ sort(toAdd); try { - writeArchive((ResourceWithFlags[]) - toAdd.toArray(new ResourceWithFlags[0])); + writeArchive(toAdd); } catch (IOException ioex) { throw new BuildException("Failed to write archive", ioex); } @@ -340,7 +339,9 @@ * Find all the resources with their flags that should be added to * the archive. */ - protected ResourceWithFlags[] findSources() throws IOException { + protected Collection/**/ findSources() + throws IOException { + List/**/ l = new ArrayList/**/(); Set/**/ addedNames = new HashSet/**/(); for (Iterator rcs = sources.iterator(); rcs.hasNext(); ) { @@ -361,10 +362,10 @@ } } } - return (ResourceWithFlags[]) l.toArray(new ResourceWithFlags[l.size()]); + return l; } - private boolean checkAndLogUpToDate(ResourceWithFlags[] src, + private boolean checkAndLogUpToDate(Collection/**/ src, Resource targetArchive, ArchiveFileSet existingEntries) { try { @@ -391,15 +392,17 @@ * * @return true if the target is up-to-date */ - protected boolean isUpToDate(ResourceWithFlags[] src, + protected boolean isUpToDate(Collection/**/ src, ArchiveFileSet existingEntries) throws IOException { - final Resource[] srcResources = new Resource[src.length]; - for (int i = 0; i < srcResources.length; i++) { - srcResources[i] = - new MappedResource(src[i].getResource(), - new MergingMapper(src[i].getName())); + final Resource[] srcResources = new Resource[src.size()]; + int index = 0; + for (Iterator i = src.iterator(); i.hasNext(); ) { + ResourceWithFlags r = (ResourceWithFlags) i.next(); + srcResources[index++] = + new MappedResource(r.getResource(), + new MergingMapper(r.getName())); } return ResourceUtils .selectOutOfDateSources(this, srcResources, @@ -413,13 +416,13 @@ * Add the resources of the target archive that shall be kept when * creating the new one. */ - private void addResourcesToKeep(List/**/ toAdd, + private void addResourcesToKeep(Collection/**/ toAdd, ArchiveFileSet target, - ResourceWithFlags[] src) { + Collection/**/ src) { if (!Mode.FORCE_CREATE.equals(mode.getValue()) && !Mode.CREATE.equals(mode.getValue())) { try { - toAdd.addAll(Arrays.asList(findUnmatchedTargets(target, src))); + toAdd.addAll(findUnmatchedTargets(target, src)); } catch (IOException ioex) { throw new BuildException("Failed to read target archive", ioex); } @@ -430,8 +433,9 @@ * Find the resources from the target archive that don't have a * matching resource in the sources to be added. */ - protected ResourceWithFlags[] findUnmatchedTargets(ArchiveFileSet target, - ResourceWithFlags[] src) + protected Collection/**/ + findUnmatchedTargets(ArchiveFileSet target, + Collection/**/ src) throws IOException { List/**/ l = new ArrayList/**/(); @@ -444,9 +448,10 @@ Not not = new Not(); Or or = new Or(); not.add(or); - for (int i = 0; i < src.length; i++) { + for (Iterator i = src.iterator(); i.hasNext(); ) { + ResourceWithFlags r = (ResourceWithFlags) i.next(); Name name = new Name(); - name.setName(src[i].getName()); + name.setName(r.getName()); or.add(name); } res.add(not); @@ -462,7 +467,7 @@ } } - return (ResourceWithFlags[]) l.toArray(new ResourceWithFlags[l.size()]); + return l; } /** @@ -481,7 +486,7 @@ /** * Creates the archive archiving the given resources. */ - protected void writeArchive(ResourceWithFlags[] src) + protected void writeArchive(Collection/**/ src) throws IOException { ArchiveOutputStream out = null; Set addedDirectories = new HashSet(); @@ -491,24 +496,25 @@ .getOutputStream()), Expand.NATIVE_ENCODING.equals(getEncoding()) ? null : getEncoding()); - for (int i = 0; i < src.length; i++) { + for (Iterator i = src.iterator(); i.hasNext(); ) { + ResourceWithFlags r = (ResourceWithFlags) i.next(); if (!isFilesOnly()) { - ensureParentDirs(out, src[i], addedDirectories); + ensureParentDirs(out, r, addedDirectories); } - ArchiveEntry ent = entryBuilder.buildEntry(src[i]); + ArchiveEntry ent = entryBuilder.buildEntry(r); out.putArchiveEntry(ent); - if (!src[i].getResource().isDirectory()) { + if (!r.getResource().isDirectory()) { InputStream in = null; try { - in = src[i].getResource().getInputStream(); + in = r.getResource().getInputStream(); IOUtils.copy(in, out); } finally { FILE_UTILS.close(in); } } else { - addedDirectories.add(src[i].getName()); + addedDirectories.add(r.getName()); } out.closeArchiveEntry();