Update required plugins if available

When plugins are updated, we should update required plugins, too, so
that we do not get errors when new plugins use features not available
in the old versions of required plugins.
This commit is contained in:
René Pfeuffer
2020-07-02 12:08:23 +02:00
parent 3b0693e744
commit e3eb8a99d0
6 changed files with 31 additions and 13 deletions

View File

@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Checkboxes can now be 'indeterminate' ([#1215](https://github.com/scm-manager/scm-manager/pull/1215))
- The old frontend extension point `changeset.description` is deprecated and should be replaced with `changeset.description.tokens` ([#1231](https://github.com/scm-manager/scm-manager/pull/1231))
- Required plugins will be updated, too, when a plugin is updated ([#1233](https://github.com/scm-manager/scm-manager/pull/1233))
### Fixed
- Fixed installation of debian packages on distros without preinstalled `at` ([#1216](https://github.com/scm-manager/scm-manager/issues/1216) and [#1217](https://github.com/scm-manager/scm-manager/pull/1217))

View File

@@ -61,7 +61,7 @@
"version": "Version",
"currentVersion": "Installierte Version",
"newVersion": "Neue Version",
"dependencyNotification": "Mit diesem Plugin werden folgende Abhängigkeiten mit installiert, wenn sie noch nicht vorhanden sind!",
"dependencyNotification": "Mit diesem Plugin werden folgende Abhängigkeiten mit installiert bzw. aktualisiert, wenn sie noch nicht in der aktuellen Version vorhanden sind!",
"dependencies": "Abhängigkeiten",
"installedNotification": "Das Plugin wurde erfolgreich installiert. Um Änderungen an der UI zu sehen, muss die Seite neu geladen werden:",
"updatedNotification": "Das Plugin wurde erfolgreich aktualisiert. Um Änderungen an der UI zu sehen, muss die Seite neu geladen werden:",

View File

@@ -61,7 +61,7 @@
"version": "Version",
"currentVersion": "Installed version",
"newVersion": "New version",
"dependencyNotification": "With this plugin, the following dependencies will be installed if they are not available yet!",
"dependencyNotification": "With this plugin, the following dependencies will be installed/updated if their latest versions are not installed yet!",
"dependencies": "Dependencies",
"installedNotification": "Successfully installed plugin. You have to reload the page, to see ui changes:",
"updatedNotification": "Successfully updated plugin. You have to reload the page, to see ui changes:",

View File

@@ -247,18 +247,18 @@ public class DefaultPluginManager implements PluginManager {
private List<AvailablePlugin> collectPluginsToInstall(String name) {
List<AvailablePlugin> plugins = new ArrayList<>();
collectPluginsToInstall(plugins, name, true);
collectPluginsToInstallOrUpdate(plugins, name);
return plugins;
}
private void collectPluginsToInstall(List<AvailablePlugin> plugins, String name, boolean isUpdate) {
if (!isInstalledOrPending(name) || isUpdate && isUpdatable(name)) {
private void collectPluginsToInstallOrUpdate(List<AvailablePlugin> plugins, String name) {
if (!isInstalledOrPending(name) || isUpdatable(name)) {
AvailablePlugin plugin = getAvailable(name).orElseThrow(() -> NotFoundException.notFound(entity(AvailablePlugin.class, name)));
Set<String> dependencies = plugin.getDescriptor().getDependencies();
if (dependencies != null) {
for (String dependency : dependencies) {
collectPluginsToInstall(plugins, dependency, false);
collectPluginsToInstallOrUpdate(plugins, dependency);
}
}

View File

@@ -227,7 +227,7 @@ class DefaultPluginManagerTest {
}
@Test
void shouldNotInstallAlreadyInstalledDependencies() {
void shouldNotInstallAlreadyInstalledDependenciesWhenUpToDate() {
AvailablePlugin review = createAvailable("scm-review-plugin");
when(review.getDescriptor().getDependencies()).thenReturn(ImmutableSet.of("scm-mail-plugin"));
AvailablePlugin mail = createAvailable("scm-mail-plugin");
@@ -244,6 +244,22 @@ class DefaultPluginManagerTest {
assertThat(captor.getValue().getDescriptor().getInformation().getName()).isEqualTo("scm-review-plugin");
}
@Test
void shouldUpdateAlreadyInstalledDependenciesWhenNewerVersionIsAvailable() {
AvailablePlugin review = createAvailable("scm-review-plugin");
when(review.getDescriptor().getDependencies()).thenReturn(ImmutableSet.of("scm-mail-plugin"));
AvailablePlugin mail = createAvailable("scm-mail-plugin", "1.1.0");
when(center.getAvailable()).thenReturn(ImmutableSet.of(review, mail));
InstalledPlugin installedMail = createInstalled("scm-mail-plugin", "1.0.0");
when(loader.getInstalledPlugins()).thenReturn(ImmutableList.of(installedMail));
manager.install("scm-review-plugin", false);
verify(installer).install(mail);
verify(installer).install(review);
}
@Test
void shouldRollbackOnFailedInstallation() {
AvailablePlugin review = createAvailable("scm-review-plugin");

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.plugin;
import org.mockito.Answers;
@@ -32,10 +32,7 @@ import static org.mockito.Mockito.when;
public class PluginTestHelper {
public static AvailablePlugin createAvailable(String name) {
PluginInformation information = new PluginInformation();
information.setName(name);
information.setVersion("1.0");
return createAvailable(information);
return createAvailable(name, "1.0");
}
public static AvailablePlugin createAvailable(String name, String version) {
@@ -46,9 +43,13 @@ public class PluginTestHelper {
}
public static InstalledPlugin createInstalled(String name) {
return createInstalled(name, "1.0");
}
public static InstalledPlugin createInstalled(String name, String version) {
PluginInformation information = new PluginInformation();
information.setName(name);
information.setVersion("1.0");
information.setVersion(version);
return createInstalled(information);
}