public static boolean is50OrHigherJRE(IJavaProject project) throws CoreException { IVMInstall vmInstall= JavaRuntime.getVMInstall(project); if (!(vmInstall instanceof IVMInstall2)) return true; // assume 5.0. String compliance= getCompilerCompliance((IVMInstall2) vmInstall, null); if (compliance == null) return true; // assume 5.0 return compliance.startsWith(JavaCore.VERSION_1_5) || compliance.startsWith(JavaCore.VERSION_1_6); }
public static boolean is50OrHigherJRE(IJavaProject project) throws CoreException { IVMInstall vmInstall= JavaRuntime.getVMInstall(project); if (!(vmInstall instanceof IVMInstall2)) return true; // assume 5.0. String compliance= getCompilerCompliance((IVMInstall2) vmInstall, null); if (compliance == null) return true; // assume 5.0 return compliance.startsWith(JavaCore.VERSION_1_5) || compliance.startsWith(JavaCore.VERSION_1_6); }
@Override public String resolveValue(IDynamicVariable variable, String argument) throws CoreException { if (argument == null) { throw new CoreException(new Status(IStatus.ERROR, LaunchingPlugin.ID_PLUGIN, EnvironmentMessages.ExecutionEnvironmentVariableResolver_0)); } IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment env = manager.getEnvironment(argument); if (env == null) { throw new CoreException(new Status(IStatus.ERROR, LaunchingPlugin.ID_PLUGIN, NLS.bind(EnvironmentMessages.ExecutionEnvironmentVariableResolver_1, new String[]{argument}))); } IPath path = JavaRuntime.newJREContainerPath(env); IVMInstall jre = JavaRuntime.getVMInstall(path); if (jre == null) { throw new CoreException(new Status(IStatus.ERROR, LaunchingPlugin.ID_PLUGIN, NLS.bind(EnvironmentMessages.ExecutionEnvironmentVariableResolver_2, new String[]{argument}))); } return jre.getInstallLocation().getAbsolutePath(); }
@Override public String resolveValue(IDynamicVariable variable, String argument) throws CoreException { if (argument == null) { throw new CoreException(new Status(IStatus.ERROR, LaunchingPlugin.ID_PLUGIN, EnvironmentMessages.ExecutionEnvironmentVariableResolver_0)); } IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment env = manager.getEnvironment(argument); if (env == null) { throw new CoreException(new Status(IStatus.ERROR, LaunchingPlugin.ID_PLUGIN, NLS.bind(EnvironmentMessages.ExecutionEnvironmentVariableResolver_1, new String[]{argument}))); } IPath path = JavaRuntime.newJREContainerPath(env); IVMInstall jre = JavaRuntime.getVMInstall(path); if (jre == null) { throw new CoreException(new Status(IStatus.ERROR, LaunchingPlugin.ID_PLUGIN, NLS.bind(EnvironmentMessages.ExecutionEnvironmentVariableResolver_2, new String[]{argument}))); } return jre.getInstallLocation().getAbsolutePath(); }
@Override public File getJVMLocation(String os) { IPath jreContainerPath = getJREContainerPath(os); if (jreContainerPath == null) // no vm was specified return null; IVMInstall vm = JavaRuntime.getVMInstall(jreContainerPath); if (vm != null) { return vm.getInstallLocation(); } return null; }
public static String getVMInstallName(IExecutionEnvironment ee) throws CoreException { IPath containerPath = JavaRuntime.newJREContainerPath(ee); IVMInstall vmi = JavaRuntime.getVMInstall(containerPath); if (vmi == null) throw new CoreException(createErrorStatus(NLS.bind(UtilMessages.VMHelper_noJreForExecEnv, ee.getId()))); return vmi.getName(); }
* * @param monitor progress monitor */ private void loadJRE(IProgressMonitor monitor) { IPath container = fTarget.getJREContainer(); monitor.beginTask(Messages.LoadTargetOperation_jreTaskName, 1); if (container != null) { IVMInstall jre = JavaRuntime.getVMInstall(container); if (jre != null) { IVMInstall def = JavaRuntime.getDefaultVMInstall(); if (!jre.equals(def)) { try { JavaRuntime.setDefaultVMInstall(jre, null); } catch (CoreException e) { } } } } monitor.done(); } /** * Resets the PDE workspace models with the new state information
private static Path javaHomeOf(final IJavaProject javaProject) { try { final IVMInstall vmInstall = JavaRuntime.getVMInstall(javaProject); if (vmInstall != null) { final File javaInstallLocation = vmInstall.getInstallLocation(); if (javaInstallLocation != null) { final Path javaInstallPath = javaInstallLocation.toPath(); if (Files.isDirectory(javaInstallPath.resolve("jre/lib"))) { // the install location points to a JDK that contains a JRE! Use the JRE as Java home return javaInstallPath.resolve("jre"); } return javaInstallPath; } } SdkLog.info("Unable to find Java home location for project '{}'. Using running Java home as fallback.", javaProject.getElementName()); return null; // use the running JRE as fallback } catch (final CoreException e) { throw new SdkException(e); } }
/** * @see ILaunchConfigurationTab#isValid(ILaunchConfiguration) */ public boolean isValid(ILaunchConfiguration config) { boolean valid = super.isValid(config); if (valid) { // bug 132132: LTW requires a >= 1.4 jre IVMInstall jre = JavaRuntime.getVMInstall(fJREBlock.getPath()); if (jre instanceof IVMInstall2) { String version = ((IVMInstall2)jre).getJavaVersion(); if (version.charAt(0) == '1' && version.charAt(1) == '.' && (version.charAt(2) >= '0' && version.charAt(2) <= '3')) { setErrorMessage(UIMessages.LTW_error_wrong_jre); return false; } } } return valid; } }
public File getJvmHome() throws CoreException { IVMInstall jvmInstall = getVMInstall(project); try { int majorVersion = parseMajorVersion(jvmInstall); if (majorVersion < 5) { jvmInstall = findFirstJava5OrGreaterJvm(jvmInstall); } } catch (UnknownJvmVersionException e) { log(WARNING, "Error determining JVM version. Using default version."); } if ((jvmInstall != null) && jvmInstall.getInstallLocation().exists()) { return jvmInstall.getInstallLocation(); } log(WARNING, "Cannot find any JVM. Using the one from JAVA_HOME."); return new File(System.getProperty("java.home")); }
/** * Checks if the JRE of the given project or workspace default JRE have source compliance 1.5 or * greater. * * @param project the project to test or <code>null</code> to test the workspace JRE * @return <code>true</code> if the JRE of the given project or workspace default JRE have * source compliance 1.5 or greater. * @throws CoreException if unable to determine the project's VM install */ public static boolean is50OrHigherJRE(IJavaProject project) throws CoreException { IVMInstall vmInstall; if (project == null) { vmInstall= JavaRuntime.getDefaultVMInstall(); } else { vmInstall= JavaRuntime.getVMInstall(project); } if (!(vmInstall instanceof IVMInstall2)) return true; // assume 1.5. String compliance= getCompilerCompliance((IVMInstall2) vmInstall, null); if (compliance == null) return true; // assume 1.5 return is50OrHigher(compliance); }
/** * Get the default VMInstall name using the available info in the config, * using the JavaProject if available. * * @param configuration * Launch configuration to check * @return name of the VMInstall * @throws CoreException * thrown if there's a problem getting the VM name */ public static String getDefaultVMInstallName(ILaunchConfiguration configuration) throws CoreException { IJavaProject javaProject = JavaRuntime.getJavaProject(configuration); IVMInstall vmInstall = null; if (javaProject != null) { vmInstall = JavaRuntime.getVMInstall(javaProject); } if (vmInstall != null) { return vmInstall.getName(); } return VMUtil.getDefaultVMInstallName(); }
/** * Returns the VM install used to launch the given snippet file. * * @exception CoreException if unable to retrieve the attribute */ public static IVMInstall getVMInstall(IFile file) throws CoreException { ILaunchConfiguration config = getLaunchConfigurationTemplate(file); if (config == null) { IJavaProject pro = JavaCore.create(file.getProject()); return JavaRuntime.getVMInstall(pro); } return JavaRuntime.computeVMInstall(config); }
private CPListElement checkAndUpdateIfModularJRE(CPListElement cpe) { boolean modularJava= false; IVMInstall vmInstall= JavaRuntime.getVMInstall(cpe.getPath()); if (vmInstall != null) { modularJava= JavaRuntime.isModularJava(vmInstall); } if (modularJava) { // If JRE is updated to modular JRE, then cpe element has to be recreated // so as to have the modular structure cpe= CPListElement.create(cpe.getClasspathEntry(), true, fCurrJProject); } return cpe; }
/** * Checks if the JRE of the given project or workspace default JRE have source compliance 1.5 or * greater. * * @param project the project to test or <code>null</code> to test the workspace JRE * @return <code>true</code> if the JRE of the given project or workspace default JRE have * source compliance 1.5 or greater. * @throws CoreException if unable to determine the project's VM install */ public static boolean is50OrHigherJRE(IJavaProject project) throws CoreException { IVMInstall vmInstall; if (project == null) { vmInstall= JavaRuntime.getDefaultVMInstall(); } else { vmInstall= JavaRuntime.getVMInstall(project); } if (!(vmInstall instanceof IVMInstall2)) return true; // assume 1.5. String compliance= getCompilerCompliance((IVMInstall2) vmInstall, null); if (compliance == null) return true; // assume 1.5 return is50OrHigher(compliance); }
/** * Returns the default {@link IVMInstall} for the given {@link ILaunchConfiguration}, which resolves to the {@link IVMInstall} for the backing * {@link IJavaProject} as specified by the project attribute in the configuration. If there is no project attribute the workspace default * {@link IVMInstall} is returned. * * @param config * @return the default {@link IVMInstall} for the given {@link ILaunchConfiguration} */ private IVMInstall getDefaultVMInstall(ILaunchConfiguration config) { try { IJavaProject project = JavaRuntime.getJavaProject(config); if (project != null) { IVMInstall vm = JavaRuntime.getVMInstall(project); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335860 // if the project does not have a JRE on the build path, return the workspace default JRE if (vm != null) { return vm; } } return JavaRuntime.getDefaultVMInstall(); } catch (CoreException e) { // core exception thrown for non-Java project return JavaRuntime.getDefaultVMInstall(); } }
@Override public String getText(Object element) { if (!(element instanceof IExecutionEnvironment)) return ""; //$NON-NLS-1$ IExecutionEnvironment env = (IExecutionEnvironment) element; IPath path = JavaRuntime.newJREContainerPath(env); IVMInstall install = JavaRuntime.getVMInstall(path); String eeItem; if (install != null) { eeItem = MessageFormat.format(PDEUIMessages.JRESection_eeBoundJRE, env.getId(), install.getName()); } else { eeItem = MessageFormat.format(PDEUIMessages.JRESection_eeUnboundJRE, env.getId()); } return eeItem; } }
public String getDescription() { IJavaProject project = getJavaProject(); String name = LauncherMessages.JavaJRETab_7; if (project == null) { IVMInstall vm = JavaRuntime.getDefaultVMInstall(); if (vm != null) { name = vm.getName(); } return MessageFormat.format(LauncherMessages.JavaJRETab_8, new String[]{name}); } try { IVMInstall vm = JavaRuntime.getVMInstall(project); if (vm != null) { name = vm.getName(); } } catch (CoreException e) { } return MessageFormat.format(LauncherMessages.JavaJRETab_9, new String[]{name}); } };
/** * @see IRuntimeClasspathEntryResolver#resolveRuntimeClasspathEntry(IRuntimeClasspathEntry, IJavaProject) */ @Override public IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entry, IJavaProject project) throws CoreException { IVMInstall jre = null; if (entry.getType() == IRuntimeClasspathEntry.CONTAINER && entry.getPath().segmentCount() > 1) { // a specific VM jre = JREContainerInitializer.resolveVM(entry.getPath()); } else { // default VM for project jre = JavaRuntime.getVMInstall(project); } if (jre == null) { // cannot resolve JRE return new IRuntimeClasspathEntry[0]; } return resolveLibraryLocations(jre, entry.getClasspathProperty()); }
/** * @see IRuntimeClasspathEntryResolver#resolveRuntimeClasspathEntry(IRuntimeClasspathEntry, IJavaProject) */ @Override public IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entry, IJavaProject project) throws CoreException { IVMInstall jre = null; if (entry.getType() == IRuntimeClasspathEntry.CONTAINER && entry.getPath().segmentCount() > 1) { // a specific VM jre = JREContainerInitializer.resolveVM(entry.getPath()); } else { // default VM for project jre = JavaRuntime.getVMInstall(project); } if (jre == null) { // cannot resolve JRE return new IRuntimeClasspathEntry[0]; } return resolveLibraryLocations(jre, entry.getClasspathProperty()); }