
org.elasticsearch.plugins.PluginDescriptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch - Open Source, Distributed, RESTful Search Engine
/*
* 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.plugins;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.jdk.JarHell;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* An in-memory representation of the plugin descriptor.
*/
public class PluginDescriptor implements Writeable, ToXContentObject {
public static final String INTERNAL_DESCRIPTOR_FILENAME = "plugin-descriptor.properties";
public static final String STABLE_DESCRIPTOR_FILENAME = "stable-plugin-descriptor.properties";
public static final String NAMED_COMPONENTS_FILENAME = "named_components.json";
public static final String ES_PLUGIN_POLICY = "plugin-security.policy";
private static final TransportVersion LICENSED_PLUGINS_SUPPORT = TransportVersion.V_7_11_0;
private static final TransportVersion MODULE_NAME_SUPPORT = TransportVersion.V_8_3_0;
private static final TransportVersion BOOTSTRAP_SUPPORT_REMOVED = TransportVersion.V_8_4_0;
private final String name;
private final String description;
private final String version;
private final Version elasticsearchVersion;
private final String javaVersion;
private final String classname;
private final String moduleName;
private final List extendedPlugins;
private final boolean hasNativeController;
private final boolean isLicensed;
private final boolean isModular;
private final boolean isStable;
/**
* Construct plugin info.
*
* @param name the name of the plugin
* @param description a description of the plugin
* @param version an opaque version identifier for the plugin
* @param elasticsearchVersion the version of Elasticsearch the plugin was built for
* @param javaVersion the version of Java the plugin was built with
* @param classname the entry point to the plugin
* @param moduleName the module name to load the plugin class from, or null if not in a module
* @param extendedPlugins other plugins this plugin extends through SPI
* @param hasNativeController whether or not the plugin has a native controller
* @param isLicensed whether is this a licensed plugin
* @param isModular whether this plugin should be loaded in a module layer
*/
public PluginDescriptor(
String name,
String description,
String version,
Version elasticsearchVersion,
String javaVersion,
String classname,
String moduleName,
List extendedPlugins,
boolean hasNativeController,
boolean isLicensed,
boolean isModular,
boolean isStable
) {
this.name = name;
this.description = description;
this.version = version;
this.elasticsearchVersion = elasticsearchVersion;
this.javaVersion = javaVersion;
this.classname = classname;
this.moduleName = moduleName;
this.extendedPlugins = Collections.unmodifiableList(extendedPlugins);
this.hasNativeController = hasNativeController;
this.isLicensed = isLicensed;
this.isModular = isModular;
this.isStable = isStable;
}
/**
* Construct plugin info from a stream.
*
* @param in the stream
* @throws IOException if an I/O exception occurred reading the plugin info from the stream
*/
public PluginDescriptor(final StreamInput in) throws IOException {
this.name = in.readString();
this.description = in.readString();
this.version = in.readString();
elasticsearchVersion = Version.readVersion(in);
javaVersion = in.readString();
this.classname = in.readString();
if (in.getTransportVersion().onOrAfter(MODULE_NAME_SUPPORT)) {
this.moduleName = in.readOptionalString();
} else {
this.moduleName = null;
}
extendedPlugins = in.readStringList();
hasNativeController = in.readBoolean();
if (in.getTransportVersion().onOrAfter(LICENSED_PLUGINS_SUPPORT)) {
if (in.getTransportVersion().before(BOOTSTRAP_SUPPORT_REMOVED)) {
in.readString(); // plugin type
in.readOptionalString(); // java opts
}
isLicensed = in.readBoolean();
} else {
isLicensed = false;
}
if (in.getTransportVersion().onOrAfter(TransportVersion.V_8_4_0)) {
isModular = in.readBoolean();
isStable = in.readBoolean();
} else {
isModular = moduleName != null;
isStable = false;
}
}
@Override
public void writeTo(final StreamOutput out) throws IOException {
out.writeString(name);
out.writeString(description);
out.writeString(version);
Version.writeVersion(elasticsearchVersion, out);
out.writeString(javaVersion);
out.writeString(classname);
if (out.getTransportVersion().onOrAfter(MODULE_NAME_SUPPORT)) {
out.writeOptionalString(moduleName);
}
out.writeStringCollection(extendedPlugins);
out.writeBoolean(hasNativeController);
if (out.getTransportVersion().onOrAfter(LICENSED_PLUGINS_SUPPORT)) {
if (out.getTransportVersion().before(BOOTSTRAP_SUPPORT_REMOVED)) {
out.writeString("ISOLATED");
out.writeOptionalString(null);
}
out.writeBoolean(isLicensed);
}
if (out.getTransportVersion().onOrAfter(TransportVersion.V_8_4_0)) {
out.writeBoolean(isModular);
out.writeBoolean(isStable);
}
}
/**
* Reads the descriptor file for a plugin.
*
* @param pluginDir the path to the root directory for the plugin
* @return the plugin info
* @throws IOException if an I/O exception occurred reading the plugin descriptor
*/
public static PluginDescriptor readFromProperties(final Path pluginDir) throws IOException {
Path internalDescriptorFile = pluginDir.resolve(INTERNAL_DESCRIPTOR_FILENAME);
Path stableDescriptorFile = pluginDir.resolve(STABLE_DESCRIPTOR_FILENAME);
final BiFunction
© 2015 - 2025 Weber Informatics LLC | Privacy Policy