diff --git a/core/src/main/java/hudson/ProxyConfiguration.java b/core/src/main/java/hudson/ProxyConfiguration.java index 3b469494bb..efee245641 100644 --- a/core/src/main/java/hudson/ProxyConfiguration.java +++ b/core/src/main/java/hudson/ProxyConfiguration.java @@ -50,6 +50,7 @@ import java.util.regex.Pattern; import javax.annotation.CheckForNull; import jenkins.model.Jenkins; import jenkins.util.JenkinsJVM; +import jenkins.util.SystemProperties; import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.UsernamePasswordCredentials; @@ -79,7 +80,7 @@ public final class ProxyConfiguration extends AbstractDescribableImpl, Q return parameters; } - if (Boolean.getBoolean(KEEP_UNDEFINED_PARAMETERS_SYSTEM_PROPERTY_NAME)) { + if (SystemProperties.getBoolean(KEEP_UNDEFINED_PARAMETERS_SYSTEM_PROPERTY_NAME)) { return parameters; } diff --git a/core/src/main/java/hudson/model/UpdateCenter.java b/core/src/main/java/hudson/model/UpdateCenter.java index 2a4ee26719..01a9c0d95c 100644 --- a/core/src/main/java/hudson/model/UpdateCenter.java +++ b/core/src/main/java/hudson/model/UpdateCenter.java @@ -151,7 +151,7 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas /** * Read timeout when downloading plugins, defaults to 1 minute */ - private static final int PLUGIN_DOWNLOAD_READ_TIMEOUT = Integer.getInteger(UpdateCenter.class.getName()+".pluginDownloadReadTimeoutSeconds", 60) * 1000; + private static final int PLUGIN_DOWNLOAD_READ_TIMEOUT = SystemProperties.getInteger(UpdateCenter.class.getName()+".pluginDownloadReadTimeoutSeconds", 60) * 1000; /** * {@linkplain UpdateSite#getId() ID} of the default update site. diff --git a/core/src/main/java/hudson/slaves/CloudSlaveRetentionStrategy.java b/core/src/main/java/hudson/slaves/CloudSlaveRetentionStrategy.java index 1948d6b10d..accfca80c3 100644 --- a/core/src/main/java/hudson/slaves/CloudSlaveRetentionStrategy.java +++ b/core/src/main/java/hudson/slaves/CloudSlaveRetentionStrategy.java @@ -9,6 +9,7 @@ import javax.annotation.concurrent.GuardedBy; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import jenkins.util.SystemProperties; /** * Default convenience implementation of {@link RetentionStrategy} for agents provisioned from {@link Cloud}. @@ -71,7 +72,7 @@ public class CloudSlaveRetentionStrategy extends RetentionSt } // for debugging, it's convenient to be able to reduce this time - public static long TIMEOUT = Long.getLong(CloudSlaveRetentionStrategy.class.getName()+".timeout", TimeUnit2.MINUTES.toMillis(10)); + public static long TIMEOUT = SystemProperties.getLong(CloudSlaveRetentionStrategy.class.getName()+".timeout", TimeUnit2.MINUTES.toMillis(10)); private static final Logger LOGGER = Logger.getLogger(CloudSlaveRetentionStrategy.class.getName()); } diff --git a/core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java b/core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java index f052fcad1f..4bd542d7de 100644 --- a/core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java +++ b/core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java @@ -90,14 +90,14 @@ public class ConnectionActivityMonitor extends AsyncPeriodicWork { /** * Time till initial ping */ - private static final long TIME_TILL_PING = Long.getLong(ConnectionActivityMonitor.class.getName()+".timeToPing",TimeUnit2.MINUTES.toMillis(3)); + private static final long TIME_TILL_PING = SystemProperties.getLong(ConnectionActivityMonitor.class.getName()+".timeToPing",TimeUnit2.MINUTES.toMillis(3)); - private static final long FREQUENCY = Long.getLong(ConnectionActivityMonitor.class.getName()+".frequency",TimeUnit2.SECONDS.toMillis(10)); + private static final long FREQUENCY = SystemProperties.getLong(ConnectionActivityMonitor.class.getName()+".frequency",TimeUnit2.SECONDS.toMillis(10)); /** * When do we abandon the effort and cut off? */ - private static final long TIMEOUT = Long.getLong(ConnectionActivityMonitor.class.getName()+".timeToPing",TimeUnit2.MINUTES.toMillis(4)); + private static final long TIMEOUT = SystemProperties.getLong(ConnectionActivityMonitor.class.getName()+".timeToPing",TimeUnit2.MINUTES.toMillis(4)); // disabled by default until proven in the production diff --git a/core/src/main/java/hudson/triggers/SCMTrigger.java b/core/src/main/java/hudson/triggers/SCMTrigger.java index f46b3654dd..5c17e49193 100644 --- a/core/src/main/java/hudson/triggers/SCMTrigger.java +++ b/core/src/main/java/hudson/triggers/SCMTrigger.java @@ -80,6 +80,7 @@ import org.kohsuke.stapler.StaplerResponse; import static java.util.logging.Level.*; import jenkins.model.RunAction2; +import jenkins.util.SystemProperties; /** @@ -664,5 +665,5 @@ public class SCMTrigger extends Trigger { /** * How long is too long for a polling activity to be in the queue? */ - public static long STARVATION_THRESHOLD =Long.getLong(SCMTrigger.class.getName()+".starvationThreshold", TimeUnit2.HOURS.toMillis(1)); + public static long STARVATION_THRESHOLD = SystemProperties.getLong(SCMTrigger.class.getName()+".starvationThreshold", TimeUnit2.HOURS.toMillis(1)); } diff --git a/core/src/main/java/jenkins/install/InstallUtil.java b/core/src/main/java/jenkins/install/InstallUtil.java index 21e7fec2de..d611ba0b41 100644 --- a/core/src/main/java/jenkins/install/InstallUtil.java +++ b/core/src/main/java/jenkins/install/InstallUtil.java @@ -166,7 +166,7 @@ public class InstallUtil { return InstallState.TEST; } - if (Boolean.getBoolean("hudson.Main.development")) { + if (SystemProperties.getBoolean("hudson.Main.development")) { return InstallState.DEVELOPMENT; } } diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index 1243858141..1aefbcf92a 100644 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -597,7 +597,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve * TCP agent port. * 0 for random, -1 to disable. */ - private int slaveAgentPort = Integer.getInteger(Jenkins.class.getName()+".slaveAgentPort",0); + private int slaveAgentPort = SystemProperties.getInteger(Jenkins.class.getName()+".slaveAgentPort",0); /** * Whitespace-separated labels assigned to the master as a {@link Node}. @@ -762,7 +762,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve public static Jenkins getInstance() { Jenkins instance = HOLDER.getInstance(); if (instance == null) { - if(Boolean.getBoolean(Jenkins.class.getName()+".enableExceptionOnNullInstance")) { + if(SystemProperties.getBoolean(Jenkins.class.getName()+".enableExceptionOnNullInstance")) { // TODO: remove that second block around 2.20 (that is: ~20 versions to battle test it) // See https://github.com/jenkinsci/jenkins/pull/2297#issuecomment-216710150 throw new IllegalStateException("Jenkins has not been started, or was already shut down"); diff --git a/core/src/main/java/jenkins/slaves/JnlpSlaveAgentProtocol3.java b/core/src/main/java/jenkins/slaves/JnlpSlaveAgentProtocol3.java index 8b6b3df129..00ae97001d 100644 --- a/core/src/main/java/jenkins/slaves/JnlpSlaveAgentProtocol3.java +++ b/core/src/main/java/jenkins/slaves/JnlpSlaveAgentProtocol3.java @@ -22,6 +22,7 @@ import java.io.PrintWriter; import java.net.Socket; import java.util.logging.Level; import java.util.logging.Logger; +import jenkins.util.SystemProperties; /** * Master-side implementation for JNLP3-connect protocol. @@ -127,8 +128,9 @@ public class JnlpSlaveAgentProtocol3 extends AgentProtocol { static { String propName = JnlpSlaveAgentProtocol3.class.getName() + ".enabled"; - if (System.getProperties().containsKey(propName)) - ENABLED = Boolean.getBoolean(propName); + String propertyString = SystemProperties.getString(propName); + if (propertyString != null) + ENABLED = SystemProperties.getBoolean(propName); else { byte hash = Util.fromHexString(Jenkins.getActiveInstance().getLegacyInstanceId())[0]; ENABLED = (hash%10)==0; diff --git a/core/src/main/java/jenkins/util/ProgressiveRendering.java b/core/src/main/java/jenkins/util/ProgressiveRendering.java index 103081a29d..22afed60d6 100644 --- a/core/src/main/java/jenkins/util/ProgressiveRendering.java +++ b/core/src/main/java/jenkins/util/ProgressiveRendering.java @@ -77,7 +77,7 @@ public abstract class ProgressiveRendering { private static final Logger LOG = Logger.getLogger(ProgressiveRendering.class.getName()); /** May be set to a number of milliseconds to sleep in {@link #canceled}, useful for watching what are normally fast computations. */ - private static final Long DEBUG_SLEEP = Long.getLong("jenkins.util.ProgressiveRendering.DEBUG_SLEEP"); + private static final Long DEBUG_SLEEP = SystemProperties.getLong("jenkins.util.ProgressiveRendering.DEBUG_SLEEP"); private static final int CANCELED = -1; private static final int ERROR = -2; diff --git a/core/src/main/java/jenkins/util/SystemProperties.java b/core/src/main/java/jenkins/util/SystemProperties.java index 4af51c943a..12643ff5a5 100644 --- a/core/src/main/java/jenkins/util/SystemProperties.java +++ b/core/src/main/java/jenkins/util/SystemProperties.java @@ -249,6 +249,51 @@ public class SystemProperties implements ServletContextListener { } return def; } + + /** + * Determines the long value of the system property with the + * specified name. + * + * This behaves just like {@link Long#getLong(java.lang.String)}, except that it + * also consults the {@link ServletContext}'s "init" parameters. + * + * @param name property name. + * @return the {@code Long} value of the property. + */ + @CheckForNull + public static Long getLong(String name) { + return getLong(name, null); + } + + /** + * Determines the integer value of the system property with the + * specified name, or a default value. + * + * This behaves just like Long.getLong(String,Long), except that it + * also consults the ServletContext's "init" parameters. If neither exist, + * return the default value. + * + * @param name property name. + * @param def a default value. + * @return the {@code Long} value of the property. + * If the property is missing, return the default value. + * Result may be {@code null} only if the default value is {@code null}. + */ + public static Long getLong(String name, Long def) { + String v = getString(name); + + if (v != null) { + try { + return Long.decode(v); + } catch (NumberFormatException e) { + // Ignore, fallback to default + if (LOGGER.isLoggable(Level.CONFIG)) { + LOGGER.log(Level.CONFIG, "Property. Value is not long: {0} => {1}", new Object[] {name, v}); + } + } + } + return def; + } @CheckForNull private static String tryGetValueFromContext(String key) {