Exemplo n.º 1
0
  static {
    try {
      String platform;
      if (isWindows()) {
        platform = "windows";
      } else if (isUnix()) {
        platform = "linux";
      } else if (isMac()) {
        platform = "mac";
      } else {
        platform = null;
      }

      String propertiesFile = "undefined";
      if (platform != null) {
        propertiesFile = "org/python/pydev/core/TestDependent." + platform + ".properties";
        InputStream stream =
            TestDependent.class.getClassLoader().getResourceAsStream(propertiesFile);
        if (stream != null) {
          // Initialize the static contents of the class.
          String streamContents = REF.getStreamContents(stream, null, null);
          Properties props = PropertiesHelper.createPropertiesFromString(streamContents);
          Map<String, String> map = PropertiesHelper.createMapFromProperties(props);
          Set<Entry<String, String>> entrySet = map.entrySet();
          for (Entry<String, String> entry : entrySet) {
            String key = entry.getKey();
            try {
              Field field = TestDependent.class.getField(key);
              if (field != null) {
                String value = entry.getValue();
                if (!value.equals("null")) {
                  field.set(null, value);
                }
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        } else {
          System.err.println(
              "Could not get stream to: "
                  + propertiesFile
                  + " to initialize TestDependent.java values.");
        }
      }

      // Checking and setting variables that do not exist (if possible).
      if (PYTHON_INSTALL == null) {
        System.err.println(
            "PYTHON_INSTALL variable MUST be set in " + propertiesFile + " to run tests.");
      } else if (!new File(PYTHON_INSTALL).exists()) {
        System.err.println(
            "PYTHON_INSTALL variable points to path that does NOT exist: " + PYTHON_INSTALL);
      }

      if (TEST_PYDEV_BASE_LOC == null) {
        System.err.println(
            "TEST_PYDEV_BASE_LOC variable MUST be set in " + propertiesFile + " to run tests.");
      } else if (!new File(TEST_PYDEV_BASE_LOC).exists()) {
        System.err.println(
            "TEST_PYDEV_BASE_LOC variable points to path that does NOT exist: "
                + TEST_PYDEV_BASE_LOC);
      }

      if (PYTHON_EXE == null) {
        if (isWindows()) {
          PYTHON_EXE = PYTHON_INSTALL + "python.exe";
        } else {
          PYTHON_EXE = PYTHON_INSTALL + "python";
        }
      }
      if (!new File(PYTHON_EXE).exists()) {
        System.err.println("PYTHON_EXE variable points to path that does NOT exist: " + PYTHON_EXE);
      }

      if (PYTHON_LIB == null) {
        PYTHON_LIB = PYTHON_INSTALL + "Lib/";
      }
      if (PYTHON_DLLS == null) {
        PYTHON_DLLS = PYTHON_INSTALL + "DLLs/";
      }
      if (PYTHON_SITE_PACKAGES == null) {
        PYTHON_SITE_PACKAGES = PYTHON_LIB + "site-packages/";
      }
      if (PYTHON_TEST_PACKAGES == null) {
        if (new File(TestDependent.PYTHON_LIB + "test/").exists()) {
          PYTHON_TEST_PACKAGES = TestDependent.PYTHON_LIB + "test/";
        }
      }

      if (TEST_PYSRC_LOC == null) {
        TEST_PYSRC_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev/tests/pysrc/";
      }

      if (TEST_PYSRC_NAVIGATOR_LOC == null) {
        TEST_PYSRC_NAVIGATOR_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev/tests_navigator/pysrc/";
      }

      if (TEST_PYSRC_LOC2 == null) {
        TEST_PYSRC_LOC2 = TEST_PYDEV_BASE_LOC + "org.python.pydev/tests/pysrc2/";
      }

      if (TEST_PYDEV_PLUGIN_LOC == null) {
        TEST_PYDEV_PLUGIN_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev/";
      }

      if (TEST_PYDEV_DEBUG_PLUGIN_LOC == null) {
        TEST_PYDEV_DEBUG_PLUGIN_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev.debug/";
      }

      if (TEST_PYDEV_JYTHON_PLUGIN_LOC == null) {
        TEST_PYDEV_JYTHON_PLUGIN_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev.jython/";
      }

      if (TEST_PYDEV_PARSER_PLUGIN_LOC == null) {
        TEST_PYDEV_PARSER_PLUGIN_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev.parser/";
      }

      if (TEST_PYDEV_REFACTORING_PLUGIN_LOC == null) {
        TEST_PYDEV_REFACTORING_PLUGIN_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev.refactoring/";
      }

      if (TEST_COM_REFACTORING_PYSRC_LOC == null) {
        TEST_COM_REFACTORING_PYSRC_LOC =
            TEST_PYDEV_BASE_LOC + "com.python.pydev.refactoring/tests/pysrcrefactoring/";
      }

    } catch (Exception e) {
      System.err.println(
          "--- Error getting contents to properly initialize TestDependent.java values ---");
      e.printStackTrace();
    }
  }