From fbfdaef4327be93be85452bc8e53bb5ca05ab06a Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 27 Mar 2011 16:22:08 -0700 Subject: [PATCH] made to work with JBoss6 --- changelog.html | 2 ++ .../src/main/java/hudson/remoting/Which.java | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/changelog.html b/changelog.html index 1ef6282ec3..71a76b5acb 100644 --- a/changelog.html +++ b/changelog.html @@ -81,6 +81,8 @@ Upcoming changes
  • Rebuilding dependency graph was taking much too long for big maven projects (issue 7535) +
  • + Maven builds didn't work in JBoss 6.
  • Ping setup for detecting bad master/slave communication is done more consistently now (issue 8990) diff --git a/remoting/src/main/java/hudson/remoting/Which.java b/remoting/src/main/java/hudson/remoting/Which.java index e266ea5709..c2196246bb 100644 --- a/remoting/src/main/java/hudson/remoting/Which.java +++ b/remoting/src/main/java/hudson/remoting/Which.java @@ -28,6 +28,7 @@ import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.net.MalformedURLException; import java.net.URLConnection; @@ -130,7 +131,29 @@ public class Which { } finally { is.close(); } + } + if(resURL.startsWith("vfs:")) { + // JBoss6 + String dotdot=""; + for (int i=clazz.getName().split("\\.").length; i>1; i--) + dotdot+="../"; + + try { + URL jar = new URL(res,dotdot); + String path = jar.getPath(); + if (path.endsWith("/")) path=path.substring(0,path.length()-1); + // obtain the file name portion + String fileName = path.substring(path.lastIndexOf('/')+1); + + Object vfs = new URL(jar,"..").getContent(); // a VirtualFile object pointing to the parent of the jar + File dir = (File)vfs.getClass().getMethod("getPhysicalFile").invoke(vfs); + + File jarFile = new File(dir,fileName); + if (jarFile.exists()) return jarFile; + } catch (Exception e) { + LOGGER.log(Level.FINE, "Failed to resolve vfs file into a location",e); + } } URLConnection con = res.openConnection();