Skip to content

Commit

Permalink
[JENKINS-8446] it's better to let those directories setting be a part…
Browse files Browse the repository at this point in the history
… of JENKINS_HOME rather than being independent configuration properties, since they aren't orthogonal.
  • Loading branch information
kohsuke committed Jul 6, 2011
1 parent 7fdb8a8 commit 68d4d22
Show file tree
Hide file tree
Showing 199 changed files with 205 additions and 213 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=rfe>
Allow build directories and workspace directories in $JENKINS_HOME to be placed elsewhere.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-8446">issue 8446</a>)
<li class=rfe>
Mac installer update: set file permissions to be more in line with Mac conventions.
(<a href="https://github.com/jenkinsci/jenkins/pull/188">pull request 188</a>)
Expand Down
88 changes: 27 additions & 61 deletions core/src/main/java/hudson/model/Job.java
@@ -1,7 +1,7 @@
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Martin Eigenbrodt, Matthew R. Harrah, Red Hat, Inc., Stephen Connolly, Tom Huybrechts
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Martin Eigenbrodt, Matthew R. Harrah, Red Hat, Inc., Stephen Connolly, Tom Huybrechts, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,19 +23,15 @@
*/
package hudson.model;

import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;

import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import hudson.EnvVars;
import hudson.Extension;
import hudson.ExtensionPoint;
import hudson.PermalinkList;
import hudson.Extension;
import hudson.cli.declarative.CLIResolver;
import hudson.model.Descriptor.FormException;
import hudson.model.PermalinkProjectAction.Permalink;
import hudson.model.Fingerprint.RangeSet;
import hudson.model.Fingerprint.Range;
import hudson.model.Fingerprint.RangeSet;
import hudson.model.PermalinkProjectAction.Permalink;
import hudson.search.QuickSilver;
import hudson.search.SearchIndex;
import hudson.search.SearchIndexBuilder;
Expand All @@ -49,40 +45,18 @@
import hudson.util.CopyOnWriteList;
import hudson.util.DataSetBuilder;
import hudson.util.DescribableList;
import hudson.util.Graph;
import hudson.util.IOException2;
import hudson.util.RunList;
import hudson.util.ShiftedCategoryAxis;
import hudson.util.StackedAreaRenderer2;
import hudson.util.TextFile;
import hudson.util.Graph;
import hudson.widgets.HistoryWidget;
import hudson.widgets.Widget;
import hudson.widgets.HistoryWidget.Adapter;

import java.awt.Color;
import java.awt.Paint;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
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 hudson.widgets.Widget;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import net.sf.json.JSONException;

import net.sf.json.JSONObject;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
Expand All @@ -94,12 +68,29 @@
import org.jfree.data.category.CategoryDataset;
import org.jfree.ui.RectangleInsets;
import org.jvnet.localizer.Localizable;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.stapler.StaplerOverridable;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;

import javax.servlet.ServletException;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;

import static javax.servlet.http.HttpServletResponse.*;

/**
* A job is an runnable entity under the monitoring of Hudson.
Expand Down Expand Up @@ -639,32 +630,7 @@ 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");
return Jenkins.getInstance().getBuildDirFor(this);
}

/**
Expand Down
84 changes: 35 additions & 49 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -26,11 +26,11 @@
package jenkins.model;

import antlr.ANTLRException;
import com.google.common.collect.ImmutableMap;
import com.thoughtworks.xstream.XStream;
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 @@ -176,9 +176,6 @@
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 @@ -310,9 +307,20 @@ public class Jenkins extends AbstractCIBase implements ModifiableItemGroup<TopLe
private volatile SecurityRealm securityRealm = SecurityRealm.NO_AUTHENTICATION;

/**
* Root directory for the workspaces.
* Root directory for the workspaces. This value will be variable-expanded against
* job name and JENKINS_HOME.
*
* @see #getWorkspaceFor(TopLevelItem)
*/
private String workspaceDir = "${ITEM_ROOTDIR}/"+WORKSPACE_DIRNAME;

/**
* Root directory for the workspaces. This value will be variable-expanded against
* job name and JENKINS_HOME.
*
* @see #getBuildDirFor(Job)
*/
private String configuredWorkspaceRoot = null;
private String buildsDir = "${ITEM_ROOTDIR}/builds";

/**
* Message displayed in the top page.
Expand Down Expand Up @@ -1696,52 +1704,27 @@ 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
}
public FilePath getWorkspaceFor(TopLevelItem item) {
return new FilePath(expandVariablesForDirectory(workspaceDir, item));
}

// 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 File getBuildDirFor(Job job) {
return expandVariablesForDirectory(buildsDir, job);
}

public FilePath getWorkspaceFor(TopLevelItem item) {
if(getConfiguredWorkspaceRoot().equals("")) {
return new FilePath(new File(item.getRootDir(), WORKSPACE_DIRNAME));
} else {
return new FilePath(new File(getConfiguredWorkspaceRoot() + "/" + item.getName(), WORKSPACE_DIRNAME));
}
private File expandVariablesForDirectory(String base, Item item) {
return new File(Util.replaceMacro(base, ImmutableMap.of(
"JENKINS_HOME", getRootDir().getPath(),
"ITEM_ROOTDIR", item.getRootDir().getPath(),
"ITEM_FULLNAME", item.getFullName())));
}

public String getRawWorkspaceDir() {
return workspaceDir;
}

public String getRawBuildsDir() {
return buildsDir;
}

public FilePath getRootPath() {
Expand Down Expand Up @@ -2379,6 +2362,9 @@ public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp

JSONObject json = req.getSubmittedForm();

workspaceDir = json.getString("rawWorkspaceDir");
buildsDir = json.getString("rawBuildsDir");

// keep using 'useSecurity' field as the main configuration setting
// until we get the new security implementation working
// useSecurity = null;
Expand Down
@@ -1,26 +1,26 @@
# The MIT License
#
# Copyright (c) 2004-2009, Sun Microsystems, Inc., Seiji Sogabe, Simon Wiest
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

Are\ you\ sure\ about\ restarting\ Jenkins?\ Jenkins\ will\ restart\ once\ all\ running\ jobs\ are\ finished.=\
Möchten Sie Jenkins wirklich neu starten? Jenkins wird neu starten, \
sobald alle laufenden Jobs abgeschlossen wurden.
Yes=Ja
# The MIT License
#
# Copyright (c) 2004-2009, Sun Microsystems, Inc., Seiji Sogabe, Simon Wiest
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

Are\ you\ sure\ about\ restarting\ Jenkins?\ Jenkins\ will\ restart\ once\ all\ running\ jobs\ are\ finished.=\
M�chten Sie Jenkins wirklich neu starten? Jenkins wird neu starten, \
sobald alle laufenden Jobs abgeschlossen wurden.
Yes=Ja
@@ -1,27 +1,27 @@
# The MIT License
#
# Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe, Simon Wiest
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

Jenkins\ Login=Jenkins Anmeldung
Access\ Denied=Zugriff verweigert
User=Benutzer
Password=Kennwort
login=Anmelden
# The MIT License
#
# Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe, Simon Wiest
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

Jenkins\ Login=Jenkins Anmeldung
Access\ Denied=Zugriff verweigert
User=Benutzer
Password=Kennwort
login=Anmelden

0 comments on commit 68d4d22

Please sign in to comment.