Skip to content
Permalink
Browse files

[FIXED JENKINS-8446] Implementing via update to patch attached to JIR…

…A item.
  • Loading branch information...
slide authored and kohsuke committed Jun 29, 2011
1 parent c49e750 commit 7fdb8a82daad4908b97d20685305643bc0072617
Showing with 83 additions and 1 deletion.
  1. +29 −0 core/src/main/java/hudson/model/Job.java
  2. +54 −1 core/src/main/java/jenkins/model/Jenkins.java
@@ -27,6 +27,7 @@
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;

import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import hudson.EnvVars;
import hudson.ExtensionPoint;
import hudson.PermalinkList;
import hudson.Extension;
@@ -73,6 +74,9 @@
import java.util.SortedMap;
import java.util.LinkedList;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;

import jenkins.model.Jenkins;
@@ -635,6 +639,31 @@ public Object getDynamic(String token, StaplerRequest req,
* @see RunMap
*/
protected File getBuildDir() {
// 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("JENKINS_BUILDS");
if(value!=null && value.trim().length()>0)
return new File(value.trim());
// look at one more place. See issue #1314
value = (String) iniCtxt.lookup("JENKINS_BUILDS");
if(value!=null && value.trim().length()>0)
return new File(value.trim() + "/" + getSearchName());
} catch (NamingException e) {
// ignore
}

// finally check the system property
String sysProp = System.getProperty("JENKINS_BUILDS");
if(sysProp!=null)
return new File(sysProp.trim() + "/" + getSearchName());

// look at the env var next
String env = EnvVars.masterEnvVars.get("JENKINS_BUILDS");
if(env!=null)
return new File(env.trim() + "/" + getSearchName()).getAbsoluteFile();

return new File(getRootDir(), "builds");
}

@@ -30,6 +30,7 @@
import hudson.BulkChange;
import hudson.DNSMultiCast;
import hudson.DescriptorExtensionList;
import hudson.EnvVars;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
@@ -175,6 +176,9 @@
import org.xml.sax.InputSource;

import javax.crypto.SecretKey;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -305,6 +309,11 @@
*/
private volatile SecurityRealm securityRealm = SecurityRealm.NO_AUTHENTICATION;

/**
* Root directory for the workspaces.
*/
private String configuredWorkspaceRoot = null;

/**
* Message displayed in the top page.
*/
@@ -1687,8 +1696,52 @@ public File getRootDir() {
return root;
}

private String getConfiguredWorkspaceRoot() {
if (configuredWorkspaceRoot == null) {
try {
InitialContext iniCtxt = new InitialContext();
Context env = (Context) iniCtxt.lookup("java:comp/env");
String value = (String) env.lookup("JENKINS_WORKSPACES");
if(value!=null && value.trim().length()>0) {
configuredWorkspaceRoot = value.trim();
return configuredWorkspaceRoot;
}
// look at one more place. See issue #1314
value = (String) iniCtxt.lookup("JENKINS_WORKSPACES");
if(value!=null && value.trim().length()>0) {
configuredWorkspaceRoot = value.trim();
return configuredWorkspaceRoot;
}
} catch (NamingException e) {
// ignore
}

// finally check the system property
String sysProp = System.getProperty("JENKINS_WORKSPACES");
if(sysProp!=null) {
configuredWorkspaceRoot = sysProp.trim();
return configuredWorkspaceRoot;
}

// look at the env var next
String env = EnvVars.masterEnvVars.get("JENKINS_WORKSPACES");
if(env!=null) {
configuredWorkspaceRoot = env.trim();
return configuredWorkspaceRoot;
}

//not set
configuredWorkspaceRoot = "";
}
return configuredWorkspaceRoot;
}

public FilePath getWorkspaceFor(TopLevelItem item) {
return new FilePath(new File(item.getRootDir(), WORKSPACE_DIRNAME));
if(getConfiguredWorkspaceRoot().equals("")) {
return new FilePath(new File(item.getRootDir(), WORKSPACE_DIRNAME));
} else {
return new FilePath(new File(getConfiguredWorkspaceRoot() + "/" + item.getName(), WORKSPACE_DIRNAME));
}
}

public FilePath getRootPath() {

0 comments on commit 7fdb8a8

Please sign in to comment.
You can’t perform that action at this time.