@@ -2,6 +2,8 @@ import sbt._
2
2
import sbt .Keys ._
3
3
import sbt .plugins .JvmPlugin
4
4
import scala .sys .process ._
5
+ import java .nio .file .Files
6
+ import java .nio .file .StandardCopyOption
5
7
6
8
object SourcegraphPlugin extends AutoPlugin {
7
9
override def trigger = allRequirements
@@ -24,9 +26,9 @@ object SourcegraphPlugin extends AutoPlugin {
24
26
taskKey[Option [String ]](
25
27
" URL of your Sourcegraph instance. By default, uploads to https://sourcegraph.com."
26
28
)
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 ."
30
32
)
31
33
val sourcegraphSrcBinary : SettingKey [String ] =
32
34
settingKey[String ](
@@ -52,20 +54,40 @@ object SourcegraphPlugin extends AutoPlugin {
52
54
import autoImport ._
53
55
54
56
override lazy val globalSettings : Seq [Def .Setting [_]] = List (
55
- sourcegraphLsifSemanticdbBinary := " lsif-semanticdb" ,
56
57
sourcegraphSrcBinary := " src" ,
57
58
sourcegraphEndpoint := None ,
58
59
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 /
61
62
" 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
+ },
62
84
sourcegraphLsif := {
63
- val out = target.in (Sourcegraph ).value / " dump.lsif"
85
+ val out = (Sourcegraph / target ).value / " dump.lsif"
64
86
out.getParentFile.mkdirs()
65
87
val directories =
66
88
sourcegraphSemanticdbDirectories.all(anyProjectFilter).value
67
89
val directoryArguments = directories.iterator.flatten
68
- .map(dir => s " --semanticdbDir= ${dir .getAbsolutePath()} " )
90
+ .map(_ .getAbsolutePath())
69
91
.toList
70
92
if (directoryArguments.isEmpty) {
71
93
throw new TaskException (
@@ -74,8 +96,13 @@ object SourcegraphPlugin extends AutoPlugin {
74
96
)
75
97
}
76
98
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" ::
79
106
directoryArguments
80
107
)
81
108
out
0 commit comments