36 import java.util.Collection; |
36 import java.util.Collection; |
37 import java.util.Collections; |
37 import java.util.Collections; |
38 import java.util.LinkedHashSet; |
38 import java.util.LinkedHashSet; |
39 import java.util.Iterator; |
39 import java.util.Iterator; |
40 import java.util.StringTokenizer; |
40 import java.util.StringTokenizer; |
41 import java.util.zip.ZipException; |
|
42 import java.util.zip.ZipFile; |
41 import java.util.zip.ZipFile; |
43 import com.sun.tools.javac.code.Lint; |
42 import com.sun.tools.javac.code.Lint; |
44 import com.sun.tools.javac.util.Context; |
|
45 import com.sun.tools.javac.util.Log; |
|
46 import com.sun.tools.javac.util.Options; |
|
47 import com.sun.tools.javac.util.Position; |
|
48 import java.util.ArrayList; |
43 import java.util.ArrayList; |
49 import java.util.concurrent.ConcurrentHashMap; |
44 import java.util.concurrent.ConcurrentHashMap; |
50 import java.util.concurrent.locks.Lock; |
45 import java.util.concurrent.locks.Lock; |
51 import java.util.concurrent.locks.ReentrantLock; |
46 import java.util.concurrent.locks.ReentrantLock; |
52 import javax.tools.JavaFileManager.Location; |
47 import javax.tools.JavaFileManager.Location; |
68 |
63 |
69 /** The context key for the todo list */ |
64 /** The context key for the todo list */ |
70 protected static final Context.Key<Paths> pathsKey = |
65 protected static final Context.Key<Paths> pathsKey = |
71 new Context.Key<Paths>(); |
66 new Context.Key<Paths>(); |
72 |
67 |
73 /** Get the Paths instance for this context. */ |
68 /** Get the Paths instance for this context. |
|
69 * @param context the context |
|
70 * @return the Paths instance for this context |
|
71 */ |
74 public static Paths instance(Context context) { |
72 public static Paths instance(Context context) { |
75 Paths instance = context.get(pathsKey); |
73 Paths instance = context.get(pathsKey); |
76 if (instance == null) |
74 if (instance == null) |
77 instance = new Paths(context); |
75 instance = new Paths(context); |
78 return instance; |
76 return instance; |
87 /** Handler for -Xlint options */ |
85 /** Handler for -Xlint options */ |
88 private Lint lint; |
86 private Lint lint; |
89 |
87 |
90 private static boolean NON_BATCH_MODE = System.getProperty("nonBatchMode") != null;// TODO: Use -XD compiler switch for this. |
88 private static boolean NON_BATCH_MODE = System.getProperty("nonBatchMode") != null;// TODO: Use -XD compiler switch for this. |
91 private static Map<File, PathEntry> pathExistanceCache = new ConcurrentHashMap<File, PathEntry>(); |
89 private static Map<File, PathEntry> pathExistanceCache = new ConcurrentHashMap<File, PathEntry>(); |
92 private static Map<File, java.util.List<String>> manifestEntries = new ConcurrentHashMap<File, java.util.List<String>>(); |
90 private static Map<File, java.util.List<File>> manifestEntries = new ConcurrentHashMap<File, java.util.List<File>>(); |
93 private static Map<File, Boolean> isDirectory = new ConcurrentHashMap<File, Boolean>(); |
91 private static Map<File, Boolean> isDirectory = new ConcurrentHashMap<File, Boolean>(); |
94 private static Lock lock = new ReentrantLock(); |
92 private static Lock lock = new ReentrantLock(); |
95 |
93 |
96 public static void clearPathExistanceCache() { |
94 public static void clearPathExistanceCache() { |
97 pathExistanceCache.clear(); |
95 pathExistanceCache.clear(); |
367 // Manifest entry. In some future release, we may want to |
365 // Manifest entry. In some future release, we may want to |
368 // update this code to recognize URLs rather than simple |
366 // update this code to recognize URLs rather than simple |
369 // filenames, but if we do, we should redo all path-related code. |
367 // filenames, but if we do, we should redo all path-related code. |
370 private void addJarClassPath(File jarFile, boolean warn) { |
368 private void addJarClassPath(File jarFile, boolean warn) { |
371 try { |
369 try { |
372 java.util.List<String> manifestsList = manifestEntries.get(jarFile); |
370 java.util.List<File> manifestsList = manifestEntries.get(jarFile); |
373 if (!NON_BATCH_MODE) { |
371 if (!NON_BATCH_MODE) { |
374 lock.lock(); |
372 lock.lock(); |
375 try { |
373 try { |
376 if (manifestsList != null) { |
374 if (manifestsList != null) { |
377 for (String entr : manifestsList) { |
375 for (File entr : manifestsList) { |
378 addFile(new File(entr), warn); |
376 addFile(entr, warn); |
379 } |
377 } |
380 return; |
378 return; |
381 } |
379 } |
382 } |
380 } |
383 finally { |
381 finally { |
384 lock.unlock(); |
382 lock.unlock(); |
385 } |
383 } |
386 } |
384 } |
387 |
385 |
388 if (!NON_BATCH_MODE) { |
386 if (!NON_BATCH_MODE) { |
389 manifestsList = new ArrayList<String>(); |
387 manifestsList = new ArrayList<File>(); |
390 manifestEntries.put(jarFile, manifestsList); |
388 manifestEntries.put(jarFile, manifestsList); |
391 } |
389 } |
392 |
390 |
393 String jarParent = jarFile.getParent(); |
391 String jarParent = jarFile.getParent(); |
394 JarFile jar = new JarFile(jarFile); |
392 JarFile jar = new JarFile(jarFile); |