|
@@ -11,6 +11,7 @@ import com.unboundid.util.NotNull;
|
|
|
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.core.PathUtils;
|
|
|
+import org.elasticsearch.license.License;
|
|
|
import org.elasticsearch.logging.LogManager;
|
|
|
import org.elasticsearch.logging.Logger;
|
|
|
import org.elasticsearch.xcontent.XContentBuilder;
|
|
@@ -46,6 +47,7 @@ import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.lang.annotation.Annotation;
|
|
|
import java.lang.reflect.Constructor;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
@@ -107,7 +109,7 @@ public abstract class DocsV3Support {
|
|
|
return new OperatorsDocsSupport(name, testClass);
|
|
|
}
|
|
|
|
|
|
- static void renderDocs(String name, Class<?> testClass) throws IOException {
|
|
|
+ static void renderDocs(String name, Class<?> testClass) throws Exception {
|
|
|
if (OPERATORS.containsKey(name)) {
|
|
|
var docs = DocsV3Support.forOperators(name, testClass);
|
|
|
docs.renderSignature();
|
|
@@ -126,7 +128,7 @@ public abstract class DocsV3Support {
|
|
|
String name,
|
|
|
Function<String, String> description,
|
|
|
Class<?> testClass
|
|
|
- ) throws IOException {
|
|
|
+ ) throws Exception {
|
|
|
var docs = forOperators("not " + name.toLowerCase(Locale.ROOT), testClass);
|
|
|
docs.renderDocsForNegatedOperators(ctor, description);
|
|
|
}
|
|
@@ -272,12 +274,46 @@ public abstract class DocsV3Support {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * This class is used to check if a license requirement method exists in the test class.
|
|
|
+ * This is used to add license requirement information to the generated documentation.
|
|
|
+ */
|
|
|
+ public static class LicenseRequirementChecker {
|
|
|
+ private Method staticMethod;
|
|
|
+ private Function<List<DataType>, License.OperationMode> fallbackLambda;
|
|
|
+
|
|
|
+ public LicenseRequirementChecker(Class<?> testClass) {
|
|
|
+ try {
|
|
|
+ staticMethod = testClass.getMethod("licenseRequirement", List.class);
|
|
|
+ if (License.OperationMode.class.equals(staticMethod.getReturnType()) == false
|
|
|
+ || java.lang.reflect.Modifier.isStatic(staticMethod.getModifiers()) == false) {
|
|
|
+ staticMethod = null; // Reset if the method doesn't match the signature
|
|
|
+ }
|
|
|
+ } catch (NoSuchMethodException e) {
|
|
|
+ staticMethod = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (staticMethod == null) {
|
|
|
+ fallbackLambda = fieldTypes -> License.OperationMode.BASIC;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public License.OperationMode invoke(List<DataType> fieldTypes) throws Exception {
|
|
|
+ if (staticMethod != null) {
|
|
|
+ return (License.OperationMode) staticMethod.invoke(null, fieldTypes);
|
|
|
+ } else {
|
|
|
+ return fallbackLambda.apply(fieldTypes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
protected final String category;
|
|
|
protected final String name;
|
|
|
protected final FunctionDefinition definition;
|
|
|
protected final Logger logger;
|
|
|
private final Supplier<Map<List<DataType>, DataType>> signatures;
|
|
|
private TempFileWriter tempFileWriter;
|
|
|
+ private final LicenseRequirementChecker licenseChecker;
|
|
|
|
|
|
protected DocsV3Support(String category, String name, Class<?> testClass, Supplier<Map<List<DataType>, DataType>> signatures) {
|
|
|
this(category, name, null, testClass, signatures);
|
|
@@ -296,6 +332,7 @@ public abstract class DocsV3Support {
|
|
|
this.logger = LogManager.getLogger(testClass);
|
|
|
this.signatures = signatures;
|
|
|
this.tempFileWriter = new DocsFileWriter();
|
|
|
+ this.licenseChecker = new LicenseRequirementChecker(testClass);
|
|
|
}
|
|
|
|
|
|
/** Used in tests to capture output for asserting on the content */
|
|
@@ -460,7 +497,7 @@ public abstract class DocsV3Support {
|
|
|
|
|
|
protected abstract void renderSignature() throws IOException;
|
|
|
|
|
|
- protected abstract void renderDocs() throws IOException;
|
|
|
+ protected abstract void renderDocs() throws Exception;
|
|
|
|
|
|
static class FunctionDocsSupport extends DocsV3Support {
|
|
|
private FunctionDocsSupport(String name, Class<?> testClass) {
|
|
@@ -488,7 +525,7 @@ public abstract class DocsV3Support {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected void renderDocs() throws IOException {
|
|
|
+ protected void renderDocs() throws Exception {
|
|
|
if (definition == null) {
|
|
|
logger.info("Skipping rendering docs because the function '{}' isn't registered", name);
|
|
|
} else {
|
|
@@ -497,7 +534,7 @@ public abstract class DocsV3Support {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void renderDocs(FunctionDefinition definition) throws IOException {
|
|
|
+ private void renderDocs(FunctionDefinition definition) throws Exception {
|
|
|
EsqlFunctionRegistry.FunctionDescription description = EsqlFunctionRegistry.description(definition);
|
|
|
if (name.equals("case")) {
|
|
|
/*
|
|
@@ -711,7 +748,7 @@ public abstract class DocsV3Support {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void renderDocs() throws IOException {
|
|
|
+ public void renderDocs() throws Exception {
|
|
|
Constructor<?> ctor = constructorWithFunctionInfo(op.clazz());
|
|
|
if (ctor != null) {
|
|
|
FunctionInfo functionInfo = ctor.getAnnotation(FunctionInfo.class);
|
|
@@ -722,7 +759,7 @@ public abstract class DocsV3Support {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void renderDocsForNegatedOperators(Constructor<?> ctor, Function<String, String> description) throws IOException {
|
|
|
+ void renderDocsForNegatedOperators(Constructor<?> ctor, Function<String, String> description) throws Exception {
|
|
|
String baseName = name.toLowerCase(Locale.ROOT).replace("not ", "");
|
|
|
OperatorConfig op = OPERATORS.get(baseName);
|
|
|
assert op != null;
|
|
@@ -795,7 +832,7 @@ public abstract class DocsV3Support {
|
|
|
}
|
|
|
|
|
|
void renderDocsForOperators(String name, String titleName, Constructor<?> ctor, FunctionInfo info, boolean variadic)
|
|
|
- throws IOException {
|
|
|
+ throws Exception {
|
|
|
renderKibanaInlineDocs(name, titleName, info);
|
|
|
|
|
|
var params = ctor.getParameters();
|
|
@@ -999,7 +1036,7 @@ public abstract class DocsV3Support {
|
|
|
FunctionInfo info,
|
|
|
List<EsqlFunctionRegistry.ArgSignature> args,
|
|
|
boolean variadic
|
|
|
- ) throws IOException {
|
|
|
+ ) throws Exception {
|
|
|
|
|
|
try (XContentBuilder builder = JsonXContent.contentBuilder().prettyPrint().lfAtEnd().startObject()) {
|
|
|
builder.field(
|
|
@@ -1019,6 +1056,10 @@ public abstract class DocsV3Support {
|
|
|
});
|
|
|
}
|
|
|
builder.field("name", name);
|
|
|
+ License.OperationMode license = licenseChecker.invoke(null);
|
|
|
+ if (license != null && license != License.OperationMode.BASIC) {
|
|
|
+ builder.field("license", license.toString());
|
|
|
+ }
|
|
|
if (titleName != null && titleName.equals(name) == false) {
|
|
|
builder.field("titleName", titleName);
|
|
|
}
|
|
@@ -1073,6 +1114,10 @@ public abstract class DocsV3Support {
|
|
|
builder.endObject();
|
|
|
}
|
|
|
builder.endArray();
|
|
|
+ license = licenseChecker.invoke(sig.getKey());
|
|
|
+ if (license != null && license != License.OperationMode.BASIC) {
|
|
|
+ builder.field("license", license.toString());
|
|
|
+ }
|
|
|
builder.field("variadic", variadic);
|
|
|
builder.field("returnType", sig.getValue().esNameIfPossible());
|
|
|
builder.endObject();
|