Skip to content

Commit 1dba130

Browse files
committed
Convert the javac targetroot setting into a task key.
1 parent 7551939 commit 1dba130

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

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

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ object SourcegraphPlugin extends AutoPlugin {
4040
taskKey[File](
4141
"The --root argument to the 'src lsif upload' command. By default, uses root directory of this build."
4242
)
43+
val sourcegraphJavacTargetroot: TaskKey[Option[File]] =
44+
taskKey[Option[File]](
45+
"The directories where the semanticdb-javac compiler plugin emits SemanticDB files."
46+
)
4347

4448
val Sourcegraph: Configuration =
4549
config("sourcegraph")
@@ -109,26 +113,34 @@ object SourcegraphPlugin extends AutoPlugin {
109113
inConfig(Test)(configSettings)
110114
).flatten
111115

112-
private lazy val semanticdbJavacTargetroot = Def.task[Option[File]] {
113-
(for {
114-
option <- javacOptions.value
115-
if option.startsWith("-Xplugin:semanticdb-javac")
116-
pluginOption <- option.split("\\s+")
117-
if pluginOption.startsWith("-targetroot:")
118-
} yield new File(pluginOption.stripPrefix("-targetroot:"))).lastOption
119-
}
120-
121116
def configSettings: Seq[Def.Setting[_]] = List(
122117
sourcegraphUpload := sourcegraphUpload.value,
118+
sourcegraphJavacTargetroot := {
119+
(for {
120+
option <- javacOptions.value
121+
if option.startsWith("-Xplugin:semanticdb-javac")
122+
pluginOption <- option.split("\\s+")
123+
if pluginOption.startsWith("-targetroot:")
124+
} yield new File(pluginOption.stripPrefix("-targetroot:"))).lastOption
125+
},
123126
sourcegraphSemanticdbDirectories := {
124-
val javacTargetroot = semanticdbJavacTargetroot.value
125-
val _ = fullClasspath.value
126-
List(
127-
javacTargetroot,
128-
Option(semanticdbTargetRoot.value)
129-
).flatten
130-
.map(f => f / "META-INF" / "semanticdb")
131-
.filter(_.isDirectory())
127+
if (!semanticdbEnabled.value) {
128+
streams.value.log.warn(
129+
s"${name.value}: " +
130+
s"Skipping LSIF upload because semanticdbEnabled.value is false. " +
131+
"To fix this problem, set the semanticdbEnabled setting to true."
132+
)
133+
Nil
134+
} else {
135+
val javacTargetroot = sourcegraphJavacTargetroot.value
136+
val _ = fullClasspath.value
137+
List(
138+
javacTargetroot,
139+
Option(semanticdbTargetRoot.value)
140+
).flatten
141+
.map(f => f / "META-INF" / "semanticdb")
142+
.filter(_.isDirectory())
143+
}
132144
}
133145
)
134146

0 commit comments

Comments
 (0)