|
87 | 87 | import org.eclipse.core.runtime.jobs.Job; |
88 | 88 | import org.eclipse.equinox.p2.engine.IProfile; |
89 | 89 | import org.eclipse.equinox.p2.metadata.IInstallableUnit; |
| 90 | +import org.eclipse.equinox.p2.metadata.MetadataFactory; |
90 | 91 | import org.eclipse.equinox.p2.metadata.Version; |
91 | 92 | import org.eclipse.equinox.p2.query.CollectionResult; |
92 | 93 | import org.eclipse.equinox.p2.query.IQueryResult; |
|
110 | 111 | import org.osgi.framework.BundleContext; |
111 | 112 |
|
112 | 113 | import java.io.File; |
| 114 | +import java.lang.reflect.Constructor; |
113 | 115 | import java.util.ArrayList; |
114 | 116 | import java.util.Collections; |
115 | 117 | import java.util.HashSet; |
@@ -481,8 +483,10 @@ private static void handleNotificationAnnotations(ProductVersion productVersion) |
481 | 483 |
|
482 | 484 | if (queriable == null) |
483 | 485 | { |
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)); |
486 | 490 | } |
487 | 491 |
|
488 | 492 | Requirement requirement = (Requirement)eObject; |
@@ -569,6 +573,54 @@ private static List<Annotation> getNotificationAnnotations(ModelElement modelEle |
569 | 573 | return result; |
570 | 574 | } |
571 | 575 |
|
| 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 | + |
572 | 624 | public static boolean isRememberedNotificationURI(String notificationURI) |
573 | 625 | { |
574 | 626 | return !rememberNotificationURI(notificationURI, SetupContext.GLOBAL_SETUPS_LOCATION_URI, false) |
|
0 commit comments