Skip to content

Commit 3bde413

Browse files
committed
Better detection for Enso's NI when launching LS
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.
1 parent b02e228 commit 3bde413

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4495,10 +4495,12 @@ lazy val `runtime-version-manager` = project
44954495
libraryDependencies ++= Seq(
44964496
"com.typesafe.scala-logging" %% "scala-logging" % scalaLoggingVersion,
44974497
"org.apache.commons" % "commons-compress" % commonsCompressVersion,
4498+
"org.apache.tika" % "tika-core" % tikaVersion,
44984499
"org.scalatest" %% "scalatest" % scalatestVersion % Test
44994500
),
45004501
Compile / moduleDependencies ++= Seq(
45014502
"org.apache.commons" % "commons-compress" % commonsCompressVersion,
4503+
"org.apache.tika" % "tika-core" % tikaVersion,
45024504
"org.slf4j" % "slf4j-api" % slf4jVersion
45034505
),
45044506
Compile / internalModuleDependencies := Seq(

lib/scala/runtime-version-manager/src/main/scala/org/enso/runtimeversionmanager/runner/NativeExecCommand.scala

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import org.enso.cli.OS
44
import org.enso.distribution.{DistributionManager, Environment}
55
import org.enso.runtimeversionmanager.components.Engine
66

7+
import org.apache.tika.config.TikaConfig
8+
import org.apache.tika.Tika
9+
710
import java.nio.file.Path
811

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

29-
if (fullExecPath.toFile.exists()) Some(NativeExecCommand(fullExecPath))
30-
else None
32+
if (fullExecPath.toFile.exists() && isBinary(fullExecPath)) {
33+
Some(NativeExecCommand(fullExecPath))
34+
} else None
35+
}
36+
37+
private def isBinary(path: Path): Boolean = {
38+
try {
39+
val config = TikaConfig.getDefaultConfig()
40+
val tika = new Tika(config)
41+
val mimeTypes = config.getMimeRepository
42+
val mime = tika.detect(path);
43+
val tpe = mimeTypes.forName(mime).getType.getType
44+
tpe != null && tpe == "application"
45+
} catch {
46+
case _: Throwable =>
47+
false
48+
}
3149
}
3250
}

0 commit comments

Comments
 (0)