1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.BufferedReader ; 23 import java.io.File ; 24 import java.io.FileReader ; 25 import java.io.IOException ; 26 import java.io.Reader ; 27 import java.util.ArrayList ; 28 import java.util.Collections ; 29 import java.util.HashMap ; 30 import java.util.HashSet ; 31 import java.util.List ; 32 import java.util.Map ; 33 import java.util.Set ; 34 import org.apache.tools.ant.BuildException; 35 import org.apache.tools.ant.DirectoryScanner; 36 import org.apache.tools.ant.Project; 37 import org.apache.tools.ant.types.EnumeratedAttribute; 38 import org.apache.tools.ant.types.FileSet; 39 40 43 public class CvsFileSet extends FileSet { 44 45 47 public static final class Mode extends EnumeratedAttribute { 48 public String [] getValues() { 49 return new String [] { 50 "controlled", 51 "uncontrolled", 52 "text", 53 "binary", 54 }; 55 } 56 } 57 58 private String mode = "controlled"; 59 60 73 public void setMode(Mode m) { 74 mode = m.getValue(); 75 } 76 77 public DirectoryScanner getDirectoryScanner(Project proj) throws BuildException { 78 DirectoryScanner scan = new CvsDirectoryScanner(); 79 setupDirectoryScanner(scan, proj); 80 scan.scan(); 81 return scan; 82 } 83 84 private static final List <Set <String >> NO_ENTRIES = new ArrayList <Set <String >>(); 85 static { 86 NO_ENTRIES.add(Collections.<String >emptySet()); 87 NO_ENTRIES.add(Collections.<String >emptySet()); 88 } 89 90 private class CvsDirectoryScanner extends DirectoryScanner { 91 92 private final Map <File ,List <Set <String >>> entries = new HashMap <File ,List <Set <String >>>(100); 94 95 protected boolean isIncluded(String name) throws BuildException { 96 if (! super.isIncluded(name)) return false; 97 File f = new File (getBasedir(), name); 98 if (! f.exists()) throw new IllegalStateException (); 99 if (!f.isFile()) { 100 return true; 102 } 103 List <Set <String >> entries = loadEntries(f.getParentFile()); 104 Set <String > text = entries.get(0); 105 Set <String > binary = entries.get(1); 106 String bname = f.getName(); 107 if (mode.equals("controlled")) { 108 return text.contains(bname) || binary.contains(bname); 109 } else if (mode.equals("uncontrolled")) { 110 return ! text.contains(bname) && ! binary.contains(bname); 111 } else if (mode.equals("text")) { 112 return text.contains(bname); 113 } else if (mode.equals("binary")) { 114 return binary.contains(bname); 115 } else { 116 throw new IllegalStateException (mode); 117 } 118 } 119 120 private List <Set <String >> loadEntries(File dir) throws BuildException { 121 List <Set <String >> tb = entries.get(dir); 122 if (tb == null) { 123 File efile = new File (new File (dir, "CVS"), "Entries"); 124 if (efile.exists()) { 125 tb = new ArrayList <Set <String >>(); 126 tb.add(new HashSet <String >(10)); 127 tb.add(new HashSet <String >(10)); 128 try { 129 Reader r = new FileReader (efile); 130 try { 131 BufferedReader buf = new BufferedReader (r); 132 String line; 133 int lineNumber = 0; 134 while ((line = buf.readLine()) != null) { 135 lineNumber++; 136 if (line.startsWith("/")) { 137 line = line.substring(1); 138 int idx = line.indexOf('/'); 139 String name = line.substring(0, idx); 140 idx = line.lastIndexOf('/'); 141 line = line.substring(0, idx); 142 idx = line.lastIndexOf('/'); 143 String subst = line.substring(idx + 1); 144 if (subst.equals("-kb")) { 145 tb.get(1).add(name); 146 } else { 147 tb.get(0).add(name); 149 } 150 } 151 } 152 } finally { 153 r.close(); 154 } 155 } catch (IOException ioe) { 156 throw new BuildException("While reading " + efile, ioe); 157 } 158 } else { 159 tb = NO_ENTRIES; 160 } 161 entries.put(dir, tb); 162 } 163 return tb; 164 } 165 166 protected boolean couldHoldIncluded(String name) { 167 if (! super.couldHoldIncluded(name)) return false; 168 return ! name.endsWith(File.separatorChar + "CVS"); 170 } 171 172 } 173 174 } 175 | Popular Tags |