diff --git a/build.sbt b/build.sbt index 8b84a3e0..2d5d4952 100644 --- a/build.sbt +++ b/build.sbt @@ -27,7 +27,7 @@ lazy val V = val testcontainers = "0.39.3" val requests = "0.6.5" val minimalMillVersion = "0.10.0" - val millScipVersion = "0.3.5" + val millScipVersion = "0.3.6" val kotlinGradlePlugin = "1.5.31" } diff --git a/docs/getting-started.md b/docs/getting-started.md index a4b499a8..5d9ae9cd 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -26,7 +26,7 @@ after we renamed the "Docker container" section into "Docker image". --> Use the `sourcegraph/scip-java` Docker image to run `scip-java`. ```sh -$ docker run -v $(pwd):/home/gradle --env JVM_VERSION=17 sourcegraph/scip-java:latest scip-java index +$ docker run -v $(pwd):/sources --env JVM_VERSION=17 sourcegraph/scip-java:latest scip-java index $ src code-intel upload # (optional) upload index to Sourcegraph ``` @@ -47,13 +47,13 @@ Use the following commands to use a different JVM version: ```sh # Java 8 -docker run -v $(pwd):/home/gradle --env JVM_VERSION=8 sourcegraph/scip-java:latest scip-java index +docker run -v $(pwd):/sources --env JVM_VERSION=8 sourcegraph/scip-java:latest scip-java index # Java 11 -docker run -v $(pwd):/home/gradle --env JVM_VERSION=11 sourcegraph/scip-java:latest scip-java index +docker run -v $(pwd):/sources --env JVM_VERSION=11 sourcegraph/scip-java:latest scip-java index # Java 17 (default) -docker run -v $(pwd):/home/gradle --env JVM_VERSION=17 sourcegraph/scip-java:latest scip-java index +docker run -v $(pwd):/sources --env JVM_VERSION=17 sourcegraph/scip-java:latest scip-java index ``` ### Java launcher diff --git a/docs/manual-configuration.md b/docs/manual-configuration.md index a9161608..3b1c1c03 100644 --- a/docs/manual-configuration.md +++ b/docs/manual-configuration.md @@ -163,6 +163,7 @@ one of the following files in the SemanticDB _targetroot_ directory (the path in - `javacopts.txt`: line-separated list of Java compiler options that got passed to the compiler. For example, + ```sh $ cat $TARGETROOT/javacopts.txt -Xlint @@ -172,22 +173,25 @@ one of the following files in the SemanticDB _targetroot_ directory (the path in /path/to/classes/directory /path/to/com/example/Main.java ``` + The `javacopts.txt` file format can only be used if the jars on the dependency classpath have sibling `.pom` files. In some build tools like Gradle, the POM files are not siblings to the jars on the classpath so the `javacopts.txt` format cannot be used. + - `dependencies.txt`: a tab-separated values file where the columns are: group ID, artifact ID, version and jar path. For example, + ```sh $ cat $TARGETROOT/dependencies.txt junit junit 4.13.2 /path/to/junit.jar org.hamcrest hamcrest-core 1.3 /path/to/hamcrest-core.jar ``` + The `dependencies.txt` format is used by scip-java to map symbols such as - `org.junit.Assert` to Maven co-ordinates like `junit:junit:4.13.2`. As long as + `org.junit.Assert` to Maven coordinates like `junit:junit:4.13.2`. As long as your Sourcegraph instance has another repository that defines that symbol, the - cross-repository navigation should succeed. Only jar files are supported at - the moment, classes directories are ignored. + cross-repository navigation should succeed. Cross-repository navigation is a feature that allows "goto definition" and "find references" to show results from multiple repositories. diff --git a/project/build.properties b/project/build.properties index 52413ab7..e8a1e246 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.3 +sbt.version=1.9.7 diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/SbtBuildTool.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/SbtBuildTool.scala index 8ac28d71..4633bc92 100644 --- a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/SbtBuildTool.scala +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/SbtBuildTool.scala @@ -43,15 +43,19 @@ class SbtBuildTool(index: IndexCommand) extends BuildTool("sbt", index) { private def unconditionallyGenerateScip(): Int = Using.resource(sourcegraphSbtPluginFile()) { _ => + val buildCommand = index.finalBuildCommand(List("sourcegraphScip")) + val sourcegraphScip = index - .process(List("sbt", "sourcegraphEnable", "sourcegraphScip")) + .process(List("sbt", "sourcegraphEnable") ++ buildCommand) + val inputDump = index .workingDirectory .resolve("target") .resolve("sbt-sourcegraph") .resolve("index.scip") + if (sourcegraphScip.exitCode == 0 && Files.isRegularFile(inputDump)) { - val outputDump = index.workingDirectory.resolve("index.scip") + val outputDump = index.workingDirectory.resolve(index.output) Files.copy(inputDump, outputDump, StandardCopyOption.REPLACE_EXISTING) index.app.info(outputDump.toString) } diff --git a/semanticdb-gradle-plugin/src/main/scala/SemanticdbGradlePlugin.scala b/semanticdb-gradle-plugin/src/main/scala/SemanticdbGradlePlugin.scala index 6cc0924f..d11cf79e 100644 --- a/semanticdb-gradle-plugin/src/main/scala/SemanticdbGradlePlugin.scala +++ b/semanticdb-gradle-plugin/src/main/scala/SemanticdbGradlePlugin.scala @@ -5,7 +5,7 @@ import java.nio.file.Paths import java.{util => ju} import scala.jdk.CollectionConverters._ -import scala.util.control.NonFatal +import scala.util._ import com.sourcegraph.scip_java.BuildInfo import org.gradle.api.DefaultTask @@ -416,42 +416,56 @@ class WriteDependencies extends DefaultTask { // List the project itself as a dependency so that we can assign project name/version to symbols that are defined in this project. // The code below is roughly equivalent to the following with Groovy: // deps += "$publication.groupId $publication.artifactId $publication.version $sourceSets.main.output.classesDirectory" - try { - for { - classesDirectory <- project - .getExtensions() - .getByType(classOf[SourceSetContainer]) - .getByName("main") - .getOutput() - .getClassesDirs() - .getFiles() - .asScala - .toList - .map(_.getAbsolutePath()) - .sorted - .take(1) - publication <- + + Try( + project + .getExtensions() + .findByType(classOf[PublishingExtension]) + .getPublications() + .withType(classOf[MavenPublication]) + .asScala + ) match { + case Failure(exception) => + System + .err + .println( + s""" + |Failed to extract Maven publication from the project `${project + .getName()}`. + |This will not prevent a SCIP index from being created, but the symbols + |extracted from this project won't be available for cross-repository navigation, + |as this project doesn't define any Maven coordinates by which it can be referred back to. + |See here for more details: https://sourcegraph.github.io/scip-java/docs/manual-configuration.html#step-5-optional-enable-cross-repository-navigation + |Here's the raw error message: + | "${exception.getMessage()}" + |Continuing without cross-repository support. + """.stripMargin.trim() + ) + + case Success(publications) => + publications.foreach { publication => project .getExtensions() - .findByType(classOf[PublishingExtension]) - .getPublications() - .withType(classOf[MavenPublication]) + .getByType(classOf[SourceSetContainer]) + .getByName("main") + .getOutput() + .getClassesDirs() + .getFiles() .asScala - } { - deps += - List( - publication.getGroupId(), - publication.getArtifactId(), - publication.getVersion(), - classesDirectory - ).mkString("\t") - } - } catch { - case NonFatal(ex) => - println( - s"Failed to extract publication from project ${project.getName()}" - ) - ex.printStackTrace() + .toList + .map(_.getAbsolutePath()) + .sorted + .take(1) + .foreach { classesDirectory => + deps += + List( + publication.getGroupId(), + publication.getArtifactId(), + publication.getVersion(), + classesDirectory + ).mkString("\t") + } + } } project diff --git a/tests/buildTools/src/test/scala/tests/SbtBuildToolSuite.scala b/tests/buildTools/src/test/scala/tests/SbtBuildToolSuite.scala index 9eea1f6f..2f97a72f 100644 --- a/tests/buildTools/src/test/scala/tests/SbtBuildToolSuite.scala +++ b/tests/buildTools/src/test/scala/tests/SbtBuildToolSuite.scala @@ -1,15 +1,18 @@ package tests -abstract class SbtBuildToolSuite(sbtVersion: String) +abstract class SbtBuildToolSuite(val sbtVersion: String) extends BaseBuildToolSuite { - List("2.11.9", "2.12.18", "2.13.11", "3.3.0").foreach { scalaVersion => + val scala2Versions = List("2.11.9", "2.12.18", "2.13.11") + val scala3Versions = List("3.3.1") + + (scala2Versions ++ scala3Versions).foreach { scalaVersion => checkBuild( s"basic-sbt=$sbtVersion-scala=$scalaVersion", s"""|/build.sbt |scalaVersion := "$scalaVersion" |libraryDependencies += "junit" % "junit" % "4.13.2" |/project/build.properties - |sbt.version=1.5.2 + |sbt.version=$sbtVersion |/src/main/java/example/ExampleJava.java |package example; |import org.junit.Assert; @@ -29,8 +32,27 @@ abstract class SbtBuildToolSuite(sbtVersion: String) targetRoot = Some("target") ) } - } -class Sbt_1_BuildToolSuite extends SbtBuildToolSuite("1.5.2") -class Sbt_013_BuildToolSuite extends SbtBuildToolSuite("0.13.17") +class Sbt_1_BuildToolSuite extends SbtBuildToolSuite("1.5.2") { + checkBuild( + s"custom-sbt-command=$sbtVersion", + s"""|/build.sbt + |lazy val bla = project.in(file("bla")) + |lazy val blaJS = project.in(file("bla-js")).enablePlugins(ScalaJSPlugin) + |/project/plugins.sbt + |addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.14.0") + |/project/build.properties + |sbt.version=$sbtVersion + |/bla/src/main/scala/example/ExampleScala.scala + |package example + |class ExampleScala() + |/bla-js/src/main/scala/example/ExampleScala.scala + |package example + |class ExampleScala!!!() // this file is intentionally broken + |""".stripMargin, + expectedSemanticdbFiles = 1, + extraArguments = List("--", "bla/compile"), + targetRoot = Some("bla/target") + ) +} diff --git a/website/project/build.properties b/website/project/build.properties index 52413ab7..e8a1e246 100644 --- a/website/project/build.properties +++ b/website/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.3 +sbt.version=1.9.7