7101146: Paths should more directly managed by BaseFileManager
Reviewed-by: mcimadamore
--- a/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Wed Oct 19 16:56:05 2011 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Wed Oct 19 15:29:46 2011 -0700
@@ -25,7 +25,6 @@
package com.sun.tools.javac.file;
-import java.util.Comparator;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
@@ -41,6 +40,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
@@ -54,6 +54,7 @@
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
+import com.sun.tools.javac.code.Lint;
import com.sun.tools.javac.file.RelativePath.RelativeFile;
import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
import com.sun.tools.javac.main.OptionName;
@@ -83,10 +84,6 @@
return buffer.toString().toCharArray();
}
- /** Encapsulates knowledge of paths
- */
- private Paths paths;
-
private FSInfo fsInfo;
private boolean contextUseOptimizedZip;
@@ -154,13 +151,6 @@
@Override
public void setContext(Context context) {
super.setContext(context);
- if (paths == null) {
- paths = Paths.instance(context);
- } else {
- // Reuse the Paths object as it stores the locations that
- // have been set with setLocation, etc.
- paths.setContext(context);
- }
fsInfo = FSInfo.instance(context);
@@ -179,7 +169,7 @@
@Override
public boolean isDefaultBootClassPath() {
- return paths.isDefaultBootClassPath();
+ return searchPaths.isDefaultBootClassPath();
}
public JavaFileObject getFileForInput(String name) {
@@ -493,7 +483,7 @@
*/
private Archive openArchive(File zipFileName, boolean useOptimizedZip) throws IOException {
File origZipFileName = zipFileName;
- if (!ignoreSymbolFile && paths.isDefaultBootClassPathRtJar(zipFileName)) {
+ if (!ignoreSymbolFile && searchPaths.isDefaultBootClassPathRtJar(zipFileName)) {
File file = zipFileName.getParentFile().getParentFile(); // ${java.home}
if (new File(file.getName()).equals(new File("jre")))
file = file.getParentFile();
@@ -780,7 +770,7 @@
} else if (location == SOURCE_OUTPUT) {
dir = (getSourceOutDir() != null ? getSourceOutDir() : getClassOutDir());
} else {
- Iterable<? extends File> path = paths.getPathForLocation(location);
+ Iterable<? extends File> path = searchPaths.getPathForLocation(location);
dir = null;
for (File f: path) {
dir = f;
@@ -815,7 +805,7 @@
throws IOException
{
nullCheck(location);
- paths.lazy();
+ searchPaths.lazy();
final File dir = location.isOutputLocation() ? getOutputDirectory(path) : null;
@@ -824,7 +814,7 @@
else if (location == SOURCE_OUTPUT)
sourceOutDir = getOutputLocation(dir, S);
else
- paths.setPathForLocation(location, path);
+ searchPaths.setPathForLocation(location, path);
}
// where
private File getOutputDirectory(Iterable<? extends File> path) throws IOException {
@@ -854,13 +844,13 @@
public Iterable<? extends File> getLocation(Location location) {
nullCheck(location);
- paths.lazy();
+ searchPaths.lazy();
if (location == CLASS_OUTPUT) {
return (getClassOutDir() == null ? null : List.of(getClassOutDir()));
} else if (location == SOURCE_OUTPUT) {
return (getSourceOutDir() == null ? null : List.of(getSourceOutDir()));
} else
- return paths.getPathForLocation(location);
+ return searchPaths.getPathForLocation(location);
}
private File getClassOutDir() {
--- a/langtools/src/share/classes/com/sun/tools/javac/file/Paths.java Wed Oct 19 16:56:05 2011 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/Paths.java Wed Oct 19 15:29:46 2011 -0700
@@ -41,7 +41,6 @@
import javax.tools.JavaFileManager.Location;
import com.sun.tools.javac.code.Lint;
-import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Options;
@@ -61,21 +60,6 @@
*/
public class Paths {
- /** The context key for the todo list */
- protected static final Context.Key<Paths> pathsKey =
- new Context.Key<Paths>();
-
- /** Get the Paths instance for this context.
- * @param context the context
- * @return the Paths instance for this context
- */
- public static Paths instance(Context context) {
- Paths instance = context.get(pathsKey);
- if (instance == null)
- instance = new Paths(context);
- return instance;
- }
-
/** The log to use for warning output */
private Log log;
@@ -88,17 +72,15 @@
/** Access to (possibly cached) file info */
private FSInfo fsInfo;
- protected Paths(Context context) {
- context.put(pathsKey, this);
+ public Paths() {
pathsForLocation = new HashMap<Location,Path>(16);
- setContext(context);
}
- void setContext(Context context) {
- log = Log.instance(context);
- options = Options.instance(context);
- lint = Lint.instance(context);
- fsInfo = FSInfo.instance(context);
+ public void update(Log log, Options options, Lint lint, FSInfo fsInfo) {
+ this.log = log;
+ this.options = options;
+ this.lint = lint;
+ this.fsInfo = fsInfo;
}
/** Whether to warn about non-existent path elements */
--- a/langtools/src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java Wed Oct 19 16:56:05 2011 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java Wed Oct 19 15:29:46 2011 -0700
@@ -25,9 +25,7 @@
package com.sun.tools.javac.nio;
-
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
@@ -60,7 +58,6 @@
import static java.nio.file.FileVisitOption.*;
import static javax.tools.StandardLocation.*;
-import com.sun.tools.javac.file.Paths;
import com.sun.tools.javac.util.BaseFileManager;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.List;
@@ -125,9 +122,8 @@
* Set the context for JavacPathFileManager.
*/
@Override
- protected void setContext(Context context) {
+ public void setContext(Context context) {
super.setContext(context);
- searchPaths = Paths.instance(context);
}
@Override
@@ -272,7 +268,6 @@
private boolean inited = false;
private Map<Location, PathsForLocation> pathsForLocation;
- private Paths searchPaths;
private static class PathsForLocation extends LinkedHashSet<Path> {
private static final long serialVersionUID = 6788510222394486733L;
--- a/langtools/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Wed Oct 19 16:56:05 2011 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Wed Oct 19 15:29:46 2011 -0700
@@ -25,11 +25,6 @@
package com.sun.tools.javac.util;
-import com.sun.tools.javac.code.Source;
-import com.sun.tools.javac.main.JavacOption;
-import com.sun.tools.javac.main.OptionName;
-import com.sun.tools.javac.main.RecognizedOptions;
-import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
@@ -54,6 +49,15 @@
import javax.tools.JavaFileObject;
import javax.tools.JavaFileObject.Kind;
+import com.sun.tools.javac.code.Lint;
+import com.sun.tools.javac.code.Source;
+import com.sun.tools.javac.file.FSInfo;
+import com.sun.tools.javac.file.Paths;
+import com.sun.tools.javac.main.JavacOption;
+import com.sun.tools.javac.main.OptionName;
+import com.sun.tools.javac.main.RecognizedOptions;
+import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition;
+
/**
* Utility methods for building a filemanager.
* There are no references here to file-system specific objects such as
@@ -63,15 +67,21 @@
protected BaseFileManager(Charset charset) {
this.charset = charset;
byteBufferCache = new ByteBufferCache();
+ searchPaths = createPaths();
}
/**
* Set the context for JavacPathFileManager.
*/
- protected void setContext(Context context) {
+ public void setContext(Context context) {
log = Log.instance(context);
options = Options.instance(context);
classLoaderClass = options.get("procloader");
+ searchPaths.update(log, options, Lint.instance(context), FSInfo.instance(context));
+ }
+
+ protected Paths createPaths() {
+ return new Paths();
}
/**
@@ -88,6 +98,8 @@
protected String classLoaderClass;
+ protected Paths searchPaths;
+
protected Source getSource() {
String sourceName = options.get(OptionName.SOURCE);
Source source = null;