提交 05683967 编写于 作者: J jjg

7101146: Paths should more directly managed by BaseFileManager

Reviewed-by: mcimadamore
上级 da6087bf
......@@ -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.ArrayList;
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.JavaFileManager;
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 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
return buffer.toString().toCharArray();
}
/** Encapsulates knowledge of paths
*/
private Paths paths;
private FSInfo fsInfo;
private boolean contextUseOptimizedZip;
......@@ -154,13 +151,6 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
@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 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
@Override
public boolean isDefaultBootClassPath() {
return paths.isDefaultBootClassPath();
return searchPaths.isDefaultBootClassPath();
}
public JavaFileObject getFileForInput(String name) {
......@@ -493,7 +483,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
*/
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 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
} 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 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
throws IOException
{
nullCheck(location);
paths.lazy();
searchPaths.lazy();
final File dir = location.isOutputLocation() ? getOutputDirectory(path) : null;
......@@ -824,7 +814,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
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 class JavacFileManager extends BaseFileManager implements StandardJavaFil
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() {
......
......@@ -41,7 +41,6 @@ import java.util.zip.ZipFile;
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 @@ import static com.sun.tools.javac.main.OptionName.*;
*/
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 @@ public class Paths {
/** 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 */
......
......@@ -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 javax.tools.StandardLocation;
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 @@ public class JavacPathFileManager extends BaseFileManager implements PathFileMan
* 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 @@ public class JavacPathFileManager extends BaseFileManager implements PathFileMan
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;
......
......@@ -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 java.util.Map;
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 @@ public abstract class BaseFileManager {
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 @@ public abstract class BaseFileManager {
protected String classLoaderClass;
protected Paths searchPaths;
protected Source getSource() {
String sourceName = options.get(OptionName.SOURCE);
Source source = null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册