diff --git a/libs/native/jna/build.gradle b/libs/native/jna/build.gradle index e34f35318126a..679191afbc574 100644 --- a/libs/native/jna/build.gradle +++ b/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' diff --git a/server/licenses/jna-LICENSE.txt b/libs/native/jna/licenses/jna-LICENSE.txt similarity index 100% rename from server/licenses/jna-LICENSE.txt rename to libs/native/jna/licenses/jna-LICENSE.txt diff --git a/server/licenses/jna-NOTICE.txt b/libs/native/jna/licenses/jna-NOTICE.txt similarity index 100% rename from server/licenses/jna-NOTICE.txt rename to libs/native/jna/licenses/jna-NOTICE.txt diff --git a/server/build.gradle b/server/build.gradle index 40cd9d31dd6c8..deadd0a330ef8 100644 --- a/server/build.gradle +++ b/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}" diff --git a/server/src/main/java/module-info.java b/server/src/main/java/module-info.java index 5f77a4211fefc..8288b449ec983 100644 --- a/server/src/main/java/module-info.java +++ b/server/src/main/java/module-info.java @@ -34,7 +34,6 @@ requires org.elasticsearch.tdigest; requires org.elasticsearch.simdvec; - requires com.sun.jna; requires hppc; requires HdrHistogram; requires jopt.simple; diff --git a/server/src/main/java/org/elasticsearch/bootstrap/JNACLibrary.java b/server/src/main/java/org/elasticsearch/bootstrap/JNACLibrary.java deleted file mode 100644 index 03b106407f45f..0000000000000 --- a/server/src/main/java/org/elasticsearch/bootstrap/JNACLibrary.java +++ /dev/null @@ -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 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() {} -} diff --git a/server/src/main/resources/org/elasticsearch/bootstrap/security.policy b/server/src/main/resources/org/elasticsearch/bootstrap/security.policy index 812dc30081d84..1635be24d2e84 100644 --- a/server/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/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"; }; diff --git a/x-pack/plugin/ml/qa/no-bootstrap-tests/build.gradle b/x-pack/plugin/ml/qa/no-bootstrap-tests/build.gradle index 4d2fdd603dbbd..6a74f40777aae 100644 --- a/x-pack/plugin/ml/qa/no-bootstrap-tests/build.gradle +++ b/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}" } diff --git a/x-pack/plugin/sql/sql-cli/build.gradle b/x-pack/plugin/sql/sql-cli/build.gradle index 2492086ac1fbb..1d3a63ec13c98 100644 --- a/x-pack/plugin/sql/sql-cli/build.gradle +++ b/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") }