Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-38865] Move the AST classes from Groovy to Java to reduce co…
…mplexity of consumption (part 2) - Fix build
- Loading branch information
Showing
5 changed files
with
115 additions
and
89 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
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: 49 additions & 44 deletions
93
...c/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTJobProperties.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 |
---|---|---|
@@ -1,90 +1,95 @@ | ||
package org.jenkinsci.plugins.pipeline.modeldefinition.ast; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import groovy.lang.Closure; | ||
import groovy.transform.EqualsAndHashCode; | ||
import groovy.transform.ToString; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import net.sf.json.JSONArray; | ||
import net.sf.json.JSONObject; | ||
import org.codehaus.groovy.runtime.DefaultGroovyMethods; | ||
import org.jenkinsci.plugins.pipeline.modeldefinition.validator.ModelValidator; | ||
|
||
/** | ||
* A container for one or more {@link ModelASTJobProperty}s | ||
* | ||
* @author Andrew Bayer | ||
*/ | ||
@ToString(includeSuper = true, includeSuperProperties = true) | ||
@EqualsAndHashCode(callSuper = true) | ||
@SuppressFBWarnings(value = "SE_NO_SERIALVERSIONID") | ||
public final class ModelASTJobProperties extends ModelASTElement { | ||
private List<ModelASTJobProperty> properties = new ArrayList<ModelASTJobProperty>(); | ||
|
||
public ModelASTJobProperties(Object sourceLocation) { | ||
super(sourceLocation); | ||
} | ||
|
||
@Override | ||
public JSONObject toJSON() { | ||
final JSONArray a = new JSONArray(); | ||
DefaultGroovyMethods.each(properties, new Closure<Boolean>(this, this) { | ||
public Boolean doCall(Object s) { | ||
return a.add(((ModelASTJobProperty) s).toJSON()); | ||
} | ||
|
||
}); | ||
|
||
for (ModelASTJobProperty property : properties) { | ||
a.add(property.toJSON()); | ||
} | ||
return new JSONObject().accumulate("properties", a); | ||
} | ||
|
||
@Override | ||
public void validate(final ModelValidator validator) { | ||
validator.validateElement(this); | ||
DefaultGroovyMethods.each(properties, new Closure<Object>(this, this) { | ||
public void doCall(Object s) { | ||
((ModelASTJobProperty) s).validate(validator); | ||
} | ||
|
||
}); | ||
for (ModelASTJobProperty property : properties) { | ||
property.validate(validator); | ||
} | ||
} | ||
|
||
@Override | ||
public String toGroovy() { | ||
return "jobProperties {\n" + DefaultGroovyMethods | ||
.join(DefaultGroovyMethods.collect(properties, new Closure<String>(this, this) { | ||
public String doCall(ModelASTJobProperty it) { | ||
return it.toGroovy(); | ||
} | ||
|
||
public String doCall() { | ||
return doCall(null); | ||
} | ||
|
||
}), "\n") + "\n}\n"; | ||
StringBuilder result = new StringBuilder("jobProperties {\n"); | ||
for (ModelASTJobProperty property : properties) { | ||
result.append(property.toGroovy()).append("\n"); | ||
} | ||
result.append("}\n"); | ||
return result.toString(); | ||
} | ||
|
||
@Override | ||
public void removeSourceLocation() { | ||
super.removeSourceLocation(); | ||
DefaultGroovyMethods.each(properties, new Closure<Object>(this, this) { | ||
public void doCall(ModelASTJobProperty it) { | ||
it.removeSourceLocation(); | ||
} | ||
|
||
public void doCall() { | ||
doCall(null); | ||
} | ||
|
||
}); | ||
for (ModelASTJobProperty property : properties) { | ||
property.removeSourceLocation(); | ||
} | ||
} | ||
|
||
public ArrayList<ModelASTJobProperty> getProperties() { | ||
public List<ModelASTJobProperty> getProperties() { | ||
return properties; | ||
} | ||
|
||
public void setProperties(List<ModelASTJobProperty> properties) { | ||
this.properties = properties; | ||
} | ||
|
||
private List<ModelASTJobProperty> properties = new ArrayList<ModelASTJobProperty>(); | ||
@Override | ||
public String toString() { | ||
return "ModelASTJobProperties{" + | ||
"properties=" + properties + | ||
"}"; | ||
} | ||
|
||
@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; | ||
} | ||
|
||
ModelASTJobProperties that = (ModelASTJobProperties) o; | ||
|
||
return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null; | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = super.hashCode(); | ||
result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0); | ||
return result; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTJobProperty.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
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