org.eclipse.jdt.launching.JavaRuntime Java Examples

The following examples show how to use org.eclipse.jdt.launching.JavaRuntime. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LaunchUtilities.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
* @return argsToConfigure updated with the new arguments.
*/
  public static Map<String, Connector.Argument> configureConnector(
  		Map<String, Connector.Argument> argsToConfigure, String host, int portNumber) {

      Connector.StringArgument hostArg = (Connector.StringArgument) argsToConfigure.get("hostname"); //$NON-NLS-1$
      hostArg.setValue(host);

      Connector.IntegerArgument portArg = (Connector.IntegerArgument) argsToConfigure.get("port"); //$NON-NLS-1$
      portArg.setValue(portNumber);

      Connector.IntegerArgument timeoutArg = (Connector.IntegerArgument) argsToConfigure.get("timeout"); //$NON-NLS-1$
      if (timeoutArg != null) {
          int timeout = Platform.getPreferencesService().getInt(
                                                                "org.eclipse.jdt.launching", //$NON-NLS-1$
                                                                JavaRuntime.PREF_CONNECT_TIMEOUT,
                                                                JavaRuntime.DEF_CONNECT_TIMEOUT,
                                                                null);
          timeoutArg.setValue(timeout);
      }

      return argsToConfigure;
  }
 
Example #2
Source File: ProjectCommand.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Gets the project settings.
 *
 * @param uri
 *                        Uri of the source/class file that needs to be queried.
 * @param settingKeys
 *                        the settings we want to query, for example:
 *                        ["org.eclipse.jdt.core.compiler.compliance",
 *                        "org.eclipse.jdt.core.compiler.source"].
 *                        Besides the options defined in JavaCore, the following keys can also be used:
 *                        - "org.eclipse.jdt.ls.core.vm.location": Get the location of the VM assigned to build the given Java project
 * @return A <code>Map<string, string></code> with all the setting keys and
 *         their values.
 * @throws CoreException
 * @throws URISyntaxException
 */
public static Map<String, String> getProjectSettings(String uri, List<String> settingKeys) throws CoreException, URISyntaxException {
	IJavaProject javaProject = getJavaProjectFromUri(uri);
	Map<String, String> settings = new HashMap<>();
	for (String key : settingKeys) {
		switch(key) {
			case VM_LOCATION:
				IVMInstall vmInstall = JavaRuntime.getVMInstall(javaProject);
				if (vmInstall == null) {
					continue;
				}
				File location = vmInstall.getInstallLocation();
				if (location == null) {
					continue;
				}
				settings.putIfAbsent(key, location.getAbsolutePath());
				break;
			default:
				settings.putIfAbsent(key, javaProject.getOption(key, true));
				break;
		}
	}
	return settings;
}
 
Example #3
Source File: ImportPlatformWizard.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
protected void fixRuntimeEnvironment( String platformDir )
{
	IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( "platform" );
	IJavaProject javaProject = JavaCore.create( project );
	IVMInstall javaInstall = null;
	try
	{
		if(javaProject.isOpen())
		{
		javaInstall = JavaRuntime.getVMInstall( javaProject );
	}
	}
	catch( CoreException e )
	{
		throw new IllegalStateException( e );
	}
	if( javaInstall != null )
	{
		setHeapSize( javaInstall );
	}
}
 
Example #4
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #5
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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;
	}
}
 
Example #6
Source File: JavadocStandardWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void collectReferencedElements(IJavaProject project, HashSet<JavadocLinkRef> result) throws CoreException {
	IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(project);
	for (int i= 0; i < unresolved.length; i++) {
		IRuntimeClasspathEntry curr= unresolved[i];
		if (curr.getType() == IRuntimeClasspathEntry.PROJECT) {
			result.add(new JavadocLinkRef(JavaCore.create((IProject) curr.getResource())));
		} else {
			IRuntimeClasspathEntry[] entries= JavaRuntime.resolveRuntimeClasspathEntry(curr, project);
			for (int k = 0; k < entries.length; k++) {
				IRuntimeClasspathEntry entry= entries[k];
				if (entry.getType() == IRuntimeClasspathEntry.PROJECT) {
					result.add(new JavadocLinkRef(JavaCore.create((IProject) entry.getResource())));
				} else if (entry.getType() == IRuntimeClasspathEntry.ARCHIVE) {
					IClasspathEntry classpathEntry= entry.getClasspathEntry();
					if (classpathEntry != null) {
						IPath containerPath= null;
						if (curr.getType() == IRuntimeClasspathEntry.CONTAINER) {
							containerPath= curr.getPath();
						}
						result.add(new JavadocLinkRef(containerPath, classpathEntry, project));
					}
				}
			}
		}
	}
}
 
Example #7
Source File: MyMvnSourceContainer.java    From m2e.sourcelookup with Eclipse Public License 1.0 6 votes vote down vote up
private ISourceContainer[] fromMavenSourcePathProvider() throws CoreException {

    final IRuntimeClasspathEntry mavenEntry = JavaRuntime.newRuntimeContainerClasspathEntry(new Path(IClasspathManager.CONTAINER_ID),
        IRuntimeClasspathEntry.USER_CLASSES);

    final ILaunchConfiguration launchConfiguration = getDirector().getLaunchConfiguration();
    // final ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy();
    // wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, getProjectName());
    // final ILaunchConfiguration doSave = wc.doSave();
    final ILaunchConfiguration javaProjectLaunchConfiguration = new JavaProjectLaunchConfiguration(launchConfiguration, this);

    final IRuntimeClasspathEntry[] resolved = mavenRuntimeClasspathProvider.resolveClasspath(new IRuntimeClasspathEntry[] {
      mavenEntry
    }, javaProjectLaunchConfiguration);

    // final IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedSourceLookupPath(doSave);
    // final IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath(entries, doSave);

    return JavaRuntime.getSourceContainers(resolved);
  }
 
Example #8
Source File: DocumentUimaImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the project class loader.
 *
 * @param project the project
 * @return the project class loader
 * @throws CoreException the core exception
 */
public static ClassLoader getProjectClassLoader(IProject project) throws CoreException {
  IProjectNature javaNature = project.getNature(JAVA_NATURE);
  if (javaNature != null) {
    JavaProject javaProject = (JavaProject) JavaCore.create(project);
    
    String[] runtimeClassPath = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
    List<URL> urls = new ArrayList<>();
    for (String cp : runtimeClassPath) {
      try {
        urls.add(Paths.get(cp).toUri().toURL());
      } catch (MalformedURLException e) {
        CasEditorPlugin.log(e);
      }
    }
    return new URLClassLoader(urls.toArray(new URL[0]));
  } 
  return null;
}
 
Example #9
Source File: MyMvnSourceContainer.java    From m2e.sourcelookup with Eclipse Public License 1.0 6 votes vote down vote up
private ISourceContainer[] fromJavaRuntimeResolver() throws CoreException {
  for (final IClasspathEntry cpe : jp.getRawClasspath()) {
    if (IClasspathEntry.CPE_CONTAINER == cpe.getEntryKind() && //
        IClasspathManager.CONTAINER_ID.equals(cpe.getPath().toString())) {
      final IRuntimeClasspathEntry newRuntimeContainerClasspathEntry = JavaRuntime.newRuntimeContainerClasspathEntry(cpe.getPath(),
          IRuntimeClasspathEntry.USER_CLASSES, jp);

      final IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry = JavaRuntime.resolveRuntimeClasspathEntry(
          newRuntimeContainerClasspathEntry, jp);

      // there is only one maven2 classpath container in a project return
      return JavaRuntime.getSourceContainers(resolveRuntimeClasspathEntry);
    }
  }

  return new ISourceContainer[] {};
}
 
Example #10
Source File: AbstractJob.java    From tlaplus with MIT License 6 votes vote down vote up
protected IVMInstall getVMInstall() {
       IVMInstall vmInstall = null;

	// Try using the very same VM the Toolbox is running with (e.g.
	// this avoids problems when the Toolbox runs with a 64bit VM, but
	// the nested VM is a 32bit one).
       final String javaHome = System.getProperty("java.home");
       if (javaHome != null) {
           final IVMInstallType installType = new StandardVMType();
           vmInstall = installType.createVMInstall("TLCModelCheckerNestedVM");
           vmInstall.setInstallLocation(new File(javaHome));
           return vmInstall;
       }

       // get OS default VM (determined by path) not necessarily the same
	// the toolbox is running with.
       return JavaRuntime.getDefaultVMInstall();
}
 
Example #11
Source File: JavaProjectsStateHelper.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected List<String> getPackageFragmentRootHandles(IJavaProject project) {
	List<String> result = Lists.newArrayList();
	List<String> binaryAndNonLocalFragments = Lists.newArrayList();
	try {
		IPackageFragmentRoot[] roots = project.getAllPackageFragmentRoots();
		result = Lists.newArrayListWithCapacity(roots.length);
		for (IPackageFragmentRoot root : roots) {
			if (root != null && !JavaRuntime.newDefaultJREContainerPath().isPrefixOf(root.getRawClasspathEntry().getPath())) {
				if (root.getKind() == IPackageFragmentRoot.K_SOURCE && project.equals(root.getJavaProject())) {
					// treat local sources with higher priority
					// see Java behavior in SameClassNamesTest
					result.add(root.getHandleIdentifier());	
				} else {
					binaryAndNonLocalFragments.add(root.getHandleIdentifier());
				}
			}
		}
	} catch (JavaModelException e) {
		if (!e.isDoesNotExist()) {
			log.error("Cannot find rootHandles in project " + project.getProject().getName(), e);
		}
	}
	result.addAll(binaryAndNonLocalFragments);
	return result;
}
 
Example #12
Source File: ExportSarlApplicationPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
protected IPath[] getClasspath(ILaunchConfiguration configuration) throws CoreException {
	IRuntimeClasspathEntry[] entries = AbstractSARLLaunchConfigurationDelegate.computeUnresolvedSARLRuntimeClasspath(
			configuration, this.configAccessor, cfg -> getJavaProject(cfg));

	entries = JavaRuntime.resolveRuntimeClasspath(entries, configuration);

	final boolean isModularConfig = JavaRuntime.isModularConfiguration(configuration);
	final List<IPath> userEntries = new ArrayList<>(entries.length);
	for (int i = 0; i < entries.length; i++) {
		final int classPathProperty = entries[i].getClasspathProperty();
		if ((!isModularConfig && classPathProperty == IRuntimeClasspathEntry.USER_CLASSES)
				|| (isModularConfig && (classPathProperty == IRuntimeClasspathEntry.CLASS_PATH
				|| classPathProperty == IRuntimeClasspathEntry.MODULE_PATH))) {

			final String location = entries[i].getLocation();
			if (location != null) {
				final IPath entry = Path.fromOSString(location);
				if (!userEntries.contains(entry)) {
					userEntries.add(entry);
				}
			}
		}
	}
	return userEntries.toArray(new IPath[userEntries.size()]);
}
 
Example #13
Source File: NativeLibrariesPropertyPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IClasspathEntry handleContainerEntry(IPath containerPath, IJavaProject jproject, IPath jarPath) throws JavaModelException {
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
	if (initializer == null || container == null) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)));
		return null;
	}
	String containerName= container.getDescription();
	IStatus status= initializer.getAttributeStatus(containerPath, jproject, JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_not_supported, containerName));
		return null;
	}
	IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_read_only, containerName));
		fIsReadOnly= true;
		return entry;
	}
	Assert.isNotNull(entry);
	return entry;
}
 
Example #14
Source File: GWTProjectsRuntime.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public URLClassLoader createClassLoader() throws SdkException, MalformedURLException {
  IJavaProject userProject = findUserProject();
  if (userProject != null) {
    IRuntimeClasspathEntry outputEntry = JavaRuntime.newDefaultProjectClasspathEntry(userProject);
    try {
      IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry =
          JavaRuntime.resolveRuntimeClasspathEntry(outputEntry, userProject);
      List<URL> urls = new ArrayList<URL>();
      for (IRuntimeClasspathEntry entry : resolveRuntimeClasspathEntry) {
        urls.add(new File(entry.getLocation()).toURI().toURL());
      }

      return new URLClassLoader(urls.toArray(NO_URLS), null);

    } catch (CoreException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

  // TODO Auto-generated method stub
  return null;
}
 
Example #15
Source File: WebAppProjectCreatorRunner.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private static String computeClasspath(GwtSdk gwtRuntime, String[] extraClassPath)
    throws CoreException {
  List<String> cpPaths = new ArrayList<String>();
  for (IClasspathEntry c : gwtRuntime.getClasspathEntries()) {
    if (c.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
      IJavaProject javaProject = JavaProjectUtilities.findJavaProject(c.getPath().toOSString());
      IRuntimeClasspathEntry projectRuntimeEntry = JavaRuntime.newDefaultProjectClasspathEntry(javaProject);
      IRuntimeClasspathEntry[] resolvedEntries = JavaRuntime.resolveRuntimeClasspathEntry(
          projectRuntimeEntry, javaProject);
      for (IRuntimeClasspathEntry resolvedEntry : resolvedEntries) {
        cpPaths.add(resolvedEntry.getLocation());
      }
    } else {
      cpPaths.add(c.getPath().toFile().getAbsolutePath());
    }
  }
  if (extraClassPath != null) {
    cpPaths.addAll(Arrays.asList(extraClassPath));
  }
  return ProcessUtilities.buildClasspathString(cpPaths);
}
 
Example #16
Source File: ComplianceConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IExecutionEnvironment getEE() {
	if (fProject == null)
		return null;
	
	try {
		IClasspathEntry[] entries= JavaCore.create(fProject).getRawClasspath();
		for (int i= 0; i < entries.length; i++) {
			IClasspathEntry entry= entries[i];
			if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
				String eeId= JavaRuntime.getExecutionEnvironmentId(entry.getPath());
				if (eeId != null) {
					return JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(eeId);
				}
			}
		}
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
	return null;
}
 
Example #17
Source File: AbstractSARLLaunchConfigurationDelegate.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Compute the class path for the given launch configuration.
 *
 * @param configuration the configuration that provides the classpath.
 * @param configAccessor the accessor to the SRE configuration.
 * @param projectAccessor the accessor to the Java project.
 * @return the filtered entries.
 * @throws CoreException if impossible to get the classpath.
 */
public static IRuntimeClasspathEntry[] computeUnresolvedSARLRuntimeClasspath(ILaunchConfiguration configuration,
		ILaunchConfigurationAccessor configAccessor,
		IJavaProjectAccessor projectAccessor) throws CoreException {
	// Get the classpath from the configuration.
	final IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(configuration);
	//
	final List<IRuntimeClasspathEntry> filteredEntries = new ArrayList<>();
	List<IRuntimeClasspathEntry> sreClasspathEntries = null;
	// Filtering the entries by replacing the "SARL Libraries" with the SARL runtime environment.
	for (final IRuntimeClasspathEntry entry : entries) {
		if (entry.getPath().equals(SARLClasspathContainerInitializer.CONTAINER_ID)) {
			if (sreClasspathEntries == null) {
				sreClasspathEntries = getSREClasspathEntries(configuration, configAccessor, projectAccessor);
			}
			filteredEntries.addAll(sreClasspathEntries);
		} else {
			filteredEntries.add(entry);
		}
	}
	return filteredEntries.toArray(new IRuntimeClasspathEntry[filteredEntries.size()]);
}
 
Example #18
Source File: FatJarPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IPath[] getClasspath(ILaunchConfiguration configuration) throws CoreException {
	IRuntimeClasspathEntry[] entries= JavaRuntime.computeUnresolvedRuntimeClasspath(configuration);
	entries= JavaRuntime.resolveRuntimeClasspath(entries, configuration);

	ArrayList<IPath> userEntries= new ArrayList<IPath>(entries.length);
	for (int i= 0; i < entries.length; i++) {
		if (entries[i].getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) {

			String location= entries[i].getLocation();
			if (location != null) {
				IPath entry= Path.fromOSString(location);
				if (!userEntries.contains(entry)) {
					userEntries.add(entry);
				}
			}
		}
	}
	return userEntries.toArray(new IPath[userEntries.size()]);
}
 
Example #19
Source File: ReorgCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean updateClasspath(IPath newPath, IProgressMonitor monitor) throws JavaModelException {
	boolean updated= false;
	
	IClasspathEntry[] classpath= fProject.getRawClasspath();
	IPath jreContainerPath= new Path(JavaRuntime.JRE_CONTAINER);
	for (int i= 0; i < classpath.length; i++) {
		IClasspathEntry curr= classpath[i];
		if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER && curr.getPath().matchingFirstSegments(jreContainerPath) > 0) {
			if (! newPath.equals(curr.getPath())) {
				updated= true;
				classpath[i]= JavaCore.newContainerEntry(newPath, curr.getAccessRules(), curr.getExtraAttributes(), curr.isExported());
			}
		}
	}
	if (updated) {
		fProject.setRawClasspath(classpath, monitor);
	}
	return updated;
}
 
Example #20
Source File: GradleProjectImporterTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testJavaHome() throws Exception {
	Preferences prefs = JavaLanguageServerPlugin.getPreferencesManager().getPreferences();
	String javaHomePreference = prefs.getJavaHome();
	IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();
	try {
		IVMInstallType installType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
		IVMInstall[] vms = installType.getVMInstalls();
		IVMInstall vm = vms[0];
		JavaRuntime.setDefaultVMInstall(vm, new NullProgressMonitor());
		String javaHome = new File(TestVMType.getFakeJDKsLocation(), "11").getAbsolutePath();
		prefs.setJavaHome(javaHome);
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
		IPath rootFolder = root.getLocation().append("/projects/gradle/simple-gradle");
		BuildConfiguration build = GradleProjectImporter.getBuildConfiguration(rootFolder.toFile().toPath());
		assertEquals(vm.getInstallLocation().getAbsolutePath(), build.getJavaHome().get().getAbsolutePath());
	} finally {
		prefs.setJavaHome(javaHomePreference);
		if (defaultVM != null) {
			JavaRuntime.setDefaultVMInstall(defaultVM, new NullProgressMonitor());
		}
	}
}
 
Example #21
Source File: WebAppServerTab.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean isValid(ILaunchConfiguration launchConfig) {
  setErrorMessage(null);
  setMessage(null);

  if (!super.isValid(launchConfig)) {
    return false;
  }

  IProject project;
  try {
    IJavaProject javaProject = JavaRuntime.getJavaProject(launchConfig);
    if (javaProject == null) {
      return false;
    }

    project = javaProject.getProject();
  } catch (CoreException ce) {
    // Thrown if the Java project does not exist, which is not of concern in
    // this tab (the Main tab handles those error messages)
    return false;
  }

  return true;
}
 
Example #22
Source File: ReorgCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IVMInstall findRequiredOrGreaterVMInstall() {
	String bestMatchingCompliance= null;
	IVMInstall bestMatchingVMInstall= null;
	IVMInstallType[] installTypes= JavaRuntime.getVMInstallTypes();
	for (int i= 0; i < installTypes.length; i++) {
		IVMInstall[] installs= installTypes[i].getVMInstalls();
		for (int k= 0; k < installs.length; k++) {
			String vmInstallCompliance= getVMInstallCompliance(installs[k]);
			
			if (fRequiredVersion.equals(vmInstallCompliance)) {
				return installs[k]; // perfect match
				
			} else if (JavaModelUtil.isVersionLessThan(vmInstallCompliance, fRequiredVersion)) {
				continue; // no match
				
			} else if (bestMatchingVMInstall != null) {
				if (JavaModelUtil.isVersionLessThan(bestMatchingCompliance, vmInstallCompliance)) {
					continue; // the other one is the least matching
				}
			}
			bestMatchingCompliance= vmInstallCompliance;
			bestMatchingVMInstall= installs[k];
		}
	}
	return null;
}
 
Example #23
Source File: GWTProjectUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the GWT-applicable source folder paths from a project (note: this
 * will not traverse into the project's dependencies, for this behavior, see
 * {@link #getGWTSourceFolderPathsFromProjectAndDependencies(IJavaProject, boolean)}
 * ).
 *
 * @param javaProject Reference to the project
 * @param sourceEntries The list to be filled with the entries corresponding
 *          to the source folder paths
 * @param includeTestSourceEntries Whether to include the entries for test
 *          source
 * @throws SdkException
 */
private static void fillGWTSourceFolderPathsFromProject(
    IJavaProject javaProject, Collection<? super IRuntimeClasspathEntry>
    sourceEntries, boolean includeTestSourceEntries) throws SdkException {

  assert (javaProject != null);

  if (GWTProjectsRuntime.isGWTRuntimeProject(javaProject)) {
    // TODO: Do we still need to handle this here since Sdk's report their
    // own runtime classpath entries?
    sourceEntries.addAll(GWTProjectsRuntime.getGWTRuntimeProjectSourceEntries(
        javaProject, includeTestSourceEntries));
  } else {
    try {
      for (IClasspathEntry curClasspathEntry : javaProject.getRawClasspath()) {
        if (curClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
          IPath sourcePath = curClasspathEntry.getPath();
          // If including tests, include all source, or if not including tests, ensure
          // it is not a test path
          if (includeTestSourceEntries || !GWTProjectUtilities.isTestPath(sourcePath)) {
            if (!isOptional(curClasspathEntry) || exists(sourcePath)) {
              sourceEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(sourcePath));
            }
          }
        }
      }
      IFolder folder = javaProject.getProject().getFolder("super");
      if (folder.exists()) {
        sourceEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(folder.getFullPath()));
      }
    } catch (JavaModelException jme) {
      GWTPluginLog.logError(jme,
          "Unable to retrieve raw classpath for project "
              + javaProject.getProject().getName());
    }
  }
}
 
Example #24
Source File: ReportLauncherUtils.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static IVMInstall[] getAllVMInstances( )
{
	ArrayList res = new ArrayList( );
	IVMInstallType[] types = JavaRuntime.getVMInstallTypes( );
	for ( int i = 0; i < types.length; i++ )
	{
		IVMInstall[] installs = types[i].getVMInstalls( );
		for ( int k = 0; k < installs.length; k++ )
		{
			res.add( installs[k] );
		}
	}
	return (IVMInstall[]) res.toArray( new IVMInstall[res.size( )] );
}
 
Example #25
Source File: TypeInfoViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public TypeInfoLabelProvider(ITypeInfoImageProvider extension) {
	fProviderExtension= extension;
	List locations= new ArrayList();
	List labels= new ArrayList();
	IVMInstallType[] installs= JavaRuntime.getVMInstallTypes();
	for (int i= 0; i < installs.length; i++) {
		processVMInstallType(installs[i], locations, labels);
	}
	fInstallLocations= (String[])locations.toArray(new String[locations.size()]);
	fVMNames= (String[])labels.toArray(new String[labels.size()]);
	
}
 
Example #26
Source File: RuntimeUtils.java    From JReFrameworker with MIT License 5 votes vote down vote up
public static File getRuntimeJar(String jarName) throws IOException {
	IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
	LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);
	for (LibraryLocation library : locations) {
		File runtime = JavaCore.newLibraryEntry(library.getSystemLibraryPath(), null, null).getPath().toFile().getCanonicalFile();
		if(runtime.getName().equals(jarName)){
			return runtime;
		}
	}
	return null;
}
 
Example #27
Source File: RuntimeUtils.java    From JReFrameworker with MIT License 5 votes vote down vote up
public static boolean isRuntimeJar(File jar) throws IOException {
	IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
	LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);
	for (LibraryLocation library : locations) {
		File runtime = JavaCore.newLibraryEntry(library.getSystemLibraryPath(), null, null).getPath().toFile().getCanonicalFile();
		if(runtime.equals(jar.getCanonicalFile())){
			return true;
		}
	}
	return false;
}
 
Example #28
Source File: WorkspaceClassLoaderFactory.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void addJavaClasspathEntries(IJavaProject project, List<URL> urls) {
	try {
		urls.addAll(Lists.newArrayList(convertClassPath(JavaRuntime
				.computeDefaultRuntimeClassPath(project))));
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example #29
Source File: AbstractXtendUITestCase.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void setJavaVersion(JavaVersion javaVersion) throws Exception {
	IJavaProject javaProject = JavaProjectSetupUtil.findJavaProject(WorkbenchTestHelper.TESTPROJECT_NAME);
	Pair<String,Boolean> result = WorkbenchTestHelper.changeBree(javaProject, javaVersion);
	IExecutionEnvironment execEnv = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(result.getKey());
	Assume.assumeNotNull("Execution environment not found for: " + javaVersion.getLabel(), execEnv);
	Assume.assumeTrue("No compatible VM was found for: " + javaVersion.getLabel(),
			execEnv.getCompatibleVMs().length > 0);
	if(result.getValue()) {
		WorkbenchTestHelper.makeCompliantFor(javaProject, javaVersion);
		IResourcesSetupUtil.reallyWaitForAutoBuild();
	}
}
 
Example #30
Source File: JVMConfiguratorTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testPreviewFeatureSettings() throws Exception {
	IVMInstallChangedListener jvmConfigurator = new JVMConfigurator();
	try {
		JavaRuntime.addVMInstallChangedListener(jvmConfigurator);
		IJavaProject defaultProject = newDefaultProject();
		IProject invisibleProject = copyAndImportFolder("singlefile/java13", "foo/bar/Foo.java");
		IJavaProject randomProject = JavaCore.create(invisibleProject);

		assertComplianceAndPreviewSupport(defaultProject, "1.8", false);
		assertComplianceAndPreviewSupport(randomProject, "1.8", false);

		String latest = JavaCore.latestSupportedJavaVersion();
		TestVMType.setTestJREAsDefault(latest);

		assertComplianceAndPreviewSupport(defaultProject, latest, true);
		assertComplianceAndPreviewSupport(randomProject, latest, true);

		TestVMType.setTestJREAsDefault("12");

		assertComplianceAndPreviewSupport(defaultProject, "12", false);
		assertComplianceAndPreviewSupport(randomProject, "12", false);

		TestVMType.setTestJREAsDefault("1.8");

		assertComplianceAndPreviewSupport(defaultProject, "1.8", false);
		assertComplianceAndPreviewSupport(randomProject, "1.8", false);


	} finally {
		JavaRuntime.removeVMInstallChangedListener(jvmConfigurator);
	}
}