Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-8446] Implementing via update to patch attached to JIR…
…A item.
  • Loading branch information
slide authored and kohsuke committed Jul 6, 2011
1 parent c49e750 commit 7fdb8a8
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
29 changes: 29 additions & 0 deletions core/src/main/java/hudson/model/Job.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}

Expand Down
55 changes: 54 additions & 1 deletion core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -305,6 +309,11 @@ public class Jenkins extends AbstractCIBase implements ModifiableItemGroup<TopLe
*/
private volatile SecurityRealm securityRealm = SecurityRealm.NO_AUTHENTICATION;

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

/**
* Message displayed in the top page.
*/
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 7fdb8a8

Please sign in to comment.