Java Code Examples for com.intellij.openapi.util.io.FileUtil#findFirstThatExist()

The following examples show how to use com.intellij.openapi.util.io.FileUtil#findFirstThatExist() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonParseUtilTest.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
@Test
public void testGetProviderJsonFromFile() {

    File testFile = FileUtil.findFirstThatExist("src/test/java/de/espend/idea/php/toolbox/tests/utils/fixtures/ide-toolbox.metadata.json");

    Map<String, Collection<JsonRawLookupElement>> elements = JsonParseUtil.getProviderJsonRawLookupElements(JsonParseUtil.getDeserializeConfig(testFile).getProviders());
    assertTrue(elements.keySet().contains("date_format"));

    JsonRawLookupElement date_format = elements.get("date_format").iterator().next();

    assertEquals("d", date_format.getLookupString());

    // defaults
    assertEquals("com.jetbrains.php.PhpIcons.METHOD", date_format.getIcon());
    assertEquals("(TailTest)", date_format.getTailText());
    assertEquals("test", date_format.getTarget());

    Collection<JsonRawLookupElement> source1 = elements.get("source_2");
    JsonRawLookupElement source1Item = source1.iterator().next();
    assertEquals("d", source1Item.getLookupString());
}
 
Example 2
Source File: JsonParseUtilTest.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
@Test
public void testGetProviderJsonFromFile() {

    File testFile = FileUtil.findFirstThatExist("src/test/java/de/espend/idea/php/toolbox/tests/utils/fixtures/ide-toolbox.metadata.json");

    Map<String, Collection<JsonRawLookupElement>> elements = JsonParseUtil.getProviderJsonRawLookupElements(JsonParseUtil.getDeserializeConfig(testFile).getProviders());
    assertTrue(elements.keySet().contains("date_format"));

    JsonRawLookupElement date_format = elements.get("date_format").iterator().next();

    assertEquals("d", date_format.getLookupString());

    // defaults
    assertEquals("com.jetbrains.php.PhpIcons.METHOD", date_format.getIcon());
    assertEquals("(TailTest)", date_format.getTailText());
    assertEquals("test", date_format.getTarget());

    Collection<JsonRawLookupElement> source1 = elements.get("source_2");
    JsonRawLookupElement source1Item = source1.iterator().next();
    assertEquals("d", source1Item.getLookupString());
}
 
Example 3
Source File: EnvironmentUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public Map<String, String> readShellEnv() throws Exception {
  File reader = FileUtil.findFirstThatExist(ContainerPathManager.get().getBinPath() + "/printenv.py");
  if (reader == null) {
    throw new Exception("bin:" + ContainerPathManager.get().getBinPath());
  }

  File envFile = FileUtil.createTempFile("intellij-shell-env.", ".tmp", false);
  try {
    List<String> command = getShellProcessCommand();
    command.add("-c");
    command.add("'" + reader.getAbsolutePath() + "' '" + envFile.getAbsolutePath() + "'");

    LOG.info("loading shell env: " + StringUtil.join(command, " "));

    return runProcessAndReadEnvs(command, envFile, "\0");
  }
  finally {
    FileUtil.delete(envFile);
  }
}
 
Example 4
Source File: JsonParseUtilTest.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Test
public void testGetRegistrarJsonFromFile() {

    File testFile = FileUtil.findFirstThatExist("src/test/java/de/espend/idea/php/toolbox/tests/utils/fixtures/ide-toolbox.metadata.json");

    Collection<JsonRegistrar> elements = JsonParseUtil.getDeserializeConfig(testFile).getRegistrar();
    JsonRegistrar next = elements.iterator().next();

    assertTrue(ContainerUtil.filter(next.getSignatures(), new MyFunctionJsonSignatureCondition("foo")).size() > 0);
    assertTrue(ContainerUtil.filter(next.getSignatures(), new MyFunctionJsonSignatureCondition("date")).size() > 0);

    assertTrue(ContainerUtil.filter(next.getSignatures(), jsonSignature -> {
        return "DateTime".equals(jsonSignature.getClassName());
    }).size() > 0);
}
 
Example 5
Source File: JsonParseUtilTest.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Test
public void testGetRegistrarJsonFromFileWithShortcut() {
    File testFile = FileUtil.findFirstThatExist("src/test/java/de/espend/idea/php/toolbox/tests/utils/fixtures/ide-toolbox.metadata.json");

    Collection<JsonRegistrar> elements = JsonParseUtil.getDeserializeConfig(testFile).getRegistrar();
    JsonRegistrar next = elements.iterator().next();

    JsonSignature object = ContainerUtil.find(next.getSignatures(), new MyFunctionJsonSignatureCondition("apple"));

    assertNotNull(object);
    assertEquals(object.hashCode(), ContainerUtil.find(next.getSignatures(), new MyFunctionJsonSignatureCondition("apple")).hashCode());

    assertTrue(ContainerUtil.filter(next.getSignatures(), jsonSignature -> "apple".equals(jsonSignature.getClassName()) && "car".equals(jsonSignature.getMethod())).size() > 0);
}
 
Example 6
Source File: JsonParseUtilTest.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Test
public void testConfigDeserialize() {
    JsonConfigFile elements = null;
    try {
        File file = FileUtil.findFirstThatExist("src/test/java/de/espend/idea/php/toolbox/tests/utils/fixtures/ide-toolbox.metadata.json");
        elements = JsonParseUtil.getDeserializeConfig(StreamUtil.readText(new FileInputStream(file), Charset.defaultCharset()));
    } catch (IOException e) {
        e.printStackTrace();
    }

    List<JsonProvider> registrar = new ArrayList<>(elements.getProviders());

    assertEquals("date_format", registrar.get(0).getName());

    Collection<JsonRawLookupElement> dateFromatProvider = registrar.get(0).getItems();
    JsonRawLookupElement item = ContainerUtil.find(dateFromatProvider, new MyJsonRawLookupElementStringCondition("d"));
    assertNotNull(item);
    assertEquals(item.hashCode(), ContainerUtil.find(dateFromatProvider, new MyJsonRawLookupElementStringCondition("d")).hashCode());

    assertNotNull(ContainerUtil.find(dateFromatProvider, new MyJsonRawLookupElementStringCondition("car")));
    assertNotNull(ContainerUtil.find(dateFromatProvider, new MyJsonRawLookupElementStringCondition("apple")));

    assertEquals("source_1", registrar.get(1).getName());
    assertEquals("return", registrar.get(1).getSource().getContributor());
    assertEquals("\\Twig_Environment::getExtension", registrar.get(1).getSource().getParameter());

    assertEquals("source_2", registrar.get(2).getName());
    assertTrue(registrar.get(2).getItems().size() > 0);
}
 
Example 7
Source File: JsonParseUtilTest.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Test
public void testParameterRegistrarMappedAsObject() {
    File testFile = FileUtil.findFirstThatExist("src/test/java/de/espend/idea/php/toolbox/tests/utils/fixtures/ide-toolbox.metadata.json");

    JsonRegistrar next = JsonParseUtil.getDeserializeConfig(testFile).getRegistrar().iterator().next();

    Map<String, Object> parameters = next.getParameters();

    assertTrue((Boolean) parameters.get("foo"));
    assertEquals(1.0, parameters.get("bar"));
    assertEquals("bobby car", parameters.get("car"));
}
 
Example 8
Source File: JsonParseUtilTest.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Test
public void testGetRegistrarJsonFromFile() {

    File testFile = FileUtil.findFirstThatExist("src/test/java/de/espend/idea/php/toolbox/tests/utils/fixtures/ide-toolbox.metadata.json");

    Collection<JsonRegistrar> elements = JsonParseUtil.getDeserializeConfig(testFile).getRegistrar();
    JsonRegistrar next = elements.iterator().next();

    assertTrue(ContainerUtil.filter(next.getSignatures(), new MyFunctionJsonSignatureCondition("foo")).size() > 0);
    assertTrue(ContainerUtil.filter(next.getSignatures(), new MyFunctionJsonSignatureCondition("date")).size() > 0);

    assertTrue(ContainerUtil.filter(next.getSignatures(), jsonSignature -> {
        return "DateTime".equals(jsonSignature.getClassName());
    }).size() > 0);
}
 
Example 9
Source File: JsonParseUtilTest.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Test
public void testGetRegistrarJsonFromFileWithShortcut() {
    File testFile = FileUtil.findFirstThatExist("src/test/java/de/espend/idea/php/toolbox/tests/utils/fixtures/ide-toolbox.metadata.json");

    Collection<JsonRegistrar> elements = JsonParseUtil.getDeserializeConfig(testFile).getRegistrar();
    JsonRegistrar next = elements.iterator().next();

    JsonSignature object = ContainerUtil.find(next.getSignatures(), new MyFunctionJsonSignatureCondition("apple"));

    assertNotNull(object);
    assertEquals(object.hashCode(), ContainerUtil.find(next.getSignatures(), new MyFunctionJsonSignatureCondition("apple")).hashCode());

    assertTrue(ContainerUtil.filter(next.getSignatures(), jsonSignature -> "apple".equals(jsonSignature.getClassName()) && "car".equals(jsonSignature.getMethod())).size() > 0);
}
 
Example 10
Source File: JsonParseUtilTest.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Test
public void testConfigDeserialize() {
    JsonConfigFile elements = null;
    try {
        File file = FileUtil.findFirstThatExist("src/test/java/de/espend/idea/php/toolbox/tests/utils/fixtures/ide-toolbox.metadata.json");
        elements = JsonParseUtil.getDeserializeConfig(StreamUtil.readText(new FileInputStream(file), Charset.defaultCharset()));
    } catch (IOException e) {
        e.printStackTrace();
    }

    List<JsonProvider> registrar = new ArrayList<>(elements.getProviders());

    assertEquals("date_format", registrar.get(0).getName());

    Collection<JsonRawLookupElement> dateFromatProvider = registrar.get(0).getItems();
    JsonRawLookupElement item = ContainerUtil.find(dateFromatProvider, new MyJsonRawLookupElementStringCondition("d"));
    assertNotNull(item);
    assertEquals(item.hashCode(), ContainerUtil.find(dateFromatProvider, new MyJsonRawLookupElementStringCondition("d")).hashCode());

    assertNotNull(ContainerUtil.find(dateFromatProvider, new MyJsonRawLookupElementStringCondition("car")));
    assertNotNull(ContainerUtil.find(dateFromatProvider, new MyJsonRawLookupElementStringCondition("apple")));

    assertEquals("source_1", registrar.get(1).getName());
    assertEquals("return", registrar.get(1).getSource().getContributor());
    assertEquals("\\Twig_Environment::getExtension", registrar.get(1).getSource().getParameter());

    assertEquals("source_2", registrar.get(2).getName());
    assertTrue(registrar.get(2).getItems().size() > 0);
}
 
Example 11
Source File: JsonParseUtilTest.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Test
public void testParameterRegistrarMappedAsObject() {
    File testFile = FileUtil.findFirstThatExist("src/test/java/de/espend/idea/php/toolbox/tests/utils/fixtures/ide-toolbox.metadata.json");

    JsonRegistrar next = JsonParseUtil.getDeserializeConfig(testFile).getRegistrar().iterator().next();

    Map<String, Object> parameters = next.getParameters();

    assertTrue((Boolean) parameters.get("foo"));
    assertEquals(1.0, parameters.get("bar"));
    assertEquals("bobby car", parameters.get("car"));
}
 
Example 12
Source File: DesktopContainerPathManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void loadProperties() {
  List<String> paths = new ArrayList<>();
  paths.add(System.getProperty(PROPERTIES_FILE));
  paths.add(System.getProperty(OLD_PROPERTIES_FILE));
  paths.add(new File(getAppHomeDirectory(), "consulo.properties").getPath());
  paths.add(getUserHome() + "/consulo.properties");

  File propFile = FileUtil.findFirstThatExist(ArrayUtil.toStringArray(paths));

  if (propFile == null) {
    return;
  }

  try (InputStream fis = new BufferedInputStream(new FileInputStream(propFile))) {
    final PropertyResourceBundle bundle = new PropertyResourceBundle(fis);
    final Enumeration keys = bundle.getKeys();
    String home = (String)bundle.handleGetObject("idea.home");
    if (home != null && ourHomePath == null) {
      ourHomePath = getAbsolutePath(substituteVars(home));
    }
    final Properties sysProperties = System.getProperties();
    while (keys.hasMoreElements()) {
      String key = (String)keys.nextElement();
      if (sysProperties.getProperty(key, null) == null) { // load the property from the property file only if it is not defined yet
        final String value = substituteVars(bundle.getString(key));
        sysProperties.setProperty(key, value);
      }
    }
  }
  catch (IOException e) {
    //noinspection HardCodedStringLiteral,UseOfSystemOutOrSystemErr
    System.err.println("Problem reading from property file: " + propFile.getPath());
  }
}