@VisibleForTesting
  public HashMap<String, File> getPluginsToLoad(String pluginsDirectories, String pluginsInclude) throws
      IllegalArgumentException {
    String[] directories = pluginsDirectories.split(";");
    LOGGER.info("Plugin directories env: {}, parsed directories to load: '{}'", pluginsDirectories, directories);

    HashMap<String, File> finalPluginsToLoad = new HashMap<>();

    for (String pluginsDirectory : directories) {
      if (!new File(pluginsDirectory).exists()) {
        throw new IllegalArgumentException(String.format("Plugins dir [%s] doesn't exist.", pluginsDirectory));
      }

      Collection<File> jarFiles = FileUtils.listFiles(
          new File(pluginsDirectory),
          new String[]{JAR_FILE_EXTENSION},
          true);
      List<String> pluginsToLoad = null;
      if (!StringUtils.isEmpty(pluginsInclude)) {
        pluginsToLoad = Arrays.asList(pluginsInclude.split(";"));
        LOGGER.info("Potential plugins to load: [{}]", Arrays.toString(pluginsToLoad.toArray()));
      } else {
        LOGGER.info("Please use env variable '{}' to customize plugins to load. Loading all plugins: {}",
            PLUGINS_INCLUDE_PROPERTY_NAME, Arrays.toString(jarFiles.toArray()));
      }

      for (File jarFile : jarFiles) {
        File pluginDir = jarFile.getParentFile();
        String pluginName = pluginDir.getName();
        LOGGER.info("Found plugin, pluginDir: {}, pluginName: {}", pluginDir, pluginName);
        if (pluginsToLoad != null) {
          if (!pluginsToLoad.contains(pluginName)) {
            LOGGER.info("Skipping plugin: {} is not inside pluginsToLoad {}", pluginName, pluginsToLoad);
            continue;
          }
        }

        if (!finalPluginsToLoad.containsKey(pluginName)) {
          finalPluginsToLoad.put(pluginName, pluginDir);
          LOGGER.info("Added [{}] from dir [{}] to final list of plugins to load", pluginName, pluginDir);
        }
      }
    }

    return finalPluginsToLoad;
  }
@Test
  public void testGetPluginsToLoad()
      throws IOException {
    /* We have two plugin directories (../plugins/d1/ and ../plugins/d2/)
     * plugins to include = [ p1, p2, p3 ]
     * d1 has plugins: p1
     * d2 has plugins: p1, p2, p3, p4
     * We expect d1/p1, d2/p2, d2/p3 to be picked up
     *   - ensuring second instance of p1 is ignored
     *   - ensuring p4 is ignored as it's not on the plugins to include list
     */

    String pluginsDirs = _tempDir + "/plugins/d1;" + _tempDir + "/plugins/d2;";
    String pluginsToInclude = "p1;p2;p3"; // specifically excluding p3.jar

    File pluginsDir = new File(_tempDir + "/plugins");
    pluginsDir.mkdir();
    File subPluginsDir1 = new File(pluginsDir + "/d1");
    subPluginsDir1.mkdir();
    File subPluginsDir2 = new File(pluginsDir + "/d2");
    subPluginsDir2.mkdir();

    _p1 = new File(pluginsDir + "/d1/p1/p1.jar");
    FileUtils.touch(_p1);
    _p1Copy = new File(pluginsDir + "/d2/p1/p1.jar");
    FileUtils.touch(_p1Copy);
    _p2 = new File(pluginsDir + "/d2/p2/p2.jar");
    FileUtils.touch(_p2);
    _p3 = new File(pluginsDir + "/d2/p3/p3.jar");
    FileUtils.touch(_p3);
    _p4 = new File(pluginsDir + "/d2/p4/p4.jar");
    FileUtils.touch(_p4);

    HashMap<String, File> actualPluginsMap = PluginManager.get().getPluginsToLoad(pluginsDirs, pluginsToInclude);
    Assert.assertEquals(actualPluginsMap.size(), 3);

    HashMap<String, String> actualPluginNamesAndPaths = new HashMap<>();
    for (Map.Entry<String, File> entry : actualPluginsMap.entrySet()) {
      actualPluginNamesAndPaths.put(entry.getKey(), entry.getValue().getAbsolutePath());
    }
    HashMap<String, String> expectedPluginNamesAndPaths = new HashMap<>();
    expectedPluginNamesAndPaths.put("p1", _p1.getParentFile().getAbsolutePath());
    expectedPluginNamesAndPaths.put("p2", _p2.getParentFile().getAbsolutePath());
    expectedPluginNamesAndPaths.put("p3", _p3.getParentFile().getAbsolutePath());

    Assert.assertEquals(actualPluginNamesAndPaths, expectedPluginNamesAndPaths);
  }