FrameworkUploader implements Runnable { @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"); } } }  void run(); static void main(String[] args);  }
@Test public void testCollectPackages() throws IOException, UploaderException { File parent = new File(testDir); try { parent.deleteOnExit(); Assert.assertTrue("Directory creation failed", parent.mkdirs()); File dirA = new File(parent, "A"); Assert.assertTrue(dirA.mkdirs()); File dirB = new File(parent, "B"); Assert.assertTrue(dirB.mkdirs()); File jarA = new File(dirA, "a.jar"); Assert.assertTrue(jarA.createNewFile()); File jarB = new File(dirA, "b.jar"); Assert.assertTrue(jarB.createNewFile()); File jarC = new File(dirA, "c.jar"); Assert.assertTrue(jarC.createNewFile()); File txtD = new File(dirA, "d.txt"); Assert.assertTrue(txtD.createNewFile()); File jarD = new File(dirB, "d.jar"); Assert.assertTrue(jarD.createNewFile()); File txtE = new File(dirB, "e.txt"); Assert.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(); Assert.assertEquals("Whitelist count error", 3, uploader.whitelistedFiles.size()); Assert.assertEquals("Blacklist count error", 1, uploader.blacklistedFiles.size()); Assert.assertTrue("File not collected", uploader.filteredInputFiles.contains(jarA.getAbsolutePath())); Assert.assertFalse("File collected", uploader.filteredInputFiles.contains(jarB.getAbsolutePath())); Assert.assertTrue("File not collected", uploader.filteredInputFiles.contains(jarD.getAbsolutePath())); Assert.assertEquals("Too many whitelists", 2, uploader.filteredInputFiles.size()); } finally { FileUtils.deleteDirectory(parent); } }