Package org.jenkinsci.plugins.workflow.cps.nodes

Source Code of org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode

package org.jenkinsci.plugins.workflow.cps.nodes;

import hudson.model.Action;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.workflow.actions.BodyInvocationAction;
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
import org.jenkinsci.plugins.workflow.graph.BlockStartNode;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;

import java.util.Collections;

/**
* {@link BlockStartNode} for executing {@link Step} with body closure.
*
* @author Kohsuke Kawaguchi
*/
public class StepStartNode extends BlockStartNode implements StepNode {
    private final String descriptorId;

    private transient StepDescriptor descriptor;

    public StepStartNode(CpsFlowExecution exec, StepDescriptor d, FlowNode parent) {
        super(exec, exec.iotaStr(), parent);
        this.descriptorId = d!=null ? d.getId() : null;

        // we use SimpleXStreamFlowNodeStorage, which uses XStream, so
        // constructor call is always for brand-new FlowNode that has not existed anywhere.
        // such nodes always have empty actions
        setActions(Collections.<Action>emptyList());
    }

    public StepDescriptor getDescriptor() {
        if (descriptor == null) {
            Jenkins j = Jenkins.getInstance();
            if (j != null) {
                descriptor = (StepDescriptor) j.getDescriptor(descriptorId);
            }
        }
        return descriptor;
    }

    @Override
    protected String getTypeDisplayName() {
        return getStepName() + (isBody() ?" : Body":"") + " : Start";
    }

    public boolean isBody() {
        return getAction(BodyInvocationAction.class)!=null;
    }

    public String getStepName() {
        StepDescriptor d = getDescriptor();
        return d!=null ? d.getDisplayName() : descriptorId;
    }
}
TOP

Related Classes of org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.