Browse Source

Remove JNA from server dependencies (#110809)

All native methods are now bound through NativeAccess. This commit
removes the jna dependency from server.

relates #104876
Ryan Ernst 1 year ago
parent
commit
e6713a5c0a

+ 1 - 2
libs/native/jna/build.gradle

@@ -15,8 +15,7 @@ base {
 dependencies {
   compileOnly project(':libs:elasticsearch-core')
   compileOnly project(':libs:elasticsearch-native')
-  // TODO: this will become an implementation dep onces jna is removed from server
-  compileOnly "net.java.dev.jna:jna:${versions.jna}"
+  implementation "net.java.dev.jna:jna:${versions.jna}"
 
   testImplementation(project(":test:framework")) {
     exclude group: 'org.elasticsearch', module: 'elasticsearch-native'

+ 0 - 0
server/licenses/jna-LICENSE.txt → libs/native/jna/licenses/jna-LICENSE.txt


+ 0 - 0
server/licenses/jna-NOTICE.txt → libs/native/jna/licenses/jna-NOTICE.txt


+ 0 - 1
server/build.gradle

@@ -68,7 +68,6 @@ dependencies {
 
   // access to native functions
   implementation project(':libs:elasticsearch-native')
-  api "net.java.dev.jna:jna:${versions.jna}"
 
   api "co.elastic.logging:log4j2-ecs-layout:${versions.ecsLogging}"
   api "co.elastic.logging:ecs-logging-core:${versions.ecsLogging}"

+ 0 - 1
server/src/main/java/module-info.java

@@ -34,7 +34,6 @@ module org.elasticsearch.server {
     requires org.elasticsearch.tdigest;
     requires org.elasticsearch.simdvec;
 
-    requires com.sun.jna;
     requires hppc;
     requires HdrHistogram;
     requires jopt.simple;

+ 0 - 64
server/src/main/java/org/elasticsearch/bootstrap/JNACLibrary.java

@@ -1,64 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0 and the Server Side Public License, v 1; you may not use this file except
- * in compliance with, at your election, the Elastic License 2.0 or the Server
- * Side Public License, v 1.
- */
-
-package org.elasticsearch.bootstrap;
-
-import com.sun.jna.Native;
-import com.sun.jna.NativeLong;
-import com.sun.jna.Structure;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.lucene.util.Constants;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * java mapping to some libc functions
- */
-final class JNACLibrary {
-
-    private static final Logger logger = LogManager.getLogger(JNACLibrary.class);
-
-    public static final int MCL_CURRENT = 1;
-    public static final int ENOMEM = 12;
-    public static final int RLIMIT_MEMLOCK = Constants.MAC_OS_X ? 6 : 8;
-    public static final int RLIMIT_AS = Constants.MAC_OS_X ? 5 : 9;
-    public static final int RLIMIT_FSIZE = Constants.MAC_OS_X ? 1 : 1;
-    public static final long RLIM_INFINITY = Constants.MAC_OS_X ? 9223372036854775807L : -1L;
-
-    static {
-        try {
-            Native.register("c");
-        } catch (UnsatisfiedLinkError e) {
-            logger.warn("unable to link C library. native methods (mlockall) will be disabled.", e);
-        }
-    }
-
-    static native int mlockall(int flags);
-
-    /** corresponds to struct rlimit */
-    public static final class Rlimit extends Structure implements Structure.ByReference {
-        public NativeLong rlim_cur = new NativeLong(0);
-        public NativeLong rlim_max = new NativeLong(0);
-
-        @Override
-        protected List<String> getFieldOrder() {
-            return Arrays.asList("rlim_cur", "rlim_max");
-        }
-    }
-
-    static native int getrlimit(int resource, Rlimit rlimit);
-
-    static native int setrlimit(int resource, Rlimit rlimit);
-
-    static native String strerror(int errno);
-
-    private JNACLibrary() {}
-}

+ 0 - 5
server/src/main/resources/org/elasticsearch/bootstrap/security.policy

@@ -67,11 +67,6 @@ grant codeBase "${codebase.elasticsearch-cli}" {
   permission java.util.PropertyPermission "*", "read,write";
 };
 
-grant codeBase "${codebase.jna}" {
-  // for registering native methods
-  permission java.lang.RuntimePermission "accessDeclaredMembers";
-};
-
 grant codeBase "${codebase.log4j-api}" {
   permission java.lang.RuntimePermission "getClassLoader";
 };

+ 1 - 0
x-pack/plugin/ml/qa/no-bootstrap-tests/build.gradle

@@ -3,4 +3,5 @@ apply plugin: 'elasticsearch.standalone-test'
 dependencies {
   testImplementation project(":x-pack:plugin:core")
   testImplementation project(path: xpackModule('ml'))
+  testImplementation "net.java.dev.jna:jna:${versions.jna}"
 }

+ 1 - 1
x-pack/plugin/sql/sql-cli/build.gradle

@@ -30,7 +30,7 @@ dependencies {
 
   api project(':x-pack:plugin:sql:sql-client')
   api project(":libs:elasticsearch-cli")
-  runtimeOnly "net.java.dev.jna:jna:${versions.jna}"
+  implementation "net.java.dev.jna:jna:${versions.jna}"
   testImplementation project(":test:framework")
 }