@Test public void regex() { final File api = JarLocation.jarFromRegex("shrinkwrap-api.*\\.jar"); assertTrue(api.exists()); }
public static File jarFromRegex(final String regex) { final Pattern pattern = Pattern.compile(regex); try { final Set<URL> urls = ClassLoaders.findUrls(Thread.currentThread().getContextClassLoader()); for (final URL url : urls) { final String decode = decode(url.getFile()); File f = new File(decode.replaceFirst("file:", "")); if (!f.exists() && f.getPath().endsWith("!")) { f = new File(f.getPath().substring(0, f.getPath().length() - 1)); } if (f.exists() && pattern.matcher(f.getName()).matches()) { return f; } } throw new IllegalArgumentException(regex + " not found in " + urls); } catch (final IOException e) { throw new IllegalStateException(e); } }
JarLocation { public static File jarFromRegex(final String regex) { final Pattern pattern = Pattern.compile(regex); try { final Set<URL> urls = ClassLoaders.findUrls(Thread.currentThread().getContextClassLoader()); for (final URL url : urls) { final String decode = decode(url.getFile()); File f = new File(decode.replaceFirst("file:", "")); if (!f.exists() && f.getPath().endsWith("!")) { f = new File(f.getPath().substring(0, f.getPath().length() - 1)); } if (f.exists() && pattern.matcher(f.getName()).matches()) { return f; } } throw new IllegalArgumentException(regex + " not found in " + urls); } catch (final IOException e) { throw new IllegalStateException(e); } } }
JarLocation { public static File jarFromRegex(final String regex) { final Pattern pattern = Pattern.compile(regex); try { final Set<URL> urls = ClassLoaders.findUrls(Thread.currentThread().getContextClassLoader()); for (final URL url : urls) { final String decode = decode(url.getFile()); File f = new File(decode.replaceFirst("file:", "")); if (!f.exists() && f.getPath().endsWith("!")) { f = new File(f.getPath().substring(0, f.getPath().length() - 1)); } if (f.exists() && pattern.matcher(f.getName()).matches()) { return f; } } throw new IllegalArgumentException(regex + " not found in " + urls); } catch (final IOException e) { throw new IllegalStateException(e); } }  }
JarLocation { public static File jarFromRegex(final String regex) { final Pattern pattern = Pattern.compile(regex); try { final Set<URL> urls = ClassLoaders.findUrls(Thread.currentThread().getContextClassLoader()); for (final URL url : urls) { final String decode = decode(url.getFile()); File f = new File(decode.replaceFirst("file:", "")); if (!f.exists() && f.getPath().endsWith("!")) { f = new File(f.getPath().substring(0, f.getPath().length() - 1)); } if (f.exists() && pattern.matcher(f.getName()).matches()) { return f; } } throw new IllegalArgumentException(regex + " not found in " + urls); } catch (final IOException e) { throw new IllegalStateException(e); } }  static File get(); static File jarFromPrefix(final String prefix); static File jarFromRegex(final String regex); static File jarFromResource(final String resourceName); static File jarFromResource(final ClassLoader loader, final String resourceName); static File jarLocation(final Class clazz); static String decode(final String fileName); }
JarLocation { public static File jarFromRegex(final String regex) { final Pattern pattern = Pattern.compile(regex); try { final Set<URL> urls = ClassLoaders.findUrls(Thread.currentThread().getContextClassLoader()); for (final URL url : urls) { final String decode = decode(url.getFile()); File f = new File(decode.replaceFirst("file:", "")); if (!f.exists() && f.getPath().endsWith("!")) { f = new File(f.getPath().substring(0, f.getPath().length() - 1)); } if (f.exists() && pattern.matcher(f.getName()).matches()) { return f; } } throw new IllegalArgumentException(regex + " not found in " + urls); } catch (final IOException e) { throw new IllegalStateException(e); } }  static File get(); static File jarFromPrefix(final String prefix); static File jarFromRegex(final String regex); static File jarFromResource(final String resourceName); static File jarFromResource(final ClassLoader loader, final String resourceName); static File jarLocation(final Class clazz); static String decode(final String fileName);  }