Search in sources :

Example 1 with VMStandin

use of org.eclipse.jdt.launching.VMStandin in project liferay-ide by liferay.

the class ProjectCoreBase method ensureDefaultVMInstallExists.

private void ensureDefaultVMInstallExists() throws CoreException {
    IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
    if (vmInstall != null) {
        return;
    }
    final IVMInstallType vmInstallType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
    String id = null;
    do {
        id = String.valueOf(System.currentTimeMillis());
    } while (vmInstallType.findVMInstall(id) != null);
    VMStandin newVm = new VMStandin(vmInstallType, id);
    newVm.setName("Default-VM");
    String jrePath = System.getProperty("java.home");
    File installLocation = new File(jrePath);
    newVm.setInstallLocation(installLocation);
    IVMInstall realVm = newVm.convertToRealVM();
    JavaRuntime.setDefaultVMInstall(realVm, new NullProgressMonitor());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IVMInstall(org.eclipse.jdt.launching.IVMInstall) IVMInstallType(org.eclipse.jdt.launching.IVMInstallType) VMStandin(org.eclipse.jdt.launching.VMStandin) File(java.io.File)

Example 2 with VMStandin

use of org.eclipse.jdt.launching.VMStandin in project sling by apache.

the class DefaultJavaVMInstall method before.

@Override
protected void before() throws Throwable {
    if (JavaRuntime.getDefaultVMInstall() != null) {
        return;
    }
    String jreHome = System.getProperty("java.home");
    File installLocation = new File(jreHome);
    final IVMInstallType vmInstallType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
    // find an unused VM id
    String id = null;
    do {
        id = String.valueOf(System.currentTimeMillis());
    } while (vmInstallType.findVMInstall(id) != null);
    VMStandin newVm = new VMStandin(vmInstallType, id);
    newVm.setName("Default-VM");
    newVm.setInstallLocation(installLocation);
    IVMInstall realVm = newVm.convertToRealVM();
    JavaRuntime.setDefaultVMInstall(realVm, new NullProgressMonitor());
    // wait for the default vm reconfiguration to settle
    // TODO - find something to poll agains rather than sleeping blindly
    Thread.sleep(5000);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IVMInstall(org.eclipse.jdt.launching.IVMInstall) IVMInstallType(org.eclipse.jdt.launching.IVMInstallType) File(java.io.File) VMStandin(org.eclipse.jdt.launching.VMStandin)

Example 3 with VMStandin

use of org.eclipse.jdt.launching.VMStandin in project liferay-ide by liferay.

the class LiferayTomcatRuntime method findPortalBundledJRE.

public IVMInstall findPortalBundledJRE(boolean addVM) {
    IPath jrePath = findBundledJREPath(getRuntime().getLocation());
    if (jrePath == null)
        return null;
    // make sure we don't have an existing JRE that has the same path
    for (IVMInstallType vmInstallType : JavaRuntime.getVMInstallTypes()) {
        for (IVMInstall vmInstall : vmInstallType.getVMInstalls()) {
            if (vmInstall.getInstallLocation().equals(jrePath.toFile())) {
                return vmInstall;
            }
        }
    }
    if (addVM) {
        IVMInstallType installType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
        VMStandin newVM = new VMStandin(installType, JavaUtil.createUniqueId(installType));
        newVM.setInstallLocation(jrePath.toFile());
        if (!CoreUtil.isNullOrEmpty(getRuntime().getName())) {
            // $NON-NLS-1$
            newVM.setName(getRuntime().getName() + " JRE");
        } else {
            // $NON-NLS-1$
            newVM.setName("Liferay JRE");
        }
        // make sure the new VM name isn't the same as existing name
        boolean existingVMWithSameName = ServerUtil.isExistingVMName(newVM.getName());
        int num = 1;
        while (existingVMWithSameName) {
            // $NON-NLS-1$ //$NON-NLS-2$
            newVM.setName(getRuntime().getName() + " JRE (" + (num++) + ")");
            existingVMWithSameName = ServerUtil.isExistingVMName(newVM.getName());
        }
        return newVM.convertToRealVM();
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IVMInstall(org.eclipse.jdt.launching.IVMInstall) IVMInstallType(org.eclipse.jdt.launching.IVMInstallType) VMStandin(org.eclipse.jdt.launching.VMStandin)

Example 4 with VMStandin

use of org.eclipse.jdt.launching.VMStandin in project eclipse.jdt.ls by eclipse.

the class JDTLanguageServer method configureVM.

public boolean configureVM() throws CoreException {
    String javaHome = preferenceManager.getPreferences().getJavaHome();
    if (javaHome != null) {
        File jvmHome = new File(javaHome);
        if (jvmHome.isDirectory()) {
            IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();
            File location = defaultVM.getInstallLocation();
            if (!location.equals(jvmHome)) {
                IVMInstall vm = findVM(jvmHome);
                if (vm == null) {
                    IVMInstallType installType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
                    long unique = System.currentTimeMillis();
                    while (installType.findVMInstall(String.valueOf(unique)) != null) {
                        unique++;
                    }
                    String vmId = String.valueOf(unique);
                    VMStandin vmStandin = new VMStandin(installType, vmId);
                    String name = StringUtils.defaultIfBlank(jvmHome.getName(), "JRE");
                    vmStandin.setName(name);
                    vmStandin.setInstallLocation(jvmHome);
                    vm = vmStandin.convertToRealVM();
                }
                JavaRuntime.setDefaultVMInstall(vm, new NullProgressMonitor());
                JDTUtils.setCompatibleVMs(vm.getId());
                return true;
            }
        }
    }
    return false;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IVMInstall(org.eclipse.jdt.launching.IVMInstall) IVMInstallType(org.eclipse.jdt.launching.IVMInstallType) File(java.io.File) VMStandin(org.eclipse.jdt.launching.VMStandin)

Aggregations

IVMInstall (org.eclipse.jdt.launching.IVMInstall)4 IVMInstallType (org.eclipse.jdt.launching.IVMInstallType)4 VMStandin (org.eclipse.jdt.launching.VMStandin)4 File (java.io.File)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 IPath (org.eclipse.core.runtime.IPath)1