Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
927 additions
and 82 deletions.
- +29 −2 ...del-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTPipelineDef.java
- +1 −1 ...line-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTStep.java
- +54 −0 ...e-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTWrapper.java
- +120 −0 ...-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTWrappers.java
- +6 −0 ...el-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidator.java
- +9 −0 ...model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Root.groovy
- +60 −0 ...l-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Wrappers.groovy
- +33 −0 ...inition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/WrappersToMap.groovy
- +19 −0 ...efinition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/JSONParser.groovy
- +50 −0 ...finition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy
- +33 −0 ...rc/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidatorImpl.groovy
- +6 −0 ...n/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ClosureModelTranslator.groovy
- +118 −76 ...inition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy
- +82 −0 .../src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/WrappersToMapTranslator.groovy
- +6 −3 ...definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/AbstractModelDefTest.java
- +8 −0 ...-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/ValidatorTest.java
- +61 −0 ...e-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/WrappersTest.java
- +40 −0 pipeline-model-definition/src/test/resources/errors/invalidWrapperType.groovy
- +26 −0 pipeline-model-definition/src/test/resources/json/errors/invalidWrapperType.json
- +47 −0 pipeline-model-definition/src/test/resources/json/multipleWrappers.json
- +38 −0 pipeline-model-definition/src/test/resources/json/simpleWrapper.json
- +41 −0 pipeline-model-definition/src/test/resources/multipleWrappers.groovy
- +40 −0 pipeline-model-definition/src/test/resources/simpleWrapper.groovy
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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 org.jenkinsci.plugins.pipeline.modeldefinition.ast; | ||
|
||
import org.jenkinsci.plugins.pipeline.modeldefinition.validator.ModelValidator; | ||
|
||
/** | ||
* A block scoped step to wrap the entire build within. | ||
* | ||
* @author Andrew Bayer | ||
*/ | ||
public class ModelASTWrapper extends ModelASTMethodCall { | ||
public ModelASTWrapper(Object sourceLocation) { | ||
super(sourceLocation); | ||
} | ||
|
||
@Override | ||
public void validate(final ModelValidator validator) { | ||
validator.validateElement(this); | ||
for (ModelASTMethodArg arg : getArgs()) { | ||
arg.validate(validator); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ModelASTWrapper{" + | ||
"name='" + getName() + '\'' + | ||
", args=" + getArgs() + | ||
"}"; | ||
} | ||
} |
@@ -0,0 +1,120 @@ | ||
/* | ||
* 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 org.jenkinsci.plugins.pipeline.modeldefinition.ast; | ||
|
||
import net.sf.json.JSONArray; | ||
import net.sf.json.JSONObject; | ||
import org.jenkinsci.plugins.pipeline.modeldefinition.validator.ModelValidator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* A container for one or more {@link ModelASTTrigger}s. | ||
* | ||
* @author Andrew Bayer | ||
*/ | ||
public final class ModelASTWrappers extends ModelASTElement { | ||
private List<ModelASTWrapper> wrappers = new ArrayList<ModelASTWrapper>(); | ||
|
||
public ModelASTWrappers(Object sourceLocation) { | ||
super(sourceLocation); | ||
} | ||
|
||
@Override | ||
public JSONObject toJSON() { | ||
final JSONArray a = new JSONArray(); | ||
for (ModelASTWrapper wrapper: wrappers) { | ||
a.add(wrapper.toJSON()); | ||
} | ||
return new JSONObject().accumulate("wrappers", a); | ||
} | ||
|
||
@Override | ||
public void validate(final ModelValidator validator) { | ||
validator.validateElement(this); | ||
for (ModelASTWrapper wrapper : wrappers) { | ||
wrapper.validate(validator); | ||
} | ||
} | ||
|
||
@Override | ||
public String toGroovy() { | ||
StringBuilder result = new StringBuilder("wrappers {\n"); | ||
for (ModelASTWrapper wrapper : wrappers) { | ||
result.append(wrapper.toGroovy()).append('\n'); | ||
} | ||
result.append("}\n"); | ||
return result.toString(); | ||
} | ||
|
||
@Override | ||
public void removeSourceLocation() { | ||
super.removeSourceLocation(); | ||
for (ModelASTWrapper wrapper: wrappers) { | ||
wrapper.removeSourceLocation(); | ||
} | ||
} | ||
|
||
public List<ModelASTWrapper> getWrappers() { | ||
return wrappers; | ||
} | ||
|
||
public void setWrappers(List<ModelASTWrapper> wrappers) { | ||
this.wrappers = wrappers; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ModelASTWrappers{" + | ||
"wrappers=" + wrappers + | ||
"}"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
if (!super.equals(o)) { | ||
return false; | ||
} | ||
|
||
ModelASTWrappers that = (ModelASTWrappers) o; | ||
|
||
return getWrappers() != null ? getWrappers().equals(that.getWrappers()) : that.getWrappers() == null; | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = super.hashCode(); | ||
result = 31 * result + (getWrappers() != null ? getWrappers().hashCode() : 0); | ||
return result; | ||
} | ||
} |
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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 org.jenkinsci.plugins.pipeline.modeldefinition.model | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings | ||
import groovy.transform.EqualsAndHashCode | ||
import groovy.transform.ToString | ||
import hudson.ExtensionList | ||
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTStep | ||
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted | ||
import org.jenkinsci.plugins.workflow.steps.StepDescriptor | ||
|
||
/** | ||
* A container for lists of wrappers to execute. | ||
* | ||
* @author Andrew Bayer | ||
*/ | ||
@ToString | ||
@EqualsAndHashCode | ||
@SuppressFBWarnings(value="SE_NO_SERIALVERSIONID") | ||
public class Wrappers extends MappedClosure<String, Wrappers> implements WrappersToMap { | ||
@Whitelisted | ||
public static List<String> getEligibleSteps() { | ||
List<String> stepNames = [] | ||
|
||
// TODO: Figure out if we want to support metasteps? Don't think so. | ||
ExtensionList.lookup(StepDescriptor.class).each { s -> | ||
if (s.takesImplicitBlockArgument() | ||
&& !(s.getFunctionName() in ModelASTStep.blockedSteps.keySet()) | ||
&& s.getRequiredContext().isEmpty()) { | ||
stepNames.add(s.getFunctionName()) | ||
} | ||
} | ||
|
||
return stepNames.sort() | ||
} | ||
} |
Oops, something went wrong.