Skip to content
Permalink
Browse files

Merge branch 'JENKINS-38585-step-editor' of github.com:kzantow/blueoc…

…ean-pipeline-editor into JENKINS-38585-step-editor
  • Loading branch information...
kzantow committed Nov 16, 2016
2 parents d962cd5 + 1f369b7 commit 4dcbabecbb58997e688bedf2810de11ee27e0da5
@@ -43,23 +43,23 @@
<dependency>
<groupId>io.jenkins.blueocean</groupId>
<artifactId>blueocean</artifactId>
<version>1.0.0-b12-SNAPSHOT</version>
<version>1.0.0-b12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jenkins.blueocean</groupId>
<artifactId>blueocean-rest</artifactId>
<version>1.0.0-b12-SNAPSHOT</version>
<version>1.0.0-b12</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.1</version>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.8</version>
<version>2.23</version>
</dependency>
</dependencies>

@@ -46,7 +46,13 @@
*/
@Exported
public String getSnippetizerUrl();


/**
* Whether this step has one and only one parameter and it is required.
*/
@Exported
public boolean getHasSingleRequiredParameter();

/**
* Properties the steps supports
*/
@@ -1,15 +1,12 @@
package io.blueocean.rest.pipeline.editor;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.structs.describable.DescribableModel;
import org.jenkinsci.plugins.structs.describable.DescribableParameter;
import org.jenkinsci.plugins.workflow.cps.Snippetizer;
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.WebMethod;
import org.kohsuke.stapler.export.Exported;
@@ -49,6 +46,7 @@ public String getUrlName() {
private List<Class<?>> requiredContext = new ArrayList<Class<?>>();
private List<Class<?>> providedContext = new ArrayList<Class<?>>();
private boolean isWrapper = false;
private boolean hasSingleRequiredParameter = false;
private String snippetizerUrl;
private List<PipelineStepPropertyMetadata> props = new ArrayList<PipelineStepPropertyMetadata>();

@@ -114,15 +112,25 @@ public String getType() {
return type.getName();
}

@Exported
@Override
public boolean getHasSingleRequiredParameter() {
return hasSingleRequiredParameter;
}

@Exported
@Override
public PipelineStepPropertyMetadata[] getProperties() {
return props.toArray(new PipelineStepPropertyMetadata[props.size()]);
}

public DescribableModel getDescribableModel() {
return new DescribableModel<>(type);
}
}

/**
* Basic exported model for {@link PipelineStepPropertyDescriptor)
* Basic exported model for {@link PipelineStepPropertyMetadata)
*/
@ExportedBean
public static class BasicPipelineStepPropertyMetadata implements PipelineStepPropertyMetadata{
@@ -178,49 +186,31 @@ public String descriptorUrl() {
return pd.toArray(new PipelineStepMetadata[pd.size()]);
}

@SuppressWarnings("deprecation")
private PipelineStepMetadata getStepMetadata(StepDescriptor d, String snippetizerUrl) {
BasicPipelineStepMetadata step = new BasicPipelineStepMetadata(d.getFunctionName(), d.clazz, d.getDisplayName());

DescribableModel<?> model = step.getDescribableModel();

step.snippetizerUrl = snippetizerUrl + "?$class=" + d.clazz.getName(); // this isn't really accurate

step.isWrapper = d.takesImplicitBlockArgument();
step.requiredContext.addAll(d.getRequiredContext());
step.providedContext.addAll(d.getProvidedContext());
step.descriptorUrl = d.getDescriptorFullUrl();
step.hasSingleRequiredParameter = model.hasSingleRequiredParameter();

for (Method m : d.clazz.getDeclaredMethods()) {
if (m.isAnnotationPresent(DataBoundSetter.class)) {
String paramName = StringUtils.uncapitalize(m.getName().substring(3));
Class<?> paramType = m.getParameterTypes()[0];
BasicPipelineStepPropertyMetadata param = new BasicPipelineStepPropertyMetadata();
param.name = paramName;
param.type = paramType;
Descriptor<?> pd = Descriptor.find(paramType.getName());
if (pd != null) {
param.descriptorUrl = pd.getDescriptorFullUrl();
}
step.props.add(param);
}
}
for (DescribableParameter descParam : model.getParameters()) {
BasicPipelineStepPropertyMetadata param = new BasicPipelineStepPropertyMetadata();

param.type = descParam.getErasedType();
param.name = descParam.getName();
param.isRequired = descParam.isRequired();

Descriptor<?> pd = Descriptor.findByDescribableClassName(ExtensionList.lookup(Descriptor.class),
param.type.getName());

for (Constructor<?> c : d.clazz.getDeclaredConstructors()) {
if (c.isAnnotationPresent(DataBoundConstructor.class)) {
Class<?>[] paramTypes = c.getParameterTypes();
String[] paramNames = nameFinder.getParameterNames(c);
if(paramNames != null) {
for (int i = 0; i < paramNames.length; i++) {
String paramName = paramNames[i];
Class<?> paramType = paramTypes[i];
BasicPipelineStepPropertyMetadata param = new BasicPipelineStepPropertyMetadata();
param.name = paramName;
param.type = paramType;
Descriptor<?> pd = Descriptor.find(paramType.getName());
if (pd != null) {
param.descriptorUrl = pd.getDescriptorFullUrl();
}
step.props.add(param);
}
}
if (pd != null) {
param.descriptorUrl = pd.getDescriptorFullUrl();
}
}

0 comments on commit 4dcbabe

Please sign in to comment.
You can’t perform that action at this time.