From 928dbdf651808afc91b9d062485582855833a560 Mon Sep 17 00:00:00 2001 From: Noah Santschi-Cooney Date: Tue, 17 Aug 2021 16:23:25 +0100 Subject: [PATCH] fix LsifBuildTool errors.nonEmpty checks --- .../lsif_java/buildtools/LsifBuildTool.scala | 49 +++++++-------- .../test/scala/tests/PackageStoreSuite.scala | 61 ------------------- 2 files changed, 25 insertions(+), 85 deletions(-) delete mode 100644 tests/unit/src/test/scala/tests/PackageStoreSuite.scala diff --git a/lsif-java/src/main/scala/com/sourcegraph/lsif_java/buildtools/LsifBuildTool.scala b/lsif-java/src/main/scala/com/sourcegraph/lsif_java/buildtools/LsifBuildTool.scala index a978c727..4aa82a24 100644 --- a/lsif-java/src/main/scala/com/sourcegraph/lsif_java/buildtools/LsifBuildTool.scala +++ b/lsif-java/src/main/scala/com/sourcegraph/lsif_java/buildtools/LsifBuildTool.scala @@ -136,7 +136,7 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) { val deps = Dependencies.resolveDependencies(config.dependencies.map(_.repr)) val sourceroot = index.workingDirectory if (!Files.isDirectory(sourceroot)) { - throw new NoSuchFileException(sourceroot.toString()) + throw new NoSuchFileException(sourceroot.toString) } val allSourceFiles = collectAllSourceFiles(sourceroot) val javaFiles = allSourceFiles.filter(path => javaPattern.matches(path)) @@ -150,8 +150,9 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) { return CommandResult(0, Nil) } val errors = ListBuffer.empty[Try[Unit]] - errors += compileJavaFiles(tmp, deps, config, javaFiles) - errors += compileScalaFiles(deps, scalaFiles) + compileJavaFiles(tmp, deps, config, javaFiles) + .recover(e => errors.addOne(Failure(e))) + compileScalaFiles(deps, scalaFiles).recover(e => errors.addOne(Failure(e))) if (index.cleanup) { Files.walkFileTree(tmp, new DeleteVisitor) } @@ -159,19 +160,18 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) { .isDirectory(targetroot.resolve("META-INF")) if (errors.nonEmpty && !isSemanticdbGenerated) { CommandResult(1, Nil) - } else { - if (isSemanticdbGenerated) { - index - .app - .reporter - .info( - "Some SemanticDB files got generated even if there were compile errors. " + - "In most cases, this means that lsif-java managed to index everything " + - "except the locations that had compile errors and you can ignore the compile errors." - ) - } - CommandResult(0, Nil) + } else if (errors.nonEmpty && isSemanticdbGenerated) { + index + .app + .reporter + .info( + "Some SemanticDB files got generated even if there were compile errors. " + + "In most cases, this means that lsif-java managed to index everything " + + "except the locations that had compile errors and you can ignore the compile errors." + + errors.mkString("\n") + ) } + CommandResult(0, Nil) } private def compileScalaFiles( @@ -179,17 +179,18 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) { allScalaFiles: List[Path] ): Try[Unit] = Try { - withScalaPresentationCompiler(deps) { compiler => - allScalaFiles.foreach { path => - try compileScalaFile(compiler, path) - catch { - case NonFatal(e) => - // We want to try and index as much as possible so we don't fail the entire - // compilation even if a single file fails to compile. - index.app.reporter.log(Diagnostic.exception(e)) + if (allScalaFiles.nonEmpty) + withScalaPresentationCompiler(deps) { compiler => + allScalaFiles.foreach { path => + try compileScalaFile(compiler, path) + catch { + case NonFatal(e) => + // We want to try and index as much as possible so we don't fail the entire + // compilation even if a single file fails to compile. + index.app.reporter.log(Diagnostic.exception(e)) + } } } - } } private def compileScalaFile( diff --git a/tests/unit/src/test/scala/tests/PackageStoreSuite.scala b/tests/unit/src/test/scala/tests/PackageStoreSuite.scala deleted file mode 100644 index 5ccc5bc5..00000000 --- a/tests/unit/src/test/scala/tests/PackageStoreSuite.scala +++ /dev/null @@ -1,61 +0,0 @@ -package tests - -import com.dimafeng.testcontainers.PostgreSQLContainer -import com.dimafeng.testcontainers.munit.TestContainerForAll -import com.sourcegraph.packagehub.Package -import com.sourcegraph.packagehub.PackageHub -import com.sourcegraph.packagehub.PostgresOptions -import com.sourcegraph.packagehub.PostgresPackageStore -import moped.testkit.MopedSuite - -class PackageStoreSuite - extends MopedSuite(PackageHub.app) - with TestContainerForAll { - val store = - new Fixture[PostgresPackageStore]("store") { - private var p: PostgresPackageStore = _ - def apply(): PostgresPackageStore = p - override def beforeEach(context: BeforeEach): Unit = { - withContainers { c => - val options = PostgresOptions( - url = c.jdbcUrl, - username = c.username, - password = c.password - ) - p = new PostgresPackageStore(options.toDataSource(app().reporter).get) - } - } - } - override def munitFixtures: Seq[Fixture[_]] = - super.munitFixtures ++ List(store) - val pkg1 = Package.parse("maven:com.sourcegraph:semanticdb-javac:0.4.0") - val pkg2 = Package.parse("maven:com.sourcegraph:semanticdb-javac:0.4.1") - val pkg3 = Package.parse("maven:com.sourcegraph:semanticdb-javac:0.4.2") - val containerDef = PostgreSQLContainer.Def() - - test("packages") { - assertEquals(store().allPackages(), Nil) - store().addPackage(pkg1) - assertEquals(store().allPackages(), List(pkg1)) - store().addPackage(pkg1) - assertEquals(store().allPackages(), List(pkg1)) - store().addPackages(List(pkg2, pkg3)) - assertEquals(store().allPackages(), List(pkg1, pkg2, pkg3)) - } - - test("indexed_packages") { - assertEquals(store().allIndexedPackages(), Nil) - store().addIndexedPackage(pkg1) - assertEquals(store().allIndexedPackages(), List(pkg1)) - assert(store().isIndexedPackage(pkg1)) - assert(!store().isIndexedPackage(pkg2)) - assert(!store().isIndexedPackage(pkg3)) - store().addIndexedPackage(pkg1) - assertEquals(store().allIndexedPackages(), List(pkg1)) - store().addIndexedPackages(List(pkg2, pkg3)) - assertEquals(store().allIndexedPackages(), List(pkg1, pkg2, pkg3)) - assert(store().isIndexedPackage(pkg1)) - assert(store().isIndexedPackage(pkg2)) - assert(store().isIndexedPackage(pkg3)) - } -}