Skip to content

Commit

Permalink
Merge pull request #2337 from oleg-nenashev/JENKINS-34755
Browse files Browse the repository at this point in the history
[JENKINS-34755] - Allow setting of system properties from context.xml in addition to setting from command line
  • Loading branch information
oleg-nenashev committed May 14, 2016
2 parents 409438f + fdabb52 commit cf64ba0
Show file tree
Hide file tree
Showing 62 changed files with 490 additions and 89 deletions.
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/ClassicPluginStrategy.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson;

import jenkins.util.SystemProperties;
import com.google.common.collect.Lists;
import hudson.Plugin.DummyImpl;
import hudson.PluginWrapper.Dependency;
Expand Down Expand Up @@ -878,7 +879,7 @@ protected Class defineClassFromData(File container, byte[] classData, String cla
}
}

public static boolean useAntClassLoader = Boolean.getBoolean(ClassicPluginStrategy.class.getName()+".useAntClassLoader");
public static boolean useAntClassLoader = SystemProperties.getBoolean(ClassicPluginStrategy.class.getName()+".useAntClassLoader");
private static final Logger LOGGER = Logger.getLogger(ClassicPluginStrategy.class.getName());
public static boolean DISABLE_TRANSFORMER = Boolean.getBoolean(ClassicPluginStrategy.class.getName()+".noBytecodeTransformer");
public static boolean DISABLE_TRANSFORMER = SystemProperties.getBoolean(ClassicPluginStrategy.class.getName()+".noBytecodeTransformer");
}
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/DNSMultiCast.java
@@ -1,5 +1,6 @@
package hudson;

import jenkins.util.SystemProperties;
import jenkins.model.Jenkins;
import jenkins.model.Jenkins.MasterComputer;

Expand Down Expand Up @@ -87,5 +88,5 @@ public void close() {

private static final Logger LOGGER = Logger.getLogger(DNSMultiCast.class.getName());

public static boolean disabled = Boolean.getBoolean(DNSMultiCast.class.getName()+".disabled");
public static boolean disabled = SystemProperties.getBoolean(DNSMultiCast.class.getName()+".disabled");
}
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/FilePath.java
Expand Up @@ -25,6 +25,7 @@
*/
package hudson;

import jenkins.util.SystemProperties;
import com.google.common.annotations.VisibleForTesting;
import com.jcraft.jzlib.GZIPInputStream;
import com.jcraft.jzlib.GZIPOutputStream;
Expand Down Expand Up @@ -2381,7 +2382,7 @@ public String validateAntFileMask(final String fileMasks, final int bound) throw
* Default bound for {@link #validateAntFileMask(String, int, boolean)}.
* @since 1.592
*/
public static int VALIDATE_ANT_FILE_MASK_BOUND = Integer.getInteger(FilePath.class.getName() + ".VALIDATE_ANT_FILE_MASK_BOUND", 10000);
public static int VALIDATE_ANT_FILE_MASK_BOUND = SystemProperties.getInteger(FilePath.class.getName() + ".VALIDATE_ANT_FILE_MASK_BOUND", 10000);

/**
* Like {@link #validateAntFileMask(String)} but performing only a bounded number of operations.
Expand Down
15 changes: 6 additions & 9 deletions core/src/main/java/hudson/Functions.java
Expand Up @@ -25,6 +25,7 @@
*/
package hudson;

import jenkins.util.SystemProperties;
import hudson.cli.CLICommand;
import hudson.console.ConsoleAnnotationDescriptor;
import hudson.console.ConsoleAnnotatorFactory;
Expand Down Expand Up @@ -570,7 +571,7 @@ public static String getYuiSuffix() {
/**
* Set to true if you need to use the debug version of YUI.
*/
public static boolean DEBUG_YUI = Boolean.getBoolean("debug.YUI");
public static boolean DEBUG_YUI = SystemProperties.getBoolean("debug.YUI");

/**
* Creates a sub map by using the given range (both ends inclusive).
Expand Down Expand Up @@ -625,7 +626,7 @@ public static void configureAutoRefresh(HttpServletRequest request, HttpServletR
response.addCookie(c);
}
if (refresh) {
response.addHeader("Refresh", System.getProperty("hudson.Functions.autoRefreshSeconds", "10"));
response.addHeader("Refresh", SystemProperties.getString("hudson.Functions.autoRefreshSeconds", "10"));
}
}

Expand Down Expand Up @@ -847,7 +848,7 @@ public static String inferHudsonURL(StaplerRequest req) {
*/
public static String getFooterURL() {
if(footerURL == null) {
footerURL = System.getProperty("hudson.footerURL");
footerURL = SystemProperties.getString("hudson.footerURL");
if(StringUtils.isBlank(footerURL)) {
footerURL = "http://jenkins-ci.org/";
}
Expand Down Expand Up @@ -1574,10 +1575,6 @@ public static String toEmailSafeString(String projectName) {
return projectName;
}

public String getSystemProperty(String key) {
return System.getProperty(key);
}

/**
* Obtains the host name of the Hudson server that clients can use to talk back to.
* <p>
Expand Down Expand Up @@ -1788,7 +1785,7 @@ public static boolean getIsUnitTest() {
* the permission can't be configured in the security screen). Got it?</p>
*/
public static boolean isArtifactsPermissionEnabled() {
return Boolean.getBoolean("hudson.security.ArtifactsPermission");
return SystemProperties.getBoolean("hudson.security.ArtifactsPermission");
}

/**
Expand All @@ -1803,7 +1800,7 @@ public static boolean isArtifactsPermissionEnabled() {
* control on the "Wipe Out Workspace" action.</p>
*/
public static boolean isWipeOutPermissionEnabled() {
return Boolean.getBoolean("hudson.security.WipeOutPermission");
return SystemProperties.getBoolean("hudson.security.WipeOutPermission");
}

public static String createRenderOnDemandProxy(JellyContext context, String attributesToCapture) {
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/LocalPluginManager.java
Expand Up @@ -24,6 +24,7 @@

package hudson;

import jenkins.util.SystemProperties;
import jenkins.model.Jenkins;

import java.io.File;
Expand Down Expand Up @@ -54,7 +55,7 @@ public LocalPluginManager(File rootDir) {
@Override
protected Collection<String> loadBundledPlugins() {
// this is used in tests, when we want to override the default bundled plugins with .jpl (or .hpl) versions
if (System.getProperty("hudson.bundled.plugins") != null) {
if (SystemProperties.getString("hudson.bundled.plugins") != null) {
return Collections.emptySet();
}

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/Main.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson;

import jenkins.util.SystemProperties;
import hudson.util.DualOutputStream;
import hudson.util.EncodingStream;
import com.thoughtworks.xstream.core.util.Base64Encoder;
Expand Down Expand Up @@ -218,10 +219,10 @@ private static HttpURLConnection open(URL url) throws IOException {
/**
* Set to true if we are running inside "mvn hpi:run" or "mvn hudson-dev:run"
*/
public static boolean isDevelopmentMode = Boolean.getBoolean(Main.class.getName()+".development");
public static boolean isDevelopmentMode = SystemProperties.getBoolean(Main.class.getName()+".development");

/**
* Time out for socket connection to Hudson.
*/
public static final int TIMEOUT = Integer.getInteger(Main.class.getName()+".timeout",15000);
public static final int TIMEOUT = SystemProperties.getInteger(Main.class.getName()+".timeout",15000);
}
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/PluginManager.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson;

import jenkins.util.SystemProperties;
import hudson.PluginWrapper.Dependency;
import hudson.init.InitMilestone;
import hudson.init.InitStrategy;
Expand Down Expand Up @@ -881,7 +882,7 @@ private void rename(File legacyFile, File newFile) throws IOException {
* Creates a hudson.PluginStrategy, looking at the corresponding system property.
*/
protected PluginStrategy createPluginStrategy() {
String strategyName = System.getProperty(PluginStrategy.class.getName());
String strategyName = SystemProperties.getString(PluginStrategy.class.getName());
if (strategyName != null) {
try {
Class<?> klazz = getClass().getClassLoader().loadClass(strategyName);
Expand Down Expand Up @@ -1704,7 +1705,7 @@ public String toString() {

private static final Logger LOGGER = Logger.getLogger(PluginManager.class.getName());

public static boolean FAST_LOOKUP = !Boolean.getBoolean(PluginManager.class.getName()+".noFastLookup");
public static boolean FAST_LOOKUP = !SystemProperties.getBoolean(PluginManager.class.getName()+".noFastLookup");

public static final Permission UPLOAD_PLUGINS = new Permission(Jenkins.PERMISSIONS, "UploadPlugins", Messages._PluginManager_UploadPluginsPermission_Description(),Jenkins.ADMINISTER,PermissionScope.JENKINS);
public static final Permission CONFIGURE_UPDATECENTER = new Permission(Jenkins.PERMISSIONS, "ConfigureUpdateCenter", Messages._PluginManager_ConfigureUpdateCenterPermission_Description(),Jenkins.ADMINISTER,PermissionScope.JENKINS);
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/TcpSlaveAgentListener.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson;

import jenkins.util.SystemProperties;
import hudson.slaves.OfflineCause;
import java.io.DataOutputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -301,7 +302,7 @@ public String toString() {
*
* TODO: think about how to expose this (including whether this needs to be exposed at all.)
*/
public static String CLI_HOST_NAME = System.getProperty(TcpSlaveAgentListener.class.getName()+".hostName");
public static String CLI_HOST_NAME = SystemProperties.getString(TcpSlaveAgentListener.class.getName()+".hostName");

/**
* Port number that we advertise the CLI client to connect to.
Expand All @@ -313,7 +314,7 @@ public String toString() {
*
* @since 1.611
*/
public static Integer CLI_PORT = Integer.getInteger(TcpSlaveAgentListener.class.getName()+".port");
public static Integer CLI_PORT = SystemProperties.getInteger(TcpSlaveAgentListener.class.getName()+".port");
}

/*
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/UDPBroadcastThread.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson;

import jenkins.util.SystemProperties;
import edu.umd.cs.findbugs.annotations.SuppressWarnings;
import hudson.model.Hudson;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -128,7 +129,7 @@ public void shutdown() {
interrupt();
}

public static final int PORT = Integer.getInteger("hudson.udp",33848);
public static final int PORT = SystemProperties.getInteger("hudson.udp",33848);

private static final Logger LOGGER = Logger.getLogger(UDPBroadcastThread.class.getName());

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/Util.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson;

import jenkins.util.SystemProperties;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
Expand Down Expand Up @@ -1634,9 +1635,9 @@ public static Properties loadProperties(@Nonnull String properties) throws IOExc
/**
* On Unix environment that cannot run "ln", set this to true.
*/
public static boolean NO_SYMLINK = Boolean.getBoolean(Util.class.getName()+".noSymLink");
public static boolean NO_SYMLINK = SystemProperties.getBoolean(Util.class.getName()+".noSymLink");

public static boolean SYMLINK_ESCAPEHATCH = Boolean.getBoolean(Util.class.getName()+".symlinkEscapeHatch");
public static boolean SYMLINK_ESCAPEHATCH = SystemProperties.getBoolean(Util.class.getName()+".symlinkEscapeHatch");

/**
* The number of times we will attempt to delete files/directory trees
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/hudson/WebAppMain.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson;

import jenkins.util.SystemProperties;
import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
import com.thoughtworks.xstream.core.JVM;
import com.trilead.ssh2.util.IOUtils;
Expand Down Expand Up @@ -120,6 +121,8 @@ public Locale get() {

installLogger();

SystemProperties.initialize( event.getServletContext() );

final FileAndDescription describedHomeDir = getHomeDir(event);
home = describedHomeDir.file.getAbsoluteFile();
home.mkdirs();
Expand Down Expand Up @@ -335,9 +338,9 @@ public FileAndDescription getHomeDir(ServletContextEvent event) {

// next the system property
for (String name : HOME_NAMES) {
String sysProp = System.getProperty(name);
String sysProp = SystemProperties.getString(name);
if(sysProp!=null)
return new FileAndDescription(new File(sysProp.trim()),"System.getProperty(\""+name+"\")");
return new FileAndDescription(new File(sysProp.trim()),"SystemProperties.getProperty(\""+name+"\")");
}

// look at the env var next
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/cli/CLICommand.java
Expand Up @@ -29,6 +29,7 @@
import hudson.ExtensionPoint;
import hudson.cli.declarative.CLIMethod;
import hudson.ExtensionPoint.LegacyInstancesAreScopedToHudson;
import jenkins.util.SystemProperties;
import hudson.cli.declarative.OptionHandlerExtension;
import jenkins.model.Jenkins;
import hudson.remoting.Callable;
Expand Down Expand Up @@ -467,7 +468,7 @@ private GetSystemProperty(String name) {
}

public String call() throws IOException {
return System.getProperty(name);
return SystemProperties.getString(name);
}

private static final long serialVersionUID = 1L;
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/init/InitStrategy.java
Expand Up @@ -14,6 +14,7 @@
import java.util.logging.Logger;

import hudson.PluginManager;
import jenkins.util.SystemProperties;
import hudson.util.DirScanner;
import hudson.util.FileVisitor;
import hudson.util.Service;
Expand Down Expand Up @@ -74,7 +75,7 @@ private void listPluginFiles(PluginManager pm, String extension, Collection<File
* TODO: maven-hpi-plugin should inject its own InitStrategy instead of having this in the core.
*/
protected void getBundledPluginsFromProperty(final List<File> r) {
String hplProperty = System.getProperty("hudson.bundled.plugins");
String hplProperty = SystemProperties.getString("hudson.bundled.plugins");
if (hplProperty != null) {
for (String hplLocation : hplProperty.split(",")) {
File hpl = new File(hplLocation.trim());
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/lifecycle/Lifecycle.java
Expand Up @@ -25,6 +25,7 @@

import hudson.ExtensionPoint;
import hudson.Functions;
import jenkins.util.SystemProperties;
import hudson.Util;
import jenkins.model.Jenkins;

Expand Down Expand Up @@ -57,7 +58,7 @@ public abstract class Lifecycle implements ExtensionPoint {
public synchronized static Lifecycle get() {
if(INSTANCE==null) {
Lifecycle instance;
String p = System.getProperty("hudson.lifecycle");
String p = SystemProperties.getString("hudson.lifecycle");
if(p!=null) {
try {
ClassLoader cl = Jenkins.getInstance().getPluginManager().uberClassLoader;
Expand Down Expand Up @@ -119,7 +120,7 @@ public void verifyRestartable() throws RestartNotSupportedException {
* to a newer version.
*/
public File getHudsonWar() {
String war = System.getProperty("executable-war");
String war = SystemProperties.getString("executable-war");
if(war!=null && new File(war).exists())
return new File(war);
return null;
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/lifecycle/WindowsInstallerLink.java
Expand Up @@ -34,6 +34,7 @@
import jenkins.model.Jenkins;
import hudson.AbortException;
import hudson.Extension;
import jenkins.util.SystemProperties;
import hudson.util.StreamTaskListener;
import hudson.util.jna.DotNet;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -257,14 +258,14 @@ public static WindowsInstallerLink registerIfApplicable() {

// this system property is set by the launcher when we run "java -jar jenkins.war"
// and this is how we know where is jenkins.war.
String war = System.getProperty("executable-war");
String war = SystemProperties.getString("executable-war");
if(war!=null && new File(war).exists()) {
WindowsInstallerLink link = new WindowsInstallerLink(new File(war));

// in certain situations where we know the user is just trying Jenkins (like when Jenkins is launched
// from JNLP), also put this link on the navigation bar to increase
// visibility
if(System.getProperty(WindowsInstallerLink.class.getName()+".prominent")!=null)
if(SystemProperties.getString(WindowsInstallerLink.class.getName()+".prominent")!=null)
Jenkins.getInstance().getActions().add(link);

return link;
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/AbstractBuild.java
Expand Up @@ -30,6 +30,7 @@
import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
import jenkins.util.SystemProperties;
import hudson.console.ModelHyperlinkNote;
import hudson.model.Fingerprint.BuildPtr;
import hudson.model.Fingerprint.RangeSet;
Expand Down Expand Up @@ -106,7 +107,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
/**
* Set if we want the blame information to flow from upstream to downstream build.
*/
private static final boolean upstreamCulprits = Boolean.getBoolean("hudson.upstreamCulprits");
private static final boolean upstreamCulprits = SystemProperties.getBoolean("hudson.upstreamCulprits");

/**
* Name of the agent this project was built on.
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/model/Computer.java
Expand Up @@ -30,6 +30,7 @@
import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher.ProcStarter;
import jenkins.util.SystemProperties;
import hudson.Util;
import hudson.cli.declarative.CLIMethod;
import hudson.cli.declarative.CLIResolver;
Expand Down Expand Up @@ -1280,7 +1281,7 @@ public List<String> call() throws IOException {

private static class GetFallbackName extends MasterToSlaveCallable<String,IOException> {
public String call() throws IOException {
return System.getProperty("host.name");
return SystemProperties.getString("host.name");
}
private static final long serialVersionUID = 1L;
}
Expand Down Expand Up @@ -1707,7 +1708,7 @@ public long getWhen() {
/**
* @since 1.532
*/
public static final Permission EXTENDED_READ = new Permission(PERMISSIONS,"ExtendedRead", Messages._Computer_ExtendedReadPermission_Description(), CONFIGURE, Boolean.getBoolean("hudson.security.ExtendedReadPermission"), new PermissionScope[]{PermissionScope.COMPUTER});
public static final Permission EXTENDED_READ = new Permission(PERMISSIONS,"ExtendedRead", Messages._Computer_ExtendedReadPermission_Description(), CONFIGURE, SystemProperties.getBoolean("hudson.security.ExtendedReadPermission"), new PermissionScope[]{PermissionScope.COMPUTER});
public static final Permission DELETE = new Permission(PERMISSIONS,"Delete", Messages._Computer_DeletePermission_Description(), Permission.DELETE, PermissionScope.COMPUTER);
public static final Permission CREATE = new Permission(PERMISSIONS,"Create", Messages._Computer_CreatePermission_Description(), Permission.CREATE, PermissionScope.JENKINS);
public static final Permission DISCONNECT = new Permission(PERMISSIONS,"Disconnect", Messages._Computer_DisconnectPermission_Description(), Jenkins.ADMINISTER, PermissionScope.COMPUTER);
Expand Down

0 comments on commit cf64ba0

Please sign in to comment.