Skip to content

Commit

Permalink
[JENKINS-45109] Also adjust StepNode.getTypeDisplayName to reflect th…
Browse files Browse the repository at this point in the history
…e delegate descriptor in case of a metastep.
  • Loading branch information
jglick committed Jun 24, 2017
1 parent a30d429 commit 8ecadd6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Expand Up @@ -25,6 +25,7 @@
package org.jenkinsci.plugins.workflow.cps.nodes;

import hudson.model.Action;
import hudson.model.Descriptor;
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
import org.jenkinsci.plugins.workflow.graph.AtomNode;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
Expand All @@ -35,6 +36,7 @@
import java.util.Collections;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.jenkinsci.plugins.structs.SymbolLookup;
import org.jenkinsci.plugins.structs.describable.DescribableModel;
import org.jenkinsci.plugins.structs.describable.DescribableParameter;
import org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable;
Expand Down Expand Up @@ -77,10 +79,33 @@ protected Object readResolve() throws ObjectStreamException {
return super.readResolve();
}

static @CheckForNull String effectiveDisplayName(@Nonnull org.jenkinsci.plugins.workflow.graph.StepNode node) {
StepDescriptor d = node.getDescriptor();
if (d == null) {
return null;
}
if (d.isMetaStep()) {
DescribableParameter p = new DescribableModel<>(d.clazz).getFirstRequiredParameter();
if (p != null) {
Object arg = ArgumentsAction.getArguments((FlowNode) node).get(p.getName());
if (arg instanceof UninstantiatedDescribable) {
String symbol = ((UninstantiatedDescribable) arg).getSymbol();
if (symbol != null) {
Descriptor<?> descriptor = SymbolLookup.get().findDescriptor(p.getErasedType(), symbol);
if (descriptor != null) {
return descriptor.getDisplayName();
}
} // TODO to support $class it might be better to go through DescribableModel.resolveClass, if it were public; cf. discussion in JENKINS-31582
}
}
}
return d.getDisplayName();
}

@Override
protected String getTypeDisplayName() {
StepDescriptor d = getDescriptor();
return d!=null ? d.getDisplayName() : descriptorId;
String n = effectiveDisplayName(this);
return n != null ? n : descriptorId;
}

static @CheckForNull String effectiveFunctionName(@Nonnull org.jenkinsci.plugins.workflow.graph.StepNode node) {
Expand Down
Expand Up @@ -66,7 +66,7 @@ public boolean isBody() {
}

public String getStepName() {
StepDescriptor d = getDescriptor();
return d!=null ? d.getDisplayName() : descriptorId;
String n = StepAtomNode.effectiveDisplayName(this);
return n != null ? n : descriptorId;
}
}
Expand Up @@ -27,8 +27,10 @@
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import hudson.model.Result;
import hudson.tasks.junit.JUnitResultArchiver;
import java.util.List;
import static org.hamcrest.Matchers.*;
import org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner;
Expand Down Expand Up @@ -62,13 +64,15 @@ public class StepNodeTest {
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("step"));
assertThat(coreStepNodes, hasSize(1));
assertEquals("junit", coreStepNodes.get(0).getDisplayFunctionName());
assertEquals(r.jenkins.getDescriptor(JUnitResultArchiver.class).getDisplayName(), coreStepNodes.get(0).getDisplayName());
List<FlowNode> coreWrapperStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), Predicates.and(new NodeStepTypePredicate("wrap"), new Predicate<FlowNode>() {
@Override public boolean apply(FlowNode n) {
return n instanceof StepStartNode && !((StepStartNode) n).isBody();
}
}));
assertThat(coreWrapperStepNodes, hasSize(1));
assertEquals("configFileProvider", coreWrapperStepNodes.get(0).getDisplayFunctionName());
assertEquals(r.jenkins.getDescriptor(ConfigFileBuildWrapper.class).getDisplayName() + " : Start", coreWrapperStepNodes.get(0).getDisplayName());
r.assertLogContains("[Pipeline] junit", b);
r.assertLogContains("[Pipeline] configFileProvider", b);
r.assertLogContains("[Pipeline] // configFileProvider", b);
Expand Down

0 comments on commit 8ecadd6

Please sign in to comment.