aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2017-10-20 10:32:27 +0200
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-10-23 08:01:13 -0700
commit061b025defefdba99fcbd45518742b8685fceb4a (patch)
tree400f76866f49654485f871224d2e639190e2d30a /server
parent68d930b10e4dbf169f52d8fe488ad06edf94e6d7 (diff)
downloadsonarqube-061b025defefdba99fcbd45518742b8685fceb4a.tar.gz
sonarqube-061b025defefdba99fcbd45518742b8685fceb4a.zip
SONAR-9333 Web service api/plugins/uninstall fails when plugin is already being uninstalling
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java12
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java17
2 files changed, 26 insertions, 3 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
index f8760d3358b..7fb654172f9 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
@@ -316,10 +316,16 @@ public class ServerPluginRepository implements PluginRepository, Startable {
for (String uninstallKey : uninstallKeys) {
PluginInfo info = getPluginInfo(uninstallKey);
+
try {
+ if (!getPluginFile(info).exists()) {
+ LOG.info("Plugin already uninstalled: {} [{}]", info.getName(), info.getKey());
+ continue;
+ }
+
LOG.info("Uninstalling plugin {} [{}]", info.getName(), info.getKey());
- File masterFile = pluginFile(info);
+ File masterFile = getPluginFile(info);
moveFileToDirectory(masterFile, uninstallDir, true);
} catch (IOException e) {
throw new IllegalStateException(format("Fail to uninstall plugin %s [%s]", info.getName(), info.getKey()), e);
@@ -344,7 +350,7 @@ public class ServerPluginRepository implements PluginRepository, Startable {
for (PluginInfo otherPlugin : getPluginInfos()) {
if (!otherPlugin.getKey().equals(pluginKey)) {
for (PluginInfo.RequiredPlugin requirement : otherPlugin.getRequiredPlugins()) {
- if (requirement.getKey().equals(pluginKey) && pluginFile(otherPlugin).exists()) {
+ if (requirement.getKey().equals(pluginKey)) {
appendTo.add(otherPlugin.getKey());
appendDependentPluginKeys(otherPlugin.getKey(), appendTo);
}
@@ -353,7 +359,7 @@ public class ServerPluginRepository implements PluginRepository, Startable {
}
}
- private File pluginFile(PluginInfo info) {
+ private File getPluginFile(PluginInfo info) {
// we don't reuse info.getFile() just to be sure that file is located in from extensions/plugins
return new File(fs.getInstalledPluginsDir(), info.getNonNullJarFile().getName());
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
index 1040c6813a9..df94b6e5d5d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
@@ -270,6 +270,23 @@ public class ServerPluginRepositoryTest {
}
@Test
+ public void dont_uninstall_non_existing_files() throws IOException {
+ File base = copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir());
+ File extension = copyTestPluginTo("test-require-plugin", fs.getInstalledPluginsDir());
+ File uninstallDir = temp.newFolder("uninstallDir");
+
+ underTest.start();
+ assertThat(underTest.getPluginInfos()).hasSize(2);
+ underTest.uninstall("testbase", uninstallDir);
+ assertThat(underTest.getPluginInfos()).hasSize(2);
+
+ underTest.uninstall("testbase", uninstallDir);
+ assertThat(base).doesNotExist();
+ assertThat(extension).doesNotExist();
+ assertThat(uninstallDir.list()).containsOnly(base.getName(), extension.getName());
+ }
+
+ @Test
public void install_plugin_and_its_extension_plugins_at_startup() throws Exception {
copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir());
copyTestPluginTo("test-extend-plugin", fs.getInstalledPluginsDir());