Skip to content
Permalink
Browse files

[FIXED JENKINS-39394] Renamed "postBuild" to "post".

Also moved ast-schema.json to pipeline-model-api, where it should be.
  • Loading branch information...
abayer committed Nov 2, 2016
1 parent d954650 commit 567066b49c0b7cf582377696317f08960bcd7407
Showing with 220 additions and 91 deletions.
  1. +12 −0 pipeline-model-api/pom.xml
  2. +79 −0 pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ASTSchema.java
  3. +2 −2 ...del-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTPipelineDef.java
  4. +1 −1 ...model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTPostBuild.java
  5. +4 −4 {pipeline-model-definition → pipeline-model-api}/src/main/resources/ast-schema.json
  6. +89 −0 pipeline-model-api/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/ASTSchemaTest.java
  7. +1 −13 pipeline-model-definition/pom.xml
  8. +4 −4 ...model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Root.groovy
  9. +2 −14 ...definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/Converter.groovy
  10. +2 −2 ...efinition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/JSONParser.groovy
  11. +4 −1 ...finition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy
  12. +1 −1 ...rc/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidatorImpl.groovy
  13. +0 −9 .../src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/endpoints/ModelConverterAction.java
  14. +1 −1 ...inition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy
  15. +1 −1 ...definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/AbstractModelDefTest.java
  16. +1 −1 ...-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/ValidatorTest.java
  17. +0 −21 .../test/java/org/jenkinsci/plugins/pipeline/modeldefinition/endpoints/ModelConverterActionTest.java
  18. +1 −1 pipeline-model-definition/src/test/resources/buildConditionOrdering.groovy
  19. +1 −1 pipeline-model-definition/src/test/resources/buildPluginParentPOM.groovy
  20. +1 −1 pipeline-model-definition/src/test/resources/errors/duplicatePostBuildConditions.groovy
  21. +1 −1 pipeline-model-definition/src/test/resources/errors/emptyPostBuild.groovy
  22. +1 −1 pipeline-model-definition/src/test/resources/errors/invalidBuildCondition.groovy
  23. +1 −1 pipeline-model-definition/src/test/resources/failingPipeline.groovy
  24. +1 −1 pipeline-model-definition/src/test/resources/failingPostBuild.groovy
  25. +1 −1 pipeline-model-definition/src/test/resources/json/errors/emptyPostBuild.json
  26. +1 −1 pipeline-model-definition/src/test/resources/json/errors/invalidBuildCondition.json
  27. +1 −1 pipeline-model-definition/src/test/resources/json/simplePostBuild.json
  28. +1 −1 pipeline-model-definition/src/test/resources/postOnChangeChanged.groovy
  29. +1 −1 pipeline-model-definition/src/test/resources/postOnChangeFailed.groovy
  30. +1 −1 pipeline-model-definition/src/test/resources/postStage/globalAndLocalAlways.groovy
  31. +1 −1 pipeline-model-definition/src/test/resources/postStage/localAll.groovy
  32. +1 −1 pipeline-model-definition/src/test/resources/simplePostBuild.groovy
  33. +1 −1 pipeline-model-definition/src/test/resources/unstablePost.groovy
@@ -38,6 +38,18 @@
<url>https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Model+Definition+Plugin</url>

<dependencies>
<!-- JSON schema stuff -->
<dependency>
<groupId>com.github.fge</groupId>
<artifactId>json-schema-validator</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-json-org</artifactId>
<version>2.2.3</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
@@ -0,0 +1,79 @@
/*
* 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;

import com.github.fge.jsonschema.exceptions.ProcessingException;
import com.github.fge.jsonschema.main.JsonSchema;
import com.github.fge.jsonschema.main.JsonSchemaFactory;
import hudson.Extension;
import hudson.model.RootAction;
import hudson.util.TimeUnit2;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import javax.servlet.ServletException;
import java.io.IOException;

/**
* Endpoint for exposing the AST JSON schema.
*
* @author Andrew Bayer
*/
@Extension
public class ASTSchema implements RootAction {
public static final String AST_SCHEMA_URL = "pipeline-model-schema";

@Override
public String getUrlName() {
return AST_SCHEMA_URL;
}

@Override
public String getIconFileName() {
return null;
}

@Override
public String getDisplayName() {
return null;
}

@SuppressWarnings("unused")
public void doJson(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
rsp.serveFile(req, getClass().getResource("/ast-schema.json"), TimeUnit2.DAYS.toMillis(1));
}

/**
* Get the Pipeline Config AST JSON schema.
*
* @return the schema in {@link JsonSchema} form.
* @throws ProcessingException
*/
public static JsonSchema getJSONSchema() throws ProcessingException {
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
return factory.getJsonSchema("resource:/ast-schema.json");
}

}
@@ -29,7 +29,7 @@ public ModelASTPipelineDef(Object sourceLocation) {
public JSONObject toJSON() {
JSONObject a = new JSONObject();
a.put("stages", stages != null ? stages.toJSON() : null);
a.put("postBuild", postBuild != null ? postBuild.toJSON() : null);
a.put("post", postBuild != null ? postBuild.toJSON() : null);
a.put("environment", environment != null ? environment.toJSON() : null);
a.put("agent", agent != null ? agent.toJSON() : null);
a.put("tools", tools != null ? tools.toJSON() : null);
@@ -276,7 +276,7 @@ public void setWrappers(ModelASTWrappers wrappers) {
public String toString() {
return "ModelASTPipelineDef{" +
"stages=" + stages +
", postBuild=" + postBuild +
", post=" + postBuild +
", environment=" + environment +
", agent=" + agent +
", tools=" + tools +
@@ -15,7 +15,7 @@ public ModelASTPostBuild(Object sourceLocation) {

@Override
public java.lang.String getName() {
return "postBuild";
return "post";
}

@Override
@@ -289,7 +289,7 @@
}
]
},
"postBuild": {
"post": {
"description": "An array of build conditions with blocks of steps to run if those conditions are satisfied at the end of the build while still on the image/node the build ran on",
"type": "object",
"properties": {
@@ -317,7 +317,7 @@
"$ref": "#/definitions/agent"
},
"post": {
"$ref": "#/definitions/postBuild"
"$ref": "#/definitions/post"
},
"tools": {
"$ref": "#/definitions/tools"
@@ -352,8 +352,8 @@
"stages": {
"$ref": "#/definitions/stages"
},
"postBuild": {
"$ref": "#/definitions/postBuild"
"post": {
"$ref": "#/definitions/post"
},
"environment": {
"$ref": "#/definitions/environment"
@@ -0,0 +1,89 @@
/*
* 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;

import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.junit.ClassRule;
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.JenkinsRule;

import java.io.IOException;
import java.net.URL;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;

public class ASTSchemaTest {
@ClassRule
public static BuildWatcher buildWatcher = new BuildWatcher();
@ClassRule
public static JenkinsRule j = new JenkinsRule();

@Test
public void doSchema() throws Exception {
JenkinsRule.WebClient wc = j.createWebClient();
String rawSchema = wc.goTo(ASTSchema.AST_SCHEMA_URL + "/json", "application/json").getWebResponse().getContentAsString();
assertNotNull(rawSchema);
JSONObject remoteSchema = JSONObject.fromObject(rawSchema);
assertNotNull(remoteSchema);
assertFalse(remoteSchema.isEmpty());
assertFalse(remoteSchema.isNullObject());

String rawInternalSchema = fileContentsFromResources("ast-schema.json");
assertNotNull(rawInternalSchema);
JSONObject internalSchema = JSONObject.fromObject(rawInternalSchema);

assertNotNull(internalSchema);
assertFalse(internalSchema.isEmpty());
assertFalse(internalSchema.isNullObject());

assertEquals(internalSchema, remoteSchema);
}

protected String fileContentsFromResources(String fileName) throws IOException {
return fileContentsFromResources(fileName, false);
}

protected String fileContentsFromResources(String fileName, boolean swallowError) throws IOException {
String fileContents = null;

URL url = getClass().getResource("/" + fileName);
if (url != null) {
fileContents = IOUtils.toString(url);
}

if (!swallowError) {
assertNotNull("No file contents for file " + fileName, fileContents);
} else {
assumeTrue(fileContents != null);
}
return fileContents;

}
}
@@ -112,19 +112,7 @@
<version>1.22</version>
</dependency>

<!-- JSON schema stuff -->
<dependency>
<groupId>com.github.fge</groupId>
<artifactId>json-schema-validator</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-json-org</artifactId>
<version>2.2.3</version>
</dependency>

<!-- TEST deps -->
<!-- TEST deps -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
@@ -46,7 +46,7 @@ public class Root implements NestedModel, Serializable {
Stages stages

@Whitelisted
PostBuild postBuild
PostBuild post

@Whitelisted
Environment environment
@@ -73,8 +73,8 @@ public class Root implements NestedModel, Serializable {
}

@Whitelisted
Root postBuild(PostBuild p) {
this.postBuild = p
Root post(PostBuild p) {
this.post = p
return this
}

@@ -147,7 +147,7 @@ public class Root implements NestedModel, Serializable {
*/
@Whitelisted
List<Closure> satisfiedPostBuilds(Object runWrapperObj) {
return satisfiedConditionsForField(postBuild, runWrapperObj)
return satisfiedConditionsForField(post, runWrapperObj)
}

@Override
@@ -28,14 +28,14 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule
import com.github.fge.jsonschema.exceptions.ProcessingException
import com.github.fge.jsonschema.main.JsonSchema
import com.github.fge.jsonschema.main.JsonSchemaFactory
import com.github.fge.jsonschema.report.ProcessingReport
import net.sf.json.JSONObject
import org.apache.commons.lang.reflect.FieldUtils
import org.codehaus.groovy.control.CompilationFailedException
import org.codehaus.groovy.control.CompilationUnit
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.SourceUnit
import org.jenkinsci.plugins.pipeline.modeldefinition.ASTSchema
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTPipelineDef
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTStep
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution
@@ -66,7 +66,7 @@ public class Converter {
public static ProcessingReport validateJSONAgainstSchema(JSONObject origJson) throws ProcessingException {
JsonNode jsonNode = jacksonJSONFromJSONObject(origJson);

JsonSchema schema = getJSONSchema();
JsonSchema schema = ASTSchema.getJSONSchema();

return schema.validate(jsonNode)
}
@@ -84,18 +84,6 @@ public class Converter {
return mapper.valueToTree(input);
}


/**
* Get the Pipeline Config AST JSON schema.
*
* @return the schema in {@link JsonSchema} form.
* @throws ProcessingException
*/
public static JsonSchema getJSONSchema() throws ProcessingException {
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
return factory.getJsonSchema("resource:/ast-schema.json");
}

/**
* Converts a script at a given URL into {@link ModelASTPipelineDef}
*
@@ -127,8 +127,8 @@ class JSONParser {
case 'agent':
pipelineDef.agent = parseAgent(pipelineJson.get("agent"))
break
case 'postBuild':
pipelineDef.postBuild = parsePostBuild(pipelineJson.getJSONObject("postBuild"))
case 'post':
pipelineDef.postBuild = parsePostBuild(pipelineJson.getJSONObject("post"))
break
case 'tools':
pipelineDef.tools = parseTools(pipelineJson.getJSONArray("tools"))
@@ -172,7 +172,7 @@ class ModelParser {
case 'environment':
r.environment = parseEnvironment(stmt);
break;
case 'postBuild':
case 'post':
r.postBuild = parsePostBuild(stmt);
break;
case 'agent':
@@ -196,6 +196,9 @@ class ModelParser {
case 'notifications':
errorCollector.error(r, "The 'notifications' section has been removed as of version 0.6. Use 'post' for all post-build actions.")
break
case 'postBuild':
errorCollector.error(r, "The 'postBuild' section has been renamed as of version 0.6. Use 'post' for all post-build actions.")
break
default:
// We need to check for unknowns here.
errorCollector.error(r, "Undefined section '$name'")
@@ -102,7 +102,7 @@ class ModelValidatorImpl implements ModelValidator {
}

public boolean validateElement(@Nonnull ModelASTPostBuild postBuild) {
// postBuild specific validation
// post specific validation
true
}

0 comments on commit 567066b

Please sign in to comment.
You can’t perform that action at this time.