Skip to content

Commit ea2fba4

Browse files
avoid printing too long argument in Pipeline Steps visualisation
In some cases it is possible that node argument will be impossible to wrap properly and is displayed as single line. In this case pipeline steps view becomes hard to read because right most columns are moved beyond the screen. This requires scrolling which is not so convenient. Also status colum is outside of screen. This change cuts arguments list to 80 characters which should be fine for most of usages. Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
1 parent 8105510 commit ea2fba4

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed

src/main/java/org/jenkinsci/plugins/workflow/support/visualization/table/ArgumentsColumn.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package org.jenkinsci.plugins.workflow.support.visualization.table;
2626

2727
import hudson.Extension;
28+
import org.apache.commons.lang.StringUtils;
2829
import org.jenkinsci.plugins.workflow.actions.ArgumentsAction;
2930
import org.jenkinsci.plugins.workflow.graph.FlowNode;
3031
import org.jenkinsci.plugins.workflow.visualization.table.FlowNodeViewColumn;
@@ -39,7 +40,7 @@ public class ArgumentsColumn extends FlowNodeViewColumn {
3940
@DataBoundConstructor public ArgumentsColumn() {}
4041

4142
public String get(FlowNode node) {
42-
return ArgumentsAction.getStepArgumentsAsString(node);
43+
return StringUtils.substring(ArgumentsAction.getStepArgumentsAsString(node), 0, 80);
4344
}
4445

4546
@Extension public static class DescriptorImpl extends FlowNodeViewColumnDescriptor {
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2018, Intel Corporation
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package org.jenkinsci.plugins.workflow.support.visualization;
26+
27+
import static org.junit.Assert.*;
28+
import org.junit.Test;
29+
30+
import java.util.ArrayList;
31+
import java.util.Map;
32+
import java.util.Set;
33+
34+
import org.jenkinsci.plugins.workflow.graph.FlowNode;
35+
import org.jenkinsci.plugins.workflow.graph.StepNode;
36+
import org.jenkinsci.plugins.workflow.steps.Step;
37+
import org.jenkinsci.plugins.workflow.steps.StepContext;
38+
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
39+
import org.jenkinsci.plugins.workflow.steps.StepExecution;
40+
import org.jenkinsci.plugins.workflow.support.visualization.table.ArgumentsColumn;
41+
42+
public class ArgumentsColumnTest extends Step {
43+
44+
private static final class DescriptorMock extends StepDescriptor {
45+
@Override
46+
public String getFunctionName() {
47+
return "func";
48+
}
49+
50+
@Override
51+
public Set<? extends Class<?>> getRequiredContext() {
52+
return null;
53+
}
54+
55+
@Override
56+
public String argumentsToString(Map<String, Object> namedArgs) {
57+
return "123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123";
58+
}
59+
}
60+
61+
private class TestedNode extends FlowNode implements StepNode {
62+
public TestedNode() {
63+
super(null, "1", new ArrayList<FlowNode>());
64+
}
65+
66+
@Override
67+
public StepDescriptor getDescriptor() {
68+
return new DescriptorMock();
69+
}
70+
71+
@Override
72+
protected String getTypeDisplayName() {
73+
return null;
74+
}
75+
}
76+
77+
@Test
78+
public void testLongStepArguments() {
79+
FlowNode f = new TestedNode();
80+
ArgumentsColumn col = new ArgumentsColumn();
81+
82+
String s = col.get(f);
83+
assertTrue(s.length()<=80);
84+
}
85+
86+
87+
@Override public StepExecution start(final StepContext context) throws Exception {
88+
return null;
89+
}
90+
91+
}

0 commit comments

Comments
 (0)