All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.matrix.MatrixRun Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2004-2009 Oracle Corporation.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: 
*
*    Kohsuke Kawaguchi
 *     
 *
 *******************************************************************************/ 

package hudson.matrix;

import hudson.FilePath;
import hudson.slaves.WorkspaceList;
import hudson.slaves.WorkspaceList.Lease;
import static hudson.matrix.MatrixConfiguration.useShortWorkspaceName;
import hudson.model.Build;
import hudson.model.Node;
import org.kohsuke.stapler.Ancestor;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;

import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * Execution of {@link MatrixConfiguration}.
 *
 * @author Kohsuke Kawaguchi
 */
public class MatrixRun extends Build {
    public MatrixRun(MatrixConfiguration job) throws IOException {
        super(job);
    }

    public MatrixRun(MatrixConfiguration job, Calendar timestamp) {
        super(job, timestamp);
    }

    public MatrixRun(MatrixConfiguration project, File buildDir) throws IOException {
        super(project, buildDir);
    }

    @Override
    public String getUpUrl() {
        StaplerRequest req = Stapler.getCurrentRequest();
        if(req!=null) {
            List ancs = req.getAncestors();
            for( int i=1; i ancs = req.getAncestors();
            for( int i=1; i vars) {
        AxisList axes = getParent().getParent().getAxes();
        for (Map.Entry e : getParent().getCombination().entrySet()) {
            Axis a = axes.find(e.getKey());
            if (a!=null) {
                a.addBuildVariable(e.getValue(),vars);
            }else {
                vars.put(e.getKey(), e.getValue());
            }
        }
    }

    /**
     * If the parent {@link MatrixBuild} is kept, keep this record too.
     */
    @Override
    public String getWhyKeepLog() {
        MatrixBuild pb = getParentBuild();
        if(pb!=null && pb.getWhyKeepLog()!=null)
            return Messages.MatrixRun_KeptBecauseOfParent(pb);
        return super.getWhyKeepLog();
    }

    @Override
    public MatrixConfiguration getParent() {// don't know why, but javac wants this
        return super.getParent();
    }

    @Override
    public void run() {
        run(new RunnerImpl());
    }

    protected class RunnerImpl extends Build.RunnerImpl {
        @Override
        protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
            // Map current combination to a directory subtree, e.g. 'axis1=a,axis2=b' to 'axis1/a/axis2/b'.
            String subtree;
            if(useShortWorkspaceName) {
                subtree = getParent().getDigestName(); 
            } else {
                subtree = getParent().getCombination().toString('/','/', true);
            }
            
            String customWorkspace = getParent().getParent().getCustomWorkspace();
            if (customWorkspace != null) {
                // Use custom workspace as defined in the matrix project settings.
                FilePath ws = n.getRootPath().child(getEnvironment(listener).expand(customWorkspace));
                // We allow custom workspaces to be used concurrently between jobs.
                return Lease.createDummyLease(ws.child(subtree));
            } else {   
                // Use default workspace as assigned by Hudson.
                Node node = getBuiltOn();
                FilePath ws = node.getWorkspaceFor(getParent().getParent());
                // Allocate unique workspace (not to be shared between jobs and runs).
                return wsl.allocate(ws.child(subtree));
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy