Skip to content

Commit 7dd34da

Browse files
committed
Improve support for in-application browser-based notifications
- Add support for determining JDT's available installed JREs mapping them to IUs so they can be used to restrict a notification based on that information. #134
1 parent ab18432 commit 7dd34da

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

plugins/org.eclipse.oomph.setup.editor/src/org/eclipse/oomph/setup/presentation/handlers/NotificationsHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ public Object execute(ExecutionEvent event) throws ExecutionException
4747
NotificationViewPart notificationView = (NotificationViewPart)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(
4848
NotificationViewPart.VIEW_ID, "ID" + ++count, //$NON-NLS-1$
4949
IWorkbenchPage.VIEW_VISIBLE);
50-
notificationView.getSite().getPage().bringToTop(notificationView);
50+
if (count == 1)
51+
{
52+
notificationView.getSite().getPage().bringToTop(notificationView);
53+
}
54+
5155
notificationView.setNotification(annotation);
5256
}
5357
}

plugins/org.eclipse.oomph.setup.ui/src/org/eclipse/oomph/setup/ui/SetupUIPlugin.java

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import org.eclipse.core.runtime.jobs.Job;
8888
import org.eclipse.equinox.p2.engine.IProfile;
8989
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
90+
import org.eclipse.equinox.p2.metadata.MetadataFactory;
9091
import org.eclipse.equinox.p2.metadata.Version;
9192
import org.eclipse.equinox.p2.query.CollectionResult;
9293
import org.eclipse.equinox.p2.query.IQueryResult;
@@ -110,6 +111,7 @@
110111
import org.osgi.framework.BundleContext;
111112

112113
import java.io.File;
114+
import java.lang.reflect.Constructor;
113115
import java.util.ArrayList;
114116
import java.util.Collections;
115117
import java.util.HashSet;
@@ -481,8 +483,10 @@ private static void handleNotificationAnnotations(ProductVersion productVersion)
481483

482484
if (queriable == null)
483485
{
484-
IInstallableUnit jreIU = P2Util.createJREIU("jre"); //$NON-NLS-1$
485-
queriable = QueryUtil.compoundQueryable(profile, new CollectionResult<>(List.of(jreIU)));
486+
List<IInstallableUnit> extraIUs = new ArrayList<>();
487+
extraIUs.add(P2Util.createJREIU("jre")); //$NON-NLS-1$
488+
extraIUs.addAll(getInstalledJREs());
489+
queriable = QueryUtil.compoundQueryable(profile, new CollectionResult<>(extraIUs));
486490
}
487491

488492
Requirement requirement = (Requirement)eObject;
@@ -569,6 +573,54 @@ private static List<Annotation> getNotificationAnnotations(ModelElement modelEle
569573
return result;
570574
}
571575

576+
@SuppressWarnings("nls")
577+
private static List<IInstallableUnit> getInstalledJREs()
578+
{
579+
List<IInstallableUnit> result = new ArrayList<>();
580+
try
581+
{
582+
Class<?> javaRuntimeClass = CommonPlugin.loadClass("org.eclipse.jdt.launching", "org.eclipse.jdt.launching.JavaRuntime");
583+
Object[] vmInstallTypes = ReflectUtil.invokeMethod("getVMInstallTypes", javaRuntimeClass);
584+
for (Object vmInstallType : vmInstallTypes)
585+
{
586+
String id = ReflectUtil.invokeMethod("getId", vmInstallType);
587+
if ("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType".equals(id))
588+
{
589+
Object[] vmInstalls = ReflectUtil.invokeMethod("getVMInstalls", vmInstallType);
590+
Class<?> vmStandinClass = CommonPlugin.loadClass("org.eclipse.jdt.launching", "org.eclipse.jdt.launching.VMStandin");
591+
Constructor<?> constructor = ReflectUtil.getConstructor(vmStandinClass, vmInstalls.getClass().getComponentType());
592+
for (Object vmInstall : vmInstalls)
593+
{
594+
Object vmStandin = constructor.newInstance(vmInstall);
595+
String javaVersion = ReflectUtil.invokeMethod("getJavaVersion", vmStandin);
596+
if (javaVersion != null)
597+
{
598+
try
599+
{
600+
Version version = Version.create(javaVersion);
601+
MetadataFactory.InstallableUnitDescription iuDescription = new MetadataFactory.InstallableUnitDescription();
602+
iuDescription.setId("installed.jre");
603+
iuDescription.setVersion(version);
604+
iuDescription.addProvidedCapabilities(List.of(MetadataFactory.createProvidedCapability("org.eclipse.equinox.p2.iu", "installed.jre", version)));
605+
result.add(MetadataFactory.createInstallableUnit(iuDescription));
606+
}
607+
catch (RuntimeException ex)
608+
{
609+
//$FALL-THROUGH$
610+
}
611+
}
612+
}
613+
}
614+
}
615+
}
616+
catch (Throwable ex)
617+
{
618+
//$FALL-THROUGH$
619+
}
620+
621+
return result;
622+
}
623+
572624
public static boolean isRememberedNotificationURI(String notificationURI)
573625
{
574626
return !rememberNotificationURI(notificationURI, SetupContext.GLOBAL_SETUPS_LOCATION_URI, false)

0 commit comments

Comments
 (0)