Skip to content

Commit

Permalink
Merge branch 'master' into JENKINS-40370
Browse files Browse the repository at this point in the history
Conflicts:
	pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidatorImpl.groovy
	pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/Messages.properties
  • Loading branch information
abayer committed Dec 30, 2016
2 parents d28a97c + a1963cd commit 221d6e8
Show file tree
Hide file tree
Showing 24 changed files with 419 additions and 198 deletions.
6 changes: 5 additions & 1 deletion SYNTAX.md
Expand Up @@ -161,7 +161,11 @@ stages {
sh 'mvn install'
script {
// any valid Pipeline Script goes here
['ie','chrome'].each { sh "./test.sh ${it}" }
def browsers = ["ie", "chrome", "safari"]
for (int i = 0; i < browsers.size(); i++) {
def browser = browsers.get(i)
sh "./test.sh ${browser}"
}
}
}
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ public class ModelASTMethodCall extends ModelASTElement implements ModelASTMetho

public static Map<String, String> getBlockedSteps() {
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("node", "The node step cannot be called as an argument to a method in Declarative Pipelines");
map.put("node", Messages.ModelASTMethodCall_BlockedSteps_Node());
map.putAll(ModelASTStep.getBlockedSteps());
return map;
}
Expand Down
Expand Up @@ -21,9 +21,9 @@ public class ModelASTStep extends ModelASTElement {

public static Map<String, String> blockedStepsBase() {
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
map.put("stage", "The stage step cannot be used in Declarative Pipelines");
map.put("properties", "The properties step cannot be used in Declarative Pipelines");
map.put("parallel", "The parallel step can only be used as the only top-level step in a stage's step block");
map.put("stage", Messages.ModelASTStep_BlockedSteps_Stage());
map.put("properties", Messages.ModelASTStep_BlockedSteps_Properties());
map.put("parallel", Messages.ModelASTStep_BlockedSteps_Parallel());
return map;
}

Expand Down
@@ -0,0 +1,30 @@
#
# 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.
#

ModelASTStep.BlockedSteps.Stage=The stage step cannot be used in Declarative Pipelines
ModelASTStep.BlockedSteps.Properties=The properties step cannot be used in Declarative Pipelines
ModelASTStep.BlockedSteps.Parallel=The parallel step can only be used as the only top-level step in a stage's step block

ModelASTMethodCall.BlockedSteps.Node=The node step cannot be called as an argument to a method in Declarative Pipelines

Expand Up @@ -41,5 +41,10 @@ public class Aborted extends BuildCondition {
return r.getResult() != null && r.getResult().equals(Result.ABORTED)
}

@Override
public String getDescription() {
return Messages.Aborted_Description()
}

public static final long serialVersionUID = 1L
}
Expand Up @@ -40,6 +40,11 @@ public class Always extends BuildCondition {
return true
}

@Override
public String getDescription() {
return Messages.Always_Description()
}

public static final long serialVersionUID = 1L

}
Expand Up @@ -59,6 +59,12 @@ public class Changed extends BuildCondition {
}
}

@Override
public String getDescription() {
return Messages.Changed_Description()
}


public static final long serialVersionUID = 1L

}
Expand Up @@ -41,5 +41,10 @@ public class Failure extends BuildCondition {
return r.getResult() != null && r.getResult().equals(Result.FAILURE)
}

@Override
public String getDescription() {
return Messages.Failure_Description()
}

public static final long serialVersionUID = 1L
}
Expand Up @@ -41,5 +41,10 @@ public class Success extends BuildCondition {
return r.getResult() == null || r.getResult().isBetterOrEqualTo(Result.SUCCESS)
}

@Override
public String getDescription() {
return Messages.Success_Description()
}

public static final long serialVersionUID = 1L
}
Expand Up @@ -41,5 +41,10 @@ public class Unstable extends BuildCondition {
return r.getResult() != null && r.getResult().equals(Result.UNSTABLE)
}

@Override
public String getDescription() {
return Messages.Unstable_Description()
}

public static final long serialVersionUID = 1L
}
Expand Up @@ -30,6 +30,7 @@ import com.github.fge.jsonschema.report.ProcessingReport
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
import net.sf.json.JSONArray
import net.sf.json.JSONObject
import org.jenkinsci.plugins.pipeline.modeldefinition.Messages
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.*
import org.jenkinsci.plugins.pipeline.modeldefinition.ModelStepLoader
import org.jenkinsci.plugins.pipeline.modeldefinition.validator.ErrorCollector
Expand All @@ -46,7 +47,7 @@ import javax.annotation.Nonnull
* @author Andrew Bayer
*/
@SuppressFBWarnings(value="SE_NO_SERIALVERSIONID")
class JSONParser {
class JSONParser implements Parser {
ErrorCollector errorCollector

ModelValidator validator
Expand Down Expand Up @@ -84,7 +85,7 @@ class JSONParser {
JSONObject pipelineJson = jsonObject.getJSONObject(ModelStepLoader.STEP_NAME)
pipelineJson.keySet().each { sectionName ->
if (!sectionsSeen.add(sectionName)) {
errorCollector.error(pipelineDef, "Multiple occurences of the ${sectionName} section")
errorCollector.error(pipelineDef, Messages.Parser_MultipleOfSection(sectionName))
}

switch (sectionName) {
Expand Down Expand Up @@ -116,7 +117,7 @@ class JSONParser {
pipelineDef.wrappers = parseWrappers(pipelineJson.getJSONObject("wrappers"))
break
default:
errorCollector.error(pipelineDef, "Undefined section '${sectionName}'")
errorCollector.error(pipelineDef, Messages.Parser_UndefinedSection(sectionName))
}
}

Expand Down Expand Up @@ -273,7 +274,7 @@ class JSONParser {
// This is a single argument
pair.value = parseValue(v)
} else {
errorCollector.error(pair, "Invalid value type")
errorCollector.error(pair, Messages.JSONParser_InvalidValueType())
}

return pair
Expand All @@ -299,20 +300,20 @@ class JSONParser {
// This is a single argument
arg = parseValue(entry)
} else {
errorCollector.error(meth, "Invalid argument syntax")
errorCollector.error(meth, Messages.JSONParser_InvalidArgumentSyntax())
}
if (arg != null) {
meth.args << arg
}
} else {
errorCollector.error(meth, "Individual method arguments must be a JSON object")
errorCollector.error(meth, Messages.JSONParser_MethArgsMustBeObj())
}
}
} else {
errorCollector.error(meth, "Method arguments missing or not an array")
errorCollector.error(meth, Messages.JSONParser_MethArgsMissing())
}
} else {
errorCollector.error(meth, "Method call definition must be a JSON object")
errorCollector.error(meth, Messages.JSONParser_MethCallMustBeObj())
}

return meth
Expand Down Expand Up @@ -374,8 +375,8 @@ class JSONParser {
// No arguments.
argList = new ModelASTNamedArgumentList(null)
} else {
argList = new ModelASTNamedArgumentList(o)
errorCollector.error(argList, "Object ${o} is neither a JSONArray nor a JSONObject")
argList = new ModelASTNamedArgumentList(o)
errorCollector.error(argList, Messages.JSONParser_ObjNotJSON(o))

}

Expand Down Expand Up @@ -497,12 +498,12 @@ class JSONParser {
if (jsonNode.has("keyword")) {
if (jsonNode.get("keyword").asText().equals("required")) {
String missingProps = jsonNode.get('missing').elements().collect { "'${it.asText()}'" }.join(", ")
return "At ${location}: Missing one or more required properties: ${missingProps}"
return Messages.JSONParser_MissingRequiredProperties(location, missingProps)
} else if (jsonNode.get("keyword").asText().equals("minItems")) {
return "At ${location}: Array has ${jsonNode.get('found').asInt()} entries, requires minimum of ${jsonNode.get('minItems').asInt()}"
return Messages.JSONParser_TooFewItems(location, jsonNode.get('found').asInt(), jsonNode.get('minItems').asInt())
}
}
return "At ${location}: ${pm.message}"
return Messages.JSONParser_ProcessingError(location, pm.message)
}

}

0 comments on commit 221d6e8

Please sign in to comment.