expose additional variables

This commit is contained in:
Kohsuke Kawaguchi committed 2013-11-16 11:09:07 -08:00
1 parent 729d41cfe8
commit 0c5338dff2
3 files changed
+92 -11

No files matched your search

+38 -9
View File
@@ -25,6 +25,7 @@ package hudson;
import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
import com.thoughtworks.xstream.core.JVM;
import com.trilead.ssh2.util.IOUtils;
import hudson.model.Hudson;
import hudson.util.BootFailure;
import jenkins.model.Jenkins;
@@ -53,15 +54,19 @@ import javax.servlet.ServletResponse;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Date;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.security.Security;
import java.util.logging.LogRecord;
import static java.util.logging.Level.*;
/**
* Entry point when Hudson is used as a webapp.
*
@@ -84,6 +89,7 @@ public final class WebAppMain implements ServletContextListener {
*/
public void contextInitialized(ServletContextEvent event) {
final ServletContext context = event.getServletContext();
File home=null;
try {
// use the current request to determine the language
@@ -111,7 +117,7 @@ public final class WebAppMain implements ServletContextListener {
installLogger();
final FileAndDescription describedHomeDir = getHomeDir(event);
final File home = describedHomeDir.file.getAbsoluteFile();
home = describedHomeDir.file.getAbsoluteFile();
home.mkdirs();
System.out.println("Jenkins home directory: "+home+" found at: "+describedHomeDir.description);
@@ -119,6 +125,8 @@ public final class WebAppMain implements ServletContextListener {
if (!home.exists())
throw new NoHomeDir(home);
recordBootAttempt(home);
// make sure that we are using XStream in the "enhanced" (JVM-specific) mode
if(jvm.bestReflectionProvider().getClass()==PureJavaReflectionProvider.class) {
throw new IncompatibleVMDetected(); // nope
@@ -191,13 +199,13 @@ public final class WebAppMain implements ServletContextListener {
// if this works we are all happy
} catch (TransformerFactoryConfigurationError x) {
// no it didn't.
LOGGER.log(Level.WARNING, "XSLT not configured correctly. Hudson will try to fix this. See http://issues.apache.org/bugzilla/show_bug.cgi?id=40895 for more details",x);
LOGGER.log(WARNING, "XSLT not configured correctly. Hudson will try to fix this. See http://issues.apache.org/bugzilla/show_bug.cgi?id=40895 for more details",x);
System.setProperty(TransformerFactory.class.getName(),"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
try {
TransformerFactory.newInstance();
LOGGER.info("XSLT is set to the JAXP RI in JRE");
} catch(TransformerFactoryConfigurationError y) {
LOGGER.log(Level.SEVERE, "Failed to correct the problem.");
LOGGER.log(SEVERE, "Failed to correct the problem.");
}
}
@@ -205,22 +213,25 @@ public final class WebAppMain implements ServletContextListener {
context.setAttribute(APP,new HudsonIsLoading());
final File _home = home;
initThread = new Thread("Jenkins initialization thread") {
@Override
public void run() {
boolean success = false;
try {
Jenkins instance = new Hudson(home, context);
Jenkins instance = new Hudson(_home, context);
context.setAttribute(APP, instance);
BootFailure.getBootFailureFile(_home).delete();
// at this point we are open for business and serving requests normally
LOGGER.info("Jenkins is fully up and running");
success = true;
} catch (Error e) {
new HudsonFailedToLoad(e).publish(context);
new HudsonFailedToLoad(e).publish(context,_home);
throw e;
} catch (Exception e) {
new HudsonFailedToLoad(e).publish(context);
new HudsonFailedToLoad(e).publish(context,_home);
} finally {
Jenkins instance = Jenkins.getInstance();
if(!success && instance!=null)
@@ -230,16 +241,34 @@ public final class WebAppMain implements ServletContextListener {
};
initThread.start();
} catch (BootFailure e) {
e.publish(context);
e.publish(context,home);
} catch (Error e) {
LOGGER.log(Level.SEVERE, "Failed to initialize Jenkins",e);
LOGGER.log(SEVERE, "Failed to initialize Jenkins",e);
throw e;
} catch (RuntimeException e) {
LOGGER.log(Level.SEVERE, "Failed to initialize Jenkins",e);
LOGGER.log(SEVERE, "Failed to initialize Jenkins",e);
throw e;
}
}
/**
* To assist boot failure script, record the number of boot attempts.
* This file gets deleted in case of successful boot.
*
* @see BootFailure
*/
private void recordBootAttempt(File home) {
FileOutputStream o=null;
try {
o = new FileOutputStream(BootFailure.getBootFailureFile(home), true);
o.write((new Date().toString() + System.getProperty("line.separator", "\n")).toString().getBytes());
} catch (IOException e) {
LOGGER.log(WARNING, "Failed to record boot attempts",e);
} finally {
IOUtils.closeQuietly(o);
}
}
public static void installExpressionFactory(ServletContextEvent event) {
JellyFacet.setExpressionFactory(event, new ExpressionFactory2());
}