Search in sources :

Example 1 with IExecutionEnvironmentsManager

use of org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager in project bndtools by bndtools.

the class AbstractOSGiLaunchDelegate method getVMInstall.

@Override
public IVMInstall getVMInstall(ILaunchConfiguration configuration) throws CoreException {
    IExecutionEnvironmentsManager eeMgr = JavaRuntime.getExecutionEnvironmentsManager();
    // Look for a matching JVM install from the -runee setting
    String runee = run.getRunee();
    if (runee != null) {
        IExecutionEnvironment ee = eeMgr.getEnvironment(runee);
        if (ee != null) {
            // Return the default VM for this EE if the user has selected one
            IVMInstall defaultVm = ee.getDefaultVM();
            if (defaultVm != null)
                return defaultVm;
            IVMInstall[] compatibleVMs = ee.getCompatibleVMs();
            if (compatibleVMs != null && compatibleVMs.length > 0) {
                // Return the strictly compatible VM (i.e. perfect match) if there is one
                for (IVMInstall vm : compatibleVMs) {
                    if (ee.isStrictlyCompatible(vm))
                        return vm;
                }
                // No strictly compatible VM, just return the last in the list.
                return compatibleVMs[compatibleVMs.length - 1];
            }
        }
        throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, StatusCode.NoVMForEE.getCode(), "Could not find JRE installation matching Execution Environment: " + runee, null));
    }
    // Still nothing? Use the default JVM from the workspace.
    // Eclipse tries really hard to force you to set a default VM, but this can still be null if the default has
    // been disposed somehow.
    IVMInstall defaultVm = JavaRuntime.getDefaultVMInstall();
    if (defaultVm != null) {
        return defaultVm;
    }
    // You still here?? The superclass will look into the Java project, if the run file is in one.
    try {
        return super.getVMInstall(configuration);
    } catch (CoreException e) {
    // ignore
    }
    throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, StatusCode.NoVMForEE.getCode(), "Could not select a JRE for launch. No Execution Environment is specified\n(using '-runee'), there is no default JRE in preferences and no relevant\nJava project settings.", null));
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IExecutionEnvironment(org.eclipse.jdt.launching.environments.IExecutionEnvironment) IVMInstall(org.eclipse.jdt.launching.IVMInstall) CoreException(org.eclipse.core.runtime.CoreException) IExecutionEnvironmentsManager(org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager)

Example 2 with IExecutionEnvironmentsManager

use of org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager in project eclipse.jdt.ls by eclipse.

the class JVMConfigurator method getExecutionEnvironment.

public static IExecutionEnvironment getExecutionEnvironment(String name) {
    IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
    IExecutionEnvironment[] environments = manager.getExecutionEnvironments();
    for (IExecutionEnvironment environment : environments) {
        if (environment.getId().equals(name)) {
            return environment;
        }
    }
    return null;
}
Also used : IExecutionEnvironment(org.eclipse.jdt.launching.environments.IExecutionEnvironment) IExecutionEnvironmentsManager(org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager)

Example 3 with IExecutionEnvironmentsManager

use of org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager in project xtext-eclipse by eclipse.

the class JavaProjectSetupUtil method makeJava7Default.

public static void makeJava7Default() {
    if (!isJava7Default) {
        IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
        IExecutionEnvironment[] environments = manager.getExecutionEnvironments();
        for (int i = 0; i < environments.length; i++) {
            IExecutionEnvironment environment = environments[i];
            if (environment.getId().equals("JavaSE-1.6") && environment.getDefaultVM() == null) {
                IVMInstall[] compatibleVMs = environment.getCompatibleVMs();
                for (IVMInstall ivmInstall : compatibleVMs) {
                    if (ivmInstall instanceof IVMInstall2) {
                        IVMInstall2 install2 = (IVMInstall2) ivmInstall;
                        if (install2.getJavaVersion().startsWith("1.7")) {
                            environment.setDefaultVM(ivmInstall);
                        }
                    }
                }
            }
        }
        isJava7Default = true;
    }
}
Also used : IExecutionEnvironment(org.eclipse.jdt.launching.environments.IExecutionEnvironment) IVMInstall(org.eclipse.jdt.launching.IVMInstall) IExecutionEnvironmentsManager(org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager) IVMInstall2(org.eclipse.jdt.launching.IVMInstall2)

Example 4 with IExecutionEnvironmentsManager

use of org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager in project xtext-eclipse by eclipse.

the class JavaProjectSetupUtil method makeJava7Default.

public static void makeJava7Default() {
    if (!isJava7Default) {
        IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
        IExecutionEnvironment[] environments = manager.getExecutionEnvironments();
        for (int i = 0; i < environments.length; i++) {
            IExecutionEnvironment environment = environments[i];
            if (environment.getId().equals("JavaSE-1.6") && environment.getDefaultVM() == null) {
                IVMInstall[] compatibleVMs = environment.getCompatibleVMs();
                for (IVMInstall ivmInstall : compatibleVMs) {
                    if (ivmInstall instanceof IVMInstall2) {
                        IVMInstall2 install2 = (IVMInstall2) ivmInstall;
                        if (install2.getJavaVersion().startsWith("1.7")) {
                            environment.setDefaultVM(ivmInstall);
                        }
                    }
                }
            }
        }
        isJava7Default = true;
    }
}
Also used : IExecutionEnvironment(org.eclipse.jdt.launching.environments.IExecutionEnvironment) IVMInstall(org.eclipse.jdt.launching.IVMInstall) IExecutionEnvironmentsManager(org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager) IVMInstall2(org.eclipse.jdt.launching.IVMInstall2)

Example 5 with IExecutionEnvironmentsManager

use of org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager in project xtext-eclipse by eclipse.

the class JREContainerProvider method getDefaultJREContainerPath.

/**
 * @since 2.6
 */
public static IPath getDefaultJREContainerPath() {
    if (defaultVMInstall() != null) {
        IExecutionEnvironmentsManager executionEnvironmentsManager = JavaRuntime.getExecutionEnvironmentsManager();
        IExecutionEnvironment[] executionEnvironments = executionEnvironmentsManager.getExecutionEnvironments();
        for (IExecutionEnvironment executionEnvironment : executionEnvironments) {
            if (executionEnvironment.isStrictlyCompatible(defaultVMInstall())) {
                return newJREContainerPath(executionEnvironment);
            }
        }
    }
    return newPreferredContainerPath();
}
Also used : IExecutionEnvironment(org.eclipse.jdt.launching.environments.IExecutionEnvironment) IExecutionEnvironmentsManager(org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager)

Aggregations

IExecutionEnvironment (org.eclipse.jdt.launching.environments.IExecutionEnvironment)7 IExecutionEnvironmentsManager (org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager)7 IVMInstall (org.eclipse.jdt.launching.IVMInstall)5 CoreException (org.eclipse.core.runtime.CoreException)2 IVMInstall2 (org.eclipse.jdt.launching.IVMInstall2)2 IProject (org.eclipse.core.resources.IProject)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1