1 19 package org.netbeans.modules.java.source.builder; 20 21 import java.io.*; 22 import java.util.*; 23 import java.util.logging.*; 24 import java.util.zip.ZipFile ; 25 import java.util.zip.ZipEntry ; 26 import org.netbeans.modules.java.source.engine.ElapsedTimer; 27 28 31 public final class SourceFileList { 32 33 public static final String JAR_URL_PREFIX = "jar:/file:/"; 34 35 public static String [] findFiles(String [] args) { 36 return findFiles(args, allFilter, null); 37 } 38 39 public static String [] findFiles(String [] args, Logger logger) { 40 return findFiles(args, allFilter, logger); 41 } 42 43 public static String [] findFiles(String [] args, SourceFileFilter filter) { 44 return findFiles(args, filter, null); 45 } 46 47 public static String [] findFiles(String [] args, SourceFileFilter filter, 48 Logger logger) { 49 ElapsedTimer timer = new ElapsedTimer(); 50 List<String > nargs = new ArrayList<String >(); 51 int limit = args.length; 52 for(int i = 0; i<limit; i++) 53 expand(null, args[i], filter, nargs); 54 String [] files = nargs.toArray(new String [0]); 55 if (logger != null) { 56 logger.fine("found " + Integer.toString(files.length) + 57 " source files in " + timer.toString()); 58 } 59 return files; 60 } 61 62 private static void expand(File dir, String name, SourceFileFilter filter, 63 List<String > nargs) { 64 File f = dir != null ? new File (dir, name) : new File (name); 65 if (filter.acceptFile(name)) { 66 String path = f.getPath(); 67 if (!nargs.contains(path)) 68 nargs.add(path); 69 return; 70 } 71 if(name.endsWith(".jar") || name.endsWith(".zip")) { 72 75 return; 77 } 78 String [] subnames = f.list(); 79 if (subnames == null) 80 return; 81 int limit = subnames.length; 82 for(int i = 0; i<limit; i++) { 83 String sn = subnames[i]; 84 if (filter.acceptDirectory(sn)) 85 expand(f, sn, filter, nargs); 86 } 87 } 88 89 private static void expandZip(String zipFileName, SourceFileFilter filter, 90 List<String > nargs) { 91 try { 92 ZipFile zf = new ZipFile (zipFileName); 93 Enumeration files = zf.entries(); 94 while (files.hasMoreElements()) { 95 ZipEntry entry = (ZipEntry )files.nextElement(); 96 String name = entry.getName(); 97 if (filter.acceptFile(name)) { 98 name = JAR_URL_PREFIX + zipFileName + '!' + name; 99 if (!nargs.contains(name)) 100 nargs.add(name); 101 } 102 } 103 } catch (IOException e) { 104 System.err.println("failed reading zip file " + zipFileName + 105 ": " + e); 106 } 107 } 108 109 private static final SourceFileFilter allFilter = 110 new DefaultSourceFileFilter(); 111 } 112 | Popular Tags |