Skip to content

Commit 0dfc5f7

Browse files
authored
Remove JNA from native access (elastic#112977)
Now that main has a minimum compile version of Java 21, native access no longer needs JNA. This commit removes JNA as a dependency, and moves the jdk implementation into the main source set. It also slightly adjusts the Mrjar plugin so that the main source set also supports preview features, like the other numbered source sets.
1 parent 4f221bb commit 0dfc5f7

33 files changed

+22
-1409
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/MrjarPlugin.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import org.gradle.api.tasks.SourceSetContainer;
2323
import org.gradle.api.tasks.compile.CompileOptions;
2424
import org.gradle.api.tasks.compile.JavaCompile;
25+
import org.gradle.api.tasks.javadoc.Javadoc;
2526
import org.gradle.api.tasks.testing.Test;
27+
import org.gradle.external.javadoc.CoreJavadocOptions;
2628
import org.gradle.jvm.tasks.Jar;
2729
import org.gradle.jvm.toolchain.JavaLanguageVersion;
2830
import org.gradle.jvm.toolchain.JavaToolchainService;
@@ -73,8 +75,10 @@ public void apply(Project project) {
7375
List<Integer> mainVersions = findSourceVersions(project);
7476
List<String> mainSourceSets = new ArrayList<>();
7577
mainSourceSets.add(SourceSet.MAIN_SOURCE_SET_NAME);
78+
configurePreviewFeatures(project, javaExtension.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME), 21);
7679
List<String> testSourceSets = new ArrayList<>(mainSourceSets);
7780
testSourceSets.add(SourceSet.TEST_SOURCE_SET_NAME);
81+
configurePreviewFeatures(project, javaExtension.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME), 21);
7882
for (int javaVersion : mainVersions) {
7983
String mainSourceSetName = SourceSet.MAIN_SOURCE_SET_NAME + javaVersion;
8084
SourceSet mainSourceSet = addSourceSet(project, javaExtension, mainSourceSetName, mainSourceSets, javaVersion);
@@ -124,11 +128,8 @@ private SourceSet addSourceSet(
124128
compileTask.setSourceCompatibility(Integer.toString(javaVersion));
125129
CompileOptions compileOptions = compileTask.getOptions();
126130
compileOptions.getRelease().set(javaVersion);
127-
compileOptions.getCompilerArgs().add("--enable-preview");
128-
compileOptions.getCompilerArgs().add("-Xlint:-preview");
129-
130-
compileTask.doLast(t -> { stripPreviewFromFiles(compileTask.getDestinationDirectory().getAsFile().get().toPath()); });
131131
});
132+
configurePreviewFeatures(project, sourceSet, javaVersion);
132133

133134
// Since we configure MRJAR sourcesets to allow preview apis, class signatures for those
134135
// apis are not known by forbidden apis, so we must ignore all missing classes. We could, in theory,
@@ -142,6 +143,21 @@ private SourceSet addSourceSet(
142143
return sourceSet;
143144
}
144145

146+
private void configurePreviewFeatures(Project project, SourceSet sourceSet, int javaVersion) {
147+
project.getTasks().withType(JavaCompile.class).named(sourceSet.getCompileJavaTaskName()).configure(compileTask -> {
148+
CompileOptions compileOptions = compileTask.getOptions();
149+
compileOptions.getCompilerArgs().add("--enable-preview");
150+
compileOptions.getCompilerArgs().add("-Xlint:-preview");
151+
152+
compileTask.doLast(t -> { stripPreviewFromFiles(compileTask.getDestinationDirectory().getAsFile().get().toPath()); });
153+
});
154+
project.getTasks().withType(Javadoc.class).named(name -> name.equals(sourceSet.getJavadocTaskName())).configureEach(javadocTask -> {
155+
CoreJavadocOptions options = (CoreJavadocOptions) javadocTask.getOptions();
156+
options.addBooleanOption("-enable-preview", true);
157+
options.addStringOption("-release", String.valueOf(javaVersion));
158+
});
159+
}
160+
145161
private void configureSourceSetInJar(Project project, SourceSet sourceSet, int javaVersion) {
146162
var jarTask = project.getTasks().withType(Jar.class).named(JavaPlugin.JAR_TASK_NAME);
147163
jarTask.configure(task -> task.into("META-INF/versions/" + javaVersion, copySpec -> copySpec.from(sourceSet.getOutput())));

libs/native/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ import org.elasticsearch.gradle.internal.precommit.CheckForbiddenApisTask
1212
apply plugin: 'elasticsearch.publish'
1313
apply plugin: 'elasticsearch.build'
1414
apply plugin: 'elasticsearch.mrjar'
15-
apply plugin: 'elasticsearch.embedded-providers'
16-
17-
embeddedProviders {
18-
impl 'native-access-jna', project(':libs:elasticsearch-native:jna')
19-
}
2015

2116
dependencies {
2217
api project(':libs:elasticsearch-core')

libs/native/jna/build.gradle

Lines changed: 0 additions & 31 deletions
This file was deleted.

libs/native/jna/licences/jna-LICENSE.txt

Lines changed: 0 additions & 177 deletions
This file was deleted.

libs/native/jna/licences/jna-NOTICE.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)