@@ -2,6 +2,8 @@ import sbt._
22import sbt .Keys ._
33import sbt .plugins .JvmPlugin
44import scala .sys .process ._
5+ import java .nio .file .Files
6+ import java .nio .file .StandardCopyOption
57
68object 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
0 commit comments