|
36 | 36 | import hudson.model.TaskListener; |
37 | 37 | import hudson.tasks.Builder; |
38 | 38 | import hudson.tasks.Publisher; |
39 | | - |
40 | 39 | import java.util.ArrayList; |
41 | 40 | import java.util.Collection; |
| 41 | +import java.util.HashMap; |
42 | 42 | import java.util.List; |
| 43 | +import java.util.Map; |
43 | 44 | import java.util.Set; |
44 | | - |
| 45 | +import javax.annotation.CheckForNull; |
45 | 46 | import jenkins.model.Jenkins; |
46 | 47 | import jenkins.tasks.SimpleBuildStep; |
47 | | - |
| 48 | +import org.jenkinsci.plugins.structs.describable.DescribableModel; |
| 49 | +import org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable; |
48 | 50 | import org.kohsuke.stapler.DataBoundConstructor; |
49 | 51 |
|
50 | 52 | /** |
@@ -122,6 +124,28 @@ private <T extends Describable<T>,D extends Descriptor<T>> void populate(List<De |
122 | 124 | return ImmutableSet.of(Run.class, FilePath.class, Launcher.class, TaskListener.class); |
123 | 125 | } |
124 | 126 |
|
| 127 | + @Override public String argumentsToString(Map<String, Object> namedArgs) { |
| 128 | + Map<String, Object> delegateArguments = delegateArguments(namedArgs.get("delegate")); |
| 129 | + return delegateArguments != null ? super.argumentsToString(delegateArguments) : null; |
| 130 | + } |
| 131 | + |
| 132 | + @SuppressWarnings("unchecked") |
| 133 | + static @CheckForNull Map<String, Object> delegateArguments(@CheckForNull Object delegate) { |
| 134 | + if (delegate instanceof UninstantiatedDescribable) { |
| 135 | + // TODO JENKINS-45101 getStepArgumentsAsString does not resolve its arguments |
| 136 | + // thus delegate.model == null and we cannot inspect DescribableModel.soleRequiredParameter |
| 137 | + // thus for, e.g., `junit testResults: '*.xml', keepLongStdio: true` we will get null |
| 138 | + return new HashMap<>(((UninstantiatedDescribable) delegate).getArguments()); |
| 139 | + } else if (delegate instanceof Map) { |
| 140 | + Map<String, Object> r = new HashMap<>(); |
| 141 | + r.putAll((Map) delegate); |
| 142 | + r.remove(DescribableModel.CLAZZ); |
| 143 | + return r; |
| 144 | + } else { |
| 145 | + return null; |
| 146 | + } |
| 147 | + } |
| 148 | + |
125 | 149 | } |
126 | 150 |
|
127 | 151 | } |
0 commit comments