Skip to content
Permalink
Browse files

[JENKINS-45101] More argumentsToString implementations.

  • Loading branch information...
jglick committed Jun 30, 2017
1 parent b5b30ec commit c77b341459e9ae2803ec7df00fc3732a3965d2ee
@@ -138,6 +138,27 @@
return Collections.emptySet();
}

@Override public String argumentsToString(Map<String, Object> namedArgs) {
Object overrides = namedArgs.get("overrides");
if (overrides instanceof List) {
StringBuilder b = new StringBuilder();
for (Object pair : (List) overrides) {
if (pair instanceof String) {
int idx = ((String) pair).indexOf('=');
if (idx > 0) {
if (b.length() > 0) {
b.append(", ");
}
b.append(((String) pair).substring(0, idx));
}
}
}
return b.toString();
} else {
return null;
}
}

}

}
@@ -28,6 +28,7 @@
import hudson.Util;
import hudson.model.TaskListener;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import jenkins.plugins.mailer.tasks.MimeMessageBuilder;

@@ -114,6 +115,11 @@ public StepExecution start(StepContext context) throws Exception {
@Override public Set<? extends Class<?>> getRequiredContext() {
return Collections.singleton(TaskListener.class);
}

@Override public String argumentsToString(Map<String, Object> namedArgs) {
Object subject = namedArgs.get("subject");
return subject instanceof String ? (String) subject : null;
}
}

/**
@@ -29,6 +29,7 @@
import hudson.FilePath;
import hudson.slaves.WorkspaceList;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
@@ -76,6 +77,10 @@ public boolean isTmp() {
return Collections.singleton(FilePath.class);
}

@Override public String argumentsToString(Map<String, Object> namedArgs) {
return null; // "true" is not a reasonable description
}

}

// TODO use 1.652 use WorkspaceList.tempDir
@@ -151,5 +151,7 @@ public ListBoxModel doFillUnitItems() {
return Collections.singleton(TaskListener.class);
}

// TODO argumentsToString should perhaps return "3m" etc.

}
}
@@ -81,6 +81,8 @@ public ListBoxModel doFillUnitItems() {
return Collections.singleton(TaskListener.class);
}

// TODO argumentsToString as for SleepStep

}

private static final long serialVersionUID = 1L;
@@ -36,6 +36,7 @@
import hudson.tools.ToolDescriptor;
import hudson.tools.ToolInstallation;
import hudson.util.ListBoxModel;
import java.util.Map;

import javax.annotation.CheckForNull;

@@ -122,6 +123,11 @@ public ListBoxModel doFillNameItems(@QueryParameter String type) {
return ImmutableSet.of(TaskListener.class, EnvVars.class, Node.class);
}

@Override public String argumentsToString(Map<String, Object> namedArgs) {
Object name = namedArgs.get("name");
return name instanceof String ? (String) name : null;
}

}

public static final class Execution extends SynchronousNonBlockingStepExecution<String> {
@@ -28,6 +28,7 @@
import hudson.FilePath;
import hudson.Util;
import java.util.Collections;
import java.util.Map;
import java.util.Set;


@@ -79,6 +80,11 @@ public String getEncoding() {
return Collections.singleton(FilePath.class);
}

@Override public String argumentsToString(Map<String, Object> namedArgs) {
Object file = namedArgs.get("file");
return file instanceof String ? (String) file : null;
}

}

public static final class Execution extends SynchronousNonBlockingStepExecution<Void> {
@@ -30,6 +30,7 @@
import hudson.Util;
import hudson.model.Run;
import hudson.model.TaskListener;
import java.util.Map;
import java.util.Set;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.workflow.flow.StashManager;
@@ -130,6 +131,11 @@ public boolean isAllowEmpty() {
return ImmutableSet.of(Run.class, FilePath.class, TaskListener.class);
}

@Override public String argumentsToString(Map<String, Object> namedArgs) {
Object name = namedArgs.get("name");
return name instanceof String ? (String) name : null;
}

}

}
@@ -24,15 +24,24 @@

package org.jenkinsci.plugins.workflow.steps;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import hudson.Functions;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.hamcrest.Matchers;
import org.jenkinsci.plugins.workflow.actions.ArgumentsAction;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner;
import org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -64,6 +73,13 @@
story.j.assertLogContains(Functions.isWindows() ? "inside CUSTOM=override NOVEL=val BUILD_TAG=custom NULLED= FOOPATH=C:\\ball;C:\\foos;" : "inside CUSTOM=override NOVEL=val BUILD_TAG=custom NULLED= FOOPATH=/opt/ball:/opt/foos:", b);
story.j.assertLogContains("groovy NULLED=null", b);
story.j.assertLogContains("outside CUSTOM=initial NOVEL= NULLED=outside", b);
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), Predicates.and(new NodeStepTypePredicate("withEnv"), new Predicate<FlowNode>() {
@Override public boolean apply(FlowNode n) {
return n instanceof StepStartNode && !((StepStartNode) n).isBody();
}
}));
assertThat(coreStepNodes, Matchers.hasSize(1));
assertEquals("CUSTOM, NOVEL, BUILD_TAG, NULLED, FOOPATH+BALL", ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));
}
});
}
@@ -24,12 +24,20 @@
package org.jenkinsci.plugins.workflow.steps;

import hudson.model.Result;
import java.util.List;
import javax.mail.Message;
import javax.mail.internet.MimeMultipart;
import org.hamcrest.Matchers;
import org.jenkinsci.plugins.workflow.actions.ArgumentsAction;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner;
import org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
@@ -80,7 +88,10 @@ public void test_send() throws Exception {
WorkflowJob job = r.jenkins.createProject(WorkflowJob.class, "workflow");
job.setDefinition(new CpsFlowDefinition("mail(to: 'tom.abcd@jenkins.org', subject: 'Hello friend', body: 'Missing you!');", true));

r.assertBuildStatusSuccess(job.scheduleBuild2(0));
WorkflowRun b = r.assertBuildStatusSuccess(job.scheduleBuild2(0));
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("mail"));
assertThat(coreStepNodes, Matchers.hasSize(1));
assertEquals("Hello friend", ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));

Mailbox mailbox = Mailbox.get("tom.abcd@jenkins.org");
Assert.assertEquals(1, mailbox.getNewMessageCount());
@@ -26,8 +26,17 @@

import hudson.FilePath;
import hudson.slaves.WorkspaceList;
import java.util.List;
import org.hamcrest.Matchers;
import org.jenkinsci.plugins.workflow.actions.ArgumentsAction;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner;
import org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;
@@ -50,7 +59,11 @@ private static FilePath tempDir(FilePath ws) {
@Test public void tmp() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {echo \"tmp='${pwd tmp: true}'\"}", true));
r.assertLogContains("tmp='" + tempDir(r.jenkins.getWorkspaceFor(p)) + "'", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("tmp='" + tempDir(r.jenkins.getWorkspaceFor(p)) + "'", b);
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("pwd"));
assertThat(coreStepNodes, Matchers.hasSize(1));
assertEquals(null, ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));
}

}
@@ -25,10 +25,18 @@
package org.jenkinsci.plugins.workflow.steps;

import hudson.Functions;
import java.util.List;
import org.hamcrest.Matchers;
import org.jenkinsci.plugins.workflow.actions.ArgumentsAction;

import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner;
import org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
@@ -48,8 +56,12 @@
" text = text.toUpperCase()\n" +
" writeFile file: 'f2', text: text\n" +
(win ? " bat 'type f2'\n" : " sh 'cat f2'\n") +
"}"));
r.assertLogContains("HELLO", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
"}", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("HELLO", b);
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("writeFile"));
assertThat(coreStepNodes, Matchers.hasSize(1));
assertEquals("f2", ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));
}

@Test
@@ -34,10 +34,16 @@
import java.util.List;
import java.util.Set;
import jenkins.model.Jenkins;
import org.hamcrest.Matchers;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.structs.SymbolLookup;
import org.jenkinsci.plugins.workflow.actions.ArgumentsAction;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner;
import org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import static org.junit.Assert.*;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -72,7 +78,11 @@
p.setDefinition(new CpsFlowDefinition("node {def home = tool name: '" + name + "', type: '" + type + "'; def settings = readFile($/$home/conf/settings.xml/$).split(); echo settings[-1]}",
true));

r.assertLogContains("</settings>", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("</settings>", b);
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("tool"));
assertThat(coreStepNodes, Matchers.hasSize(1));
assertEquals(name, ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));
}

@Test public void toolWithSymbol() throws Exception {
@@ -24,8 +24,14 @@

package org.jenkinsci.plugins.workflow.support.steps.stash;

import java.util.List;
import org.hamcrest.Matchers;
import org.jenkinsci.plugins.workflow.actions.ArgumentsAction;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.flow.StashManager;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner;
import org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
@@ -109,5 +115,8 @@
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("Stashed 0 file(s)", b);
assertEquals("{}", StashManager.stashesOf(b).toString());
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("stash"));
assertThat(coreStepNodes, Matchers.hasSize(1));
assertEquals("whatever", ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));
}
}

0 comments on commit c77b341

Please sign in to comment.
You can’t perform that action at this time.