-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better detection for Enso's NI when launching Language Server #12034
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternative check would be:
that is a common prefix of most of the shell scripts. However we'd have to add such header to our shell script: enso$ git diff
diff --git distribution/bin/enso distribution/bin/enso
index 1939fc99dc..93a45f4a6e 100755
--- distribution/bin/enso
+++ distribution/bin/enso
@@ -1,3 +1,5 @@
+#!/bin/sh
+
COMP_PATH=$(dirname "$0")/../component
JAVA_OPTS="--add-opens=java.base/java.nio=ALL-UNNAMED $JAVA_OPTS" but as you say, Tika was already available as it is used somewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That wouldn't work on Windows There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But on windows the difference is in extension:
We only need the content file check for Unixes. |
||
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 | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tika is added as a moduleDependency, but
module-info.java
for runtime-version-manager is not changed? How is it possible that this works? There should be something likerequires org.apache.tika
added to the module descriptor.It compiles because you are using tika in Scala source, but my gut feeling is that it might crash in runtime at some point on
NoClassDefFound
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that the new functionality in
NativeExecCommand
is tested?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it works.