improved the diagnosability when the explode() method fails

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11973 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke 2008-09-02 22:24:49 +00:00
parent 213a95c1a1
commit 2169dce3ca
2 changed files with 58 additions and 49 deletions

View File

@ -161,7 +161,7 @@ public abstract class HudsonTestCase extends TestCase {
protected ServletContext createWebServer() throws Exception {
server = new Server();
WebAppContext context = new WebAppContext(WarExploder.EXPLODE_DIR.getPath(), contextPath);
WebAppContext context = new WebAppContext(WarExploder.getExplodedDir().getPath(), contextPath);
context.setClassLoader(getClass().getClassLoader());
context.setConfigurations(new Configuration[]{new WebXmlConfiguration(),new NoListenerConfiguration()});
server.setHandler(context);

View File

@ -4,7 +4,6 @@ import hudson.remoting.Which;
import hudson.FilePath;
import java.io.File;
import java.io.IOException;
import java.io.FileOutputStream;
import java.net.URL;
@ -14,13 +13,30 @@ import java.net.URL;
* @author Kohsuke Kawaguchi
*/
final class WarExploder {
public static final File EXPLODE_DIR = explode();
public static File getExplodedDir() throws Exception {
// rethrow an exception every time someone tries to do this, so that when explode()
// fails, you can see the cause no matter which test case you look at.
// see http://www.nabble.com/Failing-tests-in-test-harness-module-on-hudson.ramfelt.se-td19258722.html
if(FAILURE !=null) throw new Exception("Failed to initialize exploded war", FAILURE);
return EXPLODE_DIR;
}
private static File EXPLODE_DIR;
private static Exception FAILURE;
static {
try {
EXPLODE_DIR = explode();
} catch (Exception e) {
FAILURE = e;
}
}
/**
* Explodes hudson.war, if necesasry, and returns its root dir.
*/
private static File explode() {
try {
private static File explode() throws Exception {
// are we in the hudson main workspace? If so, pick up hudson/main/war/resources
// this saves the effort of packaging a war file and makes the debug cycle faster
File d = new File(".").getAbsoluteFile();
@ -59,12 +75,5 @@ final class WarExploder {
}
return explodeDir;
} catch (IOException e) {
throw new Error(e);
} catch (InterruptedException e) {
throw new Error(e);
} catch (ClassNotFoundException e) {
throw new Error(e);
}
}
}