@@ -6,6 +6,8 @@ import java.nio.file._
6
6
import scala .collection .mutable .ListBuffer
7
7
import scala .util .Properties
8
8
9
+ import com .sourcegraph .io .DeleteVisitor
10
+ import com .sourcegraph .lsif_java .BuildInfo
9
11
import com .sourcegraph .lsif_java .Embedded
10
12
import com .sourcegraph .lsif_java .commands .IndexCommand
11
13
import os .CommandResult
@@ -78,9 +80,20 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
78
80
buildCommand +=
79
81
s " -Porg.gradle.java.installations.paths= ${toolchains.paths()}"
80
82
}
81
- buildCommand ++= index.finalBuildCommand(List (" clean" , " compileTestJava" ))
83
+ buildCommand ++=
84
+ index.finalBuildCommand(
85
+ List [Option [String ]](
86
+ Some (" clean" ),
87
+ Some (" compileTestJava" ),
88
+ if (toolchains.isScalaEnabled)
89
+ Some (" compileTestScala" )
90
+ else
91
+ None
92
+ ).flatten
93
+ )
82
94
buildCommand += lsifJavaDependencies
83
95
96
+ Files .walkFileTree(targetroot, new DeleteVisitor ())
84
97
val result = index.process(buildCommand, env = Map (" TERM" -> " dumb" ))
85
98
printDebugLogs(toolchains.tmp)
86
99
Embedded
@@ -112,6 +125,11 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
112
125
113
126
val agentpath = Embedded .agentJar(tmp)
114
127
val pluginpath = Embedded .semanticdbJar(tmp)
128
+ def handleExceptionGroovySyntax (): String =
129
+ if (index.verbose)
130
+ " e.printStackTrace()"
131
+ else
132
+ " "
115
133
val dependenciesPath = targetroot.resolve(" dependencies.txt" )
116
134
Files .deleteIfExists(dependenciesPath)
117
135
val script =
@@ -137,6 +155,22 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
137
155
| // By enabling the SemanticDB Java agent on the Zinc daemon process, we manage
138
156
| // to configure Zinc to use the semanticdb-javac compiler plugin for Java compilation.
139
157
| tasks.withType(ScalaCompile) {
158
+ |
159
+ | if (scalaCompileOptions.additionalParameters == null) scalaCompileOptions.additionalParameters = []
160
+ | try {
161
+ | def scalaVersion = lsifJavaScalaVersion(project, configurations)
162
+ | def semanticdbVersion = lsifJavaSemanticdbScalacVersions(scalaVersion)
163
+ | def semanticdbScalacDependency ="org.scalameta:semanticdb-scalac_ $$ scalaVersion: $$ semanticdbVersion"
164
+ | def semanticdbScalac = project.configurations.detachedConfiguration(dependencies.create(semanticdbScalacDependency)).files[0]
165
+ | scalaCompileOptions.additionalParameters << '-Xplugin:' + semanticdbScalac
166
+ | scalaCompileOptions.additionalParameters << '-P:semanticdb:sourceroot: $sourceroot'
167
+ | scalaCompileOptions.additionalParameters << '-P:semanticdb:targetroot: $targetroot'
168
+ | scalaCompileOptions.additionalParameters << '-P:semanticdb:exclude:(src/play/twirl|src/play/routes)' // Ignore autogenerated Playframework files
169
+ | scalaCompileOptions.additionalParameters << '-P:semanticdb:failures:warning'
170
+ | scalaCompileOptions.additionalParameters << '-Xplugin-require:semanticdb'
171
+ | } catch (Exception e) {
172
+ | ${handleExceptionGroovySyntax()}
173
+ | }
140
174
| scalaCompileOptions.forkOptions.with {
141
175
| jvmArgs << '-javaagent: $agentpath'
142
176
| jvmArgs << '-Dsemanticdb.pluginpath= $pluginpath'
@@ -180,11 +214,43 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
180
214
| }
181
215
| }
182
216
|}
183
- """ .stripMargin
217
+ |def lsifJavaSemanticdbScalacVersions(scalaVersion) {
218
+ | ${semanticdbScalacGroovySyntax()}[scalaVersion]
219
+ |}
220
+ |def lsifJavaScalaVersion(project, configurations) {
221
+ | for (config in configurations) {
222
+ | if (config.name == "zinc") continue
223
+ | if (config.canBeResolved) {
224
+ | def artifacts = config.incoming.artifactView { view ->
225
+ | view.lenient = true
226
+ | }.artifacts
227
+ | for (artifact in artifacts) {
228
+ | def id = artifact.id.componentIdentifier
229
+ | if (id instanceof org.gradle.api.artifacts.component.ModuleComponentIdentifier
230
+ | && id.group == "org.scala-lang"
231
+ | && id.module == "scala-library") {
232
+ | return id.version
233
+ | }
234
+ | }
235
+ | }
236
+ | }
237
+ | return null
238
+ |}
239
+ | """ .stripMargin
184
240
Files .write(
185
241
tmp.resolve(" init-script.gradle" ),
186
242
script.getBytes(StandardCharsets .UTF_8 )
187
243
)
188
244
}
189
245
246
+ def semanticdbScalacGroovySyntax (): String =
247
+ BuildInfo
248
+ .semanticdbScalacVersions
249
+ .removed(
250
+ " 2.12.3"
251
+ ) // Not supported because the last semanticdb-scalac_2.12.3 release doesn't support the option -P:semanticdb:targetroot:PATH.
252
+ .map { case (key, value) =>
253
+ s " ' $key':' $value' "
254
+ }.mkString(" [" , " , " , " ]" )
255
+
190
256
}
0 commit comments