@@ -10,9 +10,11 @@ import java.nio.file.Path
1010import java .nio .file .Paths
1111import java .nio .file .SimpleFileVisitor
1212import java .nio .file .attribute .BasicFileAttributes
13+
1314import scala .collection .mutable .ListBuffer
1415import scala .jdk .CollectionConverters ._
1516import scala .util .control .NonFatal
17+
1618import com .sourcegraph .io .DeleteVisitor
1719import com .sourcegraph .lsif_java .Dependencies
1820import com .sourcegraph .lsif_java .Embedded
@@ -28,8 +30,8 @@ import moped.macros.ClassShape
2830import moped .parsers .JsonParser
2931import moped .reporters .Diagnostic
3032import moped .reporters .Input
33+ import os .CommandResult
3134import os .ProcessOutput .Readlines
32- import os .{CommandResult , ProcessOutput }
3335
3436/**
3537 * A custom build tool that is specifically made for lsif-java.
@@ -100,7 +102,11 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
100102 if (! Files .isDirectory(sourceroot)) {
101103 throw new NoSuchFileException (sourceroot.toString())
102104 }
103- val javaFiles = collectAllJavaFiles(sourceroot).map(_.toString())
105+ val allJavaFiles = collectAllJavaFiles(sourceroot)
106+ val javaFiles = allJavaFiles
107+ .filterNot(_.endsWith(moduleInfo))
108+ .map(_.toString())
109+ val moduleInfos = allJavaFiles.filter(_.endsWith(moduleInfo))
104110 if (javaFiles.isEmpty) {
105111 index
106112 .app
@@ -126,7 +132,16 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
126132 arguments += actualClasspath.mkString(File .pathSeparator)
127133 arguments +=
128134 s " -Xplugin:semanticdb -targetroot: $targetroot -sourceroot: $sourceroot"
129- arguments ++= javaFiles
135+ if (! config.indexJdk && moduleInfos.nonEmpty) {
136+ moduleInfos.foreach { module =>
137+ arguments += " --module"
138+ arguments += module.getParent.getFileName.toString
139+ }
140+ arguments += " --module-source-path"
141+ arguments += sourceroot.toString
142+ } else {
143+ arguments ++= javaFiles
144+ }
130145 val quotedArguments = arguments.map(a => " \" " + a + " \" " )
131146 Files .write(argsfile, quotedArguments.asJava)
132147 if (javaFiles.size > 1 ) {
@@ -135,8 +150,17 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
135150 val pipe = Readlines (line => {
136151 index.app.reporter.info(line)
137152 })
153+ val javac = Paths .get(
154+ os.proc(coursier.toString, " java-home" , " --jvm" , config.jvm)
155+ .call()
156+ .out
157+ .trim(),
158+ " bin" ,
159+ " javac"
160+ )
161+ index.app.reporter.info(s " $$ $javac @ $argsfile" )
138162 val result = os
139- .proc(" javac" , s " @ $argsfile" )
163+ .proc(javac.toString , s " @ $argsfile" )
140164 .call(
141165 stdout = pipe,
142166 stderr = pipe,
@@ -168,11 +192,11 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
168192 private def clean (): Unit = {
169193 Files .walkFileTree(targetroot, new DeleteVisitor )
170194 }
195+ val moduleInfo = Paths .get(" module-info.java" )
171196
172197 /** Recursively collects all Java files in the working directory */
173198 private def collectAllJavaFiles (dir : Path ): List [Path ] = {
174199 val javaPattern = FileSystems .getDefault.getPathMatcher(" glob:**.java" )
175- val moduleInfo = Paths .get(" module-info.java" )
176200 val buf = ListBuffer .empty[Path ]
177201 Files .walkFileTree(
178202 dir,
@@ -190,7 +214,7 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
190214 file : Path ,
191215 attrs : BasicFileAttributes
192216 ): FileVisitResult = {
193- if (javaPattern.matches(file) && ! file.endsWith(moduleInfo) ) {
217+ if (javaPattern.matches(file)) {
194218 buf += file
195219 }
196220 FileVisitResult .CONTINUE
0 commit comments