Exemple #1
0
 private void addToolsJar(ILaunchConfiguration configuration, List rtes, String path) {
   IRuntimeClasspathEntry tools = getToolsJar(configuration);
   if (tools == null) {
     if (path != null) {
       // use the global entry
       rtes.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(path)));
     } else {
       // use the default vm install to try to find a tools.jar
       IVMInstall install = JavaRuntime.getDefaultVMInstall();
       if (install != null) {
         IAntClasspathEntry entry =
             AntCorePlugin.getPlugin()
                 .getPreferences()
                 .getToolsJarEntry(new Path(install.getInstallLocation().getAbsolutePath()));
         if (entry != null) {
           rtes.add(
               JavaRuntime.newArchiveRuntimeClasspathEntry(
                   new Path(entry.getEntryURL().getPath())));
         }
       }
     }
   } else {
     rtes.add(tools);
   }
 }
 private String getDefaultJVMName() {
   IVMInstall install = JavaRuntime.getDefaultVMInstall();
   if (install != null) {
     return install.getName();
   } else {
     return Messages.NewBlackBerryProjectWizardPageOne_UnknownDefaultJRE_name;
   }
 }
 /**
  * Sets the workspace default VM on the given working copy
  *
  * @param config
  * @since 3.5
  */
 @SuppressWarnings("deprecation")
 public static void setVM(ILaunchConfigurationWorkingCopy config) {
   IVMInstall vm = JavaRuntime.getDefaultVMInstall();
   String vmName = vm.getName();
   String vmTypeID = vm.getVMInstallType().getId();
   config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, vmName);
   config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, vmTypeID);
 }
 public static IVMInstall getVMInstall(String name) {
   if (name != null) {
     IVMInstall[] installs = VMUtil.getAllVMInstances();
     for (int i = 0; i < installs.length; i++) {
       if (installs[i].getName().equals(name)) return installs[i];
     }
   }
   return JavaRuntime.getDefaultVMInstall();
 }
 public void testArchiveLocationMemento() throws Exception {
   IVMInstall vm = JavaRuntime.getDefaultVMInstall();
   IJavaSourceLocation location =
       new ArchiveSourceLocation(
           JavaRuntime.getLibraryLocations(vm)[0].getSystemLibraryPath().toOSString(), null);
   String memento = location.getMemento();
   IJavaSourceLocation restored = new ArchiveSourceLocation();
   restored.initializeFrom(memento);
   assertEquals("archive locations should be equal", location, restored);
 }
 /**
  * Get selected JVM.
  *
  * @return Selected JVM or <code>null</code> if one is not found
  */
 public IVMInstall getSelectedJVM() {
   if (_useProjectRE.isSelected()) {
     int index = _RECombo.getSelectionIndex();
     if (index >= 0 && index < _installedVMs.length) { // paranoia
       return _installedVMs[index];
     }
     return null;
   }
   // user selects workspace default JRE
   return JavaRuntime.getDefaultVMInstall();
 }
  public static IVMInstall ensureJavaXXdefaultVM(String version) throws CoreException {
    // Before doing anything check the current default VM
    IVMInstall vm = JavaRuntime.getDefaultVMInstall();
    if (JavaUtils.isJavaXX(vm, version)) {
      return vm; // Done!
    }

    vm = getJavaXXVM(version);
    if (vm == null) {
      vm = JavaUtils.createVM(getVMLocation(version));
    }
    if (!JavaUtils.isJavaXX(vm, version)) {
      throw new Error("vm at " + vm.getInstallLocation() + " doesn't look like a Java " + version);
    }
    JavaRuntime.setDefaultVMInstall(vm, new NullProgressMonitor());
    return vm;
  }
  public void testJavaSourceLocatorMemento() throws Exception {
    IJavaSourceLocation location1 = new JavaProjectSourceLocation(get14Project());
    File dir = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
    IJavaSourceLocation location2 = new DirectorySourceLocation(dir);
    IVMInstall vm = JavaRuntime.getDefaultVMInstall();
    IJavaSourceLocation location3 =
        new ArchiveSourceLocation(
            JavaRuntime.getLibraryLocations(vm)[0].getSystemLibraryPath().toOSString(), null);

    JavaSourceLocator locator =
        new JavaSourceLocator(new IJavaSourceLocation[] {location1, location2, location3});
    String memento = locator.getMemento();
    JavaSourceLocator restored = new JavaSourceLocator();
    restored.initializeFromMemento(memento);
    IJavaSourceLocation[] locations = restored.getSourceLocations();

    assertEquals("wrong number of source locations", 3, locations.length);
    assertEquals("1st locations not equal", location1, locations[0]);
    assertEquals("2nd locations not equal", location2, locations[1]);
    assertEquals("3rd locations not equal", location3, locations[2]);
  }
 public static boolean defaultJVMInstallIsJava16() {
   IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();
   return isJava16(defaultVM);
 }