Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid refreshing bundles whose dependency closure includes JDT-LS. #2951

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,7 +107,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 +206,29 @@ 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 (selfExcludedFromDependencyClosure(bundle)) {
bundle.uninstall();
JavaLanguageServerPlugin.logInfo("Uninstalled " + bundle.getLocation());
toRefresh.add(bundle);
bundlesToStart.remove(bundle);
}
}

private static boolean selfExcludedFromDependencyClosure(Bundle bundle) throws BundleException {
Collection<Bundle> 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) {
Expand Down