diff --git a/core/src/main/java/hudson/scm/SubversionUpdateEventHandler.java b/core/src/main/java/hudson/scm/SubversionUpdateEventHandler.java index 6be3496f91..92fb35daf1 100644 --- a/core/src/main/java/hudson/scm/SubversionUpdateEventHandler.java +++ b/core/src/main/java/hudson/scm/SubversionUpdateEventHandler.java @@ -24,6 +24,7 @@ import java.io.PrintStream; import java.io.File; import java.io.IOException; import java.util.List; +import java.net.URL; import hudson.remoting.Which; @@ -118,9 +119,9 @@ final class SubversionUpdateEventHandler implements ISVNEventHandler { SVNExternal ext = event.getExternalInfo(); if(ext==null) { // prepare for the situation where the user created their own svnkit - File jarFile = null; + URL jarFile = null; try { - jarFile = Which.jarFile(SVNEvent.class); + jarFile = Which.jarURL(SVNEvent.class); } catch (IOException e) { // ignore this failure } diff --git a/core/src/main/java/hudson/util/IncompatibleAntVersionDetected.java b/core/src/main/java/hudson/util/IncompatibleAntVersionDetected.java index 86a3153a9d..c65ffa48ff 100644 --- a/core/src/main/java/hudson/util/IncompatibleAntVersionDetected.java +++ b/core/src/main/java/hudson/util/IncompatibleAntVersionDetected.java @@ -4,6 +4,7 @@ import hudson.remoting.Which; import java.io.File; import java.io.IOException; +import java.net.URL; /** * Model object used to display the error top page if @@ -21,7 +22,7 @@ public class IncompatibleAntVersionDetected extends ErrorObject { this.antClass = antClass; } - public File getWhereAntIsLoaded() throws IOException { - return Which.jarFile(antClass); + public URL getWhereAntIsLoaded() throws IOException { + return Which.jarURL(antClass); } } diff --git a/core/src/main/java/hudson/util/IncompatibleServletVersionDetected.java b/core/src/main/java/hudson/util/IncompatibleServletVersionDetected.java index 64dbaea704..9779cfa239 100644 --- a/core/src/main/java/hudson/util/IncompatibleServletVersionDetected.java +++ b/core/src/main/java/hudson/util/IncompatibleServletVersionDetected.java @@ -4,6 +4,7 @@ import hudson.remoting.Which; import java.io.File; import java.io.IOException; +import java.net.URL; /** * Model object used to display the error top page if @@ -21,7 +22,7 @@ public class IncompatibleServletVersionDetected extends ErrorObject { this.servletClass = servletClass; } - public File getWhereServletIsLoaded() throws IOException { - return Which.jarFile(servletClass); + public URL getWhereServletIsLoaded() throws IOException { + return Which.jarURL(servletClass); } } diff --git a/remoting/src/main/java/hudson/remoting/Which.java b/remoting/src/main/java/hudson/remoting/Which.java index dd1bc8dac9..bc7151e4ba 100644 --- a/remoting/src/main/java/hudson/remoting/Which.java +++ b/remoting/src/main/java/hudson/remoting/Which.java @@ -19,13 +19,28 @@ public class Which { * @throws IllegalArgumentException * if failed to determine. */ - public static File jarFile(Class clazz) throws IOException { + public static URL jarURL(Class clazz) throws IOException { ClassLoader cl = clazz.getClassLoader(); if(cl==null) cl = ClassLoader.getSystemClassLoader(); URL res = cl.getResource(clazz.getName().replace('.', '/') + ".class"); if(res==null) throw new IllegalArgumentException("Unable to locate class file for "+clazz); + return res; + } + + /** + * Locates the jar file that contains the given class. + * + *

+ * 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 { + URL res = jarURL(clazz); String resURL = res.toExternalForm(); String originalURL = resURL; if(resURL.startsWith("jar:"))