<commit_before>/*
 * Copyright (c) 2014 <NAME> (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    <NAME> - initial API and implementation
 */
package org.eclipse.oomph.jreinfo;

import org.eclipse.oomph.internal.jreinfo.JREInfoPlugin;
import org.eclipse.oomph.util.PropertiesUtil;
import org.eclipse.oomph.util.XMLUtil;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

import javax.xml.parsers.DocumentBuilder;

import java.io.File;
import java.io.FileNotFoundException;

/**
 * @author Stepper
 */
public final class JREInfo
{
  private static final boolean SKIP_USER_HOME = PropertiesUtil.isProperty("oomph.jreinfo.skip.user.home");

  private static final String[] EXTRA_SEARCH_PATH = PropertiesUtil.getProperty("oomph.jreinfo.extra.search.path", "").split(File.pathSeparator);

  public String javaHome;

  public int jdk;

  public JREInfo next;

  public static JREInfo getAll()
  {
    JREInfo jreInfo = null;

    try
    {
      switch (JREManager.OS_TYPE)
      {
        case Win:
          jreInfo = getAllWin();
          break;

        case Mac:
          jreInfo = getAllMac();
          break;

        case Linux:
          jreInfo = getAllLinux();
          break;

        default:
          //$FALL-THROUGH$
      }

      if (!SKIP_USER_HOME)
      {
        jreInfo = searchFolder(jreInfo, PropertiesUtil.USER_HOME);
        jreInfo = searchFolder(jreInfo, PropertiesUtil.USER_HOME + "/java");
        jreInfo = searchFolder(jreInfo, PropertiesUtil.USER_HOME + "/jvm");
      }

      for (int i = 0; i < EXTRA_SEARCH_PATH.length; i++)
      {
        String search = EXTRA_SEARCH_PATH[i];
        jreInfo = searchFolder(jreInfo, search);
      }
    }
    catch (Throwable ex)
    {
      JREInfoPlugin.INSTANCE.log(ex);
    }

    return jreInfo;
  }

  private static native JREInfo getAllWin();

  private static JREInfo getAllMac()
  {
    final JREInfo[] jreInfo = { null };

    try
    {
      ProcessBuilder builder = new ProcessBuilder();
      builder.command("/usr/libexec/java_home", "-X");

      Process process = builder.start();

      DocumentBuilder documentBuilder = XMLUtil.createDocumentBuilder();
      Element rootElement = XMLUtil.loadRootElement(documentBuilder, process.getInputStream());
      XMLUtil.handleElementsByTagName(rootElement, "key", new XMLUtil.ElementHandler()
      {
        public void handleElement(Element element) throws Exception
        {
          try
          {
            String text = element.getTextContent();
            if (text != null && "JVMHomePath".equals(text.trim()))
            {
              Node siblingNode = element.getNextSibling();<commit_msg>[467889] UI freeze in UIUtil$3.run (320) -  - JREInfo.getAll (53)<commit_after>/*
 * Copyright (c) 2014 <NAME> (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    <NAME> - initial API and implementation
 */
package org.eclipse.oomph.jreinfo;

import org.eclipse.oomph.internal.jreinfo.JREInfoPlugin;
import org.eclipse.oomph.util.PropertiesUtil;
import org.eclipse.oomph.util.XMLUtil;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringReader;

/**
 * @author Stepper
 */
public final class JREInfo
{
  private static final boolean SKIP_USER_HOME = PropertiesUtil.isProperty("oomph.jreinfo.skip.user.home");

  private static final String[] EXTRA_SEARCH_PATH = PropertiesUtil.getProperty("oomph.jreinfo.extra.search.path", "").split(File.pathSeparator);

  public String javaHome;

  public int jdk;

  public JREInfo next;

  public static JREInfo getAll()
  {
    JREInfo jreInfo = null;

    try
    {
      switch (JREManager.OS_TYPE)
      {
        case Win:
          jreInfo = getAllWin();
          break;

        case Mac:
          jreInfo = getAllMac();
          break;

        case Linux:
          jreInfo = getAllLinux();
          break;

        default:
          //$FALL-THROUGH$
      }

      if (!SKIP_USER_HOME)
      {
        jreInfo = searchFolder(jreInfo, PropertiesUtil.USER_HOME);
        jreInfo = searchFolder(jreInfo, PropertiesUtil.USER_HOME + "/java");
        jreInfo = searchFolder(jreInfo, PropertiesUtil.USER_HOME + "/jvm");
      }

      for (int i = 0; i < EXTRA_SEARCH_PATH.length; i++)
      {
        String search = EXTRA_SEARCH_PATH[i];
        jreInfo = searchFolder(jreInfo, search);
      }
    }
    catch (Throwable ex)
    {
      JREInfoPlugin.INSTANCE.log(ex);
    }

    return jreInfo;
  }

  private static native JREInfo getAllWin();

  private static JREInfo getAllMac()
  {
    final JREInfo[] jreInfo = { null };

    try
    {
      ProcessBuilder builder = new ProcessBuilder();
      builder.command("/usr/libexec/java_home", "-X");

      Process process = builder.start();

      DocumentBuilder documentBuilder = XMLUtil.createDocumentBuilder();
      documentBuilder.setEntityResolver(new EntityResolver()
      {
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
        {
          return new InputSource(new StringReader(""));
        }
      });

      Element rootElement = XMLUtil.loadRootElement(documentBuilder, process.getInputStream());
      XMLUtil.handleElementsByTagName(rootElement, "key", new XMLUtil.ElementHandler()
      {
        public void handleElement(Element element) throws Exception
        {
          try
          {
            String text = element.getTextContent();
            if (text != null && "JVMHomePath".equals(text.trim()))
            {
              Node siblingNode = element.getNextSibling();
{'fraction_non_alphanumeric': 0.10527994895517627, 'fraction_numerical': 0.005423512521933323, 'mean_word_length': 2.779385171790235, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5530159', 'n_tokens_mistral': 1919, 'n_tokens_neox': 1860, 'n_words': 433}