diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml
index d50f362a73e..14c2bc8ca5a 100644
--- a/buildSrc/src/main/resources/checkstyle_suppressions.xml
+++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml
@@ -470,7 +470,6 @@
-
diff --git a/core/src/main/java/org/elasticsearch/plugins/RemovePluginCommand.java b/core/src/main/java/org/elasticsearch/plugins/RemovePluginCommand.java
index 0b4f8d281d0..54cd34d6742 100644
--- a/core/src/main/java/org/elasticsearch/plugins/RemovePluginCommand.java
+++ b/core/src/main/java/org/elasticsearch/plugins/RemovePluginCommand.java
@@ -43,7 +43,7 @@ import static org.elasticsearch.cli.Terminal.Verbosity.VERBOSE;
/**
* A command for the plugin cli to remove a plugin from elasticsearch.
*/
-class RemovePluginCommand extends SettingCommand {
+final class RemovePluginCommand extends SettingCommand {
private final OptionSpec arguments;
@@ -64,14 +64,16 @@ class RemovePluginCommand extends SettingCommand {
terminal.println("-> Removing " + Strings.coalesceToEmpty(pluginName) + "...");
- Path pluginDir = env.pluginsFile().resolve(pluginName);
+ final Path pluginDir = env.pluginsFile().resolve(pluginName);
if (Files.exists(pluginDir) == false) {
- throw new UserException(ExitCodes.USAGE, "plugin " + pluginName + " not found; run 'elasticsearch-plugin list' to get list of installed plugins");
+ throw new UserException(
+ ExitCodes.USAGE,
+ "plugin " + pluginName + " not found; run 'elasticsearch-plugin list' to get list of installed plugins");
}
- List pluginPaths = new ArrayList<>();
+ final List pluginPaths = new ArrayList<>();
- Path pluginBinDir = env.binFile().resolve(pluginName);
+ final Path pluginBinDir = env.binFile().resolve(pluginName);
if (Files.exists(pluginBinDir)) {
if (Files.isDirectory(pluginBinDir) == false) {
throw new UserException(ExitCodes.IO_ERROR, "Bin dir for " + pluginName + " is not a directory");
@@ -81,10 +83,19 @@ class RemovePluginCommand extends SettingCommand {
}
terminal.println(VERBOSE, "Removing: " + pluginDir);
- Path tmpPluginDir = env.pluginsFile().resolve(".removing-" + pluginName);
+ final Path tmpPluginDir = env.pluginsFile().resolve(".removing-" + pluginName);
Files.move(pluginDir, tmpPluginDir, StandardCopyOption.ATOMIC_MOVE);
pluginPaths.add(tmpPluginDir);
IOUtils.rm(pluginPaths.toArray(new Path[pluginPaths.size()]));
+
+ // we preserve the config files in case the user is upgrading the plugin, but we print
+ // a message so the user knows in case they want to remove manually
+ final Path pluginConfigDir = env.configFile().resolve(pluginName);
+ if (Files.exists(pluginConfigDir)) {
+ terminal.println(
+ "-> Preserving plugin config files [" + pluginConfigDir + "] in case of upgrade, delete manually if not needed");
+ }
}
+
}
diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/plugins/RemovePluginCommandTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/plugins/RemovePluginCommandTests.java
index e2910be64f0..ab4f00492b0 100644
--- a/qa/evil-tests/src/test/java/org/elasticsearch/plugins/RemovePluginCommandTests.java
+++ b/qa/evil-tests/src/test/java/org/elasticsearch/plugins/RemovePluginCommandTests.java
@@ -19,6 +19,14 @@
package org.elasticsearch.plugins;
+import org.apache.lucene.util.LuceneTestCase;
+import org.elasticsearch.cli.MockTerminal;
+import org.elasticsearch.cli.UserException;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.env.Environment;
+import org.elasticsearch.test.ESTestCase;
+import org.junit.Before;
+
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
@@ -26,13 +34,8 @@ import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
-import org.apache.lucene.util.LuceneTestCase;
-import org.elasticsearch.cli.UserException;
-import org.elasticsearch.cli.MockTerminal;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.env.Environment;
-import org.elasticsearch.test.ESTestCase;
-import org.junit.Before;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.not;
@LuceneTestCase.SuppressFileSystems("*")
public class RemovePluginCommandTests extends ESTestCase {
@@ -109,4 +112,26 @@ public class RemovePluginCommandTests extends ESTestCase {
assertRemoveCleaned(env);
}
+ public void testConfigDirPreserved() throws Exception {
+ Files.createDirectories(env.pluginsFile().resolve("fake"));
+ final Path configDir = env.configFile().resolve("fake");
+ Files.createDirectories(configDir);
+ Files.createFile(configDir.resolve("fake.yml"));
+ final MockTerminal terminal = removePlugin("fake", home);
+ assertTrue(Files.exists(env.configFile().resolve("fake")));
+ assertThat(terminal.getOutput(), containsString(expectedConfigDirPreservedMessage(configDir)));
+ assertRemoveCleaned(env);
+ }
+
+ public void testNoConfigDirPreserved() throws Exception {
+ Files.createDirectories(env.pluginsFile().resolve("fake"));
+ final Path configDir = env.configFile().resolve("fake");
+ final MockTerminal terminal = removePlugin("fake", home);
+ assertThat(terminal.getOutput(), not(containsString(expectedConfigDirPreservedMessage(configDir))));
+ }
+
+ private String expectedConfigDirPreservedMessage(final Path configDir) {
+ return "-> Preserving plugin config files [" + configDir + "] in case of upgrade, delete manually if not needed";
+ }
+
}