Skip to content

Commit 3543bd9

Browse files
authored
Better detection for Enso's NI when launching Language Server (#12034)
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 516e0f2 commit 3543bd9

File tree

19 files changed

+141
-7
lines changed

19 files changed

+141
-7
lines changed

build.sbt

+2
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(

distribution/launcher/THIRD-PARTY/NOTICE

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ The license file can be found at `licenses/APACHE2.0`.
9191
Copyright notices related to this dependency can be found in the directory `org.apache.commons.commons-compress-1.23.0`.
9292

9393

94+
'tika-core', licensed under the Apache License, Version 2.0, is distributed with the launcher.
95+
The license file can be found at `licenses/APACHE2.0`.
96+
Copyright notices related to this dependency can be found in the directory `org.apache.tika.tika-core-2.4.1`.
97+
98+
9499
'scala-java8-compat_2.13', licensed under the Apache-2.0, is distributed with the launcher.
95100
The license file can be found at `licenses/APACHE2.0`.
96101
Copyright notices related to this dependency can be found in the directory `org.scala-lang.modules.scala-java8-compat_2.13-1.0.0`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
Apache Tika core
3+
Copyright 2007-2022 The Apache Software Foundation
4+
5+
This product includes software developed at
6+
The Apache Software Foundation (http://www.apache.org/).
7+
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Information about rights held in and over the resource. Typically,
3+
* a Rights element will contain a rights management statement for
4+
* the resource, or reference a service providing such information.
5+
* Rights information often encompasses Intellectual Property Rights
6+
* (IPR), Copyright, and various Property Rights. If the Rights element
7+
* is absent, no assumptions can be made about the status of these and
8+
* other rights with respect to the resource.
9+
*/

distribution/project-manager/THIRD-PARTY/NOTICE

+5
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ The license information can be found along with the copyright notices.
356356
Copyright notices related to this dependency can be found in the directory `org.apache.commons.commons-lang3-3.12.0`.
357357

358358

359+
'tika-core', licensed under the Apache License, Version 2.0, is distributed with the project-manager.
360+
The license file can be found at `licenses/APACHE2.0`.
361+
Copyright notices related to this dependency can be found in the directory `org.apache.tika.tika-core-2.4.1`.
362+
363+
359364
'reactive-streams', licensed under the CC0, is distributed with the project-manager.
360365
The license file can be found at `licenses/CC0`.
361366
Copyright notices related to this dependency can be found in the directory `org.reactivestreams.reactive-streams-1.0.3`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
Apache Tika core
3+
Copyright 2007-2022 The Apache Software Foundation
4+
5+
This product includes software developed at
6+
The Apache Software Foundation (http://www.apache.org/).
7+
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Information about rights held in and over the resource. Typically,
3+
* a Rights element will contain a rights management statement for
4+
* the resource, or reference a service providing such information.
5+
* Rights information often encompasses Intellectual Property Rights
6+
* (IPR), Copyright, and various Property Rights. If the Rights element
7+
* is absent, no assumptions can be made about the status of these and
8+
* other rights with respect to the resource.
9+
*/

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

+20-2
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
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
6EB80DB9BFB5BAC58FFE8EAB48A509A40EAC27733FCD0F46BC5FC3FDDB82339C
1+
1C7BD42739A2FD536962BEEA3DC052C025F06FFA1E25E9D7BA0D41E9714BCD24
22
29565A85352D2C3F92648DF46C368298D320747F00AE06FD83197DD6E4CC1DF7
33
0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"The copyright information."
2+
ARTWORK_OR_OBJECT_DETAIL_COPYRIGHT_NOTICE, ARTWORK_OR_OBJECT_DETAIL_CREATOR,
3+
COPYRIGHT_OWNER_ID, COPYRIGHT_OWNER_NAME, IMAGE_CREATOR_ID, IMAGE_CREATOR_NAME,
4+
Contains any necessary copyright notice for claiming the intellectual
5+
Copyright 2016 Norconex Inc.
6+
Copyright Owner, Image Supplier and Licensor may be the same or different
7+
Copyright ownership can be expressed in a more controlled way using the
8+
DATE_CREATED, DESCRIPTION_WRITER, INSTRUCTIONS, JOB_ID, TITLE, COPYRIGHT_NOTICE,
9+
Owner or owners of the copyright in the licensed image.
10+
PREFIX_IPTC_EXT + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "AOCopyrightNotice");
11+
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwner");
12+
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwnerID"),
13+
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwnerId";
14+
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwnerName");
15+
Property ARTWORK_OR_OBJECT_DETAIL_COPYRIGHT_NOTICE = Property.internalTextBag(
16+
Property COPYRIGHT = Property.externalText("xmpDM:copyright");
17+
Property COPYRIGHT_NOTICE = DublinCore.RIGHTS;
18+
Property COPYRIGHT_OWNER = Property.internalTextBag(
19+
Property COPYRIGHT_OWNER_ID = Property.composite(Property.internalTextBag(
20+
Property COPYRIGHT_OWNER_NAME = Property.internalTextBag(
21+
Serves to identify the rights holder/s for the image. The Copyright
22+
String COPYRIGHT_OWNER_ID_WRONG_CASE =
23+
The ID of the owner or owners of the copyright in the licensed image.
24+
The name of the owner or owners of the copyright in the licensed image.
25+
current owner of the copyright of this work with associated intellectual
26+
in the CopyrightNotice.
27+
new Property[]{Property.internalTextBag(IPTC.COPYRIGHT_OWNER_ID_WRONG_CASE)});
28+
regarding copyright ownership. The ASF licenses this file
29+
the copyrights of this image other rights properties may be used.
30+
standard. These parts Copyright 2010 International Press Telecommunications
31+
this work for additional information regarding copyright ownership.
32+
@deprecated use {@link IPTC#COPYRIGHT_OWNER_ID}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(IPR), Copyright, and various Property Rights. If the Rights element
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
META-INF/LICENSE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
META-INF/NOTICE
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
AB38B719F515D34ED9C306CFCCE5B436B8CAC50023F5ACE621D45CBB89AC4C8A
2-
61C62A70B9F4C08AE1C1779CA8F11375E197064992F5E0535EB8AD9679A8DE72
1+
0D98680156DAEE1AF045DF3CC156B9646A0CACA43BC631F9174F8BEAA10B40C9
2+
279C45838441742F8D12E7FCB9546C7AD404AE8DE401A80DE5E341B7481FECB9
33
0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"The copyright information."
2+
ARTWORK_OR_OBJECT_DETAIL_COPYRIGHT_NOTICE, ARTWORK_OR_OBJECT_DETAIL_CREATOR,
3+
COPYRIGHT_OWNER_ID, COPYRIGHT_OWNER_NAME, IMAGE_CREATOR_ID, IMAGE_CREATOR_NAME,
4+
Contains any necessary copyright notice for claiming the intellectual
5+
Copyright 2016 Norconex Inc.
6+
Copyright Owner, Image Supplier and Licensor may be the same or different
7+
Copyright ownership can be expressed in a more controlled way using the
8+
DATE_CREATED, DESCRIPTION_WRITER, INSTRUCTIONS, JOB_ID, TITLE, COPYRIGHT_NOTICE,
9+
PREFIX_IPTC_EXT + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "AOCopyrightNotice");
10+
Owner or owners of the copyright in the licensed image.
11+
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwner");
12+
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwnerID"),
13+
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwnerId";
14+
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwnerName");
15+
Property ARTWORK_OR_OBJECT_DETAIL_COPYRIGHT_NOTICE = Property.internalTextBag(
16+
Property COPYRIGHT = Property.externalText("xmpDM:copyright");
17+
Property COPYRIGHT_NOTICE = DublinCore.RIGHTS;
18+
Property COPYRIGHT_OWNER = Property.internalTextBag(
19+
Property COPYRIGHT_OWNER_ID = Property.composite(Property.internalTextBag(
20+
Property COPYRIGHT_OWNER_NAME = Property.internalTextBag(
21+
Serves to identify the rights holder/s for the image. The Copyright
22+
String COPYRIGHT_OWNER_ID_WRONG_CASE =
23+
The ID of the owner or owners of the copyright in the licensed image.
24+
The name of the owner or owners of the copyright in the licensed image.
25+
current owner of the copyright of this work with associated intellectual
26+
in the CopyrightNotice.
27+
new Property[]{Property.internalTextBag(IPTC.COPYRIGHT_OWNER_ID_WRONG_CASE)});
28+
regarding copyright ownership. The ASF licenses this file
29+
standard. These parts Copyright 2010 International Press Telecommunications
30+
the copyrights of this image other rights properties may be used.
31+
this work for additional information regarding copyright ownership.
32+
@deprecated use {@link IPTC#COPYRIGHT_OWNER_ID}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(IPR), Copyright, and various Property Rights. If the Rights element
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
META-INF/LICENSE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
META-INF/NOTICE
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
8FAA9FD449B96C40ED702C5EE532FCCBF853A848FE372026EB4E1FE8A52A7ACE
2-
9A28F6CA5CA670813F858F51F213FD37A3902E1B49017AEE7EED5A6C04C6C5C4
1+
84814B3648653F7BE53D330E8D7DBB23B5F2F564F37406A90D21A41A382C71F4
2+
4093B05996A6AF7CA3312C75DD7E42FFB01D783B0E77773BC0EB358322686452
33
0

0 commit comments

Comments
 (0)