Skip to content

Commit b745d90

Browse files
authored
Merge pull request #315 from olafurpg/scala-gradle
Properly fix issue with checkerframework Gradle plugin.
2 parents 8a5a263 + b74414d commit b745d90

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

lsif-java/src/main/scala/com/sourcegraph/lsif_java/buildtools/GradleBuildTool.scala

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,7 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
7878
buildCommand +=
7979
s"-Porg.gradle.java.installations.paths=${toolchains.paths()}"
8080
}
81-
buildCommand ++=
82-
index.finalBuildCommand(
83-
List(
84-
// Disable the checkerframework plugin because it updates the processorpath
85-
// in a way that causes the error "plug-in not found: semanticdb".
86-
// Details: https://github.com/kelloggm/checkerframework-gradle-plugin/blob/76d1926ae22144b082dfcfde1abe625750469398/src/main/groovy/org/checkerframework/gradle/plugin/CheckerFrameworkPlugin.groovy#L374-L376
87-
"-PskipCheckerFramework",
88-
"clean",
89-
"compileTestJava"
90-
)
91-
)
81+
buildCommand ++= index.finalBuildCommand(List("clean", "compileTestJava"))
9282
buildCommand += lsifJavaDependencies
9383

9484
val result = index.process(buildCommand, env = Map("TERM" -> "dumb"))

semanticdb-agent/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbAgent.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ public static void premain(String agentArgs, Instrumentation inst) {
4949
named("getCompileClasspath"),
5050
DefaultJvmLanguageCompileSpecAdvice.class.getName()))
5151
.installOn(inst);
52+
new AgentBuilder.Default()
53+
.disableClassFormatChanges()
54+
.type(
55+
named("org.gradle.api.internal.tasks.compile.DefaultJavaCompileSpec")
56+
.or(named("tests.GradleDefaultJavaCompileSpec")))
57+
.transform(
58+
new AgentBuilder.Transformer.ForAdvice()
59+
.advice(
60+
named("getAnnotationProcessorPath"),
61+
DefaultJavaCompileSpecAdvice.class.getName()))
62+
.installOn(inst);
5263
new AgentBuilder.Default()
5364
.type(
5465
named("org.gradle.api.internal.tasks.compile.JavaCompilerArgumentsBuilder")
@@ -92,6 +103,23 @@ public static void getClasspath(
92103
}
93104
}
94105

106+
@SuppressWarnings("all")
107+
public static class DefaultJavaCompileSpecAdvice {
108+
@Advice.OnMethodExit
109+
public static void getAnnotationProcessorPath(
110+
@Advice.Return(readOnly = false, typing = DYNAMIC) List<File> classpath) {
111+
if (classpath == null) return;
112+
String PLUGINPATH = System.getProperty("semanticdb.pluginpath");
113+
if (PLUGINPATH == null) throw new NoSuchElementException("-Dsemanticdb.pluginpath");
114+
File semanticdbJar = new File(PLUGINPATH);
115+
if (!classpath.contains(semanticdbJar)) {
116+
List<File> newClasspath = new ArrayList<>(classpath);
117+
newClasspath.add(semanticdbJar);
118+
classpath = newClasspath;
119+
}
120+
}
121+
}
122+
95123
@SuppressWarnings("all")
96124
public static class JavaCompilerArgumentsBuilderAdvice {
97125

0 commit comments

Comments
 (0)