/** * Adds a jar file that contains the given class. * @since 1.361 */ public ClasspathBuilder addJarOf(Class c) throws IOException { return add(Which.jarFile(c)); }
public URL getWhereServletIsLoaded() throws IOException { return Which.jarURL(servletClass); } }
/** * Locates the jar file that contains the given class. * * <p> * Note that jar files are not always loaded from {@link File}, * so for diagnostics purposes {@link #jarURL(Class)} is preferrable. * * @throws IllegalArgumentException * if failed to determine. */ public static File jarFile(Class clazz) throws IOException { return jarFile(classFileUrl(clazz),clazz.getName().replace('.','/')+".class"); }
URL res = jarURL(clazz); String resURL = res.toExternalForm(); String originalURL = resURL; if(resURL.startsWith("jar:file:") || resURL.startsWith("wsjar:file:")) return fromJarUrlToFile(resURL); return new File(decode(new URL("file:/"+resURL).getPath())); return new File(decode(new URL("file:"+resURL).getPath())); return new File(decode(new URL(resURL).getPath()));
String originalURL = resURL; if(resURL.startsWith("jar:file:") || resURL.startsWith("wsjar:file:")) return fromJarUrlToFile(resURL); return new File(decode(new URL("file:/"+resURL).getPath())); return new File(decode(new URL("file:"+resURL).getPath())); return new File(decode(new URL(resURL).getPath()));
private static File fromJarUrlToFile(String resURL) throws MalformedURLException { resURL = resURL.substring(resURL.indexOf(':')+1, resURL.lastIndexOf('!')); // cut off "scheme:" and the file name portion return new File(decode(new URL(resURL).getPath())); }
public static File jarFile(URL resource) throws IOException { return fromJarUrlToFile(resource.toExternalForm()); }
/** * Decode '%HH'. */ private static String decode(String s) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); for( int i=0; i<s.length();i++ ) { char ch = s.charAt(i); if(ch=='%') { baos.write(hexToInt(s.charAt(i+1))*16 + hexToInt(s.charAt(i+2))); i+=2; continue; } baos.write(ch); } try { return new String(baos.toByteArray(),"UTF-8"); } catch (UnsupportedEncodingException e) { throw new Error(e); // impossible } }
/** * Locates the jar file that contains the given class. * * <p> * Note that jar files are not always loaded from {@link File}, * so for diagnostics purposes {@link #jarURL(Class)} is preferrable. * * @param clazz Class * @throws IllegalArgumentException * if failed to determine the class File URL. * @return * JAR File, which contains the class. */ @Nonnull public static File jarFile(Class clazz) throws IOException { return jarFile(classFileUrl(clazz),clazz.getName().replace('.','/')+".class"); }
URL res = jarURL(clazz); String resURL = res.toExternalForm(); String originalURL = resURL; if(resURL.startsWith("jar:file:") || resURL.startsWith("wsjar:file:")) return fromJarUrlToFile(resURL); return new File(decode(new URL("file:/"+resURL).getPath())); return new File(decode(new URL("file:"+resURL).getPath())); return new File(decode(new URL(resURL).getPath()));
String originalURL = resURL; if(resURL.startsWith("jar:file:") || resURL.startsWith("wsjar:file:")) return fromJarUrlToFile(resURL); return new File(decode(new URL("file:/"+resURL).getPath())); return new File(decode(new URL("file:"+resURL).getPath())); return new File(decode(new URL(resURL).getPath()));
private static File fromJarUrlToFile(String resURL) throws MalformedURLException { resURL = resURL.substring(resURL.indexOf(':')+1, resURL.lastIndexOf('!')); // cut off "scheme:" and the file name portion return new File(decode(new URL(resURL).getPath())); }
public static File jarFile(URL resource) throws IOException { return fromJarUrlToFile(resource.toExternalForm()); }
/** * Decode '%HH'. */ private static String decode(String s) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); for( int i=0; i<s.length();i++ ) { char ch = s.charAt(i); if(ch=='%') { baos.write(hexToInt(s.charAt(i+1))*16 + hexToInt(s.charAt(i+2))); i+=2; continue; } baos.write(ch); } try { return new String(baos.toByteArray(),"UTF-8"); } catch (UnsupportedEncodingException e) { throw new Error(e); // impossible } }
/** * With fix to JENKINS-11251 (remoting 2.15), this is no longer necessary. * But I'm keeping it for a while so that users who manually deploy agent.jar has time to deploy new version * before this goes away. */ private void syncIO() throws InterruptedException { try { if (channel!=null) channel.syncLocalIO(); } catch (AbstractMethodError e) { // legacy agent.jar. Handle this gracefully try { LOGGER.log(Level.WARNING,"Looks like an old agent.jar. Please update "+ Which.jarFile(Channel.class)+" to the new version",e); } catch (IOException ignored) { // really ignore this time } } }
final URL urlOfClassFile = Which.classFileUrl(c); File jar = Which.jarFile(c); if (jar.isFile()) {// for historical reasons the jarFile method can return a directory Checksum sum = channel.jarLoader.calcChecksum(jar);
public URL getWhereAntIsLoaded() throws IOException { return Which.jarURL(antClass); } }
private static File fromJarUrlToFile(String resURL) throws MalformedURLException { resURL = resURL.substring(resURL.indexOf(':')+1, resURL.lastIndexOf('!')); // cut off "scheme:" and the file name portion return new File(decode(new URL(resURL).getPath())); }
public static File jarFile(URL resource) throws IOException { return fromJarUrlToFile(resource.toExternalForm()); }
/** * Decode '%HH'. */ private static String decode(String s) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); for( int i=0; i<s.length();i++ ) { char ch = s.charAt(i); if(ch=='%') { baos.write(hexToInt(s.charAt(i+1))*16 + hexToInt(s.charAt(i+2))); i+=2; continue; } baos.write(ch); } try { return new String(baos.toByteArray(),"UTF-8"); } catch (UnsupportedEncodingException e) { throw new Error(e); // impossible } }