From 8a229acc288123eec4ab0dde59f8ce55b8a7f815 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 23 Dec 2008 07:42:20 +0000 Subject: [PATCH] improved error diagnostics git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@13816 71c3de6d-444a-0410-be80-ed276b4c234a --- .../scm/SubversionUpdateEventHandler.java | 5 +++-- .../util/IncompatibleAntVersionDetected.java | 5 +++-- .../IncompatibleServletVersionDetected.java | 5 +++-- .../src/main/java/hudson/remoting/Which.java | 17 ++++++++++++++++- 4 files changed, 25 insertions(+), 7 deletions(-) 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:"))