public static File convertUrlToFile(URL url) { return new File(convertUrlToFilePath(url)); }
public static boolean isUrlContainingPackage(URL url, String aPackage) { return FileUtil.convertUrlToFilePath(url).contains(aPackage.replaceAll("\\.", "/")); } }
public static String processUrlToJarPath(URL resource) { String res = FileUtil.convertUrlToFilePath(resource); res = res.replaceAll("file:", ""); if (res.contains("!")) { return res.substring(0, res.lastIndexOf("!")); } return res; }
public static String processUrlToJarPackage(URL resource) { String res = FileUtil.convertUrlToFilePath(resource); res = res.replaceAll("file:", ""); res = res.substring(res.lastIndexOf("!") + 1); res = res.replaceAll("^/", ""); if (res.endsWith("/")) { return res; } return res + "/"; }
public static String getCurrentClasspath() { StringBuilder stringBuilder = new StringBuilder(); for (URL url : getClassPathUrl()) { stringBuilder.append(FileUtil.convertUrlToFilePath(url)); stringBuilder.append('\n'); } return stringBuilder.toString(); }
/** * Extract file name from url and test jar file * * @param url url to test. If it is a jar content, the jar file is extracted and treated as a jar * @return true if the file is a jar */ public static boolean isJar(URL url) { if ("jar".equals(url.getProtocol())) { return true; } String file = FileUtil.convertUrlToFilePath(url); if (file.contains("!")) { file = file.substring(0, file.lastIndexOf('!')); } File classFile = new File(file); return isJar(classFile); }
/** * Create a new JarMerge with a destination * * @param resource the resource to merge * @param jarPath Path to the jar to merge * @param mergeContent map linking outputstream to their content to avoir duplication */ public JarMerge(URL resource, String jarPath, Map<OutputStream, List<String>> mergeContent) { this.jarPath = jarPath; this.mergeContent = mergeContent; destination = FileUtil.convertUrlToFilePath(resource).replace(this.jarPath, "").replaceAll("file:", "").replaceAll( "!/?", "").replaceAll("//", "/"); // make sure any $ characters are escaped, otherwise inner classes won't be merged StringBuilder builder = new StringBuilder(destination.replace("$", "\\$")); if (destination.endsWith("/")) { builder.append("+(.*)"); } else { builder.append("/*(.*)"); } regexp = builder.toString(); }