Skip to content

Commit

Permalink
Don't refresh org.eclipse.jdt.ls.core
Browse files Browse the repository at this point in the history
  • Loading branch information
snjeza committed Nov 9, 2023
1 parent 2412ed9 commit 6daecf1
Showing 1 changed file with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
Expand All @@ -33,6 +35,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;
Expand Down Expand Up @@ -106,7 +109,7 @@ public static void loadBundles(Collection<String> bundleLocations) throws CoreEx
MultiStatus status = new MultiStatus(context.getBundle().getSymbolicName(), IStatus.OK, "Load bundle list", null);
Set<Bundle> bundlesToStart = new HashSet<>();
Set<Bundle> toRefresh = new HashSet<>();
FrameworkWiring frameworkWiring = context.getBundle(0).adapt(FrameworkWiring.class);
FrameworkWiring frameworkWiring = getFrameworkWiring();
for (String bundleLocation : bundleLocations) {
try {
if (StringUtils.isEmpty(bundleLocation)) {
Expand Down Expand Up @@ -205,10 +208,32 @@ private static void installBundle(BundleContext context, Set<Bundle> bundlesToSt
* @throws BundleException
*/
private static void uninstallBundle(Set<Bundle> bundlesToStart, Set<Bundle> 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 {
FrameworkWiring frameworkWiring = getFrameworkWiring();
List<Bundle> list = new ArrayList<>();
list.add(bundle);
Collection<Bundle> bundles = frameworkWiring.getDependencyClosure(list);
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) {
Expand Down

0 comments on commit 6daecf1

Please sign in to comment.