Skip to content

Commit

Permalink
[FIXED JENKINS-40240] Add .../wrapperMetadata endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Dec 8, 2016
1 parent a9339b8 commit 17b4bee
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Expand Up @@ -6,6 +6,8 @@
import java.util.List;
import java.util.Set;

import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Describable;
import hudson.tasks.Builder;
import hudson.tasks.Publisher;
Expand Down Expand Up @@ -79,6 +81,26 @@ public String[] doBuildConditions() {
}


/**
* Function to return all applicable step descriptors for the "wrappers" section.
*/
@GET
@TreeResponse
public ExportedPipelineStep[] doWrapperMetadata() {
List<ExportedPipelineStep> wrappers = new ArrayList<>();

for (StepDescriptor d : StepDescriptor.all()) {
if (isWrapper(d)) {
ExportedPipelineStep step = getStepMetadata(d);
if (step != null) {
wrappers.add(step);
}
}
}

return wrappers.toArray(new ExportedPipelineStep[wrappers.size()]);
}

/**
* Function to return all step descriptors present in the system when accessed through the REST API
*/
Expand Down Expand Up @@ -112,6 +134,13 @@ public ExportedPipelineFunction[] doPipelineStepMetadata() {
return pd.toArray(new ExportedPipelineFunction[pd.size()]);
}

private boolean isWrapper(StepDescriptor d) {
return includeStep(d)
&& d.takesImplicitBlockArgument()
&& !d.getRequiredContext().contains(FilePath.class)
&& !d.getRequiredContext().contains(Launcher.class);
}

private boolean includeStep(StepDescriptor d) {
boolean include = true;
if (ModelASTStep.getBlockedSteps().containsKey(d.getFunctionName())) {
Expand Down
Expand Up @@ -73,6 +73,26 @@ public void declarativeAgents() throws Exception {
assertEquals(3, m.getParameters().size());
}

@Test
public void wrappers() throws Exception {
PipelineMetadataService svc = new PipelineMetadataService();

List<ExportedPipelineStep> wrappers = new ArrayList<>();
wrappers.addAll(Arrays.asList(svc.doWrapperMetadata()));

assertFalse(wrappers.isEmpty());

ExportedPipelineStep w = null;

for (ExportedPipelineStep s : wrappers) {
if (s.getFunctionName().equals("timeout")) {
w = s;
}
}

assertNotNull(w);
}

@Test
public void verifyFunctionNames() throws Exception {
PipelineMetadataService svc = new PipelineMetadataService();
Expand Down

0 comments on commit 17b4bee

Please sign in to comment.