@Override
    public void pluginJarUpdated(BundleOrPluginFileDetails bundleOrPluginFileDetails) {
        final GoPluginBundleDescriptor bundleDescriptor = goPluginBundleDescriptorBuilder.build(bundleOrPluginFileDetails);

        try {
            LOGGER.info("Plugin update starting: {}", bundleOrPluginFileDetails.file());

            validateIfExternalPluginRemovingBundledPlugin(bundleDescriptor);
            validateIfSamePluginUpdated(bundleDescriptor);
            validatePluginCompatibilityWithCurrentOS(bundleDescriptor);
            validatePluginCompatibilityWithGoCD(bundleDescriptor);
            removePlugin(bundleDescriptor);
            addPlugin(bundleOrPluginFileDetails, bundleDescriptor);
        } finally {
            LOGGER.info("Plugin update finished: {}", bundleOrPluginFileDetails.file());
        }
    }
@Test
    void shouldNotTryAndUpdateManifestOfAnUpdatedInvalidPlugin() throws Exception {
        DefaultPluginJarChangeListener spy = spy(listener);
        String pluginId = "plugin-id";
        File pluginFile = new File(pluginWorkDir, PLUGIN_JAR_FILE_NAME);
        copyPluginToTheDirectory(pluginWorkDir, PLUGIN_JAR_FILE_NAME);
        File expectedBundleDirectoryForInvalidPlugin = new File(bundleDir, PLUGIN_JAR_FILE_NAME);
        File bundleDirectoryForOldPlugin = new File(bundleDir, "descriptor-aware-test-plugin-old.jar");
        FileUtils.forceMkdir(bundleDirectoryForOldPlugin);

        String pluginJarFileLocation = pluginFile.getAbsolutePath();
        GoPluginBundleDescriptor descriptorForInvalidPlugin = new GoPluginBundleDescriptor(GoPluginDescriptor.builder()
                .id("testplugin.descriptorValidator")
                .bundleLocation(expectedBundleDirectoryForInvalidPlugin)
                .pluginJarFileLocation(pluginJarFileLocation)
                .pluginJarFileLocation(pluginJarFileLocation)
                .isBundledPlugin(true)
                .build())
                .markAsInvalid(List.of("For a test"), null);

        Bundle oldBundle = mock(Bundle.class);
        final GoPluginDescriptor oldPluginDescriptor = GoPluginDescriptor.builder()
                .id("some.old.id")
                .bundleLocation(bundleDirectoryForOldPlugin)
                .pluginJarFileLocation("some/path/to/plugin.jar")
                .isBundledPlugin(true)
                .build();
        GoPluginBundleDescriptor oldBundleDescriptor = new GoPluginBundleDescriptor(oldPluginDescriptor).setBundle(oldBundle);

        when(goPluginBundleDescriptorBuilder.build(new BundleOrPluginFileDetails(pluginFile, true, pluginWorkDir))).thenReturn(descriptorForInvalidPlugin);
        when(registry.getPlugin(pluginId)).thenReturn(oldPluginDescriptor);
        when(registry.unloadPlugin(descriptorForInvalidPlugin)).thenReturn(oldBundleDescriptor);
        doNothing().when(registry).loadPlugin(descriptorForInvalidPlugin);


        spy.pluginJarUpdated(new BundleOrPluginFileDetails(pluginFile, true, pluginWorkDir));

        assertThat(expectedBundleDirectoryForInvalidPlugin).exists();
        assertThat(bundleDirectoryForOldPlugin).doesNotExist();
        verify(registry).unloadPlugin(descriptorForInvalidPlugin);
        verify(pluginLoader).unloadPlugin(oldBundleDescriptor);
        verify(registry).loadPlugin(descriptorForInvalidPlugin);
        verifyNoMoreInteractions(osgiManifestGenerator);
        verifyNoMoreInteractions(pluginLoader);
    }