Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from kzantow/JENKINS-38585-step-editor
[WIP JENKINS-38585] pipeline step editor
- Loading branch information
Showing
24 changed files
with
1,219 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ node/ | |
node_modules/ | ||
target/ | ||
work/ | ||
/.classpath | ||
/.project | ||
/.settings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ pipeline { | |
} | ||
} | ||
} | ||
postBuild { | ||
post { | ||
success { | ||
archive 'target/blueocean-pipeline-editor.hpi' | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/io/blueocean/rest/pipeline/editor/ExportedDescribableModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
src/main/java/io/blueocean/rest/pipeline/editor/ExportedDescribableParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/io/blueocean/rest/pipeline/editor/ExportedDescribableParameterDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/io/blueocean/rest/pipeline/editor/ExportedPipelineFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.