Skip to content

Commit

Permalink
[JENKINS-34854] - Migrate missing settings to SystemProperties (#2362)
Browse files Browse the repository at this point in the history
* [JENKINS-34854] - Migrate missing Integer and Boolean properties to SystemProperties

* [JENKINS-34854] - API methods for Long variables

* [JENKINS-34854] - Migrate Long settings to SystemProperties

* [JENKINS-34854] - Leftover change (I should use Save All)

* [JENKINS-34854] - Some fixes in Long methods Javadoc and log messages
  • Loading branch information
oleg-nenashev committed May 21, 2016
1 parent f02746a commit 1d2b151
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 26 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/ProxyConfiguration.java
Expand Up @@ -50,6 +50,7 @@
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;
Expand Down Expand Up @@ -79,7 +80,7 @@ public final class ProxyConfiguration extends AbstractDescribableImpl<ProxyConfi
* Holds a default TCP connect timeout set on all connections returned from this class,
* note this is value is in milliseconds, it's passed directly to {@link URLConnection#setConnectTimeout(int)}
*/
private static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = Integer.getInteger("hudson.ProxyConfiguration.DEFAULT_CONNECT_TIMEOUT_MILLIS", 20 * 1000);
private static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = SystemProperties.getInteger("hudson.ProxyConfiguration.DEFAULT_CONNECT_TIMEOUT_MILLIS", 20 * 1000);

public final String name;
public final int port;
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/hudson/Util.java
Expand Up @@ -1654,7 +1654,7 @@ public static Properties loadProperties(@Nonnull String properties) throws IOExc
* give up, thus improving build reliability.
*/
@Restricted(value = NoExternalUse.class)
static int DELETION_MAX = Math.max(1, Integer.getInteger(Util.class.getName() + ".maxFileDeletionRetries", 3).intValue());
static int DELETION_MAX = Math.max(1, SystemProperties.getInteger(Util.class.getName() + ".maxFileDeletionRetries", 3).intValue());

/**
* The time (in milliseconds) that we will wait between attempts to
Expand All @@ -1666,7 +1666,7 @@ public static Properties loadProperties(@Nonnull String properties) throws IOExc
* between attempts.
*/
@Restricted(value = NoExternalUse.class)
static int WAIT_BETWEEN_DELETION_RETRIES = Integer.getInteger(Util.class.getName() + ".deletionRetryWait", 100).intValue();
static int WAIT_BETWEEN_DELETION_RETRIES = SystemProperties.getInteger(Util.class.getName() + ".deletionRetryWait", 100).intValue();

/**
* If this flag is set to true then we will request a garbage collection
Expand All @@ -1690,5 +1690,5 @@ public static Properties loadProperties(@Nonnull String properties) throws IOExc
* unless you can tolerate the performance impact.
*/
@Restricted(value = NoExternalUse.class)
static boolean GC_AFTER_FAILED_DELETE = Boolean.getBoolean(Util.class.getName() + ".performGCOnFailedDelete");
static boolean GC_AFTER_FAILED_DELETE = SystemProperties.getBoolean(Util.class.getName() + ".performGCOnFailedDelete");
}
9 changes: 5 additions & 4 deletions core/src/main/java/hudson/model/AsyncAperiodicWork.java
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import jenkins.model.Jenkins;
import jenkins.util.SystemProperties;

/**
* {@link AperiodicWork} that takes a long time to run. Similar to {@link AsyncPeriodicWork}, see {@link AsyncPeriodicWork} for
Expand All @@ -48,7 +49,7 @@ public abstract class AsyncAperiodicWork extends AperiodicWork {
*
* @since 1.651
*/
private static final long LOG_ROTATE_MINUTES = Long.getLong(AsyncAperiodicWork.class.getName() +
private static final long LOG_ROTATE_MINUTES = SystemProperties.getLong(AsyncAperiodicWork.class.getName() +
".logRotateMinutes", TimeUnit.DAYS.toMinutes(1));
/**
* The default file size after which to try and rotate the log file used by {@link #createListener()}.
Expand All @@ -59,7 +60,7 @@ public abstract class AsyncAperiodicWork extends AperiodicWork {
*
* @since 1.651
*/
private static final long LOG_ROTATE_SIZE = Long.getLong(AsyncAperiodicWork.class.getName() + ".logRotateSize",
private static final long LOG_ROTATE_SIZE = SystemProperties.getLong(AsyncAperiodicWork.class.getName() + ".logRotateSize",
-1L);
/**
* The number of milliseconds (since startup or previous rotation) after which to try and rotate the log file.
Expand Down Expand Up @@ -91,8 +92,8 @@ public abstract class AsyncAperiodicWork extends AperiodicWork {
protected AsyncAperiodicWork(String name) {
this.name = name;
this.logRotateMillis = TimeUnit.MINUTES.toMillis(
Long.getLong(getClass().getName()+".logRotateMinutes", LOG_ROTATE_MINUTES));
this.logRotateSize = Long.getLong(getClass().getName() +".logRotateSize", LOG_ROTATE_SIZE);
SystemProperties.getLong(getClass().getName()+".logRotateMinutes", LOG_ROTATE_MINUTES));
this.logRotateSize = SystemProperties.getLong(getClass().getName() +".logRotateSize", LOG_ROTATE_SIZE);
}

/**
Expand Down
9 changes: 5 additions & 4 deletions core/src/main/java/hudson/model/AsyncPeriodicWork.java
Expand Up @@ -9,6 +9,7 @@
import java.util.logging.Level;
import java.util.logging.LogRecord;
import jenkins.model.Jenkins;
import jenkins.util.SystemProperties;

/**
* {@link PeriodicWork} that takes a long time to run.
Expand All @@ -29,7 +30,7 @@ public abstract class AsyncPeriodicWork extends PeriodicWork {
*
* @since 1.651
*/
private static final long LOG_ROTATE_MINUTES = Long.getLong(AsyncPeriodicWork.class.getName() + ".logRotateMinutes",
private static final long LOG_ROTATE_MINUTES = SystemProperties.getLong(AsyncPeriodicWork.class.getName() + ".logRotateMinutes",
TimeUnit.DAYS.toMinutes(1));
/**
* The default file size after which to try and rotate the log file used by {@link #createListener()}.
Expand All @@ -40,7 +41,7 @@ public abstract class AsyncPeriodicWork extends PeriodicWork {
*
* @since 1.651
*/
private static final long LOG_ROTATE_SIZE = Long.getLong(AsyncPeriodicWork.class.getName() + ".logRotateSize", -1L);
private static final long LOG_ROTATE_SIZE = SystemProperties.getLong(AsyncPeriodicWork.class.getName() + ".logRotateSize", -1L);
/**
* The number of milliseconds (since startup or previous rotation) after which to try and rotate the log file.
*
Expand Down Expand Up @@ -71,8 +72,8 @@ public abstract class AsyncPeriodicWork extends PeriodicWork {
protected AsyncPeriodicWork(String name) {
this.name = name;
this.logRotateMillis = TimeUnit.MINUTES.toMillis(
Long.getLong(getClass().getName() + ".logRotateMinutes", LOG_ROTATE_MINUTES));
this.logRotateSize = Long.getLong(getClass().getName() + ".logRotateSize", LOG_ROTATE_SIZE);
SystemProperties.getLong(getClass().getName() + ".logRotateMinutes", LOG_ROTATE_MINUTES));
this.logRotateSize = SystemProperties.getLong(getClass().getName() + ".logRotateSize", LOG_ROTATE_SIZE);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/DownloadService.java
Expand Up @@ -489,7 +489,7 @@ public static Downloadable get(String id) {

private static final Logger LOGGER = Logger.getLogger(Downloadable.class.getName());
private static final long DEFAULT_INTERVAL =
Long.getLong(Downloadable.class.getName()+".defaultInterval", DAYS.toMillis(1));
SystemProperties.getLong(Downloadable.class.getName()+".defaultInterval", DAYS.toMillis(1));
}

public static boolean neverUpdate = SystemProperties.getBoolean(DownloadService.class.getName()+".never");
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/ParametersAction.java
Expand Up @@ -306,7 +306,7 @@ private List<? extends ParameterValue> filter(List<ParameterValue> parameters) {
return parameters;
}

if (Boolean.getBoolean(KEEP_UNDEFINED_PARAMETERS_SYSTEM_PROPERTY_NAME)) {
if (SystemProperties.getBoolean(KEEP_UNDEFINED_PARAMETERS_SYSTEM_PROPERTY_NAME)) {
return parameters;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/UpdateCenter.java
Expand Up @@ -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.
Expand Down
Expand Up @@ -9,6 +9,7 @@
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}.
Expand Down Expand Up @@ -71,7 +72,7 @@ protected long getIdleMaxTime() {
}

// 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());
}
Expand Up @@ -90,14 +90,14 @@ public long getRecurrencePeriod() {
/**
* 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
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/triggers/SCMTrigger.java
Expand Up @@ -80,6 +80,7 @@

import static java.util.logging.Level.*;
import jenkins.model.RunAction2;
import jenkins.util.SystemProperties;


/**
Expand Down Expand Up @@ -664,5 +665,5 @@ public int hashCode() {
/**
* 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));
}
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/install/InstallUtil.java
Expand Up @@ -166,7 +166,7 @@ private static InstallState getDefaultInstallState() {
return InstallState.TEST;
}

if (Boolean.getBoolean("hudson.Main.development")) {
if (SystemProperties.getBoolean("hudson.Main.development")) {
return InstallState.DEVELOPMENT;
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -597,7 +597,7 @@ protected void onModified() throws IOException {
* 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}.
Expand Down Expand Up @@ -762,7 +762,7 @@ public static Jenkins getInstanceOrNull() {
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");
Expand Down
Expand Up @@ -22,6 +22,7 @@
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.
Expand Down Expand Up @@ -127,8 +128,9 @@ protected String getNodeSecret(String nodeName) throws Failure {

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;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/util/ProgressiveRendering.java
Expand Up @@ -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;

Expand Down
45 changes: 45 additions & 0 deletions core/src/main/java/jenkins/util/SystemProperties.java
Expand Up @@ -249,6 +249,51 @@ public static Integer getInteger(String name, Integer def) {
}
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 <code>Long.getLong(String,Long)</code>, except that it
* also consults the <code>ServletContext</code>'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) {
Expand Down

0 comments on commit 1d2b151

Please sign in to comment.