Skip to content

Commit

Permalink
Merge branch 'JENKINS-38585-step-editor' of github.com:kzantow/blueoc…
Browse files Browse the repository at this point in the history
…ean-pipeline-editor into JENKINS-38585-step-editor
  • Loading branch information
kzantow committed Nov 16, 2016
2 parents d962cd5 + 1f369b7 commit 4dcbabe
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 44 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Expand Up @@ -43,23 +43,23 @@
<dependency> <dependency>
<groupId>io.jenkins.blueocean</groupId> <groupId>io.jenkins.blueocean</groupId>
<artifactId>blueocean</artifactId> <artifactId>blueocean</artifactId>
<version>1.0.0-b12-SNAPSHOT</version> <version>1.0.0-b12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.jenkins.blueocean</groupId> <groupId>io.jenkins.blueocean</groupId>
<artifactId>blueocean-rest</artifactId> <artifactId>blueocean-rest</artifactId>
<version>1.0.0-b12-SNAPSHOT</version> <version>1.0.0-b12</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId> <groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId> <artifactId>workflow-api</artifactId>
<version>2.1</version> <version>2.6</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId> <groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId> <artifactId>workflow-cps</artifactId>
<version>2.8</version> <version>2.23</version>
</dependency> </dependency>
</dependencies> </dependencies>


Expand Down
Expand Up @@ -46,7 +46,13 @@ public interface PipelineStepMetadata {
*/ */
@Exported @Exported
public String getSnippetizerUrl(); public String getSnippetizerUrl();


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

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


import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.cps.Snippetizer;
import org.jenkinsci.plugins.workflow.steps.StepDescriptor; 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.Stapler;
import org.kohsuke.stapler.WebMethod; import org.kohsuke.stapler.WebMethod;
import org.kohsuke.stapler.export.Exported; import org.kohsuke.stapler.export.Exported;
Expand Down Expand Up @@ -49,6 +46,7 @@ public static class BasicPipelineStepMetadata implements PipelineStepMetadata {
private List<Class<?>> requiredContext = new ArrayList<Class<?>>(); private List<Class<?>> requiredContext = new ArrayList<Class<?>>();
private List<Class<?>> providedContext = new ArrayList<Class<?>>(); private List<Class<?>> providedContext = new ArrayList<Class<?>>();
private boolean isWrapper = false; private boolean isWrapper = false;
private boolean hasSingleRequiredParameter = false;
private String snippetizerUrl; private String snippetizerUrl;
private List<PipelineStepPropertyMetadata> props = new ArrayList<PipelineStepPropertyMetadata>(); private List<PipelineStepPropertyMetadata> props = new ArrayList<PipelineStepPropertyMetadata>();


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


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

@Exported @Exported
@Override @Override
public PipelineStepPropertyMetadata[] getProperties() { public PipelineStepPropertyMetadata[] getProperties() {
return props.toArray(new PipelineStepPropertyMetadata[props.size()]); 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 @ExportedBean
public static class BasicPipelineStepPropertyMetadata implements PipelineStepPropertyMetadata{ public static class BasicPipelineStepPropertyMetadata implements PipelineStepPropertyMetadata{
Expand Down Expand Up @@ -178,49 +186,31 @@ public PipelineStepMetadata[] getPipelineStepMetadata() {
return pd.toArray(new PipelineStepMetadata[pd.size()]); return pd.toArray(new PipelineStepMetadata[pd.size()]);
} }


@SuppressWarnings("deprecation")
private PipelineStepMetadata getStepMetadata(StepDescriptor d, String snippetizerUrl) { private PipelineStepMetadata getStepMetadata(StepDescriptor d, String snippetizerUrl) {
BasicPipelineStepMetadata step = new BasicPipelineStepMetadata(d.getFunctionName(), d.clazz, d.getDisplayName()); 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.snippetizerUrl = snippetizerUrl + "?$class=" + d.clazz.getName(); // this isn't really accurate


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


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


for (Constructor<?> c : d.clazz.getDeclaredConstructors()) { if (pd != null) {
if (c.isAnnotationPresent(DataBoundConstructor.class)) { param.descriptorUrl = pd.getDescriptorFullUrl();
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);
}
}
} }
} }


Expand Down

0 comments on commit 4dcbabe

Please sign in to comment.