From 86f013448de63cc05aa782ce4ac178e6a7db79dc Mon Sep 17 00:00:00 2001 From: Snjezana Peco Date: Thu, 9 Nov 2023 19:08:39 +0100 Subject: [PATCH] Avoid refreshing bundles whose dependency closure includes JDT-LS. --- .../core/internal/handlers/BundleUtils.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BundleUtils.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BundleUtils.java index 5363fa1c30..1e2f27e93c 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BundleUtils.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BundleUtils.java @@ -33,6 +33,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.ls.core.internal.IConstants; import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; import org.eclipse.osgi.container.ModuleContainer; import org.eclipse.osgi.util.ManifestElement; @@ -106,7 +107,7 @@ public static void loadBundles(Collection bundleLocations) throws CoreEx MultiStatus status = new MultiStatus(context.getBundle().getSymbolicName(), IStatus.OK, "Load bundle list", null); Set bundlesToStart = new HashSet<>(); Set toRefresh = new HashSet<>(); - FrameworkWiring frameworkWiring = context.getBundle(0).adapt(FrameworkWiring.class); + FrameworkWiring frameworkWiring = getFrameworkWiring(); for (String bundleLocation : bundleLocations) { try { if (StringUtils.isEmpty(bundleLocation)) { @@ -205,10 +206,29 @@ private static void installBundle(BundleContext context, Set bundlesToSt * @throws BundleException */ private static void uninstallBundle(Set bundlesToStart, Set toRefresh, Bundle bundle) throws BundleException { - bundle.uninstall(); - JavaLanguageServerPlugin.logInfo("Uninstalled " + bundle.getLocation()); - toRefresh.add(bundle); - bundlesToStart.remove(bundle); + if (selfExcludedFromDependencyClosure(bundle)) { + bundle.uninstall(); + JavaLanguageServerPlugin.logInfo("Uninstalled " + bundle.getLocation()); + toRefresh.add(bundle); + bundlesToStart.remove(bundle); + } + } + + private static boolean selfExcludedFromDependencyClosure(Bundle bundle) throws BundleException { + Collection bundles = getFrameworkWiring().getDependencyClosure(Collections.singletonList(bundle)); + for (Bundle b : bundles) { + if (IConstants.PLUGIN_ID.equals(b.getSymbolicName())) { + JavaLanguageServerPlugin.logError("Cannot refresh bundle " + b.getSymbolicName() + " because its dependency closure includes the " + IConstants.PLUGIN_ID + " bundle."); + return false; + } + } + return true; + } + + private static FrameworkWiring getFrameworkWiring() { + BundleContext context = JavaLanguageServerPlugin.getBundleContext(); + FrameworkWiring frameworkWiring = context.getBundle(0).adapt(FrameworkWiring.class); + return frameworkWiring; } private static Bundle[] getBundles(String symbolicName, FrameworkWiring fwkWiring) {