Skip to content

Commit 24a0805

Browse files
authored
Merge pull request #12 from olafurpg/lsif-java
2 parents 1dba130 + 8eea9ad commit 24a0805

File tree

7 files changed

+54
-22
lines changed

7 files changed

+54
-22
lines changed

.github/workflows/sourcegraph.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ jobs:
1414
- uses: actions/setup-go@v2
1515
with:
1616
go-version: "1.15.6"
17-
- run: go get github.com/sourcegraph/lsif-semanticdb/cmd/lsif-semanticdb
1817
- run: |
1918
mkdir -p bin
2019
curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o bin/src

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ inThisBuild(
2222
)
2323
)
2424

25-
skip in publish := true
25+
publish / skip := true
2626

2727
lazy val plugin = project
2828
.settings(
41.6 KB
Binary file not shown.

plugin/src/main/scala/com/sourcegraph/sbtsourcegraph/SourcegraphPlugin.scala

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import sbt._
22
import sbt.Keys._
33
import sbt.plugins.JvmPlugin
44
import scala.sys.process._
5+
import java.nio.file.Files
6+
import java.nio.file.StandardCopyOption
57

68
object SourcegraphPlugin extends AutoPlugin {
79
override def trigger = allRequirements
@@ -24,9 +26,9 @@ object SourcegraphPlugin extends AutoPlugin {
2426
taskKey[Option[String]](
2527
"URL of your Sourcegraph instance. By default, uploads to https://sourcegraph.com."
2628
)
27-
val sourcegraphLsifSemanticdbBinary: SettingKey[String] =
28-
settingKey[String](
29-
"Binary name of the lsif-semanticdb command-line tool. By default, assumes the binary name 'lsif-semanticdb' is available on the $PATH."
29+
val sourcegraphCoursierBinary: TaskKey[String] =
30+
taskKey[String](
31+
"Binary name of the Coursier command-line tool. By default, Coursier is launched from a small binary that's embedded in resources."
3032
)
3133
val sourcegraphSrcBinary: SettingKey[String] =
3234
settingKey[String](
@@ -52,20 +54,40 @@ object SourcegraphPlugin extends AutoPlugin {
5254
import autoImport._
5355

5456
override lazy val globalSettings: Seq[Def.Setting[_]] = List(
55-
sourcegraphLsifSemanticdbBinary := "lsif-semanticdb",
5657
sourcegraphSrcBinary := "src",
5758
sourcegraphEndpoint := None,
5859
sourcegraphExtraUploadArguments := Nil,
59-
sourcegraphRoot := baseDirectory.in(ThisBuild).value,
60-
target.in(Sourcegraph) := baseDirectory.in(ThisBuild).value /
60+
sourcegraphRoot := (ThisBuild / baseDirectory).value,
61+
Sourcegraph / target := (ThisBuild / baseDirectory).value /
6162
"target" / "sbt-sourcegraph",
63+
sourcegraphCoursierBinary := {
64+
val out = (Sourcegraph / target).value / "coursier"
65+
if (!out.exists()) {
66+
val key = "/sbt-sourcegraph/coursier"
67+
val in = this.getClass().getResourceAsStream(key)
68+
if (in == null) {
69+
throw new NoSuchElementException(
70+
s"the resource '$key' does not exist. " +
71+
"To fix this problem, define the `sourcegraphCoursierBinary` setting."
72+
)
73+
}
74+
try {
75+
out.getParentFile().mkdirs()
76+
Files.copy(in, out.toPath(), StandardCopyOption.REPLACE_EXISTING)
77+
} finally {
78+
in.close()
79+
}
80+
out.setExecutable(true)
81+
}
82+
out.getAbsolutePath()
83+
},
6284
sourcegraphLsif := {
63-
val out = target.in(Sourcegraph).value / "dump.lsif"
85+
val out = (Sourcegraph / target).value / "dump.lsif"
6486
out.getParentFile.mkdirs()
6587
val directories =
6688
sourcegraphSemanticdbDirectories.all(anyProjectFilter).value
6789
val directoryArguments = directories.iterator.flatten
68-
.map(dir => s"--semanticdbDir=${dir.getAbsolutePath()}")
90+
.map(_.getAbsolutePath())
6991
.toList
7092
if (directoryArguments.isEmpty) {
7193
throw new TaskException(
@@ -74,8 +96,13 @@ object SourcegraphPlugin extends AutoPlugin {
7496
)
7597
}
7698
runProcess(
77-
sourcegraphLsifSemanticdbBinary.value ::
78-
s"--out=$out" ::
99+
sourcegraphCoursierBinary.value ::
100+
"launch" ::
101+
"--contrib" ::
102+
"lsif-java" ::
103+
"--" ::
104+
"index-semanticdb" ::
105+
s"--output=$out" ::
79106
directoryArguments
80107
)
81108
out

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.4.6
1+
sbt.version=1.5.2

project/plugins.sbt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
33
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
44
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.25")
55

6-
unmanagedSourceDirectories.in(Compile) +=
7-
baseDirectory.in(ThisBuild).value.getParentFile /
6+
Compile / unmanagedSourceDirectories +=
7+
(ThisBuild / baseDirectory).value.getParentFile /
88
"plugin" / "src" / "main" / "scala"
9+
Compile / unmanagedResourceDirectories +=
10+
(ThisBuild / baseDirectory).value.getParentFile /
11+
"plugin" / "src" / "main" / "resources"

readme.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,8 @@ can adjust the installation steps from
110110
[`sourcegraph.yml`](.github/workflows/sourcegraph.yml) to work with your own CI
111111
system.
112112

113-
In short, first install the following binaries to `$PATH`.
114-
115-
- https://github.com/sourcegraph/lsif-semanticdb as `lsif-semanticdb`
116-
- https://github.com/sourcegraph/src-cli as `src`
113+
First, install the `src` command-line tool
114+
(https://github.com/sourcegraph/src-cli) to `$PATH`.
117115

118116
Next, create a GitHub access token following the instructions
119117
[here](https://docs.sourcegraph.com/admin/external_service/github#github-api-token-and-access).
@@ -145,9 +143,9 @@ sbt sourcegraphUpload
145143
**Optional settings**:
146144

147145
- `sourcegraphEndpoint: String`: URL of the Sourcegraph instance.
148-
- `sourcegraphLsifSemanticdbBinary: String`: path to the
149-
[`lsif-semanticdb`](https://github.com/sourcegraph/lsif-semanticdb/) binary.
150-
The `lsif-semanticdb` binary needs to be installed separately.
146+
- `sourcegraphCoursierBinary: String`: name of the `coursier` command-line
147+
interface. By default, sbt-sourcegraph launches coursier from a binary that's
148+
embedded in the resources.
151149
- `sourcegraphSrcBinary: String`: path to the
152150
[`src`](https://github.com/sourcegraph/src-cli) binary. The `src` binary needs
153151
to be installed separately.
@@ -156,6 +154,11 @@ sbt sourcegraphUpload
156154
flags you may want to configure.
157155
- `sourcegraphRoot: String`: root directory of this sbt build.
158156

157+
**Removed settings**:
158+
159+
- (no longer used) `sourcegraphLsifSemanticdbBinary: String`: path to the
160+
[`lsif-semanticdb`](https://github.com/sourcegraph/lsif-semanticdb/) binary.
161+
159162
## Disable plugin for specific project
160163

161164
Use `.disablePlugins(SourcegraphPlugin))` to disable this plugin for a specific

0 commit comments

Comments
 (0)