Skip to content

Commit 8a5a263

Browse files
authored
Merge pull request #314 from olafurpg/xrepo-docs
2 parents 450d402 + 5dfd2fb commit 8a5a263

File tree

5 files changed

+61
-10
lines changed

5 files changed

+61
-10
lines changed

docs/manual-configuration.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ javac -classpath semanticdb-javac.jar MyApplication.java
3838
If you're using Gradle.
3939

4040
```groovy
41-
compileOnly group: 'com.sourcegraph', name: 'semanticdb-javac', version: '@STABLE_VERSION@'
41+
// Option 1: if you are not using annotation processors
42+
compileOnly 'com.sourcegraph:semanticdb-javac:@STABLE_VERSION@'
43+
// Option 2: if you are using annotation processors
44+
annotationProcessor 'com.sourcegraph:semanticdb-javac:@STABLE_VERSION@'
4245
```
4346

4447
If you're using Maven.

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,17 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
7878
buildCommand +=
7979
s"-Porg.gradle.java.installations.paths=${toolchains.paths()}"
8080
}
81-
buildCommand ++= index.finalBuildCommand(List("clean", "compileTestJava"))
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+
)
8292
buildCommand += lsifJavaDependencies
8393

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

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,18 @@ public static void build(
135135
switch (previousOption) {
136136
case "-processorpath":
137137
case "-processor-path":
138+
case "-cp":
138139
case "-classpath":
139140
case "-class-path":
140141
isProcessorpathUpdated = true;
141142
newOptions.add(PLUGINPATH + File.pathSeparator + option);
142143
break;
144+
case "-Xlint":
145+
break;
143146
default:
147+
if (option.startsWith("-Xplugin:ErrorProne")) {
148+
break;
149+
}
144150
newOptions.add(option);
145151
break;
146152
}
@@ -155,13 +161,19 @@ public static void build(
155161
"-Xplugin:semanticdb -sourceroot:%s -targetroot:%s", SOURCEROOT, TARGETROOT));
156162

157163
if (DEBUGPATH != null) {
158-
try (PrintStream fos =
159-
new PrintStream(
160-
Files.newOutputStream(
161-
Paths.get(DEBUGPATH), StandardOpenOption.APPEND, StandardOpenOption.CREATE))) {
162-
fos.println("Java Home: " + System.getProperty("java.home"));
163-
fos.println("Old Options: " + arguments);
164-
fos.println("New Options: " + newOptions);
164+
ArrayList<String> debuglines = new ArrayList<>();
165+
debuglines.add("============== Java Home: " + System.getProperty("java.home"));
166+
debuglines.add("============== Old Options");
167+
debuglines.addAll(arguments);
168+
debuglines.add("============== New Options");
169+
debuglines.addAll(newOptions);
170+
171+
try {
172+
Files.write(
173+
Paths.get(DEBUGPATH),
174+
debuglines,
175+
StandardOpenOption.CREATE,
176+
StandardOpenOption.APPEND);
165177
} catch (IOException e) {
166178
}
167179
}

tests/buildTools/src/test/scala/tests/BaseBuildToolSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ abstract class BaseBuildToolSuite extends MopedSuite(LsifJava.app) {
7676
if (semanticdbFiles.length != expectedSemanticdbFiles) {
7777
fail(
7878
s"Expected $expectedSemanticdbFiles SemanticDB file(s) to be generated.",
79-
clues(semanticdbFiles)
79+
clues(semanticdbFiles, app.capturedOutput)
8080
)
8181
}
8282
if (expectedPackages.nonEmpty) {

tests/buildTools/src/test/scala/tests/GradleBuildToolSuite.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,30 @@ class GradleBuildToolSuite extends BaseBuildToolSuite {
207207
2, // Two files because `conf/routes` generates a Java file.
208208
initCommand = gradleVersion("6.8")
209209
)
210+
211+
checkBuild(
212+
"checkerframework",
213+
"""|/build.gradle
214+
|plugins {
215+
| id 'java'
216+
| id 'org.checkerframework' version '0.5.24'
217+
|}
218+
|repositories {
219+
| mavenCentral()
220+
|}
221+
|java {
222+
| toolchain {
223+
| languageVersion = JavaLanguageVersion.of(8)
224+
| }
225+
|}
226+
|/src/main/java/foo/Example.java
227+
|package foo;
228+
|public class Example {}
229+
|/src/test/java/foo/ExampleSuite.java
230+
|package foo;
231+
|public class ExampleSuite {}
232+
|""".stripMargin,
233+
2,
234+
initCommand = gradleVersion("6.8.3")
235+
)
210236
}

0 commit comments

Comments
 (0)