Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[JENKINS-37781] Split ModelASTScriptBlock and ModelASTWhen
Into having one common ancestor instead of when extending script
- Loading branch information
Showing
with
69 additions
and 43 deletions.
- +62 −0 ...i/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/AbstractModelASTCodeBlock.java
- +2 −31 ...del-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTScriptBlock.java
- +1 −9 ...line-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTWhen.java
- +4 −3 ...finition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.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() + | ||
"}"; | ||
} | ||
} |