@Test public void testConvertToNameRegex() { try { AssembleUtil.convertToNameRegex(null); fail("Expected NullPointerException"); } catch (final NullPointerException e) { } try { AssembleUtil.convertToNameRegex(""); fail("Expected IllegalArgumentException"); } catch (final IllegalArgumentException e) { } testRegexMatch("*", "^.*", "spring:webmvc", "okhttp", "lettuce", "jdbc", "spring:boot", "spring:web:3", "spring:web:4", "spring:web:5", "spring:webmvc", "spring:webmvc:3", "spring:webmvc:4", "spring:webmvc:5"); testRegexMatch("spring:*", "^spring:.*", "spring:boot", "spring:web:3", "spring:web:4", "spring:web:5", "spring:webmvc", "spring:webmvc:3", "spring:webmvc:4", "spring:webmvc:5"); testRegexMatch("spring:*:*", "^spring:[^:]*:.*", "spring:web:3", "spring:web:4", "spring:web:5", "spring:webmvc:3", "spring:webmvc:4", "spring:webmvc:5"); testRegexMatch("spring:boot", "(^spring:boot$|^spring:boot:.*)", "spring:boot"); testRegexMatch("spring:webmvc", "(^spring:webmvc$|^spring:webmvc:.*)", "spring:webmvc", "spring:webmvc:3", "spring:webmvc:4", "spring:webmvc:5"); testRegexMatch("spring:web", "(^spring:web$|^spring:web:.*)", "spring:web:3", "spring:web:4", "spring:web:5"); testRegexMatch("lettuce:5.?", "^lettuce:5\\..", "lettuce:5.0", "lettuce:5.1", "lettuce:5.2"); testRegexMatch("lettuce:5", "^lettuce:5.*", "lettuce:5", "lettuce:5.1", "lettuce:5.2"); testRegexMatch("lettuce", "(^lettuce$|^lettuce:.*)", "lettuce:5", "lettuce:5.0", "lettuce:5.1", "lettuce:5.2"); }
public static Pattern convertToNameRegex(String pattern) { if (pattern.length() == 0) throw new IllegalArgumentException("Empty pattern"); final char lastCh = pattern.charAt(pattern.length() - 1); if (lastCh == '*') pattern = pattern.substring(0, pattern.length() - 1); final String regex = "^" + AssembleUtil.convertToRegex(pattern).replace(".*", "[^:]*"); boolean hasDigit = false; for (int i = regex.length() - 2; i >= 0; --i) { if (regex.charAt(i) == ':') { hasDigit = Character.isDigit(regex.charAt(i + 1)); break; } } if (lastCh == '?') return Pattern.compile(regex); if (hasDigit || regex.length() == 1 || regex.endsWith(":")) return Pattern.compile(regex + ".*"); return Pattern.compile("(" + regex + "$|" + regex + ":.*)"); }
AssembleUtil { public static Pattern convertToNameRegex(String pattern) { if (pattern.length() == 0) throw new IllegalArgumentException("Empty pattern"); final char lastCh = pattern.charAt(pattern.length() - 1); if (lastCh == '*') pattern = pattern.substring(0, pattern.length() - 1); final String regex = "^" + AssembleUtil.convertToRegex(pattern).replace(".*", "[^:]*"); boolean hasDigit = false; for (int i = regex.length() - 2; i >= 0; --i) { if (regex.charAt(i) == ':') { hasDigit = Character.isDigit(regex.charAt(i + 1)); break; } } if (lastCh == '?') return Pattern.compile(regex); if (hasDigit || regex.length() == 1 || regex.endsWith(":")) return Pattern.compile(regex + ".*"); return Pattern.compile("(" + regex + "$|" + regex + ":.*)"); } }
AssembleUtil { public static Pattern convertToNameRegex(String pattern) { if (pattern.length() == 0) throw new IllegalArgumentException("Empty pattern"); final char lastCh = pattern.charAt(pattern.length() - 1); if (lastCh == '*') pattern = pattern.substring(0, pattern.length() - 1); final String regex = "^" + AssembleUtil.convertToRegex(pattern).replace(".*", "[^:]*"); boolean hasDigit = false; for (int i = regex.length() - 2; i >= 0; --i) { if (regex.charAt(i) == ':') { hasDigit = Character.isDigit(regex.charAt(i + 1)); break; } } if (lastCh == '?') return Pattern.compile(regex); if (hasDigit || regex.length() == 1 || regex.endsWith(":")) return Pattern.compile(regex + ".*"); return Pattern.compile("(" + regex + "$|" + regex + ":.*)"); } private  AssembleUtil(); }
AssembleUtil { public static Pattern convertToNameRegex(String pattern) { if (pattern.length() == 0) throw new IllegalArgumentException("Empty pattern"); final char lastCh = pattern.charAt(pattern.length() - 1); if (lastCh == '*') pattern = pattern.substring(0, pattern.length() - 1); final String regex = "^" + AssembleUtil.convertToRegex(pattern).replace(".*", "[^:]*"); boolean hasDigit = false; for (int i = regex.length() - 2; i >= 0; --i) { if (regex.charAt(i) == ':') { hasDigit = Character.isDigit(regex.charAt(i + 1)); break; } } if (lastCh == '?') return Pattern.compile(regex); if (hasDigit || regex.length() == 1 || regex.endsWith(":")) return Pattern.compile(regex + ".*"); return Pattern.compile("(" + regex + "$|" + regex + ":.*)"); } private  AssembleUtil(); static boolean hasFileInJar(final File jarFile, final String name); static String readFileFromJar(final File jarFile, final String name); static Set<String> getLocations(final Class<?> ... classes); static byte[] readBytes(final URL url); static byte[] readBytes(final InputStream in); static String toIndentedString(final Object[] a); static String toIndentedString(final Collection<?> l); static String toIndentedString(final Map<?,?> m); static boolean recurseDir(final File dir, final Predicate<File> predicate); static FileVisitResult recurseDir(final File dir, final Function<File,FileVisitResult> function); static int compare(final T[] a, final T[] b); static int compare(final List<T> a, final List<T> b); static boolean containsAll(final T[] a, final T[] b); static boolean containsAll(final T[] a, final T[] b, final Comparator<T> c); @SuppressWarnings("unchecked") static T[] retain(final T[] a, final T[] b, final int i, final int j, final int r); static T[] sort(final T[] array); static List<T> sort(final List<T> list); static String getNameId(final Object obj); static String getSimpleNameId(final Object obj); static String toString(final Object[] a, final String del); static String toString(final Collection<?> c, final String del); static void absorbProperties(final String command); static void forEachClass(final URL[] urls, final T arg, final BiConsumer<String,T> consumer); static URL toURL(final File file); static URL[] toURLs(final File ... files); static URL[] toURLs(final List<File> files); static URL[] toURLs(final Collection<File> files); static String convertToRegex(String pattern); static String classNameToResource(final String className); static String classNameToResource(final Class<?> cls); static String resourceToClassName(final String resource); static boolean isSystemProperty(final String key, final String deprecatedKey); static Pattern convertToNameRegex(String pattern); static File getSourceLocation(final URL url, final String resourcePath); static String getName(final String path); static File[] classPathToFiles(final String classpath); static URL toURL(final String path); }
AssembleUtil { public static Pattern convertToNameRegex(String pattern) { if (pattern.length() == 0) throw new IllegalArgumentException("Empty pattern"); final char lastCh = pattern.charAt(pattern.length() - 1); if (lastCh == '*') pattern = pattern.substring(0, pattern.length() - 1); final String regex = "^" + AssembleUtil.convertToRegex(pattern).replace(".*", "[^:]*"); boolean hasDigit = false; for (int i = regex.length() - 2; i >= 0; --i) { if (regex.charAt(i) == ':') { hasDigit = Character.isDigit(regex.charAt(i + 1)); break; } } if (lastCh == '?') return Pattern.compile(regex); if (hasDigit || regex.length() == 1 || regex.endsWith(":")) return Pattern.compile(regex + ".*"); return Pattern.compile("(" + regex + "$|" + regex + ":.*)"); } private  AssembleUtil(); static boolean hasFileInJar(final File jarFile, final String name); static String readFileFromJar(final File jarFile, final String name); static Set<String> getLocations(final Class<?> ... classes); static byte[] readBytes(final URL url); static byte[] readBytes(final InputStream in); static String toIndentedString(final Object[] a); static String toIndentedString(final Collection<?> l); static String toIndentedString(final Map<?,?> m); static boolean recurseDir(final File dir, final Predicate<File> predicate); static FileVisitResult recurseDir(final File dir, final Function<File,FileVisitResult> function); static int compare(final T[] a, final T[] b); static int compare(final List<T> a, final List<T> b); static boolean containsAll(final T[] a, final T[] b); static boolean containsAll(final T[] a, final T[] b, final Comparator<T> c); @SuppressWarnings("unchecked") static T[] retain(final T[] a, final T[] b, final int i, final int j, final int r); static T[] sort(final T[] array); static List<T> sort(final List<T> list); static String getNameId(final Object obj); static String getSimpleNameId(final Object obj); static String toString(final Object[] a, final String del); static String toString(final Collection<?> c, final String del); static void absorbProperties(final String command); static void forEachClass(final URL[] urls, final T arg, final BiConsumer<String,T> consumer); static URL toURL(final File file); static URL[] toURLs(final File ... files); static URL[] toURLs(final List<File> files); static URL[] toURLs(final Collection<File> files); static String convertToRegex(String pattern); static String classNameToResource(final String className); static String classNameToResource(final Class<?> cls); static String resourceToClassName(final String resource); static boolean isSystemProperty(final String key, final String deprecatedKey); static Pattern convertToNameRegex(String pattern); static File getSourceLocation(final URL url, final String resourcePath); static String getName(final String path); static File[] classPathToFiles(final String classpath); static URL toURL(final String path);  }