Skip to content

Commit 90bb5c1

Browse files
committed
Drop SemanticdbAgent, PackageHub, and other dead code paths
- Delete the semanticdb-agent module and its in-Gradle fallback (the ByteBuddy advice that injected -Xplugin:semanticdb when the normal compileOnly attachment didn't reach javac). - Add a post-build diagnostic in GradleBuildTool that surfaces a clear actionable error when Gradle finishes successfully but produces no .semanticdb files (the case the agent used to silently rescue). - Delete dead Gradle toolchain code: GradleJavaCompiler, GradleJavaToolchains.fromWorkspace, paths(), executableJavacPath(), and the printDebugLogs helper they fed. - Drop PackageHub support: hidden --packagehub flag on the CLI, the HTTP POST plumbing, and the com.lihaoyi:requests dependency. - Drop the broken nativeImageProfiled sbt command (no GraalVM plugin). - Drop the orphan bin/packagehub.sh script. - Inline CommentSyntax into ScipPrinters (4-entry map, no codec needed).
1 parent 1f339b8 commit 90bb5c1

22 files changed

Lines changed: 176 additions & 931 deletions

bin/packagehub.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

build.sbt

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ lazy val V =
1515
val gradle = "7.0"
1616
val scala213 = "2.13.13"
1717
val scalameta = "4.9.3"
18-
val requests = "0.8.0"
1918
val kotlinVersion = "2.2.0"
2019
val kotest = "4.6.3"
2120
val kctfork = "0.7.1"
@@ -86,25 +85,6 @@ lazy val semanticdbShared = project
8685
libraryDependencies += "com.google.protobuf" % "protobuf-java" % V.protobuf
8786
)
8887

89-
lazy val agent = project
90-
.in(file("semanticdb-agent"))
91-
.settings(
92-
fatjarPackageSettings,
93-
javaOnlySettings,
94-
moduleName := "semanticdb-agent",
95-
libraryDependencies ++=
96-
List(
97-
"net.bytebuddy" % "byte-buddy" % "1.15.11",
98-
"net.bytebuddy" % "byte-buddy-agent" % "1.15.11"
99-
),
100-
Compile / packageBin / packageOptions +=
101-
Package.ManifestAttributes(
102-
"Agent-Class" -> "com.sourcegraph.semanticdb_javac.SemanticdbAgent",
103-
"Can-Redefine-Classes" -> "true",
104-
"Can-Retransform-Classes" -> "true",
105-
"Premain-Class" -> "com.sourcegraph.semanticdb_javac.SemanticdbAgent"
106-
)
107-
)
10888
lazy val gradlePlugin = project
10989
.in(file("semanticdb-gradle-plugin"))
11090
.settings(
@@ -243,7 +223,6 @@ lazy val cli = project
243223
libraryDependencies ++=
244224
List(
245225
"org.scala-lang.modules" %% "scala-xml" % V.scalaXml,
246-
"com.lihaoyi" %% "requests" % V.requests,
247226
"org.scalameta" %% "moped" % V.moped,
248227
"org.jetbrains.kotlin" % "kotlin-compiler-embeddable" % V.kotlinVersion,
249228
"org.jetbrains.kotlin" % "kotlin-scripting-common" % V.kotlinVersion,
@@ -267,10 +246,6 @@ lazy val cli = project
267246
(javacPlugin / Compile / Keys.`package`).value,
268247
"semanticdb-plugin.jar"
269248
)
270-
addJar(
271-
(agent / Compile / Keys.`package`).value,
272-
"semanticdb-agent.jar"
273-
)
274249
addJar((gradlePlugin / Compile / assembly).value, "gradle-plugin.jar")
275250
addJar(
276251
(semanticdbKotlinc / Compile / Keys.`package`).value,
@@ -532,16 +507,6 @@ lazy val semanticdbKotlincMinimized = project
532507
.value
533508
)
534509

535-
commands +=
536-
Command.command("nativeImageProfiled") { s =>
537-
val targetroot =
538-
file("tests/minimized/.j11/target/scala-2.13/meta").absolutePath
539-
val output = Files.createTempFile("scip-java", "index.scip")
540-
"minimized/compile" ::
541-
s"""nativeImageRunAgent " index-semanticdb --output=$output $targetroot"""" ::
542-
"nativeImage" :: s
543-
}
544-
545510
def minimizedSourceDirectory =
546511
file("tests/minimized/src/main/java").getAbsoluteFile
547512

@@ -577,7 +542,7 @@ lazy val minimizedSettings = List[Def.Setting[_]](
577542
lazy val minimized = project
578543
.in(file("tests/minimized/.j11"))
579544
.settings(minimizedSettings, javaOnlySettings)
580-
.dependsOn(agent, javacPlugin)
545+
.dependsOn(javacPlugin)
581546
.disablePlugins(JavaFormatterPlugin)
582547

583548
def javacModuleOptions = List(
@@ -617,15 +582,6 @@ lazy val buildTools = project
617582
.in(file("tests/buildTools"))
618583
.settings(
619584
testSettings,
620-
(Test / javaOptions) ++=
621-
List(
622-
s"-javaagent:${(agent / Compile / Keys.`package`).value}",
623-
s"-Dsemanticdb.pluginpath=${(javacPlugin / Compile / Keys.`package`)
624-
.value}",
625-
s"-Dsemanticdb.sourceroot=${(ThisBuild / baseDirectory).value}",
626-
s"-Dsemanticdb.targetroot=${(agent / Compile / target).value /
627-
"semanticdb-targetroot"}"
628-
),
629585
Test / envVars ++=
630586
Map(
631587
"SCIP_JAVA_CLI" -> ((cli / pack).value / "bin" / "scip-java").toString
@@ -635,7 +591,7 @@ lazy val buildTools = project
635591
// everything worse
636592
Test / testForkedParallel := !sys.env.contains("CI")
637593
)
638-
.dependsOn(agent, unit)
594+
.dependsOn(unit)
639595

640596
lazy val snapshots = project
641597
.in(file("tests/snapshots"))

scip-java/src/main/scala/com/sourcegraph/scip_java/Embedded.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ object Embedded {
2121
"gradle-plugin.jar"
2222
)
2323

24-
def agentJar(tmpDir: Path): Path = copyFile(tmpDir, "semanticdb-agent.jar")
25-
2624
def semanticdbKotlincJar(tmpDir: Path): Path = copyFile(
2725
tmpDir,
2826
"semanticdb-kotlinc.jar"

scip-java/src/main/scala/com/sourcegraph/scip_java/ScipPrinters.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import scala.collection.mutable
44
import scala.jdk.CollectionConverters.CollectionHasAsScala
55
import scala.math.Ordering.Implicits.seqOrdering
66

7-
import com.sourcegraph.scip_java.commands.CommentSyntax
87
import moped.reporters.Input
98
import moped.reporters.Position
109
import org.scip_code.scip.Document
@@ -20,11 +19,12 @@ object ScipPrinters {
2019
*/
2120
val sourceIndent = " "
2221

23-
def printTextDocument(
24-
doc: Document,
25-
text: String,
26-
comments: CommentSyntax = CommentSyntax.default
27-
): String = {
22+
// Snapshot comment prefix for each rendered file extension. Languages not
23+
// listed fall back to `//`.
24+
private val commentSyntaxByExtension: Map[String, String] =
25+
Map("py" -> "#", "sql" -> "--", "yaml" -> "#", "yml" -> "#")
26+
27+
def printTextDocument(doc: Document, text: String): String = {
2828
val out = new mutable.StringBuilder()
2929
val occurrencesByLine = doc
3030
.getOccurrencesList
@@ -57,7 +57,7 @@ object ScipPrinters {
5757
)
5858
.toMap
5959
val extension = doc.getRelativePath.split("\\.").lastOption.getOrElse("")
60-
val commentSyntax = comments.extensionSyntax(extension)
60+
val commentSyntax = commentSyntaxByExtension.getOrElse(extension, "//")
6161
val input = Input.filename(doc.getRelativePath, text)
6262

6363
// Collect enclosing ranges from all occurrences, grouped by start/end line.

scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/BuildTool.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ object BuildTool {
5757
.copy(
5858
output = index.finalOutput,
5959
targetroot = List(targetroot),
60-
packagehub = index.packagehub,
6160
app = index.app
6261
)
6362
.run()

scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/ClasspathEntry.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ case class ClasspathEntry(
2323
artifactId: String,
2424
version: String
2525
) {
26-
def toPackageHubId: String = s"maven:$groupId:$artifactId:$version"
26+
def mavenCoordinate: String = s"maven:$groupId:$artifactId:$version"
2727
def toPackageInformation: MavenPackage =
2828
new MavenPackage(entry, groupId, artifactId, version)
2929
}

scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala

Lines changed: 92 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import java.nio.charset.StandardCharsets
44
import java.nio.file._
55

66
import scala.collection.mutable.ListBuffer
7+
import scala.jdk.CollectionConverters._
78
import scala.util.Properties
9+
import scala.util.Try
810

911
import com.sourcegraph.io.DeleteVisitor
1012
import com.sourcegraph.scip_java.Embedded
@@ -26,13 +28,98 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
2628
}
2729

2830
override def generateScip(): Int = {
29-
BuildTool.generateScipFromTargetroot(
30-
generateSemanticdb(),
31-
targetroot,
32-
index
33-
)
31+
val gradleResult = generateSemanticdb()
32+
if (gradleResult.exitCode == 0) {
33+
reportMissingSemanticdbOutput()
34+
}
35+
BuildTool.generateScipFromTargetroot(gradleResult, targetroot, index)
36+
}
37+
38+
/**
39+
* Diagnose the case where Gradle finished successfully but our SemanticDB
40+
* compiler plugin never produced any `.semanticdb` files. This used to be
41+
* silently rescued by a `-javaagent` fallback; now it surfaces as a clear
42+
* error pointing at the two known causes.
43+
*/
44+
private def reportMissingSemanticdbOutput(): Unit = {
45+
val semanticdbFileCount = countSemanticdbFiles(targetroot)
46+
if (semanticdbFileCount > 0)
47+
return
48+
val classFileCount = countClassFiles(index.workingDirectory)
49+
if (classFileCount == 0)
50+
// Project has no compiled JVM output — nothing to index, stay quiet.
51+
return
52+
index
53+
.app
54+
.reporter
55+
.error(
56+
s"""scip-java: Gradle finished successfully but produced no SemanticDB output.
57+
|Compiled $classFileCount .class file(s); expected at least one .semanticdb file in $targetroot.
58+
|
59+
|This means our SemanticDB compiler plugin was not attached to one or more JavaCompile tasks. Two known causes:
60+
|
61+
| 1. The 'compileOnly' configuration was already resolved before our init script ran.
62+
| Check the Gradle output above for warnings of the form:
63+
| "scip-java: failed to attach SemanticDB compiler plugin to project '<name>'"
64+
| Workaround: apply the SemanticDB plugin earlier (e.g. via a settings plugin),
65+
| or restructure the build so that 'compileOnly' is not resolved at evaluation time.
66+
|
67+
| 2. Another Gradle plugin is replacing the compiler arguments we add (rather than appending).
68+
| Verify with: ./gradlew compileJava --info | grep -- '-Xplugin:semanticdb'
69+
| If '-Xplugin:semanticdb' is missing from the printed javac command, another plugin
70+
| is overwriting JavaCompile.options.compilerArgs.
71+
|""".stripMargin
72+
)
73+
}
74+
75+
private def countSemanticdbFiles(dir: Path): Long = {
76+
if (!Files.isDirectory(dir))
77+
return 0L
78+
Try {
79+
val stream = Files.walk(dir)
80+
try stream
81+
.filter(p =>
82+
Files.isRegularFile(p) && p.getFileName.toString.endsWith(".semanticdb")
83+
)
84+
.count()
85+
finally stream.close()
86+
}.getOrElse(0L)
3487
}
3588

89+
private def countClassFiles(workingDirectory: Path): Long = {
90+
// Gradle places compiled classes under <project>/build/classes/**. Walk
91+
// every `build/classes` directory we can find (top-level + immediate
92+
// subprojects) and count `.class` files. Bounded so this stays cheap even
93+
// on large multi-project builds.
94+
val rootBuildClasses = workingDirectory.resolve("build").resolve("classes")
95+
val subprojectBuildClasses = Try {
96+
val stream = Files.list(workingDirectory)
97+
try stream
98+
.iterator()
99+
.asScala
100+
.filter(Files.isDirectory(_))
101+
.map(_.resolve("build").resolve("classes"))
102+
.toList
103+
finally stream.close()
104+
}.getOrElse(Nil)
105+
(rootBuildClasses :: subprojectBuildClasses)
106+
.filter(Files.isDirectory(_))
107+
.iterator
108+
.map(countClassFilesIn)
109+
.sum
110+
}
111+
112+
private def countClassFilesIn(dir: Path): Long =
113+
Try {
114+
val stream = Files.walk(dir)
115+
try stream
116+
.filter(p =>
117+
Files.isRegularFile(p) && p.getFileName.toString.endsWith(".class")
118+
)
119+
.count()
120+
finally stream.close()
121+
}.getOrElse(0L)
122+
36123
def targetroot: Path = index.finalTargetroot(defaultTargetroot)
37124

38125
private def defaultTargetroot: Path = Paths.get(
@@ -62,7 +149,6 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
62149
}
63150

64151
private def runCompileCommand(
65-
// toolchains: GradleJavaToolchains,
66152
tmp: Path,
67153
gradleCommand: String
68154
): CommandResult = {
@@ -81,27 +167,14 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
81167

82168
Files.walkFileTree(targetroot, new DeleteVisitor())
83169
val result = index.process(buildCommand, env = Map("TERM" -> "dumb"))
84-
printDebugLogs(tmp)
85170
Embedded
86171
.reportUnexpectedJavacErrors(index.app.reporter, tmp)
87172
.getOrElse(result)
88173
}
89174

90175
private def scipJavaDependencies = "scipJavaDependencies"
91176

92-
private def printDebugLogs(tmp: Path): Unit = {
93-
val path = GradleJavaCompiler.debugPath(tmp)
94-
if (index.verbose && Files.isRegularFile(path)) {
95-
Files
96-
.readAllLines(path)
97-
.forEach { line =>
98-
index.app.info(line)
99-
}
100-
}
101-
}
102-
103177
private def initScript(tmp: Path): Path = {
104-
val agentpath = Embedded.agentJar(tmp)
105178
val pluginpath = Embedded.semanticdbJar(tmp)
106179
val gradlePluginPath = Embedded.gradlePluginJar(tmp)
107180
val semanticdbKotlincPath = Embedded.semanticdbKotlincJar(tmp)
@@ -122,7 +195,6 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
122195
| project.ext["semanticdbTarget"] = "$targetroot"
123196
| project.ext["javacPluginJar"] = "$pluginpath"
124197
| project.ext["dependenciesOut"] = "$dependenciesPath"
125-
| project.ext["javacAgentPath"] = "$agentpath"
126198
| project.ext["semanticdbKotlincJar"] = "$semanticdbKotlincPath"
127199
| apply plugin: SemanticdbGradlePlugin
128200
| }

0 commit comments

Comments
 (0)