Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-40239] Add build condition descriptions to metadata
  • Loading branch information
abayer committed Dec 20, 2016
1 parent e297c92 commit 60123c7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -24,7 +24,7 @@
<node.version>5.8.0</node.version>
<npm.version>3.7.3</npm.version>
<blueocean.version>1.0.0-b13-SNAPSHOT</blueocean.version>
<declarative.version>0.7.1</declarative.version>
<declarative.version>0.8-SNAPSHOT</declarative.version>
</properties>

<repositories>
Expand Down
@@ -0,0 +1,53 @@
/*
* The MIT License
*
* Copyright (c) 2016, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package io.blueocean.rest.pipeline.editor;

import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

@ExportedBean
public class ExportedBuildCondition implements Comparable<ExportedBuildCondition> {
private final String name;
private final String description;

public ExportedBuildCondition(String n, String d) {
this.name = n;
this.description = d;
}

@Exported
public String getName() {
return name;
}

@Exported
public String getDescription() {
return description;
}

public int compareTo(ExportedBuildCondition other) {
return this.name.compareTo(other.getName());
}
}
Expand Up @@ -22,8 +22,6 @@
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
import org.kohsuke.stapler.NoStaplerConstructorException;
import org.kohsuke.stapler.verb.GET;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;

import hudson.Extension;
import hudson.ExtensionList;
Expand Down Expand Up @@ -75,9 +73,14 @@ public ExportedDescribableModel[] doAgentMetadata() {
*/
@GET
@TreeResponse
public String[] doBuildConditions() {
List<String> conditions = BuildCondition.getOrderedConditionNames();
return conditions.toArray(new String[conditions.size()]);
public ExportedBuildCondition[] doBuildConditions() {
List<ExportedBuildCondition> exported = new ArrayList<>();
for (BuildCondition c : BuildCondition.all()) {
exported.add(new ExportedBuildCondition(symbolForObject(c), c.getDescription()));
}

Collections.sort(exported);
return exported.toArray(new ExportedBuildCondition[exported.size()]);
}


Expand Down Expand Up @@ -156,13 +159,13 @@ private boolean includeStep(StepDescriptor d) {
private <T extends Describable<T>,D extends Descriptor<T>> void populateMetaSteps(List<Descriptor<?>> r, Class<T> c) {
Jenkins j = Jenkins.getInstance();
for (Descriptor<?> d : j.getDescriptorList(c)) {
if (SimpleBuildStep.class.isAssignableFrom(d.clazz) && symbolForDescriptor(d) != null) {
if (SimpleBuildStep.class.isAssignableFrom(d.clazz) && symbolForObject(d) != null) {
r.add(d);
}
}
}

private @CheckForNull String symbolForDescriptor(Descriptor<?> d) {
private @CheckForNull String symbolForObject(Object d) {
Set<String> symbols = SymbolLookup.getSymbolValue(d);
if (!symbols.isEmpty()) {
return symbols.iterator().next();
Expand All @@ -172,7 +175,7 @@ private <T extends Describable<T>,D extends Descriptor<T>> void populateMetaStep
}

private @CheckForNull ExportedPipelineFunction getStepMetadata(Descriptor<?> d) {
String symbol = symbolForDescriptor(d);
String symbol = symbolForObject(d);

if (symbol != null) {
ExportedPipelineFunction f = new ExportedPipelineFunction(new DescribableModel<>(d.clazz), symbol);
Expand Down

0 comments on commit 60123c7

Please sign in to comment.