@Override
    public void pluginJarRemoved(BundleOrPluginFileDetails bundleOrPluginFileDetails) {
        GoPluginDescriptor existingDescriptor = registry.getPluginByIdOrFileName(null, bundleOrPluginFileDetails.file().getName());
        if (existingDescriptor == null) {
            return;
        }
        try {
            LOGGER.info("Plugin removal starting: {}", bundleOrPluginFileDetails.file());

            boolean externalPlugin = !bundleOrPluginFileDetails.isBundledPlugin();
            boolean bundledPlugin = existingDescriptor.isBundledPlugin();
            boolean externalPluginWithSameIdAsBundledPlugin = bundledPlugin && externalPlugin;
            if (externalPluginWithSameIdAsBundledPlugin) {
                LOGGER.info("External Plugin file '{}' having same name as bundled plugin file has been removed. Refusing to unload bundled plugin with id: '{}'", bundleOrPluginFileDetails.file(), existingDescriptor.id());
                return;
            }
            removePlugin(existingDescriptor.bundleDescriptor());
        } finally {
            LOGGER.info("Plugin removal finished: {}", bundleOrPluginFileDetails.file());
        }
    }
@Test
    void shouldRemovePluginFromBundlePathAndInformRegistryWhenAPluginIsRemoved() throws Exception {
        File pluginJarFile = new File(pluginWorkDir, PLUGIN_JAR_FILE_NAME);
        File removedBundleDirectory = new File(bundleDir, PLUGIN_JAR_FILE_NAME);

        String pluginJarFileLocation = pluginJarFile.getAbsolutePath();
        final GoPluginDescriptor descriptorOfThePluginWhichWillBeRemoved = GoPluginDescriptor.builder()
                .id("testplugin.descriptorValidator")
                .bundleLocation(removedBundleDirectory)
                .pluginJarFileLocation(pluginJarFileLocation)
                .isBundledPlugin(true)
                .build();
        GoPluginBundleDescriptor descriptorOfThePluginBundleWhichWillBeRemoved = new GoPluginBundleDescriptor(descriptorOfThePluginWhichWillBeRemoved);

        when(registry.getPluginByIdOrFileName(null, descriptorOfThePluginWhichWillBeRemoved.fileName())).thenReturn(descriptorOfThePluginWhichWillBeRemoved);
        when(registry.unloadPlugin(descriptorOfThePluginBundleWhichWillBeRemoved)).thenReturn(descriptorOfThePluginBundleWhichWillBeRemoved);

        copyPluginToTheDirectory(bundleDir, PLUGIN_JAR_FILE_NAME);

        listener.pluginJarRemoved(new BundleOrPluginFileDetails(pluginJarFile, true, pluginWorkDir));

        verify(registry).unloadPlugin(descriptorOfThePluginBundleWhichWillBeRemoved);
        verify(pluginLoader).unloadPlugin(descriptorOfThePluginBundleWhichWillBeRemoved);
        assertThat(removedBundleDirectory).doesNotExist();
    }