diff --git a/core/src/main/java/hudson/Main.java b/core/src/main/java/hudson/Main.java index 89ad4b9076..769f830369 100644 --- a/core/src/main/java/hudson/Main.java +++ b/core/src/main/java/hudson/Main.java @@ -64,7 +64,7 @@ public class Main { public static int run(String[] args) throws Exception { String home = getHudsonHome(); if (home==null) { - System.err.println("HUDSON_HOME is not set."); + System.err.println("JENKINS_HOME is not set."); return -1; } if (args.length < 2) { @@ -76,7 +76,9 @@ public class Main { } private static String getHudsonHome() { - return EnvVars.masterEnvVars.get("HUDSON_HOME"); + String home = EnvVars.masterEnvVars.get("JENKINS_HOME"); + if (home!=null) return home; + return EnvVars.masterEnvVars.get("JENKINS_HOME"); } /** diff --git a/core/src/main/java/hudson/WebAppMain.java b/core/src/main/java/hudson/WebAppMain.java index cab42133d4..3e226c019e 100644 --- a/core/src/main/java/hudson/WebAppMain.java +++ b/core/src/main/java/hudson/WebAppMain.java @@ -261,36 +261,46 @@ public final class WebAppMain implements ServletContextListener { } /** - * Determines the home directory for Hudson. + * Determines the home directory for Jenkins. * + *
+ * We look for a setting that affects the smallest scope first, then bigger ones later. + * + *
* People makes configuration mistakes, so we are trying to be nice * with those by doing {@link String#trim()}. */ private File getHomeDir(ServletContextEvent event) { // check JNDI for the home directory first - try { - InitialContext iniCtxt = new InitialContext(); - Context env = (Context) iniCtxt.lookup("java:comp/env"); - String value = (String) env.lookup("HUDSON_HOME"); - if(value!=null && value.trim().length()>0) - return new File(value.trim()); - // look at one more place. See issue #1314 - value = (String) iniCtxt.lookup("HUDSON_HOME"); - if(value!=null && value.trim().length()>0) - return new File(value.trim()); - } catch (NamingException e) { - // ignore + for (String name : HOME_NAMES) { + try { + InitialContext iniCtxt = new InitialContext(); + Context env = (Context) iniCtxt.lookup("java:comp/env"); + String value = (String) env.lookup(name); + if(value!=null && value.trim().length()>0) + return new File(value.trim()); + // look at one more place. See issue #1314 + value = (String) iniCtxt.lookup(name); + if(value!=null && value.trim().length()>0) + return new File(value.trim()); + } catch (NamingException e) { + // ignore + } + } + + // next the system property + for (String name : HOME_NAMES) { + String sysProp = System.getProperty(name); + if(sysProp!=null) + return new File(sysProp.trim()); } - // finally check the system property - String sysProp = System.getProperty("HUDSON_HOME"); - if(sysProp!=null) - return new File(sysProp.trim()); - // look at the env var next - String env = EnvVars.masterEnvVars.get("HUDSON_HOME"); - if(env!=null) - return new File(env.trim()).getAbsoluteFile(); + for (String name : HOME_NAMES) { + String env = EnvVars.masterEnvVars.get(name); + if(env!=null) + return new File(env.trim()).getAbsoluteFile(); + } // otherwise pick a place by ourselves @@ -304,8 +314,11 @@ public final class WebAppMain implements ServletContextListener { return ws; } - // if for some reason we can't put it within the webapp, use home directory. - return new File(new File(System.getProperty("user.home")),".hudson"); + File legacyHome = new File(new File(System.getProperty("user.home")), ".hudson"); + if (legacyHome.exists()) + return legacyHome; // before rename, this is where it was stored + + return new File(new File(System.getProperty("user.home")), ".jenkins"); } public void contextDestroyed(ServletContextEvent event) { @@ -320,4 +333,6 @@ public final class WebAppMain implements ServletContextListener { private static final Logger LOGGER = Logger.getLogger(WebAppMain.class.getName()); + + private static final String[] HOME_NAMES = {"JENKINS_HOME","HUDSON_HOME"}; } diff --git a/core/src/main/java/hudson/diagnosis/HudsonHomeDiskUsageChecker.java b/core/src/main/java/hudson/diagnosis/HudsonHomeDiskUsageChecker.java index 5f101d91e5..10723c7da6 100644 --- a/core/src/main/java/hudson/diagnosis/HudsonHomeDiskUsageChecker.java +++ b/core/src/main/java/hudson/diagnosis/HudsonHomeDiskUsageChecker.java @@ -31,7 +31,7 @@ import org.jvnet.animal_sniffer.IgnoreJRERequirement; import java.util.logging.Logger; /** - * Periodically checks the disk usage of HUDSON_HOME, + * Periodically checks the disk usage of JENKINS_HOME, * and activate {@link HudsonHomeDiskUsageMonitor} if necessary. * * @author Kohsuke Kawaguchi @@ -49,12 +49,12 @@ public class HudsonHomeDiskUsageChecker extends PeriodicWork { long total = Hudson.getInstance().getRootDir().getTotalSpace(); if(free<=0 || total<=0) { // information unavailable. pointless to try. - LOGGER.info("HUDSON_HOME disk usage information isn't available. aborting to monitor"); + LOGGER.info("JENKINS_HOME disk usage information isn't available. aborting to monitor"); cancel(); return; } - LOGGER.fine("Monitoring disk usage of HUDSON_HOME. total="+total+" free="+free); + LOGGER.fine("Monitoring disk usage of JENKINS_HOME. total="+total+" free="+free); // if it's more than 90% full and less than the minimum, activate @@ -63,7 +63,7 @@ public class HudsonHomeDiskUsageChecker extends PeriodicWork { HudsonHomeDiskUsageMonitor.get().activated = (total/free>10 && free< FREE_SPACE_THRESHOLD); } catch (LinkageError _) { // pre Mustang - LOGGER.info("Not on JDK6. Cannot monitor HUDSON_HOME disk usage"); + LOGGER.info("Not on JDK6. Cannot monitor JENKINS_HOME disk usage"); cancel(); } } diff --git a/core/src/main/java/hudson/diagnosis/HudsonHomeDiskUsageMonitor.java b/core/src/main/java/hudson/diagnosis/HudsonHomeDiskUsageMonitor.java index ae1f5ea1b1..b0b9373586 100644 --- a/core/src/main/java/hudson/diagnosis/HudsonHomeDiskUsageMonitor.java +++ b/core/src/main/java/hudson/diagnosis/HudsonHomeDiskUsageMonitor.java @@ -37,7 +37,7 @@ import java.io.IOException; import java.util.List; /** - * Monitors the disk usage of HUDSON_HOME, and if it's almost filled up, warn the user. + * Monitors the disk usage of JENKINS_HOME, and if it's almost filled up, warn the user. * * @author Kohsuke Kawaguchi */ @@ -90,13 +90,13 @@ public final class HudsonHomeDiskUsageMonitor extends AdministrativeMonitor { } /** - * Extension point for suggesting solutions for full HUDSON_HOME. + * Extension point for suggesting solutions for full JENKINS_HOME. * *
- * Normally we look at {@code $HUDSON_HOME/plugins/*.hpi} and *.hpl.
+ * Normally we look at {@code $JENKINS_HOME/plugins/*.hpi} and *.hpl.
*
* @return
* never null but can be empty. The list can contain different versions of the same plugin,
diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java
index 38cc7d6908..780e21e862 100644
--- a/core/src/main/java/hudson/model/Hudson.java
+++ b/core/src/main/java/hudson/model/Hudson.java
@@ -2363,7 +2363,7 @@ public final class Hudson extends Node implements ItemGroup
diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonHomeLoader.java b/test/src/main/java/org/jvnet/hudson/test/HudsonHomeLoader.java
index 8c5b9c8142..7beb020c5e 100644
--- a/test/src/main/java/org/jvnet/hudson/test/HudsonHomeLoader.java
+++ b/test/src/main/java/org/jvnet/hudson/test/HudsonHomeLoader.java
@@ -33,13 +33,13 @@ import java.net.MalformedURLException;
import java.net.URL;
/**
- * Controls how a {@link HudsonTestCase} initializes HUDSON_HOME.
+ * Controls how a {@link HudsonTestCase} initializes JENKINS_HOME.
*
* @author Kohsuke Kawaguchi
*/
public interface HudsonHomeLoader {
/**
- * Returns a directory to be used as HUDSON_HOME
+ * Returns a directory to be used as JENKINS_HOME
*
* @throws Exception
* to cause a test to fail.
diff --git a/test/src/main/java/org/jvnet/hudson/test/TestPluginManager.java b/test/src/main/java/org/jvnet/hudson/test/TestPluginManager.java
index 999b4a0d26..1140f72212 100644
--- a/test/src/main/java/org/jvnet/hudson/test/TestPluginManager.java
+++ b/test/src/main/java/org/jvnet/hudson/test/TestPluginManager.java
@@ -84,7 +84,7 @@ public class TestPluginManager extends PluginManager {
}
// and pick up test dependency *.hpi that are placed by maven-hpi-plugin TestDependencyMojo.
- // and copy them into $HUDSON_HOME/plugins.
+ // and copy them into $JENKINS_HOME/plugins.
URL index = getClass().getResource("/test-dependencies/index");
if (index!=null) {// if built with maven-hpi-plugin < 1.52 this file won't exist.
BufferedReader r = new BufferedReader(new InputStreamReader(index.openStream(),"UTF-8"));
diff --git a/test/src/main/java/org/jvnet/hudson/test/recipes/LocalData.java b/test/src/main/java/org/jvnet/hudson/test/recipes/LocalData.java
index 00ab80617e..5bc007e457 100644
--- a/test/src/main/java/org/jvnet/hudson/test/recipes/LocalData.java
+++ b/test/src/main/java/org/jvnet/hudson/test/recipes/LocalData.java
@@ -36,7 +36,7 @@ import static java.lang.annotation.ElementType.METHOD;
* Runs a test case with a data set local to test method or the test class.
*
*
- * This recipe allows your test case to start with the preset HUDSON_HOME data loaded
+ * This recipe allows your test case to start with the preset JENKINS_HOME data loaded
* either from your test method or from the test class.
*
*
@@ -47,12 +47,12 @@ import static java.lang.annotation.ElementType.METHOD;
*
*
diff --git a/test/src/main/java/org/jvnet/hudson/test/recipes/PresetData.java b/test/src/main/java/org/jvnet/hudson/test/recipes/PresetData.java
index 8d88964f35..9b383c237b 100644
--- a/test/src/main/java/org/jvnet/hudson/test/recipes/PresetData.java
+++ b/test/src/main/java/org/jvnet/hudson/test/recipes/PresetData.java
@@ -33,7 +33,7 @@ import java.lang.annotation.Target;
import java.util.Locale;
/**
- * Runs a test case with one of the preset HUDSON_HOME data set.
+ * Runs a test case with one of the preset JENKINS_HOME data set.
*
* @author Kohsuke Kawaguchi
* @see LocalData