forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into docs-esql-stats-by-nested-functions
- Loading branch information
Showing
914 changed files
with
14,319 additions
and
15,660 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/MrjarPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* 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.gradle.internal; | ||
|
||
import org.elasticsearch.gradle.util.GradleUtils; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.plugins.JavaLibraryPlugin; | ||
import org.gradle.api.plugins.JavaPlugin; | ||
import org.gradle.api.plugins.JavaPluginExtension; | ||
import org.gradle.api.tasks.SourceSet; | ||
import org.gradle.api.tasks.compile.CompileOptions; | ||
import org.gradle.api.tasks.compile.JavaCompile; | ||
import org.gradle.jvm.tasks.Jar; | ||
import org.gradle.jvm.toolchain.JavaLanguageVersion; | ||
import org.gradle.jvm.toolchain.JavaToolchainService; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.tree.ClassNode; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Stream; | ||
|
||
import javax.inject.Inject; | ||
|
||
import static org.objectweb.asm.Opcodes.V_PREVIEW; | ||
|
||
public class MrjarPlugin implements Plugin<Project> { | ||
|
||
private static final Pattern MRJAR_SOURCESET_PATTERN = Pattern.compile("main(\\d{2})"); | ||
|
||
private final JavaToolchainService javaToolchains; | ||
|
||
@Inject | ||
MrjarPlugin(JavaToolchainService javaToolchains) { | ||
this.javaToolchains = javaToolchains; | ||
} | ||
|
||
@Override | ||
public void apply(Project project) { | ||
project.getPluginManager().apply(JavaLibraryPlugin.class); | ||
var javaExtension = project.getExtensions().getByType(JavaPluginExtension.class); | ||
|
||
var srcDir = project.getProjectDir().toPath().resolve("src"); | ||
try (var subdirStream = Files.list(srcDir)) { | ||
for (Path sourceset : subdirStream.toList()) { | ||
assert Files.isDirectory(sourceset); | ||
String sourcesetName = sourceset.getFileName().toString(); | ||
Matcher sourcesetMatcher = MRJAR_SOURCESET_PATTERN.matcher(sourcesetName); | ||
if (sourcesetMatcher.matches()) { | ||
int javaVersion = Integer.parseInt(sourcesetMatcher.group(1)); | ||
addMrjarSourceset(project, javaExtension, sourcesetName, javaVersion); | ||
} | ||
} | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
private void addMrjarSourceset(Project project, JavaPluginExtension javaExtension, String sourcesetName, int javaVersion) { | ||
SourceSet sourceSet = javaExtension.getSourceSets().maybeCreate(sourcesetName); | ||
GradleUtils.extendSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME, sourcesetName); | ||
|
||
project.getTasks().withType(Jar.class).named(JavaPlugin.JAR_TASK_NAME).configure(jarTask -> { | ||
jarTask.into("META-INF/versions/" + javaVersion, copySpec -> copySpec.from(sourceSet.getOutput())); | ||
jarTask.manifest(manifest -> { manifest.attributes(Map.of("Multi-Release", "true")); }); | ||
}); | ||
|
||
project.getTasks().withType(JavaCompile.class).named(sourceSet.getCompileJavaTaskName()).configure(compileTask -> { | ||
compileTask.getJavaCompiler() | ||
.set(javaToolchains.compilerFor(spec -> { spec.getLanguageVersion().set(JavaLanguageVersion.of(javaVersion)); })); | ||
compileTask.setSourceCompatibility(Integer.toString(javaVersion)); | ||
CompileOptions compileOptions = compileTask.getOptions(); | ||
compileOptions.getRelease().set(javaVersion); | ||
compileOptions.getCompilerArgs().add("--enable-preview"); | ||
compileOptions.getCompilerArgs().add("-Xlint:-preview"); | ||
|
||
compileTask.doLast(t -> { stripPreviewFromFiles(compileTask.getDestinationDirectory().getAsFile().get().toPath()); }); | ||
}); | ||
} | ||
|
||
private static void stripPreviewFromFiles(Path compileDir) { | ||
try (Stream<Path> fileStream = Files.walk(compileDir)) { | ||
fileStream.filter(p -> p.toString().endsWith(".class")).forEach(MrjarPlugin::maybeStripPreview); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
private static void maybeStripPreview(Path file) { | ||
ClassWriter classWriter = null; | ||
try (var in = Files.newInputStream(file)) { | ||
ClassReader classReader = new ClassReader(in); | ||
ClassNode classNode = new ClassNode(); | ||
classReader.accept(classNode, 0); | ||
|
||
if ((classNode.version & V_PREVIEW) != 0) { | ||
classNode.version = classNode.version & ~V_PREVIEW; | ||
classWriter = new ClassWriter(0); | ||
classNode.accept(classWriter); | ||
} | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
|
||
if (classWriter != null) { | ||
try (var out = Files.newOutputStream(file)) { | ||
out.write(classWriter.toByteArray()); | ||
} catch (IOException e) { | ||
throw new org.gradle.api.UncheckedIOException(e); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 0 additions & 174 deletions
174
...t/rest-high-level/src/main/java/org/elasticsearch/client/analytics/ParsedStringStats.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.