Skip to content

Commit 42069f4

Browse files
authored
Merge pull request #212 from olafurpg/jdk-navigation
2 parents 45e927d + 2d412a1 commit 42069f4

File tree

7 files changed

+65
-36
lines changed

7 files changed

+65
-36
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: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import moped.parsers.JsonParser
3131
import moped.reporters.Diagnostic
3232
import moped.reporters.Input
3333
import os.CommandResult
34+
import os.ProcessOutput.Readlines
3435

3536
/**
3637
* A custom build tool that is specifically made for lsif-java.
@@ -101,7 +102,11 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
101102
if (!Files.isDirectory(sourceroot)) {
102103
throw new NoSuchFileException(sourceroot.toString())
103104
}
104-
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))
105110
if (javaFiles.isEmpty) {
106111
index
107112
.app
@@ -127,17 +132,38 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
127132
arguments += actualClasspath.mkString(File.pathSeparator)
128133
arguments +=
129134
s"-Xplugin:semanticdb -targetroot:$targetroot -sourceroot:$sourceroot"
130-
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+
}
131145
val quotedArguments = arguments.map(a => "\"" + a + "\"")
132146
Files.write(argsfile, quotedArguments.asJava)
133147
if (javaFiles.size > 1) {
134148
index.app.reporter.info(f"Compiling ${javaFiles.size}%,.0f Java sources")
135149
}
150+
val pipe = Readlines(line => {
151+
index.app.reporter.info(line)
152+
})
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")
136162
val result = os
137-
.proc("javac", s"@$argsfile")
163+
.proc(javac.toString, s"@$argsfile")
138164
.call(
139-
stdout = os.Pipe,
140-
stderr = os.Pipe,
165+
stdout = pipe,
166+
stderr = pipe,
141167
cwd = os.Path(sourceroot),
142168
check = false
143169
)
@@ -166,11 +192,11 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
166192
private def clean(): Unit = {
167193
Files.walkFileTree(targetroot, new DeleteVisitor)
168194
}
195+
val moduleInfo = Paths.get("module-info.java")
169196

170197
/** Recursively collects all Java files in the working directory */
171198
private def collectAllJavaFiles(dir: Path): List[Path] = {
172199
val javaPattern = FileSystems.getDefault.getPathMatcher("glob:**.java")
173-
val moduleInfo = Paths.get("module-info.java")
174200
val buf = ListBuffer.empty[Path]
175201
Files.walkFileTree(
176202
dir,
@@ -188,7 +214,7 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
188214
file: Path,
189215
attrs: BasicFileAttributes
190216
): FileVisitResult = {
191-
if (javaPattern.matches(file) && !file.endsWith(moduleInfo)) {
217+
if (javaPattern.matches(file)) {
192218
buf += file
193219
}
194220
FileVisitResult.CONTINUE

lsif-semanticdb/src/main/java/com/sourcegraph/lsif_semanticdb/JdkPackage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public JdkPackage(String version) {
99

1010
@Override
1111
public String repoName() {
12-
return String.format("jdk:%s", version);
12+
return String.format("jdk/%s", version);
1313
}
1414

1515
@Override

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

tests/snapshots/src/main/generated/index-semanticdb/packages-jvm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ public class Example {
4343
│ ││
4444
v │v
4545
╭──────────╮ ╭─────────────┴─────╮
46-
│jdk:11(33)│ │referenceResult(35)│
46+
│jdk/11(33)│ │referenceResult(35)│
4747
╰──────────╯ ╰───────────────────╯

0 commit comments

Comments
 (0)