Skip to content

Commit

Permalink
Merge pull request #252 from jglick/DefaultStepContext
Browse files Browse the repository at this point in the history
`DefaultStepContext.get` should directly handle certain types
  • Loading branch information
jglick authored Nov 18, 2024
2 parents b555de1 + ae014c3 commit 9fa7721
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,25 @@ public abstract class DefaultStepContext extends StepContext {

/**
* Uses {@link #doGet} but automatically translates certain kinds of objects into others.
* <p>Note that some basic types are handled directly by {@link #get} and cannot be overridden,
* such as {@link Run}, {@link Job}, {@link FlowExecution}, and {@link FlowNode}.
* <p>{@inheritDoc}
*/
@Override public final <T> T get(Class<T> key) throws IOException, InterruptedException {
T value = doGet(key);
T value = null;
if (Run.class.isAssignableFrom(key)) {
value = castOrNull(key, getExecution().getOwner().getExecutable());
} else if (Job.class.isAssignableFrom(key)) {

Check warning on line 80 in src/main/java/org/jenkinsci/plugins/workflow/support/DefaultStepContext.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 80 is only partially covered, one branch is missing
value = castOrNull(key, get(Run.class).getParent());

Check warning on line 81 in src/main/java/org/jenkinsci/plugins/workflow/support/DefaultStepContext.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 81 is not covered by tests
} else if (FlowExecution.class.isAssignableFrom(key)) {
value = castOrNull(key, getExecution());
} else if (FlowNode.class.isAssignableFrom(key)) {
value = castOrNull(key, getNode());
}
if (value != null) {
return value;
}
value = doGet(key);
if (key == EnvVars.class) {
Run<?,?> run = get(Run.class);
EnvironmentAction a = run == null ? null : run.getAction(EnvironmentAction.class);
Expand Down Expand Up @@ -100,14 +115,6 @@ public abstract class DefaultStepContext extends StepContext {
}
*/
return castOrNull(key, n);
} else if (Run.class.isAssignableFrom(key)) {
return castOrNull(key, getExecution().getOwner().getExecutable());
} else if (Job.class.isAssignableFrom(key)) {
return castOrNull(key, get(Run.class).getParent());
} else if (FlowExecution.class.isAssignableFrom(key)) {
return castOrNull(key,getExecution());
} else if (FlowNode.class.isAssignableFrom(key)) {
return castOrNull(key, getNode());
} else {
// unrecognized key
return null;
Expand Down

0 comments on commit 9fa7721

Please sign in to comment.