Repository navigation
Expand file tree
/
Copy pathDocs.java
More file actions
69 lines (61 loc) · 2.08 KB
/
Copy pathDocs.java
File metadata and controls
69 lines (61 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.javacs;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.logging.Logger;
import javax.tools.*;
public class Docs {
/** File manager with source-path + platform sources, which we will use to look up individual source files */
final SourceFileManager fileManager = new SourceFileManager();
Docs(Set<Path> docPath) {
var srcZipPath = srcZip();
// Path to source .jars + src.zip
var sourcePath = new ArrayList<Path>(docPath);
if (srcZipPath != NOT_FOUND) {
sourcePath.add(srcZipPath);
}
try {
fileManager.setLocationFromPaths(StandardLocation.SOURCE_PATH, sourcePath);
if (srcZipPath != NOT_FOUND) {
fileManager.setLocationFromPaths(StandardLocation.MODULE_SOURCE_PATH, Set.of(srcZipPath));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static final Path NOT_FOUND = Paths.get("");
private static Path cacheSrcZip;
private static Path srcZip() {
if (cacheSrcZip == null) {
cacheSrcZip = findSrcZip();
}
if (cacheSrcZip == NOT_FOUND) {
return NOT_FOUND;
}
try {
var fs = FileSystems.newFileSystem(cacheSrcZip, Docs.class.getClassLoader());
return fs.getPath("/");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static Path findSrcZip() {
var javaHome = JavaHomeHelper.javaHome();
String[] locations = {
"lib/src.zip", "src.zip",
};
for (var rel : locations) {
var abs = javaHome.resolve(rel);
if (Files.exists(abs)) {
LOG.info("Found " + abs);
return abs;
}
}
LOG.warning("Couldn't find src.zip in " + javaHome);
return NOT_FOUND;
}
private static final Logger LOG = Logger.getLogger("main");
}