Skip to content

Commit

Permalink
Merge pull request #71 from abayer/i18n
Browse files Browse the repository at this point in the history
[FIXED JENKINS-40393] i18n for validation messages
  • Loading branch information
abayer committed Dec 20, 2016
2 parents 01ba61a + 2d4cc63 commit 3f75171
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 198 deletions.
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 @@ -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 @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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))

}

Expand Down Expand Up @@ -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 3f75171

Please sign in to comment.