@VisibleForTesting
  void collectPackages() throws UploaderException {
    parseLists();
    String[] list = StringUtils.split(input, File.pathSeparatorChar);
    for (String item : list) {
      LOG.info("Original source " + item);
      String expanded = expandEnvironmentVariables(item, System.getenv());
      LOG.info("Expanded source " + expanded);
      if (expanded.endsWith("*")) {
        File path = new File(expanded.substring(0, expanded.length() - 1));
        if (path.isDirectory()) {
          File[] files = path.listFiles();
          if (files != null) {
            for (File jar : files) {
              if (!jar.isDirectory()) {
                addJar(jar);
              } else {
                LOG.info("Ignored " + jar + " because it is a directory");
              }
            }
          } else {
            LOG.warn("Could not list directory " + path);
          }
        } else {
          LOG.warn("Ignored " + expanded + ". It is not a directory");
        }
      } else if (expanded.endsWith(".jar")) {
        File jarFile = new File(expanded);
        addJar(jarFile);
      } else if (!expanded.isEmpty()) {
        LOG.warn("Ignored " + expanded + " only jars are supported");
      }
    }
  }
@Test
  void testCollectPackages() throws IOException, UploaderException {
    File parent = new File(testDir);
    try {
      parent.deleteOnExit();
      assertTrue(parent.mkdirs(), "Directory creation failed");
      File dirA = new File(parent, "A");
      assertTrue(dirA.mkdirs());
      File dirB = new File(parent, "B");
      assertTrue(dirB.mkdirs());
      File jarA = new File(dirA, "a.jar");
      assertTrue(jarA.createNewFile());
      File jarB = new File(dirA, "b.jar");
      assertTrue(jarB.createNewFile());
      File jarC = new File(dirA, "c.jar");
      assertTrue(jarC.createNewFile());
      File txtD = new File(dirA, "d.txt");
      assertTrue(txtD.createNewFile());
      File jarD = new File(dirB, "d.jar");
      assertTrue(jarD.createNewFile());
      File txtE = new File(dirB, "e.txt");
      assertTrue(txtE.createNewFile());

      FrameworkUploader uploader = new FrameworkUploader();
      uploader.whitelist = ".*a\\.jar,.*b\\.jar,.*d\\.jar";
      uploader.blacklist = ".*b\\.jar";
      uploader.input = dirA.getAbsolutePath() + File.separatorChar + "*" +
          File.pathSeparatorChar +
          dirB.getAbsolutePath() + File.separatorChar + "*";
      uploader.collectPackages();
      assertEquals(3,
          uploader.whitelistedFiles.size(),
          "Whitelist count error");
      assertEquals(1,
          uploader.blacklistedFiles.size(),
          "Blacklist count error");

      assertTrue(uploader.filteredInputFiles.contains(jarA.getAbsolutePath()),
          "File not collected");
      assertFalse(uploader.filteredInputFiles.contains(jarB.getAbsolutePath()),
          "File collected");
      assertTrue(uploader.filteredInputFiles.contains(jarD.getAbsolutePath()),
          "File not collected");
      assertEquals(2,
          uploader.filteredInputFiles.size(),
          "Too many whitelists");
    } finally {
      FileUtils.deleteDirectory(parent);
    }
  }