Search in sources :

Example 1 with IVMInstall2

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

the class PortalRuntime method validate.

@Override
public IStatus validate() {
    IStatus status = super.validate();
    if (!status.isOK()) {
        return status;
    }
    if (portalBundle == null) {
        return new Status(IStatus.ERROR, LiferayServerCore.PLUGIN_ID, 0, Msgs.errorPortalNotExisted, null);
    }
    if (!portalBundle.getVersion().startsWith("7")) {
        return new Status(IStatus.ERROR, LiferayServerCore.PLUGIN_ID, 0, Msgs.errorPortalVersion70, null);
    }
    if (getVMInstall() == null) {
        return new Status(IStatus.ERROR, LiferayServerCore.PLUGIN_ID, 0, Msgs.errorJRE, null);
    }
    if (portalBundle.getVersion().startsWith("7")) {
        IVMInstall vmInstall = getVMInstall();
        if (vmInstall instanceof IVMInstall2) {
            String javaVersion = ((IVMInstall2) vmInstall).getJavaVersion();
            if (javaVersion != null && !isVMRequireVersion(javaVersion, 108)) {
                return new Status(IStatus.ERROR, LiferayServerCore.PLUGIN_ID, 0, Msgs.errorJRE80, null);
            }
        }
    }
    File jdkInstallLocation = getVMInstall().getInstallLocation();
    if (jdkInstallLocation != null) {
        String rootPath = jdkInstallLocation.getAbsolutePath();
        StringBuilder javacPath = new StringBuilder(rootPath);
        javacPath.append(File.separator).append("bin").append(File.separator);
        if (CoreUtil.isWindows()) {
            javacPath.append("javac.exe");
        } else if (CoreUtil.isLinux() || CoreUtil.isMac()) {
            javacPath.append("javac");
        }
        if (FileUtil.notExists(new File(javacPath.toString()))) {
            return new Status(IStatus.WARNING, LiferayServerCore.PLUGIN_ID, 0, Msgs.warningjre, null);
        }
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) IVMInstall(org.eclipse.jdt.launching.IVMInstall) File(java.io.File) IVMInstall2(org.eclipse.jdt.launching.IVMInstall2)

Example 2 with IVMInstall2

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

the class JVMConfiguratorTest method testJVM.

@Test
public void testJVM() throws Exception {
    try {
        Preferences prefs = new Preferences();
        Bundle bundle = Platform.getBundle(JavaLanguageServerTestPlugin.PLUGIN_ID);
        URL url = FileLocator.toFileURL(bundle.getEntry("/fakejdk2/11a"));
        File file = URIUtil.toFile(URIUtil.toURI(url));
        String path = file.getAbsolutePath();
        String javadoc = "file:///javadoc";
        Set<RuntimeEnvironment> runtimes = new HashSet<>();
        RuntimeEnvironment runtime = new RuntimeEnvironment();
        runtime.setPath(path);
        runtime.setName(ENVIRONMENT_NAME);
        runtime.setJavadoc(javadoc);
        runtime.setDefault(true);
        assertTrue(runtime.isValid());
        runtimes.add(runtime);
        prefs.setRuntimes(runtimes);
        file = runtime.getInstallationFile();
        assertTrue(file != null && file.isDirectory());
        IVMInstallType installType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
        IStatus status = installType.validateInstallLocation(file);
        assertTrue(status.toString(), status.isOK());
        boolean changed = JVMConfigurator.configureJVMs(prefs);
        assertTrue("A VM hasn't been changed", changed);
        JobHelpers.waitForJobsToComplete();
        IVMInstall vm = JVMConfigurator.findVM(runtime.getInstallationFile(), ENVIRONMENT_NAME);
        assertNotNull(vm);
        assertTrue(vm instanceof IVMInstall2);
        String version = ((IVMInstall2) vm).getJavaVersion();
        assertTrue(version.startsWith(JavaCore.VERSION_11));
        StandardVMType svt = (StandardVMType) vm.getVMInstallType();
        LibraryLocation[] libs = vm.getLibraryLocations();
        assertNotNull(libs);
        for (LibraryLocation lib : libs) {
            assertEquals(runtime.getJavadocURL(), lib.getJavadocLocation());
        }
        IVMInstall newDefaultVM = JavaRuntime.getDefaultVMInstall();
        assertNotEquals(originalVm, newDefaultVM);
        assertEquals(vm, newDefaultVM);
        IExecutionEnvironment environment = JVMConfigurator.getExecutionEnvironment(ENVIRONMENT_NAME);
        assertNotNull(environment);
        assertEquals(vm, environment.getDefaultVM());
    } finally {
        IVMInstall vm = JVMConfigurator.findVM(null, ENVIRONMENT_NAME);
        if (vm != null) {
            vm.getVMInstallType().disposeVMInstall(vm.getId());
        }
    }
    IVMInstall vm = JVMConfigurator.findVM(null, ENVIRONMENT_NAME);
    assertNull(vm);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Bundle(org.osgi.framework.Bundle) IVMInstallType(org.eclipse.jdt.launching.IVMInstallType) LibraryLocation(org.eclipse.jdt.launching.LibraryLocation) URL(java.net.URL) IExecutionEnvironment(org.eclipse.jdt.launching.environments.IExecutionEnvironment) IVMInstall(org.eclipse.jdt.launching.IVMInstall) StandardVMType(org.eclipse.jdt.internal.launching.StandardVMType) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) File(java.io.File) IVMInstall2(org.eclipse.jdt.launching.IVMInstall2) HashSet(java.util.HashSet) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest) Test(org.junit.Test)

Example 3 with IVMInstall2

use of org.eclipse.jdt.launching.IVMInstall2 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 IVMInstall2

use of org.eclipse.jdt.launching.IVMInstall2 in project webtools.servertools by eclipse.

the class TomcatServerBehaviour method setupLaunchConfiguration.

public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProgressMonitor monitor) throws CoreException {
    String existingProgArgs = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String) null);
    workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, mergeArguments(existingProgArgs, getRuntimeProgramArguments(true), getExcludedRuntimeProgramArguments(true), true));
    String existingVMArgs = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, (String) null);
    String[] parsedVMArgs = null;
    if (null != existingVMArgs) {
        parsedVMArgs = DebugPlugin.parseArguments(existingVMArgs);
    }
    String[] configVMArgs = getRuntimeVMArguments();
    if (getTomcatServer().isSecure()) {
        boolean addSecurityArgs = true;
        if (null != parsedVMArgs) {
            for (int i = 0; i < parsedVMArgs.length; i++) {
                if (parsedVMArgs[i].startsWith("wtp.configured.security")) {
                    addSecurityArgs = false;
                    break;
                }
            }
        }
        if (addSecurityArgs) {
            String[] newVMArgs = new String[configVMArgs.length + 3];
            System.arraycopy(configVMArgs, 0, newVMArgs, 0, configVMArgs.length);
            newVMArgs[configVMArgs.length] = "-Djava.security.manager";
            newVMArgs[configVMArgs.length + 1] = "-Djava.security.policy=\"" + getRuntimePolicyFile() + "\"";
            newVMArgs[configVMArgs.length + 2] = "-Dwtp.configured.security=true";
            configVMArgs = newVMArgs;
        }
    } else if (null != parsedVMArgs) {
        boolean removeSecurityArgs = false;
        for (int i = 0; i < parsedVMArgs.length; i++) {
            if (parsedVMArgs[i].startsWith("-Dwtp.configured.security")) {
                removeSecurityArgs = true;
                break;
            }
        }
        if (removeSecurityArgs) {
            StringBuffer filteredVMArgs = new StringBuffer();
            for (int i = 0; i < parsedVMArgs.length; i++) {
                String arg = parsedVMArgs[i];
                if (!arg.startsWith("-Djava.security.manager") && !arg.startsWith("-Djava.security.policy=") && !arg.startsWith("-Dwtp.configured.security=")) {
                    if (filteredVMArgs.length() > 0) {
                        filteredVMArgs.append(' ');
                    }
                    filteredVMArgs.append(arg);
                }
            }
            existingVMArgs = filteredVMArgs.toString();
        }
    }
    String mergedVMArguments = mergeArguments(existingVMArgs, configVMArgs, null, false);
    workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, mergedVMArguments);
    ITomcatRuntime runtime = getTomcatRuntime();
    IVMInstall vmInstall = runtime.getVMInstall();
    if (vmInstall != null)
        workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, JavaRuntime.newJREContainerPath(vmInstall).toPortableString());
    // update classpath
    IRuntimeClasspathEntry[] originalClasspath = JavaRuntime.computeUnresolvedRuntimeClasspath(workingCopy);
    int size = originalClasspath.length;
    List<IRuntimeClasspathEntry> oldCp = new ArrayList<IRuntimeClasspathEntry>(originalClasspath.length + 2);
    for (int i = 0; i < size; i++) oldCp.add(originalClasspath[i]);
    List cp2 = runtime.getRuntimeClasspath(getRuntimeBaseDirectory());
    Iterator iterator = cp2.iterator();
    while (iterator.hasNext()) {
        IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry) iterator.next();
        mergeClasspath(oldCp, entry);
    }
    if (vmInstall != null) {
        try {
            String typeId = vmInstall.getVMInstallType().getId();
            replaceJREContainer(oldCp, JavaRuntime.newRuntimeContainerClasspathEntry(new Path(JavaRuntime.JRE_CONTAINER).append(typeId).append(vmInstall.getName()), IRuntimeClasspathEntry.BOOTSTRAP_CLASSES));
        } catch (Exception e) {
        // ignore
        }
        IPath jrePath = new Path(vmInstall.getInstallLocation().getAbsolutePath());
        if (jrePath != null) {
            IPath toolsPath = jrePath.append("lib").append("tools.jar");
            if (toolsPath.toFile().exists()) {
                IRuntimeClasspathEntry toolsJar = JavaRuntime.newArchiveRuntimeClasspathEntry(toolsPath);
                // Search for index to any existing tools.jar entry
                int toolsIndex;
                for (toolsIndex = 0; toolsIndex < oldCp.size(); toolsIndex++) {
                    IRuntimeClasspathEntry entry = oldCp.get(toolsIndex);
                    if (entry.getType() == IRuntimeClasspathEntry.ARCHIVE && entry.getPath().lastSegment().equals("tools.jar")) {
                        break;
                    }
                }
                // If existing tools.jar found, replace in case it's different.  Otherwise add.
                if (toolsIndex < oldCp.size())
                    oldCp.set(toolsIndex, toolsJar);
                else
                    mergeClasspath(oldCp, toolsJar);
            }
            String version = null;
            if (vmInstall instanceof IVMInstall2) {
                version = ((IVMInstall2) vmInstall).getJavaVersion();
            }
            int version_num = 8;
            if (version != null)
                version_num = Integer.parseInt(version.split("\\.")[0]);
            if (version == null || version_num < 9) {
                String endorsedDirectories = getTomcatVersionHandler().getEndorsedDirectories(getServer().getRuntime().getLocation());
                if (endorsedDirectories.length() > 0) {
                    String[] endorsements = new String[] { "-Djava.endorsed.dirs=\"" + endorsedDirectories + "\"" };
                    mergedVMArguments = mergeArguments(mergedVMArguments, endorsements, null, false);
                    workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, mergedVMArguments);
                }
            }
        }
    }
    iterator = oldCp.iterator();
    List<String> list = new ArrayList<String>();
    while (iterator.hasNext()) {
        IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry) iterator.next();
        try {
            list.add(entry.getMemento());
        } catch (Exception e) {
            Trace.trace(Trace.SEVERE, "Could not resolve classpath entry: " + entry, e);
        }
    }
    workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, list);
    workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
}
Also used : ArrayList(java.util.ArrayList) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) IOException(java.io.IOException) IVMInstall(org.eclipse.jdt.launching.IVMInstall) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) IVMInstall2(org.eclipse.jdt.launching.IVMInstall2)

Example 5 with IVMInstall2

use of org.eclipse.jdt.launching.IVMInstall2 in project mdw-designer by CenturyLinkCloud.

the class ProjectConfigurator method getJreContainerClasspathEntry.

private IClasspathEntry getJreContainerClasspathEntry(String desiredVersion) {
    for (IVMInstallType installType : JavaRuntime.getVMInstallTypes()) {
        if (installType instanceof AbstractVMInstallType) {
            AbstractVMInstallType install = (AbstractVMInstallType) installType;
            for (IVMInstall vmInstall : install.getVMInstalls()) {
                if (vmInstall instanceof IVMInstall2) {
                    IVMInstall2 vmInstall2 = (IVMInstall2) vmInstall;
                    if (vmInstall2.getJavaVersion() != null && vmInstall2.getJavaVersion().startsWith(desiredVersion)) {
                        IPath containerPath = new Path(JavaRuntime.JRE_CONTAINER);
                        IPath vmPath = containerPath.append(vmInstall.getVMInstallType().getId()).append(vmInstall.getName());
                        return JavaCore.newContainerEntry(vmPath);
                    }
                }
            }
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IVMInstall(org.eclipse.jdt.launching.IVMInstall) IPath(org.eclipse.core.runtime.IPath) IVMInstallType(org.eclipse.jdt.launching.IVMInstallType) AbstractVMInstallType(org.eclipse.jdt.launching.AbstractVMInstallType) IVMInstall2(org.eclipse.jdt.launching.IVMInstall2)

Aggregations

IVMInstall (org.eclipse.jdt.launching.IVMInstall)6 IVMInstall2 (org.eclipse.jdt.launching.IVMInstall2)6 IExecutionEnvironment (org.eclipse.jdt.launching.environments.IExecutionEnvironment)3 File (java.io.File)2 IStatus (org.eclipse.core.runtime.IStatus)2 IVMInstallType (org.eclipse.jdt.launching.IVMInstallType)2 IExecutionEnvironmentsManager (org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager)2 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 Status (org.eclipse.core.runtime.Status)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 StandardVMType (org.eclipse.jdt.internal.launching.StandardVMType)1 AbstractVMInstallType (org.eclipse.jdt.launching.AbstractVMInstallType)1 IRuntimeClasspathEntry (org.eclipse.jdt.launching.IRuntimeClasspathEntry)1