FileUtil { public static List<Path> getJarsInDirectory(String path) { return getJarsInDirectory(path, true); }  static Path[] stat2Paths(FileStatus[] stats); static Path[] stat2Paths(FileStatus[] stats, Path path); static void fullyDeleteOnExit(final File file); static boolean fullyDelete(final File dir); static boolean fullyDelete(final File dir, boolean tryGrantPermissions); static String readLink(File f); static boolean fullyDeleteContents(final File dir); static boolean fullyDeleteContents(final File dir, final boolean tryGrantPermissions); @Deprecated static void fullyDelete(FileSystem fs, Path dir); static boolean copy(FileSystem srcFS, Path src,
                             FileSystem dstFS, Path dst,
                             boolean deleteSource,
                             Configuration conf); static boolean copy(FileSystem srcFS, Path[] srcs,
                             FileSystem dstFS, Path dst,
                             boolean deleteSource,
                             boolean overwrite, Configuration conf); static boolean copy(FileSystem srcFS, Path src,
                             FileSystem dstFS, Path dst,
                             boolean deleteSource,
                             boolean overwrite,
                             Configuration conf); static boolean copy(FileSystem srcFS, FileStatus srcStatus,
                             FileSystem dstFS, Path dst,
                             boolean deleteSource,
                             boolean overwrite,
                             Configuration conf); static boolean copy(File src,
                             FileSystem dstFS, Path dst,
                             boolean deleteSource,
                             Configuration conf); static boolean copy(FileSystem srcFS, Path src,
                             File dst, boolean deleteSource,
                             Configuration conf); static String makeShellPath(String filename); static String makeShellPath(File file); static String makeSecureShellPath(File file); static String makeShellPath(File file, boolean makeCanonicalPath); static long getDU(File dir); static void unZip(InputStream inputStream, File toDir); static void unZip(File inFile, File unzipDir); static void unTar(InputStream inputStream, File untarDir,
                           boolean gzipped); static void unTar(File inFile, File untarDir); static int symLink(String target, String linkname); static int chmod(String filename, String perm
                          ); static int chmod(String filename, String perm, boolean recursive); static void setOwner(File file, String username,
      String groupname); static boolean setReadable(File f, boolean readable); static boolean setWritable(File f, boolean writable); static boolean setExecutable(File f, boolean executable); static boolean canRead(File f); static boolean canWrite(File f); static boolean canExecute(File f); static void setPermission(File f, FsPermission permission
                                   ); static final File createLocalTempFile(final File basefile,
                                               final String prefix,
                                               final boolean isDeleteOnExit); static void replaceFile(File src, File target); static File[] listFiles(File dir); static String[] list(File dir); static String[] createJarWithClassPath(String inputClassPath, Path pwd,
      Map<String, String> callerEnv); static String[] createJarWithClassPath(String inputClassPath, Path pwd,
      Path targetDir,
      Map<String, String> callerEnv); static List<Path> getJarsInDirectory(String path); static List<Path> getJarsInDirectory(String path, boolean useLocal); static boolean compareFs(FileSystem srcFs, FileSystem destFs); static final int SYMLINK_NO_PRIVILEGE; }
@Test public void testGetJarsInDirectory() throws Exception { List<Path> jars = FileUtil.getJarsInDirectory("/foo/bar/bogus/"); assertTrue("no jars should be returned for a bogus path", jars.isEmpty()); assertFalse(tmp.exists()); assertTrue(tmp.mkdirs()); File jar1 = new File(tmp, "wildcard1.jar"); File jar2 = new File(tmp, "wildcard2.JAR"); List<File> matches = Arrays.asList(jar1, jar2); for (File match: matches) { assertTrue("failure creating file: " + match, match.createNewFile()); } assertTrue(new File(tmp, "text.txt").createNewFile()); assertTrue(new File(tmp, "executable.exe").createNewFile()); assertTrue(new File(tmp, "README").createNewFile()); String directory = tmp.getCanonicalPath(); jars = FileUtil.getJarsInDirectory(directory); assertEquals("there should be 2 jars", 2, jars.size()); for (Path jar: jars) { URL url = jar.toUri().toURL(); assertTrue("the jar should match either of the jars", url.equals(jar1.toURI().toURL()) || url.equals(jar2.toURI().toURL())); } }