Skip to content

Commit

Permalink
Merge pull request #3 from kzantow/JENKINS-38585-step-editor
Browse files Browse the repository at this point in the history
[WIP JENKINS-38585] pipeline step editor
  • Loading branch information
kzantow committed Dec 3, 2016
2 parents bc3336b + 8af9eb8 commit a9af14f
Show file tree
Hide file tree
Showing 24 changed files with 1,219 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,6 @@ node/
node_modules/
target/
work/
/.classpath
/.project
/.settings/
2 changes: 1 addition & 1 deletion Jenkinsfile
Expand Up @@ -7,7 +7,7 @@ pipeline {
}
}
}
postBuild {
post {
success {
archive 'target/blueocean-pipeline-editor.hpi'
}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -37,9 +37,11 @@
"react-addons-test-utils": "15.0.1"
},
"dependencies": {
"@jenkins-cd/design-language": "0.0.79",
"@jenkins-cd/blueocean-core-js": "0.0.21",
"@jenkins-cd/design-language": "0.0.89-beta1",
"@jenkins-cd/js-extensions": "0.0.25",
"@jenkins-cd/js-modules": "0.0.8",
"lodash.debounce": "4.0.8",
"react": "15.1.0",
"react-addons-css-transition-group": "15.1.0",
"react-dom": "15.1.0",
Expand Down
28 changes: 25 additions & 3 deletions pom.xml
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
Expand All @@ -24,6 +23,8 @@
<jenkins.version>2.7.1</jenkins.version>
<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-SNAPSHOT</declarative.version>
</properties>

<repositories>
Expand All @@ -41,10 +42,31 @@
</pluginRepositories>

<dependencies>
<dependency>
<groupId>io.jenkins.blueocean</groupId>
<artifactId>blueocean-rest</artifactId>
<version>${blueocean.version}</version>
</dependency>
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-definition</artifactId>
<version>${declarative.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.23</version>
</dependency>

<dependency>
<groupId>io.jenkins.blueocean</groupId>
<artifactId>blueocean</artifactId>
<version>1.0.0-b07</version>
<version>${blueocean.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
@@ -0,0 +1,93 @@
/*
* 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.jenkinsci.plugins.structs.describable.DescribableModel;
import org.jenkinsci.plugins.structs.describable.DescribableParameter;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@ExportedBean
public class ExportedDescribableModel {
protected final DescribableModel<?> model;

public ExportedDescribableModel(DescribableModel<?> model) {
this.model = model;
}

/**
* The Java class name for this describable (since we can't seem to export a Class<?>...)
* See {@link DescribableModel#getType()}
*/
@Exported
public String getType() {
return model.getType().getName();
}

/**
* Display Name of the describable class
* See {@link DescribableModel#getDisplayName()}
*/
@Exported
public String getDisplayName() {
return model.getDisplayName();
}

/**
* Whether this describable has one and only one parameter and it is required.
* See {@link DescribableModel#hasSingleRequiredParameter()}
*/
@Exported
public boolean getHasSingleRequiredParameter() {
return model.hasSingleRequiredParameter();
}

/**
* Loads help defined for this object as a whole if available, else null.
* See {@link DescribableModel#getHelp()}
*/
@Exported
public String getHelp() throws IOException {
return model.getHelp();
}

/**
* Properties the describable supports
* See {@link DescribableModel#getParameters()}
*/
@Exported
public List<ExportedDescribableParameter> getParameters() {
List<ExportedDescribableParameter> params = new ArrayList<>();

for (DescribableParameter p : model.getParameters()) {
params.add(new ExportedDescribableParameter(p));
}
return params;
}
}
@@ -0,0 +1,113 @@
package io.blueocean.rest.pipeline.editor;

import hudson.ExtensionList;
import hudson.model.Descriptor;
import org.jenkinsci.plugins.structs.describable.DescribableParameter;
import org.jenkinsci.plugins.structs.describable.ParameterType;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;


/**
* Exportable form of {@link DescribableParameter}
*/
@ExportedBean
public class ExportedDescribableParameter {
protected final DescribableParameter param;

public ExportedDescribableParameter(DescribableParameter param) {
this.param = param;
}

/**
* Name of the parameter
* See {@link DescribableParameter#getName()}
*/
@Exported
public String getName() {
return param.getName();
}

/**
* Indicates this parameter is required
* See {@link DescribableParameter#isRequired()}
*/
@Exported
public boolean getIsRequired() {
return param.isRequired();
}

/**
* Java class name for the parameter
* See {@link DescribableParameter#getErasedType()}
*/
@Exported
public String getType() {
return param.getErasedType().getName();
}

/**
* Java types allowed if this is a collection
* See {@link DescribableParameter#getType()} and {@link ParameterType#getActualType()}
*/
@Exported
public List<String> getCollectionTypes() {
List<String> collectionTypes = new ArrayList<>();

Type typ = param.getType().getActualType();
if (typ instanceof ParameterizedType) {
Type[] typeArgs = ((ParameterizedType) typ).getActualTypeArguments();
for (Type ptyp : typeArgs) {
if (ptyp instanceof Class<?>) {
collectionTypes.add(((Class<?>) ptyp).getName());
}
}
}
return collectionTypes;
}

/**
* Capitalized name of the parameter
* See {@link DescribableParameter#getCapitalizedName()}
*/
@Exported
public String getCapitalizedName() {
return param.getCapitalizedName();
}

/**
* Indicates this parameter is deprecated
* See {@link DescribableParameter#isDeprecated()}
*/
@Exported
public boolean getIsDeprecated() {
return param.isDeprecated();
}

/**
* Help HTML (in English locale) for this parameter if available, else null
* See {@link DescribableParameter#getHelp()}
*/
@Exported
public String getHelp() throws IOException {
return param.getHelp();
}

@Exported
public String getDescriptorUrl() {
Descriptor<?> pd = Descriptor.findByDescribableClassName(ExtensionList.lookup(Descriptor.class),
param.getErasedType().getName());

if (pd != null) {
return pd.getDescriptorUrl();
}

return null;
}
}
@@ -0,0 +1,15 @@
package io.blueocean.rest.pipeline.editor;

import java.util.List;

import hudson.ExtensionPoint;

/**
* Allows plugins to modify property metadata, e.g. providing additional form fields and such
*/
public interface ExportedDescribableParameterDecorator extends ExtensionPoint {
/**
* Adjust the PipelineStepPropertyMetadata for the pipeline step
*/
public ExportedDescribableParameter decorate(ExportedDescribableModel model, List<ExportedDescribableParameter> parameters);
}
@@ -0,0 +1,47 @@
/*
* 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.jenkinsci.plugins.structs.describable.DescribableModel;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

@ExportedBean
public class ExportedPipelineFunction extends ExportedDescribableModel {
protected final String functionName;

public ExportedPipelineFunction(DescribableModel<?> model, String functionName) {
super(model);
this.functionName = functionName;
}

/**
* Identifier used for the 'function' name in the pipeline step, used in the pipeline file
*/
@Exported
public String getFunctionName() {
return functionName;
}
}

0 comments on commit a9af14f

Please sign in to comment.