diff --git a/.gitignore b/.gitignore index f171a7b..ac89f67 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ out/ .bsp/ .bloop/ index.scip +.vscode/ diff --git a/plugin/src-mill0.10/io/kipp/mill/scip/Scip.scala b/plugin/src-mill0.10/io/kipp/mill/scip/Scip.scala index d86e067..3af5eff 100644 --- a/plugin/src-mill0.10/io/kipp/mill/scip/Scip.scala +++ b/plugin/src-mill0.10/io/kipp/mill/scip/Scip.scala @@ -1,14 +1,9 @@ package io.kipp.mill.scip -import com.sourcegraph.lsif_protocol.LsifToolInfo -import com.sourcegraph.scip_semanticdb.ScipOutputFormat -import com.sourcegraph.scip_semanticdb.ScipSemanticdb -import com.sourcegraph.scip_semanticdb.ScipSemanticdbOptions +import com.sourcegraph.scip_java.ScipJava import mill._ import mill.api.Logger -import mill.api.Result import mill.define.ExternalModule -import mill.define.Task import mill.eval.Evaluator import mill.main.EvaluatorScopt import mill.scalalib.JavaModule @@ -16,7 +11,6 @@ import mill.scalalib.ScalaModule import mill.scalalib.api.ZincWorkerUtil.isScala3 import os.Path -import scala.jdk.CollectionConverters._ import scala.util.Properties object Scip extends ExternalModule { @@ -33,8 +27,6 @@ object Scip extends ExternalModule { val log = T.ctx().log - val outputFormat = validateFormat(output)() - val semanticdbVersion = ScipBuildInfo.semanticDBVersion val modules = computeModules(ev) @@ -231,35 +223,10 @@ object Scip extends ExternalModule { } .map(_.path) - createScip(log, T.dest, T.workspace, classpath, output, outputFormat) + createScip(log, T.dest, T.workspace, classpath, output) T.dest / output } - /** Given an output string, determine that a ScipOutputFormat can be - * determined from it. - * - * @param output - * the given output from the user - * @return - * the parsed output format to be generated - */ - private def validateFormat(output: String): Task[ScipOutputFormat] = T.task { - val format = ScipOutputFormat.fromFilename(output) - if (format == ScipOutputFormat.UNKNOWN) { - val msg = - s"""Detected an unknown output type. You'll want to use one of the following: - | - | - *.lsif - | - *.lsif-protobuf - | - *.scip - | - *.scip.ndjson - |""".stripMargin - Result.Failure(msg) - } else { - format - } - } - /** After all the semanticDB has been produced we can create the SCIP index * from it. * @@ -273,28 +240,16 @@ object Scip extends ExternalModule { * Full classpath of the project to be used for cross-project navigation. * @param output * The name out of the output file - * @param outputFormat - * The format of the output */ private def createScip( log: Logger, dest: Path, workspace: Path, classpath: Seq[Path], - output: String, - outputFormat: ScipOutputFormat + output: String ): Unit = { val scipFile = dest / output - val reporter = new ScipReporter(log) - val toolInfo = - LsifToolInfo - .newBuilder() - .setName( - "scip-java" - ) // Make sure this stays a recognized name by src or it won't index deps. Don't use mill-scip. - .setVersion(ScipBuildInfo.semanticDBJavaVersion) - .build() log.info(s"Creating a ${output} in ${scipFile}") @@ -311,30 +266,10 @@ object Scip extends ExternalModule { createFolders = true ) - val classPathEntries = - classpath.flatMap(project => ClasspathEntry.fromPom(project.toNIO)) - - log.info(s"Including ${classPathEntries.size} classpath entries") - - val options = new ScipSemanticdbOptions( - List(dest).map(_.toNIO).asJava, - scipFile.toNIO, - workspace.toNIO, - reporter, - toolInfo, - "java", - outputFormat, - true, // parallel -- this is fine - classPathEntries - .map(_.toPackageInformation) - .asJava, - "", // BuildKind here is fine being "" - true, // emit inverse releationships, - false, // we want to fail with mill if no documents have been indexed - false // we're only dealing with jar files here - ) - - ScipSemanticdb.run(options) + val exit = ScipJava.app.run(List("index-semanticdb", "--cwd", workspace.toString, "--output", scipFile.toString, dest.toString)) + if (exit != 0) { + sys.error("Failed to create SCIP index") + } } private def computeModules(ev: Evaluator) = diff --git a/plugin/src-mill0.11/io/kipp/mill/scip/Scip.scala b/plugin/src-mill0.11/io/kipp/mill/scip/Scip.scala index 3d9e86e..bfe9ea2 100644 --- a/plugin/src-mill0.11/io/kipp/mill/scip/Scip.scala +++ b/plugin/src-mill0.11/io/kipp/mill/scip/Scip.scala @@ -1,22 +1,16 @@ package io.kipp.mill.scip -import com.sourcegraph.lsif_protocol.LsifToolInfo -import com.sourcegraph.scip_semanticdb.ScipOutputFormat -import com.sourcegraph.scip_semanticdb.ScipSemanticdb -import com.sourcegraph.scip_semanticdb.ScipSemanticdbOptions +import com.sourcegraph.scip_java.ScipJava import mill._ import mill.api.BuildInfo import mill.api.Logger -import mill.api.Result import mill.define.ExternalModule -import mill.define.Task import mill.eval.Evaluator import mill.scalalib.JavaModule import mill.scalalib.ScalaModule import mill.scalalib.api.ZincWorkerUtil.isScala3 import os.Path -import scala.jdk.CollectionConverters._ import scala.util.Properties object Scip extends ExternalModule { @@ -33,8 +27,6 @@ object Scip extends ExternalModule { val log = T.ctx().log - val outputFormat = validateFormat(output)() - val semanticdbVersion = ScipBuildInfo.semanticDBVersion val modules = computeModules(ev) @@ -229,35 +221,10 @@ object Scip extends ExternalModule { } .map(_.path) - createScip(log, T.dest, T.workspace, classpath, output, outputFormat) + createScip(log, T.dest, T.workspace, classpath, output) T.dest / output } - /** Given an output string, determine that a ScipOutputFormat can be - * determined from it. - * - * @param output - * the given output from the user - * @return - * the parsed output format to be generated - */ - private def validateFormat(output: String): Task[ScipOutputFormat] = T.task { - val format = ScipOutputFormat.fromFilename(output) - if (format == ScipOutputFormat.UNKNOWN) { - val msg = - s"""Detected an unknown output type. You'll want to use one of the following: - | - | - *.lsif - | - *.lsif-protobuf - | - *.scip - | - *.scip.ndjson - |""".stripMargin - Result.Failure(msg) - } else { - format - } - } - /** After all the semanticDB has been produced we can create the SCIP index * from it. * @@ -280,19 +247,9 @@ object Scip extends ExternalModule { workspace: Path, classpath: Seq[Path], output: String, - outputFormat: ScipOutputFormat ): Unit = { val scipFile = dest / output - val reporter = new ScipReporter(log) - val toolInfo = - LsifToolInfo - .newBuilder() - .setName( - "scip-java" - ) // Make sure this stays a recognized name by src or it won't index deps. Don't use mill-scip. - .setVersion(ScipBuildInfo.semanticDBJavaVersion) - .build() log.info(s"Creating a ${output} in ${scipFile}") @@ -309,30 +266,10 @@ object Scip extends ExternalModule { createFolders = true ) - val classPathEntries = - classpath.flatMap(project => ClasspathEntry.fromPom(project.toNIO)) - - log.info(s"Including ${classPathEntries.size} classpath entries") - - val options = new ScipSemanticdbOptions( - List(dest).map(_.toNIO).asJava, - scipFile.toNIO, - workspace.toNIO, - reporter, - toolInfo, - "java", - outputFormat, - true, // parallel -- this is fine - classPathEntries - .map(_.toPackageInformation) - .asJava, - "", // BuildKind here is fine being "" - true, // emit inverse releationships - false, // we want to fail with mill if no documents have been indexed - false // we're only dealing with jar files here - ) - - ScipSemanticdb.run(options) + val exit = ScipJava.app.run(List("index-semanticdb", "--cwd", workspace.toString, "--output", scipFile.toString, dest.toString)) + if (exit != 0) { + sys.error("Failed to create SCIP index") + } } private def computeModules(ev: Evaluator) = diff --git a/plugin/src/io/kipp/mill/scip/ClasspathEntry.scala b/plugin/src/io/kipp/mill/scip/ClasspathEntry.scala deleted file mode 100644 index 3d010d3..0000000 --- a/plugin/src/io/kipp/mill/scip/ClasspathEntry.scala +++ /dev/null @@ -1,45 +0,0 @@ -package io.kipp.mill.scip - -import com.sourcegraph.scip_java.buildtools - -import java.nio.file.Files -import java.nio.file.Path - -/** Helpers to calculate the classpath entries needed. - */ -object ClasspathEntry { - - /** Tries to parse a ClasspathEntry from the POM file that lies next to the - * given jar file. - * - * Taken from: - * https://github.com/sourcegraph/scip-java/blob/9648fa9b2f0fc676aafa54c84342375666ce682b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/ClasspathEntry.scala#L102-L131 - */ - private[scip] def fromPom(jar: Path): Option[buildtools.ClasspathEntry] = { - val pom = jar - .resolveSibling(jar.getFileName.toString.stripSuffix(".jar") + ".pom") - val sources = Option( - jar.resolveSibling( - jar.getFileName.toString.stripSuffix(".jar") + ".sources" - ) - ).filter(Files.isRegularFile(_)) - if (Files.isRegularFile(pom)) { - val xml = scala.xml.XML.loadFile(pom.toFile) - def xmlValue(key: String): String = { - val node = xml \ key - if (node.isEmpty) - (xml \ "parent" \ key).text - else - node.text - }.trim - val groupId = xmlValue("groupId") - val artifactId = xmlValue("artifactId") - val version = xmlValue("version") - Some( - buildtools.ClasspathEntry(jar, sources, groupId, artifactId, version) - ) - } else { - None - } - } -} diff --git a/plugin/src/io/kipp/mill/scip/ScipReporter.scala b/plugin/src/io/kipp/mill/scip/ScipReporter.scala deleted file mode 100644 index e6b04c5..0000000 --- a/plugin/src/io/kipp/mill/scip/ScipReporter.scala +++ /dev/null @@ -1,31 +0,0 @@ -package io.kipp.mill.scip - -import com.sourcegraph.scip_semanticdb.ScipSemanticdbReporter -import mill.api.Logger - -import java.util.concurrent.atomic.AtomicInteger - -class ScipReporter(log: Logger) extends ScipSemanticdbReporter { - private var totalSize = 0 - private val currentSize = new AtomicInteger() - - override def startProcessing(taskSize: Int): Unit = { - totalSize = taskSize - log.info( - s"Staring to create a scip index from ${totalSize} SemanticDB documents." - ) - log.ticker(s"[${currentSize.get}/${totalSize}] processing semanticdb") - } - - override def endProcessing(): Unit = - log.ticker(s"[${totalSize}/${totalSize}] Finished creating your scip index") - - override def error(e: Throwable): Unit = - // TODO do we want to capture anything specific here like file not found - log.error(e.getMessage()) - - override def processedOneItem(): Unit = { - currentSize.incrementAndGet() - log.ticker(s"[${currentSize.get}/${totalSize}] processing semanticdb") - } -}