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..be4ee6af94 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 (checkBundle(bundle)) { + bundle.uninstall(); + JavaLanguageServerPlugin.logInfo("Uninstalled " + bundle.getLocation()); + toRefresh.add(bundle); + bundlesToStart.remove(bundle); + } + } + + private static boolean checkBundle(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 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) {