Skip to content

Commit

Permalink
Renaming folder name parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Vacha Shah <vachshah@amazon.com>
  • Loading branch information
VachaShah committed Jul 20, 2021
1 parent ebf6706 commit e7daf15
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class PluginBuildPlugin implements Plugin<Project> {
'opensearchVersion' : Version.fromString(VersionProperties.getOpenSearch()).toString(),
'javaVersion' : project.targetCompatibility as String,
'classname' : extension1.classname,
'folderName' : extension1.folderName,
'customFolderName' : extension1.customFolderName,
'extendedPlugins' : extension1.extendedPlugins.join(','),
'hasNativeController' : extension1.hasNativeController,
'requiresKeystore' : extension1.requiresKeystore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class PluginPropertiesExtension {

private String classname;

private String folderName = "";
private String customFolderName = "";

/** Other plugins this plugin extends through SPI */
private List<String> extendedPlugins = new ArrayList<>();
Expand All @@ -78,12 +78,12 @@ public PluginPropertiesExtension(Project project) {
this.project = project;
}

public String getFolderName() {
return folderName;
public String getCustomFolderName() {
return customFolderName;
}

public void setFolderName(String folderName) {
this.folderName = folderName;
public void setCustomFolderName(String customFolderName) {
this.customFolderName = customFolderName;
}

public String getName() {
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/resources/plugin-descriptor.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ java.version=${javaVersion}
opensearch.version=${opensearchVersion}
### optional elements for plugins:
#
# 'folderName': the custom name of the folder in which the plugin is installed.
folderName=${folderName}
# 'custom.foldername': the custom name of the folder in which the plugin is installed.
custom.foldername=${customFolderName}
#
# 'extended.plugins': other plugins this plugin extends through SPI
extended.plugins=${extendedPlugins}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ void execute(Terminal terminal, Environment env, String pluginName, boolean purg
* to find if the concerned plugin is installed with a custom folder name.
*/
if (!Files.exists(pluginDir)) {
terminal.println("searching in other folders to find if plugin exists with custom folder name");
pluginDir = PluginHelper.verifyIfPluginExists(env.pluginsFile(), pluginName);
pluginConfigDir = env.configFile().resolve(pluginDir.getFileName());
removing = env.pluginsFile().resolve(".removing-" + pluginDir.getFileName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public void testExistingPlugin() throws Exception {
public void testExistingPluginWithCustomFolderName() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
Path pluginDir = createPluginDir(temp);
String pluginZip = createPluginUrl("fake", pluginDir, "folderName", "fake-folder");
String pluginZip = createPluginUrl("fake", pluginDir, "custom.foldername", "fake-folder");
installPlugin(pluginZip, env.v1());
assertPlugin("fake-folder", pluginDir, env.v2());
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
Expand Down Expand Up @@ -887,7 +887,7 @@ public void testPluginAlreadyInstalled() throws Exception {
public void testPluginInstallationWithCustomFolderName() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
Path pluginDir = createPluginDir(temp);
String pluginZip = createPluginUrl("fake", pluginDir, "folderName", "fake-folder");
String pluginZip = createPluginUrl("fake", pluginDir, "custom.foldername", "fake-folder");
installPlugin(pluginZip, env.v1());
assertPlugin("fake-folder", pluginDir, env.v2());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static void buildFakePlugin(
"1.8",
"classname",
classname,
"folderName",
"custom.foldername",
"custom-folder",
"has.native.controller",
Boolean.toString(hasNativeController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void testBasic() throws Exception {
}

public void testRemovePluginWithCustomFolderName() throws Exception {
createPlugin("fake", "folderName", "custom-folder");
createPlugin("fake", "custom.foldername", "custom-folder");
Files.createFile(env.pluginsFile().resolve("custom-folder").resolve("plugin.jar"));
Files.createDirectory(env.pluginsFile().resolve("custom-folder").resolve("subdir"));
createPlugin("other");
Expand Down Expand Up @@ -274,6 +274,7 @@ protected boolean addShutdownHook() {
BufferedReader reader = new BufferedReader(new StringReader(terminal.getOutput()));
BufferedReader errorReader = new BufferedReader(new StringReader(terminal.getErrorOutput()))
) {
assertEquals("searching in other folders to find if plugin exists with custom folder name", reader.readLine());
assertEquals("-> removing [fake]...", reader.readLine());
assertEquals(
"ERROR: plugin [fake] not found; run 'opensearch-plugin list' to get list of installed plugins",
Expand Down
34 changes: 17 additions & 17 deletions server/src/main/java/org/opensearch/plugins/PluginInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class PluginInfo implements Writeable, ToXContentObject {
private final Version opensearchVersion;
private final String javaVersion;
private final String classname;
private final String folderName;
private final String customFolderName;
private final List<String> extendedPlugins;
private final boolean hasNativeController;

Expand All @@ -82,19 +82,19 @@ public class PluginInfo implements Writeable, ToXContentObject {
* @param opensearchVersion the version of OpenSearch 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 folderName the custom folder name for the plugin
* @param customFolderName the custom folder name for the plugin
* @param extendedPlugins other plugins this plugin extends through SPI
* @param hasNativeController whether or not the plugin has a native controller
*/
public PluginInfo(String name, String description, String version, Version opensearchVersion, String javaVersion,
String classname, String folderName, List<String> extendedPlugins, boolean hasNativeController) {
String classname, String customFolderName, List<String> extendedPlugins, boolean hasNativeController) {
this.name = name;
this.description = description;
this.version = version;
this.opensearchVersion = opensearchVersion;
this.javaVersion = javaVersion;
this.classname = classname;
this.folderName = folderName;
this.customFolderName = customFolderName;
this.extendedPlugins = Collections.unmodifiableList(extendedPlugins);
this.hasNativeController = hasNativeController;
}
Expand All @@ -120,9 +120,9 @@ public PluginInfo(final StreamInput in) throws IOException {
}
this.classname = in.readString();
if (in.getVersion().after(Version.V_1_0_0)) {
folderName = in.readString();
customFolderName = in.readString();
} else {
folderName = this.name;
customFolderName = this.name;
}
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_2_0)) {
extendedPlugins = in.readStringList();
Expand Down Expand Up @@ -150,8 +150,8 @@ public void writeTo(final StreamOutput out) throws IOException {
}
out.writeString(classname);
if (out.getVersion().after(Version.V_1_0_0)) {
if (folderName != null) {
out.writeString(folderName);
if (customFolderName != null) {
out.writeString(customFolderName);
} else {
out.writeString(name);
}
Expand Down Expand Up @@ -222,12 +222,12 @@ public static PluginInfo readFromProperties(final Path path) throws IOException
"property [classname] is missing for plugin [" + name + "]");
}

final String folderNameValue = propsMap.remove("folderName");
final String folderName;
final String customFolderNameValue = propsMap.remove("custom.foldername");
final String customFolderName;
if (esVersion.after(Version.V_1_0_0)) {
folderName = folderNameValue;
customFolderName = customFolderNameValue;
} else {
folderName = name;
customFolderName = name;
}

final String extendedString = propsMap.remove("extended.plugins");
Expand Down Expand Up @@ -271,7 +271,7 @@ public static PluginInfo readFromProperties(final Path path) throws IOException
}

return new PluginInfo(name, description, version, esVersion, javaVersionString,
classname, folderName, extendedPlugins, hasNativeController);
classname, customFolderName, extendedPlugins, hasNativeController);
}

/**
Expand Down Expand Up @@ -307,7 +307,7 @@ public String getClassname() {
* @return the custom folder name for the plugin
*/
public String getFolderName() {
return folderName;
return customFolderName;
}

/**
Expand Down Expand Up @@ -361,7 +361,7 @@ public boolean hasNativeController() {
* @return the custom folder name for the plugin if the folder name is specified, else return the id with kebab-case.
*/
public String getTargetFolderName() {
return (this.folderName == null || this.folderName.isEmpty()) ? this.name : this.folderName;
return (this.customFolderName == null || this.customFolderName.isEmpty()) ? this.name : this.customFolderName;
}

@Override
Expand All @@ -374,7 +374,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field("java_version", javaVersion);
builder.field("description", description);
builder.field("classname", classname);
builder.field("folderName", folderName);
builder.field("custom_foldername", customFolderName);
builder.field("extended_plugins", extendedPlugins);
builder.field("has_native_controller", hasNativeController);
}
Expand Down Expand Up @@ -418,7 +418,7 @@ public String toString(String prefix) {
.append(prefix).append("Native Controller: ").append(hasNativeController).append("\n")
.append(prefix).append("Extended Plugins: ").append(extendedPlugins).append("\n")
.append(prefix).append(" * Classname: ").append(classname).append("\n")
.append(prefix).append("Folder name: ").append(folderName);
.append(prefix).append("Folder name: ").append(customFolderName);
return information.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testReadFromPropertiesWithFolderNameAndVersionBefore() throws Except
"opensearch.version", Version.V_1_0_0.toString(),
"java.version", System.getProperty("java.specification.version"),
"classname", "FakePlugin",
"folderName", "custom-folder");
"custom.foldername", "custom-folder");
PluginInfo info = PluginInfo.readFromProperties(pluginDir);
assertEquals("my_plugin", info.getName());
assertEquals("fake desc", info.getDescription());
Expand All @@ -98,7 +98,7 @@ public void testReadFromPropertiesWithFolderNameAndVersionAfter() throws Excepti
"opensearch.version", Version.CURRENT.toString(),
"java.version", System.getProperty("java.specification.version"),
"classname", "FakePlugin",
"folderName", "custom-folder");
"custom.foldername", "custom-folder");
PluginInfo info = PluginInfo.readFromProperties(pluginDir);
assertEquals("my_plugin", info.getName());
assertEquals("fake desc", info.getDescription());
Expand Down

0 comments on commit e7daf15

Please sign in to comment.