Wed, 19 Oct 2011 15:29:46 -0700
7101146: Paths should more directly managed by BaseFileManager
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Wed Oct 19 16:56:05 2011 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Wed Oct 19 15:29:46 2011 -0700 1.3 @@ -25,7 +25,6 @@ 1.4 1.5 package com.sun.tools.javac.file; 1.6 1.7 -import java.util.Comparator; 1.8 import java.io.ByteArrayOutputStream; 1.9 import java.io.File; 1.10 import java.io.FileNotFoundException; 1.11 @@ -41,6 +40,7 @@ 1.12 import java.util.Arrays; 1.13 import java.util.Collection; 1.14 import java.util.Collections; 1.15 +import java.util.Comparator; 1.16 import java.util.EnumSet; 1.17 import java.util.HashMap; 1.18 import java.util.Iterator; 1.19 @@ -54,6 +54,7 @@ 1.20 import javax.tools.JavaFileObject; 1.21 import javax.tools.StandardJavaFileManager; 1.22 1.23 +import com.sun.tools.javac.code.Lint; 1.24 import com.sun.tools.javac.file.RelativePath.RelativeFile; 1.25 import com.sun.tools.javac.file.RelativePath.RelativeDirectory; 1.26 import com.sun.tools.javac.main.OptionName; 1.27 @@ -83,10 +84,6 @@ 1.28 return buffer.toString().toCharArray(); 1.29 } 1.30 1.31 - /** Encapsulates knowledge of paths 1.32 - */ 1.33 - private Paths paths; 1.34 - 1.35 private FSInfo fsInfo; 1.36 1.37 private boolean contextUseOptimizedZip; 1.38 @@ -154,13 +151,6 @@ 1.39 @Override 1.40 public void setContext(Context context) { 1.41 super.setContext(context); 1.42 - if (paths == null) { 1.43 - paths = Paths.instance(context); 1.44 - } else { 1.45 - // Reuse the Paths object as it stores the locations that 1.46 - // have been set with setLocation, etc. 1.47 - paths.setContext(context); 1.48 - } 1.49 1.50 fsInfo = FSInfo.instance(context); 1.51 1.52 @@ -179,7 +169,7 @@ 1.53 1.54 @Override 1.55 public boolean isDefaultBootClassPath() { 1.56 - return paths.isDefaultBootClassPath(); 1.57 + return searchPaths.isDefaultBootClassPath(); 1.58 } 1.59 1.60 public JavaFileObject getFileForInput(String name) { 1.61 @@ -493,7 +483,7 @@ 1.62 */ 1.63 private Archive openArchive(File zipFileName, boolean useOptimizedZip) throws IOException { 1.64 File origZipFileName = zipFileName; 1.65 - if (!ignoreSymbolFile && paths.isDefaultBootClassPathRtJar(zipFileName)) { 1.66 + if (!ignoreSymbolFile && searchPaths.isDefaultBootClassPathRtJar(zipFileName)) { 1.67 File file = zipFileName.getParentFile().getParentFile(); // ${java.home} 1.68 if (new File(file.getName()).equals(new File("jre"))) 1.69 file = file.getParentFile(); 1.70 @@ -780,7 +770,7 @@ 1.71 } else if (location == SOURCE_OUTPUT) { 1.72 dir = (getSourceOutDir() != null ? getSourceOutDir() : getClassOutDir()); 1.73 } else { 1.74 - Iterable<? extends File> path = paths.getPathForLocation(location); 1.75 + Iterable<? extends File> path = searchPaths.getPathForLocation(location); 1.76 dir = null; 1.77 for (File f: path) { 1.78 dir = f; 1.79 @@ -815,7 +805,7 @@ 1.80 throws IOException 1.81 { 1.82 nullCheck(location); 1.83 - paths.lazy(); 1.84 + searchPaths.lazy(); 1.85 1.86 final File dir = location.isOutputLocation() ? getOutputDirectory(path) : null; 1.87 1.88 @@ -824,7 +814,7 @@ 1.89 else if (location == SOURCE_OUTPUT) 1.90 sourceOutDir = getOutputLocation(dir, S); 1.91 else 1.92 - paths.setPathForLocation(location, path); 1.93 + searchPaths.setPathForLocation(location, path); 1.94 } 1.95 // where 1.96 private File getOutputDirectory(Iterable<? extends File> path) throws IOException { 1.97 @@ -854,13 +844,13 @@ 1.98 1.99 public Iterable<? extends File> getLocation(Location location) { 1.100 nullCheck(location); 1.101 - paths.lazy(); 1.102 + searchPaths.lazy(); 1.103 if (location == CLASS_OUTPUT) { 1.104 return (getClassOutDir() == null ? null : List.of(getClassOutDir())); 1.105 } else if (location == SOURCE_OUTPUT) { 1.106 return (getSourceOutDir() == null ? null : List.of(getSourceOutDir())); 1.107 } else 1.108 - return paths.getPathForLocation(location); 1.109 + return searchPaths.getPathForLocation(location); 1.110 } 1.111 1.112 private File getClassOutDir() {
2.1 --- a/src/share/classes/com/sun/tools/javac/file/Paths.java Wed Oct 19 16:56:05 2011 +0100 2.2 +++ b/src/share/classes/com/sun/tools/javac/file/Paths.java Wed Oct 19 15:29:46 2011 -0700 2.3 @@ -41,7 +41,6 @@ 2.4 import javax.tools.JavaFileManager.Location; 2.5 2.6 import com.sun.tools.javac.code.Lint; 2.7 -import com.sun.tools.javac.util.Context; 2.8 import com.sun.tools.javac.util.ListBuffer; 2.9 import com.sun.tools.javac.util.Log; 2.10 import com.sun.tools.javac.util.Options; 2.11 @@ -61,21 +60,6 @@ 2.12 */ 2.13 public class Paths { 2.14 2.15 - /** The context key for the todo list */ 2.16 - protected static final Context.Key<Paths> pathsKey = 2.17 - new Context.Key<Paths>(); 2.18 - 2.19 - /** Get the Paths instance for this context. 2.20 - * @param context the context 2.21 - * @return the Paths instance for this context 2.22 - */ 2.23 - public static Paths instance(Context context) { 2.24 - Paths instance = context.get(pathsKey); 2.25 - if (instance == null) 2.26 - instance = new Paths(context); 2.27 - return instance; 2.28 - } 2.29 - 2.30 /** The log to use for warning output */ 2.31 private Log log; 2.32 2.33 @@ -88,17 +72,15 @@ 2.34 /** Access to (possibly cached) file info */ 2.35 private FSInfo fsInfo; 2.36 2.37 - protected Paths(Context context) { 2.38 - context.put(pathsKey, this); 2.39 + public Paths() { 2.40 pathsForLocation = new HashMap<Location,Path>(16); 2.41 - setContext(context); 2.42 } 2.43 2.44 - void setContext(Context context) { 2.45 - log = Log.instance(context); 2.46 - options = Options.instance(context); 2.47 - lint = Lint.instance(context); 2.48 - fsInfo = FSInfo.instance(context); 2.49 + public void update(Log log, Options options, Lint lint, FSInfo fsInfo) { 2.50 + this.log = log; 2.51 + this.options = options; 2.52 + this.lint = lint; 2.53 + this.fsInfo = fsInfo; 2.54 } 2.55 2.56 /** Whether to warn about non-existent path elements */
3.1 --- a/src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java Wed Oct 19 16:56:05 2011 +0100 3.2 +++ b/src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java Wed Oct 19 15:29:46 2011 -0700 3.3 @@ -25,9 +25,7 @@ 3.4 3.5 package com.sun.tools.javac.nio; 3.6 3.7 - 3.8 import java.io.File; 3.9 -import java.io.FileNotFoundException; 3.10 import java.io.IOException; 3.11 import java.net.MalformedURLException; 3.12 import java.net.URL; 3.13 @@ -60,7 +58,6 @@ 3.14 import static java.nio.file.FileVisitOption.*; 3.15 import static javax.tools.StandardLocation.*; 3.16 3.17 -import com.sun.tools.javac.file.Paths; 3.18 import com.sun.tools.javac.util.BaseFileManager; 3.19 import com.sun.tools.javac.util.Context; 3.20 import com.sun.tools.javac.util.List; 3.21 @@ -125,9 +122,8 @@ 3.22 * Set the context for JavacPathFileManager. 3.23 */ 3.24 @Override 3.25 - protected void setContext(Context context) { 3.26 + public void setContext(Context context) { 3.27 super.setContext(context); 3.28 - searchPaths = Paths.instance(context); 3.29 } 3.30 3.31 @Override 3.32 @@ -272,7 +268,6 @@ 3.33 private boolean inited = false; 3.34 3.35 private Map<Location, PathsForLocation> pathsForLocation; 3.36 - private Paths searchPaths; 3.37 3.38 private static class PathsForLocation extends LinkedHashSet<Path> { 3.39 private static final long serialVersionUID = 6788510222394486733L;
4.1 --- a/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Wed Oct 19 16:56:05 2011 +0100 4.2 +++ b/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Wed Oct 19 15:29:46 2011 -0700 4.3 @@ -25,11 +25,6 @@ 4.4 4.5 package com.sun.tools.javac.util; 4.6 4.7 -import com.sun.tools.javac.code.Source; 4.8 -import com.sun.tools.javac.main.JavacOption; 4.9 -import com.sun.tools.javac.main.OptionName; 4.10 -import com.sun.tools.javac.main.RecognizedOptions; 4.11 -import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; 4.12 import java.io.ByteArrayOutputStream; 4.13 import java.io.Closeable; 4.14 import java.io.IOException; 4.15 @@ -54,6 +49,15 @@ 4.16 import javax.tools.JavaFileObject; 4.17 import javax.tools.JavaFileObject.Kind; 4.18 4.19 +import com.sun.tools.javac.code.Lint; 4.20 +import com.sun.tools.javac.code.Source; 4.21 +import com.sun.tools.javac.file.FSInfo; 4.22 +import com.sun.tools.javac.file.Paths; 4.23 +import com.sun.tools.javac.main.JavacOption; 4.24 +import com.sun.tools.javac.main.OptionName; 4.25 +import com.sun.tools.javac.main.RecognizedOptions; 4.26 +import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; 4.27 + 4.28 /** 4.29 * Utility methods for building a filemanager. 4.30 * There are no references here to file-system specific objects such as 4.31 @@ -63,15 +67,21 @@ 4.32 protected BaseFileManager(Charset charset) { 4.33 this.charset = charset; 4.34 byteBufferCache = new ByteBufferCache(); 4.35 + searchPaths = createPaths(); 4.36 } 4.37 4.38 /** 4.39 * Set the context for JavacPathFileManager. 4.40 */ 4.41 - protected void setContext(Context context) { 4.42 + public void setContext(Context context) { 4.43 log = Log.instance(context); 4.44 options = Options.instance(context); 4.45 classLoaderClass = options.get("procloader"); 4.46 + searchPaths.update(log, options, Lint.instance(context), FSInfo.instance(context)); 4.47 + } 4.48 + 4.49 + protected Paths createPaths() { 4.50 + return new Paths(); 4.51 } 4.52 4.53 /** 4.54 @@ -88,6 +98,8 @@ 4.55 4.56 protected String classLoaderClass; 4.57 4.58 + protected Paths searchPaths; 4.59 + 4.60 protected Source getSource() { 4.61 String sourceName = options.get(OptionName.SOURCE); 4.62 Source source = null;