Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge remote-tracking branch 'origin/master' into JENKINS-37778
Conflicts: pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy
- Loading branch information
Showing
with
513 additions
and 50 deletions.
- +62 −0 ...i/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/AbstractModelASTCodeBlock.java
- +2 −27 ...del-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTScriptBlock.java
- +27 −0 ...ine-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTStage.java
- +53 −0 ...line-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTWhen.java
- +3 −0 ...el-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidator.java
- +7 −0 ...odel-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Stage.groovy
- +14 −0 ...efinition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/JSONParser.groovy
- +38 −7 ...finition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy
- +11 −0 ...rc/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidatorImpl.groovy
- +16 −0 pipeline-model-definition/src/main/resources/ast-schema.json
- +31 −16 ...inition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy
- +114 −0 ...-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/WhenStageTest.java
- +48 −0 pipeline-model-definition/src/test/resources/when/simpleWhen.groovy
- +43 −0 pipeline-model-definition/src/test/resources/when/whenEmpty.groovy
- +44 −0 pipeline-model-definition/src/test/resources/when/whenException.groovy
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Represents the special step which are executed without validation against the declarative subset. | ||
* @see ModelASTScriptBlock | ||
* @see ModelASTWhen | ||
*/ | ||
public abstract class AbstractModelASTCodeBlock extends ModelASTStep { | ||
|
||
protected AbstractModelASTCodeBlock(Object sourceLocation, String name) { | ||
super(sourceLocation); | ||
this.setName(name); | ||
} | ||
|
||
@Override | ||
public String toGroovy() { | ||
StringBuilder result = new StringBuilder(getName()).append(" {\n"); | ||
if (getArgs() != null | ||
&& getArgs() instanceof ModelASTSingleArgument | ||
&& ((ModelASTSingleArgument) getArgs()).getValue()!=null | ||
&& ((ModelASTSingleArgument) getArgs()).getValue().isLiteral()) { | ||
result.append(((ModelASTSingleArgument) getArgs()).getValue().getValue()); | ||
} else if (getArgs() != null) { | ||
result.append(getArgs().toGroovy()); | ||
} | ||
result.append("\n}\n"); | ||
return result.toString(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "{" + | ||
"name='" + getName() + '\'' + | ||
", args=" + getArgs() + | ||
"}"; | ||
} | ||
} |
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.JSONObject; | ||
import org.jenkinsci.plugins.pipeline.modeldefinition.validator.ModelValidator; | ||
|
||
/** | ||
* Represents a block for when/if a {@link ModelASTStage} will be executed or not. | ||
*/ | ||
public class ModelASTWhen extends AbstractModelASTCodeBlock { | ||
public ModelASTWhen(Object sourceLocation) { | ||
super(sourceLocation, "when"); | ||
} | ||
|
||
@Override | ||
public JSONObject toJSON() { | ||
JSONObject o = new JSONObject(); | ||
if (getArgs() != null) { | ||
o.accumulate("arguments", getArgs().toJSON()); | ||
} | ||
return o; | ||
} | ||
|
||
@Override | ||
public void validate(ModelValidator validator) { | ||
super.validate(validator); | ||
validator.validateElement(this); | ||
} | ||
} |
Oops, something went wrong.