/**
   * Adds a duplicate of the selected VM to the block
   *
   * @since 3.2
   */
  protected void copyVM() {
    IStructuredSelection selection = (IStructuredSelection) fVMList.getSelection();
    Iterator<IVMInstall> it = selection.iterator();

    ArrayList<VMStandin> newEntries = new ArrayList<VMStandin>();
    while (it.hasNext()) {
      IVMInstall selectedVM = it.next();
      // duplicate & add VM
      VMStandin standin = new VMStandin(selectedVM, createUniqueId(selectedVM.getVMInstallType()));
      standin.setName(generateName(selectedVM.getName()));
      EditVMInstallWizard wizard =
          new EditVMInstallWizard(standin, fVMs.toArray(new IVMInstall[fVMs.size()]));
      WizardDialog dialog = new WizardDialog(getShell(), wizard);
      int dialogResult = dialog.open();
      if (dialogResult == Window.OK) {
        VMStandin result = wizard.getResult();
        if (result != null) {
          newEntries.add(result);
        }
      } else if (dialogResult == Window.CANCEL) {
        // Canceling one wizard should cancel all subsequent wizards
        break;
      }
    }
    if (newEntries.size() > 0) {
      fVMs.addAll(newEntries);
      fVMList.refresh();
      fVMList.setSelection(new StructuredSelection(newEntries.toArray()));
    } else {
      fVMList.setSelection(selection);
    }
    fVMList.refresh(true);
  }
 private String getDefaultJVMName() {
   IVMInstall install = JavaRuntime.getDefaultVMInstall();
   if (install != null) {
     return install.getName();
   } else {
     return Messages.NewBlackBerryProjectWizardPageOne_UnknownDefaultJRE_name;
   }
 }
 public static void javaXXeveryone(String version) throws CoreException {
   // 1: The eclipse workspace default VM should be Java 7
   IVMInstall vm = ensureJavaXXdefaultVM(version);
   // 2: Compiler/source compliance for JDT
   JavaUtils.setJavaXXCompliance(version); // Compiler/source compliance also Java 7
   // 3: Force Gradle JVM default
   GradleCore.getInstance().getPreferences().setJavaHomeJREName(vm.getName());
 }
 /**
  * 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);
 }
示例#5
0
 public static boolean isExistingVMName(String name) {
   for (IVMInstall vm :
       JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE).getVMInstalls()) {
     if (vm.getName().equals(name)) {
       return true;
     }
   }
   return false;
 }
 /** @see IAddVMDialogRequestor#isDuplicateName(String) */
 @Override
 public boolean isDuplicateName(String name) {
   for (int i = 0; i < fVMs.size(); i++) {
     IVMInstall vm = fVMs.get(i);
     if (vm.getName().equals(name)) {
       return true;
     }
   }
   return false;
 }
 /** @see ITableLabelProvider#getColumnText(Object, int) */
 @Override
 public String getColumnText(Object element, int columnIndex) {
   if (element instanceof IVMInstall) {
     IVMInstall vm = (IVMInstall) element;
     switch (columnIndex) {
       case 0:
         if (JavaRuntime.isContributedVMInstall(vm.getId())) {
           return NLS.bind(JREMessages.InstalledJREsBlock_19, new String[] {vm.getName()});
         }
         if (fVMList.getChecked(element)) {
           return NLS.bind(JREMessages.InstalledJREsBlock_7, vm.getName());
         }
         return vm.getName();
       case 1:
         return vm.getInstallLocation().getAbsolutePath();
       case 2:
         return vm.getVMInstallType().getName();
     }
   }
   return element.toString();
 }
示例#8
0
  /**
   * 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();
  }
 private StringBuffer appendVMAttributes(IVMInstall vmInstall, StringBuffer buf) {
   if (vmInstall != null) {
     String str = vmInstall.getName();
     buf.append('[').append(str.length()).append(']').append(str);
     str = vmInstall.getVMInstallType().getName();
     buf.append('[').append(str.length()).append(']').append(str);
     if (vmInstall.getVMArguments() != null && vmInstall.getVMArguments().length > 0) {
       buf.append('[').append(vmInstall.getVMArguments().length).append(']');
       for (int i = 0; i < vmInstall.getVMArguments().length; i++) {
         str = vmInstall.getVMArguments()[i];
         buf.append('[').append(str.length()).append(']').append(str);
       }
     }
     str = vmInstall.getInstallLocation().getAbsolutePath();
     buf.append('[').append(str.length()).append(']').append(str).append(';');
   } else {
     buf.append('[').append(']').append(';');
   }
   return buf;
 }
  /* (non-Javadoc)
   * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
   */
  public String getText(Object element) {
    IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry) element;
    switch (entry.getType()) {
      case IRuntimeClasspathEntry.PROJECT:
        IResource res = entry.getResource();
        IJavaElement proj = JavaCore.create(res);
        if (proj == null) {
          return entry.getPath().lastSegment();
        } else {
          return lp.getText(proj);
        }
      case IRuntimeClasspathEntry.ARCHIVE:
        IPath path = entry.getPath();
        if (path == null) {
          return MessageFormat.format("Invalid path: {0}", new Object[] {"null"}); // $NON-NLS-1$
        }
        if (!path.isAbsolute() || !path.isValidPath(path.toString())) {
          return MessageFormat.format("Invalid path: {0}", new Object[] {path.toOSString()});
        }
        String[] segments = path.segments();
        StringBuffer displayPath = new StringBuffer();
        if (segments.length > 0) {
          String device = path.getDevice();
          if (device != null) {
            displayPath.append(device);
            displayPath.append(File.separator);
          }
          for (int i = 0; i < segments.length - 1; i++) {
            displayPath.append(segments[i]).append(File.separator);
          }
          displayPath.append(segments[segments.length - 1]);

          // getDevice means that's a absolute path.
          if (path.getDevice() != null && !path.toFile().exists()) {
            displayPath.append(" (missing) ");
          }
        } else {
          displayPath.append(path.toOSString());
        }
        return displayPath.toString();
      case IRuntimeClasspathEntry.VARIABLE:
        path = entry.getPath();
        IPath srcPath = entry.getSourceAttachmentPath();
        StringBuffer buf = new StringBuffer(path.toString());
        if (srcPath != null) {
          buf.append(" ["); // $NON-NLS-1$
          buf.append(srcPath.toString());
          IPath rootPath = entry.getSourceAttachmentRootPath();
          if (rootPath != null) {
            buf.append(IPath.SEPARATOR);
            buf.append(rootPath.toString());
          }
          buf.append(']');
        }
        // append JRE name if we can compute it
        if (path.equals(new Path(JavaRuntime.JRELIB_VARIABLE)) && fLaunchConfiguration != null) {
          try {
            IVMInstall vm = JavaRuntime.computeVMInstall(fLaunchConfiguration);
            buf.append(" - "); // $NON-NLS-1$
            buf.append(vm.getName());
          } catch (CoreException e) {
          }
        }
        return buf.toString();
      case IRuntimeClasspathEntry.CONTAINER:
        path = entry.getPath();
        if (fLaunchConfiguration != null) {
          try {
            IJavaProject project = null;
            try {
              project = JavaRuntime.getJavaProject(fLaunchConfiguration);
            } catch (CoreException e) {
            }
            if (project == null) {
            } else {
              IClasspathContainer container =
                  JavaCore.getClasspathContainer(entry.getPath(), project);
              if (container != null) {
                if (container.getDescription().startsWith("Persisted container")) {
                  return container.getPath().toString();
                } else {
                  return container.getDescription();
                }
              }
            }
          } catch (CoreException e) {
          }
        }
        return entry.getPath().toString();
      case IRuntimeClasspathEntry.OTHER:
        IRuntimeClasspathEntry delegate = entry;
        if (entry instanceof ClasspathEntry) {
          delegate = ((ClasspathEntry) entry).getDelegate();
        }
        String name = lp.getText(delegate);
        if (name == null || name.length() == 0) {
          return ((IRuntimeClasspathEntry2) delegate).getName();
        }
        return name;
    }
    return ""; //$NON-NLS-1$
  }
 private String getDefaultBBJRE() {
   IVMInstall vm = VMUtils.getDefaultBBVM();
   return vm != null ? vm.getName() : "";
 }