Ejemplo n.º 1
0
  /**
   * Parse the specified VM node, create a VMStandin for it, and add this to the specified
   * container.
   */
  private static void legacyPopulateVMForType(
      IVMInstallType vmType, Element vmElement, VMDefinitionsContainer container) {
    String id = vmElement.getAttribute("name"); // $NON-NLS-1$
    if (id != null) {

      // Retrieve the 'path' attribute.  If none, skip this node.
      String installPath = vmElement.getAttribute("path"); // $NON-NLS-1$
      if (installPath == null) {
        return;
      }

      // Create a VMStandin for the node and set its 'name' & 'installLocation' attributes
      VMStandin vmStandin = new VMStandin(vmType, id);
      vmStandin.setName(id); // $NON-NLS-1$
      File installLocation = new File(installPath);
      //  If the path is to the executable (which it should be), chop off last part of path!
      if (installLocation.isFile()) {
        installLocation = installLocation.getParentFile(); // move up to "bin"
        if (installLocation != null && installLocation.getParentFile() != null) {
          installLocation =
              installLocation.getParentFile(); // this should now be ruby install location
        }
      }
      if (installLocation == null) return;
      vmStandin.setInstallLocation(installLocation);
      container.addVM(vmStandin);
    } else {
      LaunchingPlugin.log(
          LaunchingMessages.RubyRuntime_VM_element_specified_with_no_id_attribute_2);
    }
  }
Ejemplo n.º 2
0
  /**
   * Parse the specified VM node, create a VMStandin for it, and add this to the specified
   * container.
   */
  private static void populateVMForType(
      IVMInstallType vmType, Element vmElement, VMDefinitionsContainer container) {
    String id = vmElement.getAttribute("id"); // $NON-NLS-1$
    if (id != null) {

      // Retrieve the 'path' attribute.  If none, skip this node.
      String installPath = vmElement.getAttribute("path"); // $NON-NLS-1$
      if (installPath == null) {
        return;
      }

      // Create a VMStandin for the node and set its 'name' & 'installLocation' attributes
      VMStandin vmStandin = new VMStandin(vmType, id);
      vmStandin.setName(vmElement.getAttribute("name")); // $NON-NLS-1$
      File installLocation = new File(installPath);
      vmStandin.setInstallLocation(installLocation);
      container.addVM(vmStandin);

      // Look for subordinate nodes.  These may be 'libraryLocation',
      // 'libraryLocations' or 'versionInfo'.
      NodeList list = vmElement.getChildNodes();
      int length = list.getLength();
      for (int i = 0; i < length; ++i) {
        Node node = list.item(i);
        short type = node.getNodeType();
        if (type == Node.ELEMENT_NODE) {
          Element subElement = (Element) node;
          String subElementName = subElement.getNodeName();
          if (subElementName.equals("libraryLocation")) { // $NON-NLS-1$
            IPath loc = getLibraryLocation(subElement);
            vmStandin.setLibraryLocations(new IPath[] {loc});
            break;
          } else if (subElementName.equals("libraryLocations")) { // $NON-NLS-1$
            setLibraryLocations(vmStandin, subElement);
            break;
          }
        }
      }

      // vm Arguments
      String vmArgs = vmElement.getAttribute("vmargs"); // $NON-NLS-1$
      if (vmArgs != null && vmArgs.length() > 0) {
        vmStandin.setVMArgs(vmArgs);
      }
    } else {
      LaunchingPlugin.log(
          LaunchingMessages.RubyRuntime_VM_element_specified_with_no_id_attribute_2);
    }
  }
Ejemplo n.º 3
0
  /**
   * Parse the VM definitions contained in the specified InputStream into the specified container.
   *
   * <p>The VMs in the returned container are instances of <code>VMStandin</code>.
   *
   * <p>This method has no side-effects. That is, no notifications are sent for VM adds, changes,
   * deletes, and the workbench preferences are not affected.
   *
   * <p>If the <code>getAsXML</code> method is called on the returned container object, the
   * resulting XML will be sematically equivalent (though not necessarily syntactically equivalent)
   * as the XML contained in <code>inputStream</code>.
   *
   * @param inputStream the <code>InputStream</code> containing XML that declares a set of VMs and a
   *     default VM
   * @param container the container to add the VM defs to
   * @return VMDefinitionsContainer a container for the VM objects declared in <code>inputStream
   *     </code>
   * @throws IOException if this method fails. Reasons include:
   *     <ul>
   *       <li>the XML in <code>inputStream</code> was badly formatted
   *       <li>the top-level node was not 'vmSettings'
   *     </ul>
   *
   * @since 3.2
   */
  public static void parseXMLIntoContainer(
      InputStream inputStream, VMDefinitionsContainer container) throws IOException {

    // Wrapper the stream for efficient parsing
    InputStream stream = new BufferedInputStream(inputStream);

    // Do the parsing and obtain the top-level node
    Element config = null;
    try {
      DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      parser.setErrorHandler(new DefaultHandler());
      config = parser.parse(new InputSource(stream)).getDocumentElement();
    } catch (SAXException e) {
      throw new IOException(LaunchingMessages.RubyRuntime_badFormat);
    } catch (ParserConfigurationException e) {
      stream.close();
      throw new IOException(LaunchingMessages.RubyRuntime_badFormat);
    } finally {
      stream.close();
    }

    String nodeName = config.getNodeName();
    if (nodeName.equalsIgnoreCase("runtimeconfig")) {
      // Do the legacy stuff
      importLegacyInterpreters(config, container);
      return;
    } else if (!config.getNodeName().equalsIgnoreCase("vmSettings")) { // $NON-NLS-1$
      // If the top-level node wasn't what we expected, bail out
      throw new IOException(LaunchingMessages.RubyRuntime_badFormat);
    }

    // Populate the default VM-related fields
    container.setDefaultVMInstallCompositeID(config.getAttribute("defaultVM")); // $NON-NLS-1$

    // Traverse the parsed structure and populate the VMType to VM Map
    NodeList list = config.getChildNodes();
    int length = list.getLength();
    for (int i = 0; i < length; ++i) {
      Node node = list.item(i);
      short type = node.getNodeType();
      if (type == Node.ELEMENT_NODE) {
        Element vmTypeElement = (Element) node;
        if (vmTypeElement.getNodeName().equalsIgnoreCase("vmType")) { // $NON-NLS-1$
          populateVMTypes(vmTypeElement, container);
        }
      }
    }
  }