Skip to content

Commit 0d25c0c

Browse files
committed
Merge branch 'jvmArch'
2 parents 408a360 + e6aad47 commit 0d25c0c

4 files changed

Lines changed: 54 additions & 6 deletions

File tree

launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/internal/launching/ext/PDEUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111
package org.eclipse.rcptt.internal.launching.ext;
1212

1313
import java.util.Map;
14+
import java.util.Optional;
1415
import java.util.Set;
1516
import java.util.stream.Stream;
1617

1718
import org.eclipse.core.runtime.CoreException;
19+
import org.eclipse.core.runtime.IPath;
1820
import org.eclipse.debug.core.ILaunchConfiguration;
21+
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
1922
import org.eclipse.jdt.launching.IVMInstall;
23+
import org.eclipse.jdt.launching.JavaRuntime;
2024
import org.eclipse.osgi.service.resolver.BundleDescription;
2125
import org.eclipse.pde.core.plugin.IPluginModelBase;
2226
import org.eclipse.pde.internal.build.IPDEBuildConstants;
@@ -73,5 +77,16 @@ public static IVMInstall getVMInstall(ILaunchConfiguration configuration, Set<IP
7377
public static Stream<String> startupPackageNames() {
7478
return Stream.of(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER);
7579
}
80+
81+
public static Optional<String> getExecutionEnvironmentId(ILaunchConfiguration configuration) throws CoreException {
82+
String jre = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String) null);
83+
if (jre == null) {
84+
return Optional.empty();
85+
}
86+
87+
// Launch configuration has a JRE or EE set, throw exception if associated vm not found
88+
IPath jrePath = IPath.fromPortableString(jre);
89+
return Optional.ofNullable(JavaRuntime.getExecutionEnvironmentId(jrePath));
90+
}
7691

7792
}

launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/ext/JvmTargetCompatibility.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ public String explainJvmRequirements() throws CoreException {
219219
return result.toString();
220220
}
221221

222-
222+
public Stream<VmInstallMetaData> findForEnvironment(String executionEnvironmentId) {
223+
return VmInstallMetaData.forEnvironment(executionEnvironmentId).filter(this::isCompatible);
224+
}
225+
223226

224227
private static final String[] EMPTY = new String[0];
225228
private static String[] getExecutionEnironments(IPluginModelBase plugin) {

launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/ext/Q7ExternalLaunchDelegate.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,13 @@ public boolean preLaunchCheck(ILaunchConfiguration configuration,
229229
info.target = target;
230230

231231

232-
JvmTargetCompatibility compatibility = new JvmTargetCompatibility(target);
233-
234-
IVMInstall configuredJvm = getVMInstall(configuration, target);
232+
try {
233+
getVMInstall(configuration, target);
234+
} catch (CoreException e) {
235+
error.add(e.getStatus());
236+
throw new CoreException(error);
237+
}
235238

236-
error.add(compatibility.checkCompatibilty(configuredJvm));
237239
if (error.matches(IStatus.CANCEL)) {
238240
return false;
239241
}
@@ -251,7 +253,25 @@ public boolean preLaunchCheck(ILaunchConfiguration configuration,
251253
}
252254

253255
public static IVMInstall getVMInstall(ILaunchConfiguration configuration, ITargetPlatformHelper target) throws CoreException {
254-
return PDEUtils.getVMInstall(configuration, target.getModels().map(m -> m.model()).collect(Collectors.toSet()));
256+
JvmTargetCompatibility compatibility = new JvmTargetCompatibility(target);
257+
IVMInstall pdeDerived = PDEUtils.getVMInstall(configuration, target.getModels().map(m -> m.model()).collect(Collectors.toSet()));
258+
IStatus error = compatibility.checkCompatibilty(pdeDerived);
259+
if (error.matches(IStatus.CANCEL)) {
260+
throw new CoreException(error);
261+
}
262+
if (!error.matches(IStatus.ERROR)) {
263+
return pdeDerived;
264+
}
265+
266+
Stream<VmInstallMetaData> byEnv = PDEUtils.getExecutionEnvironmentId(configuration).map(envId -> compatibility.findForEnvironment(envId)).orElse(Stream.empty());
267+
268+
return byEnv.findFirst().orElseThrow(() -> {
269+
try {
270+
return new CoreException(Status.error(compatibility.explainJvmRequirements()));
271+
} catch (CoreException e) {
272+
return e;
273+
}
274+
}).install;
255275
}
256276

257277
private void removeTargetPlatform(ILaunchConfiguration configuration)

launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/ext/VmInstallMetaData.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.nio.file.Path;
1616
import java.util.Arrays;
1717
import java.util.Collection;
18+
import java.util.Collections;
1819
import java.util.Objects;
1920
import java.util.Optional;
2021
import java.util.Set;
@@ -85,6 +86,14 @@ public static Stream<VmInstallMetaData> all() {
8586
return JDTUtils.installedVms().map(vm -> adapt(vm, environments.get(vm))).flatMap(Optional::stream);
8687
}
8788

89+
public static Stream<VmInstallMetaData> forEnvironment(String executionEnvironmentId) {
90+
IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
91+
IExecutionEnvironment environment = manager.getEnvironment(executionEnvironmentId);
92+
Collection<IExecutionEnvironment> environments = Collections.singletonList(environment);
93+
return Stream.concat(Stream.ofNullable(environment.getDefaultVM()), Arrays.stream(environment.getCompatibleVMs())).distinct().flatMap(install -> adapt(install, environments).stream());
94+
}
95+
96+
8897
private static Optional<VmInstallMetaData> adapt(IVMInstall install, Collection<IExecutionEnvironment> environments) {
8998
try {
9099
OSArchitecture jvmArch = JDTUtils.detect(install);
@@ -102,4 +111,5 @@ public static Stream<VmInstallMetaData> register(Path location) throws CoreExcep
102111
IVMInstall install = JDTUtils.registerVM(location.toFile());
103112
return adapt(install);
104113
}
114+
105115
}

0 commit comments

Comments
 (0)