1 28 29 package com.idaremedia.antx.ownhelpers; 30 31 import java.io.File ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 import java.util.NoSuchElementException ; 35 36 import org.apache.tools.ant.BuildException; 37 import org.apache.tools.ant.DirectoryScanner; 38 import org.apache.tools.ant.Project; 39 import org.apache.tools.ant.types.FileSet; 40 41 import com.idaremedia.antx.AntX; 42 import com.idaremedia.antx.helpers.ArrayIterator; 43 44 56 57 public class FileSetsIterator extends ProjectDependentSkeleton implements Iterator 58 { 59 private static final String IAM_ = AntX.utilities+"FileSetsIterator:"; 60 61 62 68 public FileSetsIterator(List filesets, Project project) 69 { 70 super(); 71 AntX.require_(filesets!=null,IAM_,"ctor- nonzro fileset list"); 72 setProject(project); 73 m_includesItr = filesets.isEmpty() ? null : filesets.iterator(); 74 } 75 76 77 78 82 public boolean hasNext() 83 { 84 if (m_includesItr==null) { 85 return false; 86 } 87 88 boolean gotOne = (m_nextItem!=null); 89 90 if (!gotOne) { 91 if (m_innerItr!=null) { 92 if (m_innerItr.hasNext()) { 93 m_nextItem = m_innerItr.next(); 94 return true; 95 } 96 m_innerItr = null; 97 if (m_privateCall) { 98 return false; 99 } 100 } 101 while (m_includesItr.hasNext()) { 102 Object candidate = m_includesItr.next(); 103 104 if (candidate instanceof FileSet) { 105 DirectoryScanner ds = ((FileSet)candidate).getDirectoryScanner(getProject()); 106 String [] list = ds.getIncludedFiles(); 107 LocalTk.resolveAllFilesOrDirs(list,ds,false); 108 m_innerItr = new ArrayIterator(list); 109 m_privateCall=true; 110 gotOne = this.hasNext(); m_privateCall=false; 112 if (gotOne) { 113 return true; 114 } 115 candidate = null; 116 } 117 else if (candidate instanceof File ) { 118 candidate = ((File )candidate).getPath(); 119 } 120 else if (!(candidate instanceof String )) { 121 String error = AntX.uistrs().get("task.bad.path.from", 122 String.valueOf(candidate)); 123 getProject().log(error,Project.MSG_ERR); 124 throw new BuildException(error); 125 } 126 127 if (candidate!=null) { 128 m_nextItem = candidate; 129 gotOne = true; 130 break; 131 } 132 } 133 } 134 135 return gotOne; 136 } 137 138 139 140 145 public Object next() 146 { 147 if (m_nextItem==null) { 148 throw new NoSuchElementException (); 149 } 150 Object result = m_nextItem; 151 m_nextItem = null; 152 return result; 153 } 154 155 156 157 162 public void remove() 163 { 164 throw new UnsupportedOperationException (); 165 } 166 167 168 private Iterator m_includesItr; private Iterator m_innerItr; private Object m_nextItem; private boolean m_privateCall; 172 } 173 174 175 | Popular Tags |