Skip to content

Commit

Permalink
Better detection for Enso's NI when launching LS
Browse files Browse the repository at this point in the history
Previosly we were wrongly relying on the presence of the file. That way,
a bash script meant that NI integration was wrongly used.
This change uses Tika, but it has already been present in other
subprojects so no additional dependency shall be added.

Follow up on #11880.
  • Loading branch information
hubertp committed Jan 10, 2025
1 parent b02e228 commit 3bde413
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4495,10 +4495,12 @@ lazy val `runtime-version-manager` = project
libraryDependencies ++= Seq(
"com.typesafe.scala-logging" %% "scala-logging" % scalaLoggingVersion,
"org.apache.commons" % "commons-compress" % commonsCompressVersion,
"org.apache.tika" % "tika-core" % tikaVersion,
"org.scalatest" %% "scalatest" % scalatestVersion % Test
),
Compile / moduleDependencies ++= Seq(
"org.apache.commons" % "commons-compress" % commonsCompressVersion,
"org.apache.tika" % "tika-core" % tikaVersion,
"org.slf4j" % "slf4j-api" % slf4jVersion
),
Compile / internalModuleDependencies := Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import org.enso.cli.OS
import org.enso.distribution.{DistributionManager, Environment}
import org.enso.runtimeversionmanager.components.Engine

import org.apache.tika.config.TikaConfig
import org.apache.tika.Tika

import java.nio.file.Path

case class NativeExecCommand(executablePath: Path) extends ExecCommand {
Expand All @@ -26,7 +29,22 @@ object NativeExecCommand {
val fullExecPath =
dm.paths.engines.resolve(version).resolve("bin").resolve(execName)

if (fullExecPath.toFile.exists()) Some(NativeExecCommand(fullExecPath))
else None
if (fullExecPath.toFile.exists() && isBinary(fullExecPath)) {
Some(NativeExecCommand(fullExecPath))
} else None
}

private def isBinary(path: Path): Boolean = {
try {
val config = TikaConfig.getDefaultConfig()
val tika = new Tika(config)
val mimeTypes = config.getMimeRepository
val mime = tika.detect(path);
val tpe = mimeTypes.forName(mime).getType.getType
tpe != null && tpe == "application"
} catch {
case _: Throwable =>
false
}
}
}

0 comments on commit 3bde413

Please sign in to comment.