PluginInfo info = getPluginInfo(uninstallKey);
try {
LOG.info("Uninstalling plugin {} [{}]", info.getName(), info.getKey());
- // we don't reuse info.getFile() just to be sure that file is located in from extensions/plugins
- File masterFile = new File(fs.getInstalledPluginsDir(), info.getNonNullJarFile().getName());
+
+ File masterFile = pluginFile(info);
moveFileToDirectory(masterFile, uninstallDir, true);
} catch (IOException e) {
throw new IllegalStateException(format("Fail to uninstall plugin %s [%s]", info.getName(), info.getKey()), e);
}
}
+ /**
+ * Appends dependent plugins, only the ones that still exist in the plugins folder.
+ */
private void appendDependentPluginKeys(String pluginKey, Set<String> appendTo) {
for (PluginInfo otherPlugin : getPluginInfos()) {
if (!otherPlugin.getKey().equals(pluginKey)) {
for (PluginInfo.RequiredPlugin requirement : otherPlugin.getRequiredPlugins()) {
- if (requirement.getKey().equals(pluginKey)) {
+ if (requirement.getKey().equals(pluginKey) && pluginFile(otherPlugin).exists()) {
appendTo.add(otherPlugin.getKey());
appendDependentPluginKeys(otherPlugin.getKey(), appendTo);
}
}
}
+ private File pluginFile(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());
+ }
+
public Map<String, PluginInfo> getPluginInfosByKeys() {
return pluginInfosByKeys;
}
public void uninstall() throws Exception {
File installedJar = copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir());
File uninstallDir = temp.newFolder("uninstallDir");
-
+
underTest.start();
assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase");
underTest.uninstall("testbase", uninstallDir);
assertThat(uninstallDir.list()).containsOnly(base.getName(), extension.getName());
}
+ @Test
+ public void dont_uninstall_non_existing_dependents() 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("testrequire", 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());