Skip to content

Commit c1733a9

Browse files
committed
Simplify code with EnvironmentExpander.constant.
1 parent ada9bab commit c1733a9

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/main/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStep.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ private static final class ExpanderImpl extends EnvironmentExpander {
107107
this.overrides = /* ensure serializability*/ new HashMap<>(overrides);
108108
}
109109
@Override public void expand(EnvVars env) throws IOException, InterruptedException {
110+
// Distinct from EnvironmentExpander.constant since we are also expanding variables.
110111
env.overrideExpandingAll(overrides);
111112
}
112113
}

src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,14 @@ public static class Execution extends AbstractStepExecutionImpl {
7676
}
7777

7878
@Override public boolean start() throws Exception {
79+
Map<String, String> overridesM = new HashMap<>();
80+
for (String pair : overrides) {
81+
int split = pair.indexOf('=');
82+
assert split != -1;
83+
overridesM.put(pair.substring(0, split), pair.substring(split + 1));
84+
}
7985
getContext().newBodyInvoker().
80-
withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new ExpanderImpl(overrides))).
86+
withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), EnvironmentExpander.constant(overridesM))).
8187
withCallback(BodyExecutionCallback.wrap(getContext())).
8288
start();
8389
return false;
@@ -90,18 +96,11 @@ public static class Execution extends AbstractStepExecutionImpl {
9096
@Override public void onResume() {}
9197

9298
}
93-
99+
100+
@Deprecated // kept only for serial compatibility
94101
private static final class ExpanderImpl extends EnvironmentExpander {
95102
private static final long serialVersionUID = 1;
96-
private final Map<String,String> overrides;
97-
private ExpanderImpl(List<String> overrides) {
98-
this.overrides = new HashMap<>();
99-
for (String pair : overrides) {
100-
int split = pair.indexOf('=');
101-
assert split != -1;
102-
this.overrides.put(pair.substring(0, split), pair.substring(split + 1));
103-
}
104-
}
103+
private Map<String,String> overrides;
105104
@Override public void expand(EnvVars env) throws IOException, InterruptedException {
106105
env.overrideAll(overrides);
107106
}

0 commit comments

Comments
 (0)