Skip to content

Commit 686acd9

Browse files
authored
Be more graceful about cross-repo navigation error (#660)
1 parent 83cdcdf commit 686acd9

File tree

2 files changed

+55
-37
lines changed

2 files changed

+55
-37
lines changed

Diff for: docs/manual-configuration.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ one of the following files in the SemanticDB _targetroot_ directory (the path in
163163

164164
- `javacopts.txt`: line-separated list of Java compiler options that got passed
165165
to the compiler. For example,
166+
166167
```sh
167168
$ cat $TARGETROOT/javacopts.txt
168169
-Xlint
@@ -172,22 +173,25 @@ one of the following files in the SemanticDB _targetroot_ directory (the path in
172173
/path/to/classes/directory
173174
/path/to/com/example/Main.java
174175
```
176+
175177
The `javacopts.txt` file format can only be used if the jars on the dependency
176178
classpath have sibling `.pom` files. In some build tools like Gradle, the POM
177179
files are not siblings to the jars on the classpath so the `javacopts.txt`
178180
format cannot be used.
181+
179182
- `dependencies.txt`: a tab-separated values file where the columns are: group
180183
ID, artifact ID, version and jar path. For example,
184+
181185
```sh
182186
$ cat $TARGETROOT/dependencies.txt
183187
junit junit 4.13.2 /path/to/junit.jar
184188
org.hamcrest hamcrest-core 1.3 /path/to/hamcrest-core.jar
185189
```
190+
186191
The `dependencies.txt` format is used by scip-java to map symbols such as
187-
`org.junit.Assert` to Maven co-ordinates like `junit:junit:4.13.2`. As long as
192+
`org.junit.Assert` to Maven coordinates like `junit:junit:4.13.2`. As long as
188193
your Sourcegraph instance has another repository that defines that symbol, the
189-
cross-repository navigation should succeed. Only jar files are supported at
190-
the moment, classes directories are ignored.
194+
cross-repository navigation should succeed.
191195

192196
Cross-repository navigation is a feature that allows "goto definition" and "find
193197
references" to show results from multiple repositories.

Diff for: semanticdb-gradle-plugin/src/main/scala/SemanticdbGradlePlugin.scala

+48-34
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.nio.file.Paths
55
import java.{util => ju}
66

77
import scala.jdk.CollectionConverters._
8-
import scala.util.control.NonFatal
8+
import scala.util._
99

1010
import com.sourcegraph.scip_java.BuildInfo
1111
import org.gradle.api.DefaultTask
@@ -416,42 +416,56 @@ class WriteDependencies extends DefaultTask {
416416
// List the project itself as a dependency so that we can assign project name/version to symbols that are defined in this project.
417417
// The code below is roughly equivalent to the following with Groovy:
418418
// deps += "$publication.groupId $publication.artifactId $publication.version $sourceSets.main.output.classesDirectory"
419-
try {
420-
for {
421-
classesDirectory <- project
422-
.getExtensions()
423-
.getByType(classOf[SourceSetContainer])
424-
.getByName("main")
425-
.getOutput()
426-
.getClassesDirs()
427-
.getFiles()
428-
.asScala
429-
.toList
430-
.map(_.getAbsolutePath())
431-
.sorted
432-
.take(1)
433-
publication <-
419+
420+
Try(
421+
project
422+
.getExtensions()
423+
.findByType(classOf[PublishingExtension])
424+
.getPublications()
425+
.withType(classOf[MavenPublication])
426+
.asScala
427+
) match {
428+
case Failure(exception) =>
429+
System
430+
.err
431+
.println(
432+
s"""
433+
|Failed to extract Maven publication from the project `${project
434+
.getName()}`.
435+
|This will not prevent a SCIP index from being created, but the symbols
436+
|extracted from this project won't be available for cross-repository navigation,
437+
|as this project doesn't define any Maven coordinates by which it can be referred back to.
438+
|See here for more details: https://sourcegraph.github.io/scip-java/docs/manual-configuration.html#step-5-optional-enable-cross-repository-navigation
439+
|Here's the raw error message:
440+
| "${exception.getMessage()}"
441+
|Continuing without cross-repository support.
442+
""".stripMargin.trim()
443+
)
444+
445+
case Success(publications) =>
446+
publications.foreach { publication =>
434447
project
435448
.getExtensions()
436-
.findByType(classOf[PublishingExtension])
437-
.getPublications()
438-
.withType(classOf[MavenPublication])
449+
.getByType(classOf[SourceSetContainer])
450+
.getByName("main")
451+
.getOutput()
452+
.getClassesDirs()
453+
.getFiles()
439454
.asScala
440-
} {
441-
deps +=
442-
List(
443-
publication.getGroupId(),
444-
publication.getArtifactId(),
445-
publication.getVersion(),
446-
classesDirectory
447-
).mkString("\t")
448-
}
449-
} catch {
450-
case NonFatal(ex) =>
451-
println(
452-
s"Failed to extract publication from project ${project.getName()}"
453-
)
454-
ex.printStackTrace()
455+
.toList
456+
.map(_.getAbsolutePath())
457+
.sorted
458+
.take(1)
459+
.foreach { classesDirectory =>
460+
deps +=
461+
List(
462+
publication.getGroupId(),
463+
publication.getArtifactId(),
464+
publication.getVersion(),
465+
classesDirectory
466+
).mkString("\t")
467+
}
468+
}
455469
}
456470

457471
project

0 commit comments

Comments
 (0)