|
17 | 17 | package com.google.errorprone;
|
18 | 18 |
|
19 | 19 | import static java.nio.charset.StandardCharsets.UTF_8;
|
| 20 | +import static javax.tools.StandardLocation.SOURCE_PATH; |
20 | 21 |
|
21 | 22 | import com.google.common.base.Joiner;
|
22 | 23 | import com.google.common.base.Optional;
|
@@ -89,6 +90,34 @@ public JavaFileObject forResource(Class<?> clazz, String fileName) {
|
89 | 90 | return Iterables.getOnlyElement(getJavaFileObjects(path));
|
90 | 91 | }
|
91 | 92 |
|
| 93 | + @Override |
| 94 | + public boolean hasLocation(Location location) { |
| 95 | + /* |
| 96 | + * Short-circuit the check that module-info.java is found under the sourcepath. |
| 97 | + * |
| 98 | + * Here's why this short-circuits it: |
| 99 | + * http://hg.openjdk.java.net/jdk/jdk11/file/1ddf9a99e4ad/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java#l523 |
| 100 | + * |
| 101 | + * Here's why we want to do so: |
| 102 | + * |
| 103 | + * To determine whether a module-info.java is found under the sourcepath, javac looks for the |
| 104 | + * sourcepath Path objects on the default filesystem (i.e., using Paths.get(...)): |
| 105 | + * http://hg.openjdk.java.net/jdk/jdk11/file/1ddf9a99e4ad/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java#l112 |
| 106 | + * |
| 107 | + * With some reflection on javac internals, we can override it to use our fileSystem.get(...). |
| 108 | + * However, there's still a problem, as javac converts the Path objects to File objects to do |
| 109 | + * its work: |
| 110 | + * http://hg.openjdk.java.net/jdk/jdk11/file/1ddf9a99e4ad/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java#l940 |
| 111 | + * |
| 112 | + * This doesn't work for custom file systems like jimfs. So javac will never find anything under |
| 113 | + * our sourcepath (unless we start writing files to disk, which we could, like in our |
| 114 | + * integration tests). |
| 115 | + * |
| 116 | + * Thus, we short-circuit the check entirely. |
| 117 | + */ |
| 118 | + return location != SOURCE_PATH && super.hasLocation(location); |
| 119 | + } |
| 120 | + |
92 | 121 | // TODO(cushon): the testdata/ fallback is a hack, fix affected tests and remove it
|
93 | 122 | private InputStream findResource(Class<?> clazz, String name) {
|
94 | 123 | InputStream is = clazz.getResourceAsStream(name);
|
|
0 commit comments