From b67a0cb89d0a1f341b6a0d5f99f767d7415d0275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Tue, 24 Nov 2020 18:18:16 +0100 Subject: [PATCH 1/3] Improve logging for failures during plugin installation --- .../sonia/scm/plugin/DefaultPluginManager.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scm-webapp/src/main/java/sonia/scm/plugin/DefaultPluginManager.java b/scm-webapp/src/main/java/sonia/scm/plugin/DefaultPluginManager.java index b53d715ef6..816bd5639e 100644 --- a/scm-webapp/src/main/java/sonia/scm/plugin/DefaultPluginManager.java +++ b/scm-webapp/src/main/java/sonia/scm/plugin/DefaultPluginManager.java @@ -192,10 +192,16 @@ public class DefaultPluginManager implements PluginManager { dependencyTracker.addInstalled(plugin.getDescriptor()); pendingInstallations.add(pending); eventBus.post(new PluginEvent(PluginEvent.PluginEventType.INSTALLED, plugin)); - } catch (PluginInstallException ex) { - cancelPending(pendingInstallations); - eventBus.post(new PluginEvent(PluginEvent.PluginEventType.INSTALLATION_FAILED, plugin)); - throw ex; + } catch (PluginInstallException installException) { + try { + cancelPending(pendingInstallations); + } catch (PluginFailedToCancelInstallationException cancelInstallationException) { + LOG.error("could not install plugin {}; uninstallation failed (see next exception)", plugin.getDescriptor().getInformation().getName(), installException); + throw cancelInstallationException; + } finally { + eventBus.post(new PluginEvent(PluginEvent.PluginEventType.INSTALLATION_FAILED, plugin)); + } + throw installException; } } From fc9176ec5a12e4b169b6d4f1718ed0154ec70465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Tue, 24 Nov 2020 18:18:50 +0100 Subject: [PATCH 2/3] No exception for missing file on cancelled installation --- .../scm/plugin/PendingPluginInstallation.java | 14 +++++++++----- .../scm/plugin/PendingPluginInstallationTest.java | 7 ++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/scm-webapp/src/main/java/sonia/scm/plugin/PendingPluginInstallation.java b/scm-webapp/src/main/java/sonia/scm/plugin/PendingPluginInstallation.java index 1da4823b7d..13f18c74c3 100644 --- a/scm-webapp/src/main/java/sonia/scm/plugin/PendingPluginInstallation.java +++ b/scm-webapp/src/main/java/sonia/scm/plugin/PendingPluginInstallation.java @@ -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.slf4j.Logger; @@ -50,10 +50,14 @@ class PendingPluginInstallation { void cancel() { String name = plugin.getDescriptor().getInformation().getName(); LOG.info("cancel installation of plugin {}", name); - try { - Files.delete(file); - } catch (IOException ex) { - throw new PluginFailedToCancelInstallationException("failed to cancel plugin installation ", name, ex); + if (Files.exists(file)) { + try { + Files.delete(file); + } catch (IOException ex) { + throw new PluginFailedToCancelInstallationException("failed to cancel plugin installation ", name, ex); + } + } else { + LOG.info("plugin file {} did not exists for plugin {}; nothing deleted", file, name); } } } diff --git a/scm-webapp/src/test/java/sonia/scm/plugin/PendingPluginInstallationTest.java b/scm-webapp/src/test/java/sonia/scm/plugin/PendingPluginInstallationTest.java index b668870488..f8fe44e8f0 100644 --- a/scm-webapp/src/test/java/sonia/scm/plugin/PendingPluginInstallationTest.java +++ b/scm-webapp/src/test/java/sonia/scm/plugin/PendingPluginInstallationTest.java @@ -59,8 +59,13 @@ class PendingPluginInstallationTest { } @Test - void shouldThrowExceptionIfCancelFailed(@TempDir Path directory) { + void shouldThrowExceptionIfCancelFailed(@TempDir Path directory) throws IOException { Path file = directory.resolve("file"); + Files.createDirectory(file); + + Path makeFileNotDeletable = file.resolve("not_deletable"); + Files.write(makeFileNotDeletable, "42".getBytes()); + when(plugin.getDescriptor().getInformation().getName()).thenReturn("scm-awesome-plugin"); PendingPluginInstallation installation = new PendingPluginInstallation(plugin, file); From c6139c647e3ef9199604c1b0b243833d845047d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Tue, 24 Nov 2020 18:18:59 +0100 Subject: [PATCH 3/3] Log change --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d901774353..5607b47e33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased +### Fixed +- Improved logging of failures during plugin installation ([#1442](https://github.com/scm-manager/scm-manager/pull/1442)) +- Do not throw exception when plugin file does not exist on cancelled installation ([#1442](https://github.com/scm-manager/scm-manager/pull/1442)) + ## [2.10.0] - 2020-11-20 ### Added - Delete branches directly in the UI ([#1422](https://github.com/scm-manager/scm-manager/pull/1422))