Skip to content
Permalink
Browse files
[FIXED JENKINS-40393] i18n for validation messages
  • Loading branch information
abayer committed Dec 16, 2016
1 parent 1596f6e commit 165db74375e95b484825b41f6631b2c966c7a8ed
Showing with 352 additions and 198 deletions.
  1. +1 −1 ...odel-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTMethodCall.java
  2. +3 −3 ...line-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTStep.java
  3. +30 −0 ...del-api/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ast/Messages.properties
  4. +14 −13 ...efinition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/JSONParser.groovy
  5. +48 −45 ...finition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy
  6. +35 −0 ...el-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/Parser.groovy
  7. +46 −45 ...rc/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidatorImpl.groovy
  8. +81 −1 ...-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/Messages.properties
  9. +26 −24 ...definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/AbstractModelDefTest.java
  10. +1 −1 ...on/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/DeclarativeLinterCommandTest.java
  11. +58 −58 ...-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/ValidatorTest.java
  12. +1 −1 ...-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/WhenStageTest.java
  13. +3 −2 .../test/java/org/jenkinsci/plugins/pipeline/modeldefinition/endpoints/ModelConverterActionTest.java
  14. +3 −3 ...test/java/org/jenkinsci/plugins/pipeline/modeldefinition/parser/GroovyShellDecoratorImplTest.java
  15. +2 −1 ...finition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParserTest.java
@@ -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;
}
@@ -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;
}

@@ -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

@@ -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
@@ -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
@@ -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) {
@@ -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))
}
}

@@ -264,7 +265,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
@@ -290,20 +291,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
@@ -363,8 +364,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))

}

@@ -486,12 +487,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 165db74

Please sign in to comment.