/** Create a plausible URI to use in {@link #compilesWithFix}. */ @VisibleForTesting static URI sourceURI(URI uri) { if (!uri.getScheme().equals("jar")) { return uri; } try { return URI.create( "file:/" + ((JarURLConnection) uri.toURL().openConnection()).getEntryName()); } catch (IOException e) { throw new UncheckedIOException(e); } }
} else { if (connection.getEntryName() != null) { LOGGER.log(WARNING, "Accessing modification date of {0} file, which is an entry in JAR file. " + "The access protocol is not file:, falling back to the default logic (risk of file descriptor leak).",
private static List<JavaFileObject> browseJar(URL packageFolderURL) { List<JavaFileObject> result = new ArrayList<>(); try { String jarUri = packageFolderURL.toExternalForm().split("!")[0]; JarURLConnection jarConn = (JarURLConnection) packageFolderURL.openConnection(); String rootEntryName = jarConn.getEntryName(); int rootEnd = rootEntryName.length() + 1; Enumeration<JarEntry> entryEnum = jarConn.getJarFile().entries(); while (entryEnum.hasMoreElements()) { JarEntry jarEntry = entryEnum.nextElement(); String name = jarEntry.getName(); if (name.startsWith(rootEntryName) && name.indexOf('/', rootEnd) == -1 && name.endsWith(CLASS_FILE)) { String binaryName = name.replaceAll("/", ".").replaceAll(CLASS_FILE + "$", ""); result.add(new CustomJavaFileObject(URI.create(jarUri + "!/" + name), JavaFileObject.Kind.CLASS, binaryName)); } } } catch (Exception e) { throw new RuntimeException(packageFolderURL + " is not a JAR file", e); } return result; } }
final String entryName = jarURLConnection.getEntryName();
/** * Extract the filename from the URI, with special handling for jar files. The return value is * normalized to always use '/' to separate elements of the path and to always have a leading '/'. */ @Nullable public static String getFileNameFromUri(URI uri) { if (!uri.getScheme().equals("jar")) { return uri.getPath(); } try { String jarEntryFileName = ((JarURLConnection) uri.toURL().openConnection()).getEntryName(); // It's possible (though it violates the zip file spec) for paths to zip file entries to use // '\' as the separator. Normalize to use '/'. jarEntryFileName = BACKSLASH_MATCHER.replaceFrom(jarEntryFileName, '/'); if (!jarEntryFileName.startsWith("/")) { jarEntryFileName = "/" + jarEntryFileName; } return jarEntryFileName; } catch (IOException e) { return null; } }
while (em.hasMoreElements()) { JarEntry entry = em.nextElement(); if (entry.getName().startsWith(jarConnection.getEntryName())) { String fileName = StringUtils.removeStart(entry.getName(), jarConnection.getEntryName()); if (!fileName.equals("/")) { // exclude the directory InputStream entryInputStream = null;
while (em.hasMoreElements()) { JarEntry entry = em.nextElement(); if (entry.getName().startsWith(jarConnection.getEntryName())) { String fileName = StringUtils.removeStart(entry.getName(), jarConnection.getEntryName()); if (!fileName.equals("/")) { // exclude the directory InputStream entryInputStream = null;
jarFile = jarCon.getJarFile(); baseEntryPath = normalizeJarEntryPath(jarCon.getEntryName(), true); if (baseEntryPath == null) { throw newFailedToExtractEntryPathException(jarBaseEntryUrl);
private static List<JavaFileObject> browseJar(URL packageFolderURL) { List<JavaFileObject> result = new ArrayList<>(); try { String jarUri = packageFolderURL.toExternalForm().split("!")[0]; JarURLConnection jarConn = (JarURLConnection) packageFolderURL.openConnection(); String rootEntryName = jarConn.getEntryName(); int rootEnd = rootEntryName.length() + 1; Enumeration<JarEntry> entryEnum = jarConn.getJarFile().entries(); while (entryEnum.hasMoreElements()) { JarEntry jarEntry = entryEnum.nextElement(); String name = jarEntry.getName(); if (name.startsWith(rootEntryName) && name.indexOf('/', rootEnd) == -1 && name.endsWith(CLASS_FILE)) { String binaryName = name.replaceAll("/", ".").replaceAll(CLASS_FILE + "$", ""); result.add(new CustomJavaFileObject(URI.create(jarUri + "!/" + name), JavaFileObject.Kind.CLASS, binaryName)); } } } catch (Exception e) { throw new RuntimeException(packageFolderURL + " is not a JAR file", e); } return result; } }
try { JarFile jarFile = jarConnection.getJarFile(); String jarConnectionEntryName = jarConnection.getEntryName();
String jarConnectionEntryName = jarConnection.getEntryName(); if (!jarConnectionEntryName.endsWith("/")) { jarConnectionEntryName += "/";
if (entry.getName().startsWith(jarConnection.getEntryName())) { final String filename = StringUtils.removeStart(entry.getName(), // jarConnection.getEntryName());
@Override public String getEntryName() { return jarURLConnection.getEntryName(); }
@Override public String getEntryName() { return jarURLConnection.getEntryName(); }
URL jarEntryURL = new URL("jar:file:/C:/Program%20Files%20(x86)/OurSoftware/OurJar_x86_1.0.68.220.jar!/com/our_company/javaFXViewCode.fxml"); JarURLConnection jarEntryConn = (JarURLConnection) jarEntryURL.openConnection(); URL jarFileURL = jarEntryConn.getJarFileURL(); // file:/C:/Program%20Files%20(x86)/OurSoftware/OurJar_x86_1.0.68.220.jar String entryName = jarEntryConn.getEntryName(); // com/our_company/javaFXViewCode.fxml
/** Create a plausible URI to use in {@link #compilesWithFix}. */ @VisibleForTesting static URI sourceURI(URI uri) { if (!uri.getScheme().equals("jar")) { return uri; } try { return URI.create( "file:/" + ((JarURLConnection) uri.toURL().openConnection()).getEntryName()); } catch (IOException e) { throw new UncheckedIOException(e); } }
public static boolean isJarDirectory(JarURLConnection conn) throws IOException { JarFile jarFile = conn.getJarFile(); String entryName = conn.getEntryName(); ZipEntry dirEntry = jarFile.getEntry(addEndingSlash(entryName)); return dirEntry != null && dirEntry.isDirectory(); }
public interface Factory { SPARQLSyntaxTest createSPARQLSyntaxTest(String testURI, String testName, String testAction, boolean positiveTest); }
@Override public String getName() { try { URLConnection con = url.openConnection(); if (con instanceof JarURLConnection) return ((JarURLConnection) con).getEntryName(); else return (new FileProvider()).filePathFromURL(url); } catch (IOException e) { Assertions.UNREACHABLE(); return null; } }
@Override public String getName() { try { URLConnection con = url.openConnection(); if (con instanceof JarURLConnection) return ((JarURLConnection) con).getEntryName(); else return (new FileProvider()).filePathFromURL(url); } catch (IOException e) { Assertions.UNREACHABLE(); return null; } }