~ubuntu-branches/ubuntu/saucy/jenkins/saucy

« back to all changes in this revision

Viewing changes to core/src/main/java/hudson/matrix/MatrixRun.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-01-10 09:50:50 UTC
  • mfrom: (5.1.10 experimental)
  • Revision ID: package-import@ubuntu.com-20130110095050-kj8xuw20gcfh62k3
Tags: 1.480.2+dfsg-1~exp1
* New upstream release (Closes: #696816, #697617):
  - d/control: Added new BD on libjbcrypt-java.
  - d/control: Versioned BD jenkins-winstone >= 0.9.10-jenkins-40.
  - d/control: Versioned BD jenkins-trilead-ssh2 >= 214-jenkins-1.
  - Fixes the following security vulnerabilities:
    CVE-2012-6072, CVE-2012-6073, CVE-2012-6072, CVE-2013-0158.
* Tidied lintian warnings.
* Bumped Standards-Version: 3.9.4, no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 */
24
24
package hudson.matrix;
25
25
 
 
26
import hudson.EnvVars;
26
27
import hudson.FilePath;
27
28
import hudson.model.AbstractBuild;
 
29
import hudson.model.Build;
 
30
import hudson.model.Node;
28
31
import hudson.slaves.WorkspaceList;
29
32
import hudson.slaves.WorkspaceList.Lease;
30
 
import static hudson.matrix.MatrixConfiguration.useShortWorkspaceName;
31
 
import hudson.model.Build;
32
 
import hudson.model.Node;
33
33
import org.kohsuke.stapler.Ancestor;
34
34
import org.kohsuke.stapler.Stapler;
35
35
import org.kohsuke.stapler.StaplerRequest;
143
143
 
144
144
    @Override
145
145
    public void run() {
146
 
        run(new RunnerImpl());
 
146
        execute(new MatrixRunExecution());
147
147
    }
148
148
 
149
 
    protected class RunnerImpl extends Build<MatrixConfiguration,MatrixRun>.RunnerImpl {
 
149
    private class MatrixRunExecution extends BuildExecution {
 
150
        protected Lease getParentWorkspaceLease(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
 
151
            MatrixProject mp = getParent().getParent();
 
152
 
 
153
            String customWorkspace = mp.getCustomWorkspace();
 
154
            if (customWorkspace != null) {
 
155
                // we allow custom workspaces to be concurrently used between jobs.
 
156
                return Lease.createDummyLease(n.getRootPath().child(getEnvironment(listener).expand(customWorkspace)));
 
157
            }
 
158
            return wsl.allocate(n.getWorkspaceFor(mp), getParentBuild());
 
159
        }
 
160
 
150
161
        @Override
151
162
        protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
152
 
            // Map current combination to a directory subtree, e.g. 'axis1=a,axis2=b' to 'axis1/a/axis2/b'.
153
 
            String subtree;
154
 
            if(useShortWorkspaceName) {
155
 
                subtree = getParent().getDigestName(); 
156
 
            } else {
157
 
                subtree = getParent().getCombination().toString('/','/');
158
 
            }
159
 
            
160
 
            String customWorkspace = getParent().getParent().getCustomWorkspace();
161
 
            if (customWorkspace != null) {
162
 
                // Use custom workspace as defined in the matrix project settings.
163
 
                FilePath ws = n.getRootPath().child(getEnvironment(listener).expand(customWorkspace));
164
 
                // We allow custom workspaces to be used concurrently between jobs.
165
 
                return Lease.createDummyLease(ws.child(subtree));
166
 
            } else {
167
 
                // Use default workspace as assigned by Hudson.
168
 
                Node node = getBuiltOn();
169
 
                FilePath ws = node.getWorkspaceFor(getParent().getParent());
170
 
                // Allocate unique workspace (not to be shared between jobs and runs).
171
 
                return wsl.allocate(ws.child(subtree));
172
 
            }
 
163
            MatrixProject mp = getParent().getParent();
 
164
 
 
165
            // lock is done at the parent level, so that concurrent MatrixProjects get respective workspace,
 
166
            // but within MatrixConfigurations that belong to the same MatrixBuild.
 
167
            // if MatrixProject is configured with custom workspace, we assume that the user knows what he's doing
 
168
            // and try not to append unique random suffix.
 
169
            Lease baseLease = getParentWorkspaceLease(n,wsl);
 
170
 
 
171
            // resolve the relative path against the parent workspace, which needs locking
 
172
            FilePath baseDir = baseLease.path;
 
173
 
 
174
            // prepare variables that can be used in the child workspace setting
 
175
            EnvVars env = getEnvironment(listener);
 
176
            env.put("COMBINATION",getParent().getCombination().toString('/','/'));  // e.g., "axis1/a/axis2/b"
 
177
            env.put("SHORT_COMBINATION",getParent().getDigestName());               // e.g., "0fbcab35"
 
178
            env.put("PARENT_WORKSPACE",baseDir.getRemote());
 
179
            env.putAll(getBuildVariables());
 
180
 
 
181
            // child workspace need no individual locks, whether or not we use custom workspace
 
182
            String childWs = mp.getChildCustomWorkspace();
 
183
            return Lease.createLinkedDummyLease(baseDir.child(env.expand(childWs)),baseLease);
173
184
        }
174
185
    }
175
186
}