chore(java indexer): Store absolute path
Store the absolute path for the temp directory so we don't have to compute it for every getPath call
@@ -58,10 +58,11 @@ public final class CompilationUnitPathFileManager extends ForwardingStandardJava
private final CompilationUnitFileSystem fileSystem;
private final ImmutableSet<String> defaultPlatformClassPath;
- // The path given to us that we are allowed to write in.
+ // The path given to us that we are allowed to write in. This will be stored as an absolute
+ // path.
private final @Nullable Path temporaryDirectoryPrefix;
// A temporary directory inside of temporaryDirectoryPrefix that we will use and delete when the
- // close method is called.
+ // close method is called. This should be will as an absolute path.
private @Nullable Path temporaryDirectory;
public CompilationUnitPathFileManager(
@@ -70,7 +71,9 @@ public final class CompilationUnitPathFileManager extends ForwardingStandardJava
StandardJavaFileManager fileManager,
@Nullable Path temporaryDirectory) {
super(fileManager);
- this.temporaryDirectoryPrefix = temporaryDirectory;
+ // Store the absolute path so we can safely do startsWith checks later.
+ this.temporaryDirectoryPrefix =
+ temporaryDirectory == null ? null : temporaryDirectory.toAbsolutePath();
defaultPlatformClassPath =
ImmutableSet.copyOf(
Iterables.transform(
@@ -191,11 +194,12 @@ public final class CompilationUnitPathFileManager extends ForwardingStandardJava
}
private Path getPath(String path, String... rest) {
+ // Get the absolute path so we can safely do the startsWith check.
+ Path local = Paths.get(path, rest).toAbsolutePath();
// If this is a path underneath the temporary directory, use it. This is required for --system
// flags to work correctly.
- Path local = Paths.get(path, rest);
if (temporaryDirectory != null) {
- if (local.toAbsolutePath().startsWith(temporaryDirectory.toAbsolutePath())) {
+ if (local.startsWith(temporaryDirectory)) {
logger.atInfo().log("Using the filesystem for temporary path %s", local);
return local;
}
@@ -242,8 +246,10 @@ public final class CompilationUnitPathFileManager extends ForwardingStandardJava
throw new IllegalStateException("Temporary directory set twice");
}
temporaryDirectory =
- Files.createTempDirectory(temporaryDirectoryPrefix, "kythe_java_indexer");
- Path systemRoot = Files.createDirectory(temporaryDirectory.resolve("system"));
+ Files.createTempDirectory(temporaryDirectoryPrefix, "kythe_java_indexer")
+ .toAbsolutePath();
+ Path systemRoot =
+ Files.createDirectory(temporaryDirectory.resolve("system")).toAbsolutePath();
try (Stream<Path> stream = Files.walk(sys.resolve("lib"))) {
for (Path path : (Iterable<Path>) stream::iterator) {
Path p =
@@ -254,9 +260,8 @@ public final class CompilationUnitPathFileManager extends ForwardingStandardJava
logger.atInfo().log("Copied file to %s", p.toAbsolutePath());
}
}
- logger.atInfo().log("Setting system path to %s", systemRoot.toAbsolutePath());
- super.handleOption(
- "--system", Iterators.singletonIterator(systemRoot.toAbsolutePath().toString()));
+ logger.atInfo().log("Setting system path to %s", systemRoot);
+ super.handleOption("--system", Iterators.singletonIterator(systemRoot.toString()));
} else if (Files.isDirectory(sys.resolve("modules"))) {
// TODO(salguarnieri) Due to a bug in the javac argument validation, bypass it and set the
// location directly.
