@Test public void testFindContainingJar() throws Exception { String result = TempletonUtils.findContainingJar(Configuration.class, ".*hadoop.*\\.jar.*"); Assert.assertNotNull(result); result = TempletonUtils.findContainingJar(FileSystem.class, ".*hadoop.*\\.jar.*"); Assert.assertNotNull(result); result = TempletonUtils.findContainingJar(HadoopShimsSecure.class, ".*unknownjar.*"); Assert.assertNull("unexpectedly found jar for HadoopShimsSecure class: " + result, result); }
public static String findContainingJar(Class<?> clazz, String fileNamePattern) { ClassLoader loader = clazz.getClassLoader(); String classFile = clazz.getName().replaceAll("\\.", "/") + ".class"; try { for(final Enumeration<URL> itr = loader.getResources(classFile); itr.hasMoreElements();) { final URL url = itr.nextElement(); if ("jar".equals(url.getProtocol())) { String toReturn = url.getPath(); if (fileNamePattern == null || toReturn.matches(fileNamePattern)) { toReturn = URLDecoder.decode(toReturn, "UTF-8"); return toReturn.replaceAll("!.*$", ""); } } } } catch (IOException e) { throw new RuntimeException(e); } return null; }
TempletonUtils { public static String findContainingJar(Class<?> clazz, String fileNamePattern) { ClassLoader loader = clazz.getClassLoader(); String classFile = clazz.getName().replaceAll("\\.", "/") + ".class"; try { for(final Enumeration<URL> itr = loader.getResources(classFile); itr.hasMoreElements();) { final URL url = itr.nextElement(); if ("jar".equals(url.getProtocol())) { String toReturn = url.getPath(); if (fileNamePattern == null || toReturn.matches(fileNamePattern)) { toReturn = URLDecoder.decode(toReturn, "UTF-8"); return toReturn.replaceAll("!.*$", ""); } } } } catch (IOException e) { throw new RuntimeException(e); } return null; } }
TempletonUtils { public static String findContainingJar(Class<?> clazz, String fileNamePattern) { ClassLoader loader = clazz.getClassLoader(); String classFile = clazz.getName().replaceAll("\\.", "/") + ".class"; try { for(final Enumeration<URL> itr = loader.getResources(classFile); itr.hasMoreElements();) { final URL url = itr.nextElement(); if ("jar".equals(url.getProtocol())) { String toReturn = url.getPath(); if (fileNamePattern == null || toReturn.matches(fileNamePattern)) { toReturn = URLDecoder.decode(toReturn, "UTF-8"); return toReturn.replaceAll("!.*$", ""); } } } } catch (IOException e) { throw new RuntimeException(e); } return null; }  }
TempletonUtils { public static String findContainingJar(Class<?> clazz, String fileNamePattern) { ClassLoader loader = clazz.getClassLoader(); String classFile = clazz.getName().replaceAll("\\.", "/") + ".class"; try { for(final Enumeration<URL> itr = loader.getResources(classFile); itr.hasMoreElements();) { final URL url = itr.nextElement(); if ("jar".equals(url.getProtocol())) { String toReturn = url.getPath(); if (fileNamePattern == null || toReturn.matches(fileNamePattern)) { toReturn = URLDecoder.decode(toReturn, "UTF-8"); return toReturn.replaceAll("!.*$", ""); } } } } catch (IOException e) { throw new RuntimeException(e); } return null; }  static boolean isset(String s); static boolean isset(char ch); static boolean isset(T[] a); static boolean isset(Collection<T> col); static boolean isset(Map<K, V> col); static String extractPercentComplete(String line); static String extractChildJobId(String line); static String encodeArray(String[] plain); static String encodeArray(List<String> list); static String[] decodeArray(String s); static String[] hadoopFsListAsArray(String files, Configuration conf,
                         String user); static String hadoopFsListAsString(String files, Configuration conf,
                        String user); static String hadoopFsFilename(String fname, Configuration conf, String user); static List<Path> hadoopFsListChildren(String dirName, Configuration conf, String user); static boolean hadoopFsIsMissing(FileSystem fs, Path p); static String addUserHomeDirectoryIfApplicable(String origPathStr, String user); static Path hadoopFsPath(String fname, final Configuration conf, String user); static int fetchUrl(URL url); static Map<String, String> hadoopUserEnv(String user,
                          String overrideClasspath); static String quoteForWindows(String param); static void addCmdForWindows(ArrayList<String> args); static String unEscapeString(String s); static String findContainingJar(Class<?> clazz, String fileNamePattern); static StringBuilder dumpPropMap(String header, Properties props); static StringBuilder dumpPropMap(String header, Map<String, String> map); }
TempletonUtils { public static String findContainingJar(Class<?> clazz, String fileNamePattern) { ClassLoader loader = clazz.getClassLoader(); String classFile = clazz.getName().replaceAll("\\.", "/") + ".class"; try { for(final Enumeration<URL> itr = loader.getResources(classFile); itr.hasMoreElements();) { final URL url = itr.nextElement(); if ("jar".equals(url.getProtocol())) { String toReturn = url.getPath(); if (fileNamePattern == null || toReturn.matches(fileNamePattern)) { toReturn = URLDecoder.decode(toReturn, "UTF-8"); return toReturn.replaceAll("!.*$", ""); } } } } catch (IOException e) { throw new RuntimeException(e); } return null; }  static boolean isset(String s); static boolean isset(char ch); static boolean isset(T[] a); static boolean isset(Collection<T> col); static boolean isset(Map<K, V> col); static String extractPercentComplete(String line); static String extractChildJobId(String line); static String encodeArray(String[] plain); static String encodeArray(List<String> list); static String[] decodeArray(String s); static String[] hadoopFsListAsArray(String files, Configuration conf,
                         String user); static String hadoopFsListAsString(String files, Configuration conf,
                        String user); static String hadoopFsFilename(String fname, Configuration conf, String user); static List<Path> hadoopFsListChildren(String dirName, Configuration conf, String user); static boolean hadoopFsIsMissing(FileSystem fs, Path p); static String addUserHomeDirectoryIfApplicable(String origPathStr, String user); static Path hadoopFsPath(String fname, final Configuration conf, String user); static int fetchUrl(URL url); static Map<String, String> hadoopUserEnv(String user,
                          String overrideClasspath); static String quoteForWindows(String param); static void addCmdForWindows(ArrayList<String> args); static String unEscapeString(String s); static String findContainingJar(Class<?> clazz, String fileNamePattern); static StringBuilder dumpPropMap(String header, Properties props); static StringBuilder dumpPropMap(String header, Map<String, String> map); static final Pattern JAR_COMPLETE; static final Pattern PIG_COMPLETE; static final Pattern HIVE_COMPLETE; static final Pattern TEZ_COMPLETE; static final Pattern TEZ_COUNTERS; static final Pattern JAR_ID; static final Pattern PIG_ID; static final Pattern[] ID_PATTERNS; }