Skip to content
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

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member

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 like requires 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.

Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for runtime-version-manager is not changed? How is it possible that this works?

Don't we build native image in classpath mode instead of using modulepath? If so, then that might be an explanation of the module-info having no effect. Just a thought...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - the runtime-version-manager should be just fine when you run it in NI. It might also be fine when you run it in JVM, because we might have the org.apache.tika module already in the set of observable modules. Anyway, if the changes work, I am fine with that, I was just surprised that it works.

"org.slf4j" % "slf4j-api" % slf4jVersion
),
Compile / internalModuleDependencies := Seq(
Expand Down
5 changes: 5 additions & 0 deletions distribution/launcher/THIRD-PARTY/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ The license file can be found at `licenses/APACHE2.0`.
Copyright notices related to this dependency can be found in the directory `org.apache.commons.commons-compress-1.23.0`.


'tika-core', licensed under the Apache License, Version 2.0, is distributed with the launcher.
The license file can be found at `licenses/APACHE2.0`.
Copyright notices related to this dependency can be found in the directory `org.apache.tika.tika-core-2.4.1`.


'scala-java8-compat_2.13', licensed under the Apache-2.0, is distributed with the launcher.
The license file can be found at `licenses/APACHE2.0`.
Copyright notices related to this dependency can be found in the directory `org.scala-lang.modules.scala-java8-compat_2.13-1.0.0`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

Apache Tika core
Copyright 2007-2022 The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Information about rights held in and over the resource. Typically,
* a Rights element will contain a rights management statement for
* the resource, or reference a service providing such information.
* Rights information often encompasses Intellectual Property Rights
* (IPR), Copyright, and various Property Rights. If the Rights element
* is absent, no assumptions can be made about the status of these and
* other rights with respect to the resource.
*/
5 changes: 5 additions & 0 deletions distribution/project-manager/THIRD-PARTY/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ The license information can be found along with the copyright notices.
Copyright notices related to this dependency can be found in the directory `org.apache.commons.commons-lang3-3.12.0`.


'tika-core', licensed under the Apache License, Version 2.0, is distributed with the project-manager.
The license file can be found at `licenses/APACHE2.0`.
Copyright notices related to this dependency can be found in the directory `org.apache.tika.tika-core-2.4.1`.


'reactive-streams', licensed under the CC0, is distributed with the project-manager.
The license file can be found at `licenses/CC0`.
Copyright notices related to this dependency can be found in the directory `org.reactivestreams.reactive-streams-1.0.3`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

Apache Tika core
Copyright 2007-2022 The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Information about rights held in and over the resource. Typically,
* a Rights element will contain a rights management statement for
* the resource, or reference a service providing such information.
* Rights information often encompasses Intellectual Property Rights
* (IPR), Copyright, and various Property Rights. If the Rights element
* is absent, no assumptions can be made about the status of these and
* other rights with respect to the resource.
*/
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 = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative check would be:

return !Files.readLines("bin/enso").get(0).startsWith("#!/bin/sh");

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wouldn't work on Windows

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But on windows the difference is in extension:

  • enso.bat - is the shell script
  • enso.exe - is the native binary

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
}
}
}
2 changes: 1 addition & 1 deletion tools/legal-review/engine/report-state
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
6EB80DB9BFB5BAC58FFE8EAB48A509A40EAC27733FCD0F46BC5FC3FDDB82339C
1C7BD42739A2FD536962BEEA3DC052C025F06FFA1E25E9D7BA0D41E9714BCD24
29565A85352D2C3F92648DF46C368298D320747F00AE06FD83197DD6E4CC1DF7
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"The copyright information."
ARTWORK_OR_OBJECT_DETAIL_COPYRIGHT_NOTICE, ARTWORK_OR_OBJECT_DETAIL_CREATOR,
COPYRIGHT_OWNER_ID, COPYRIGHT_OWNER_NAME, IMAGE_CREATOR_ID, IMAGE_CREATOR_NAME,
Contains any necessary copyright notice for claiming the intellectual
Copyright 2016 Norconex Inc.
Copyright Owner, Image Supplier and Licensor may be the same or different
Copyright ownership can be expressed in a more controlled way using the
DATE_CREATED, DESCRIPTION_WRITER, INSTRUCTIONS, JOB_ID, TITLE, COPYRIGHT_NOTICE,
Owner or owners of the copyright in the licensed image.
PREFIX_IPTC_EXT + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "AOCopyrightNotice");
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwner");
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwnerID"),
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwnerId";
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwnerName");
Property ARTWORK_OR_OBJECT_DETAIL_COPYRIGHT_NOTICE = Property.internalTextBag(
Property COPYRIGHT = Property.externalText("xmpDM:copyright");
Property COPYRIGHT_NOTICE = DublinCore.RIGHTS;
Property COPYRIGHT_OWNER = Property.internalTextBag(
Property COPYRIGHT_OWNER_ID = Property.composite(Property.internalTextBag(
Property COPYRIGHT_OWNER_NAME = Property.internalTextBag(
Serves to identify the rights holder/s for the image. The Copyright
String COPYRIGHT_OWNER_ID_WRONG_CASE =
The ID of the owner or owners of the copyright in the licensed image.
The name of the owner or owners of the copyright in the licensed image.
current owner of the copyright of this work with associated intellectual
in the CopyrightNotice.
new Property[]{Property.internalTextBag(IPTC.COPYRIGHT_OWNER_ID_WRONG_CASE)});
regarding copyright ownership. The ASF licenses this file
the copyrights of this image other rights properties may be used.
standard. These parts Copyright 2010 International Press Telecommunications
this work for additional information regarding copyright ownership.
@deprecated use {@link IPTC#COPYRIGHT_OWNER_ID}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(IPR), Copyright, and various Property Rights. If the Rights element
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
META-INF/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
META-INF/NOTICE
4 changes: 2 additions & 2 deletions tools/legal-review/launcher/report-state
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
AB38B719F515D34ED9C306CFCCE5B436B8CAC50023F5ACE621D45CBB89AC4C8A
61C62A70B9F4C08AE1C1779CA8F11375E197064992F5E0535EB8AD9679A8DE72
0D98680156DAEE1AF045DF3CC156B9646A0CACA43BC631F9174F8BEAA10B40C9
279C45838441742F8D12E7FCB9546C7AD404AE8DE401A80DE5E341B7481FECB9
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"The copyright information."
ARTWORK_OR_OBJECT_DETAIL_COPYRIGHT_NOTICE, ARTWORK_OR_OBJECT_DETAIL_CREATOR,
COPYRIGHT_OWNER_ID, COPYRIGHT_OWNER_NAME, IMAGE_CREATOR_ID, IMAGE_CREATOR_NAME,
Contains any necessary copyright notice for claiming the intellectual
Copyright 2016 Norconex Inc.
Copyright Owner, Image Supplier and Licensor may be the same or different
Copyright ownership can be expressed in a more controlled way using the
DATE_CREATED, DESCRIPTION_WRITER, INSTRUCTIONS, JOB_ID, TITLE, COPYRIGHT_NOTICE,
PREFIX_IPTC_EXT + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "AOCopyrightNotice");
Owner or owners of the copyright in the licensed image.
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwner");
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwnerID"),
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwnerId";
PREFIX_PLUS + TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "CopyrightOwnerName");
Property ARTWORK_OR_OBJECT_DETAIL_COPYRIGHT_NOTICE = Property.internalTextBag(
Property COPYRIGHT = Property.externalText("xmpDM:copyright");
Property COPYRIGHT_NOTICE = DublinCore.RIGHTS;
Property COPYRIGHT_OWNER = Property.internalTextBag(
Property COPYRIGHT_OWNER_ID = Property.composite(Property.internalTextBag(
Property COPYRIGHT_OWNER_NAME = Property.internalTextBag(
Serves to identify the rights holder/s for the image. The Copyright
String COPYRIGHT_OWNER_ID_WRONG_CASE =
The ID of the owner or owners of the copyright in the licensed image.
The name of the owner or owners of the copyright in the licensed image.
current owner of the copyright of this work with associated intellectual
in the CopyrightNotice.
new Property[]{Property.internalTextBag(IPTC.COPYRIGHT_OWNER_ID_WRONG_CASE)});
regarding copyright ownership. The ASF licenses this file
standard. These parts Copyright 2010 International Press Telecommunications
the copyrights of this image other rights properties may be used.
this work for additional information regarding copyright ownership.
@deprecated use {@link IPTC#COPYRIGHT_OWNER_ID}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(IPR), Copyright, and various Property Rights. If the Rights element
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
META-INF/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
META-INF/NOTICE
4 changes: 2 additions & 2 deletions tools/legal-review/project-manager/report-state
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
8FAA9FD449B96C40ED702C5EE532FCCBF853A848FE372026EB4E1FE8A52A7ACE
9A28F6CA5CA670813F858F51F213FD37A3902E1B49017AEE7EED5A6C04C6C5C4
84814B3648653F7BE53D330E8D7DBB23B5F2F564F37406A90D21A41A382C71F4
4093B05996A6AF7CA3312C75DD7E42FFB01D783B0E77773BC0EB358322686452
0
Loading