Skip to content

Commit e934d45

Browse files
committed
Fix bug when indexing JDK 11 sources
Previously, PackageHub was unable to auto-index the JDK 11 sources because it was missing appropriate `--module` flags that are not needed for JDK 8.
1 parent 8d5c5f3 commit e934d45

File tree

5 files changed

+60
-33
lines changed

5 files changed

+60
-33
lines changed

Dockerfile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
FROM openjdk:8-jdk-alpine@sha256:94792824df2df33402f201713f932b58cb9de94a0cd524164a0f2283343547b3
2-
COPY bin/coursier coursier
3-
RUN apk add --no-cache git curl \
4-
&& git config --global user.email "[email protected]" \
5-
&& git config --global user.name "Your Name" \
6-
&& git config --global http.postBuffer 1048576000 \
7-
&& curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /src \
8-
&& chmod +x /src \
9-
&& /coursier bootstrap -r sonatype:snapshots com.sourcegraph:packagehub_2.13:0.5.0-12-69905fcb-SNAPSHOT -o /packagehub
1+
FROM sourcegraph/lsif-java
2+
COPY bin/packagehub.sh /packagehub.sh
3+
RUN chmod +x /packagehub.sh
4+
RUN git config --global user.email "[email protected]"
5+
RUN git config --global user.name "Your Name"
6+
RUN git config --global http.postBuffer 1048576000
7+
RUN curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /src
8+
RUN chmod +x /src
9+
RUN /coursier bootstrap -r sonatype:snapshots com.sourcegraph:packagehub_2.13:0.5.1-26-2d4609cc-SNAPSHOT -o /packagehub
1010
ENV COURSIER_REPOSITORIES=central|https://maven.google.com/|jitpack
11-
ENTRYPOINT /packagehub --host 0.0.0.0 --port $PORT --src /src --coursier /coursier --postgres.username=$DB_USER --postgres.password=$DB_PASS --postgres.url=$DB_URL --auto-index-delay=PT1M
11+
CMD ["/packagehub.sh"]

Dockerfile.template

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
FROM openjdk:8-jdk-alpine@sha256:94792824df2df33402f201713f932b58cb9de94a0cd524164a0f2283343547b3
2-
COPY bin/coursier coursier
3-
RUN apk add --no-cache git curl \
4-
&& git config --global user.email "[email protected]" \
5-
&& git config --global user.name "Your Name" \
6-
&& git config --global http.postBuffer 1048576000 \
7-
&& curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /src \
8-
&& chmod +x /src \
9-
&& /coursier bootstrap -r sonatype:snapshots com.sourcegraph:packagehub_2.13:VERSION -o /packagehub
1+
FROM sourcegraph/lsif-java
2+
COPY bin/packagehub.sh /packagehub.sh
3+
RUN chmod +x /packagehub.sh
4+
RUN git config --global user.email "[email protected]"
5+
RUN git config --global user.name "Your Name"
6+
RUN git config --global http.postBuffer 1048576000
7+
RUN curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /src
8+
RUN chmod +x /src
9+
RUN /coursier bootstrap -r sonatype:snapshots com.sourcegraph:packagehub_2.13:VERSION -o /packagehub
1010
ENV COURSIER_REPOSITORIES=central|https://maven.google.com/|jitpack
11-
ENTRYPOINT /packagehub --host 0.0.0.0 --port $PORT --src /src --coursier /coursier --postgres.username=$DB_USER --postgres.password=$DB_PASS --postgres.url=$DB_URL --auto-index-delay=PT1M
11+
CMD ["/packagehub.sh"]

bin/packagehub.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
/packagehub --host 0.0.0.0 --port $PORT --src /src --coursier /coursier --postgres.username=$DB_USER --postgres.password=$DB_PASS --postgres.url=$DB_URL --auto-index-delay=PT1M

lsif-java/src/main/scala/com/sourcegraph/lsif_java/buildtools/LsifBuildTool.scala

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import java.nio.file.Path
1010
import java.nio.file.Paths
1111
import java.nio.file.SimpleFileVisitor
1212
import java.nio.file.attribute.BasicFileAttributes
13+
1314
import scala.collection.mutable.ListBuffer
1415
import scala.jdk.CollectionConverters._
1516
import scala.util.control.NonFatal
17+
1618
import com.sourcegraph.io.DeleteVisitor
1719
import com.sourcegraph.lsif_java.Dependencies
1820
import com.sourcegraph.lsif_java.Embedded
@@ -28,8 +30,8 @@ import moped.macros.ClassShape
2830
import moped.parsers.JsonParser
2931
import moped.reporters.Diagnostic
3032
import moped.reporters.Input
33+
import os.CommandResult
3134
import 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

packagehub/src/main/scala/com/sourcegraph/packagehub/PackageActor.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import os.SubProcess
3030
import ujson.Arr
3131
import ujson.Bool
3232
import ujson.Obj
33+
import ujson.Str
3334

3435
/**
3536
* Actor that creates git repos from package sources and (optionally LSIF
@@ -237,13 +238,13 @@ class PackageActor(
237238
List("dump.lsif", packagehubCached).asJava
238239
)
239240
val build = Obj()
240-
val dependencies =
241-
dep match {
242-
case MavenPackage(dep) =>
243-
build("dependencies") = Arr(packageId(dep))
244-
case _ =>
245-
build("indexJdk") = Bool(false)
246-
}
241+
dep match {
242+
case MavenPackage(dep) =>
243+
build("dependencies") = Arr(packageId(dep))
244+
case JdkPackage(version) =>
245+
build("indexJdk") = Bool(false)
246+
build("jvm") = Str(version)
247+
}
247248
Files.write(
248249
repo.resolve("lsif-java.json"),
249250
List(ujson.write(build, indent = 2)).asJava

0 commit comments

Comments
 (0)