Skip to content

Commit

Permalink
fixesssss
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaGolomozy committed Jul 29, 2018
1 parent 1e91b49 commit 023383f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/main/java/com/dg/gocd/jenkins/JenkinsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@Extension
public class JenkinsPlugin extends AbstractGoPlugin {
private static final Logger logger = Logger.getLoggerFor(JenkinsPlugin.class);
private static final Pattern PARAMS_PATTERN = Pattern.compile("\\w+=(\\$(\\{\\w+}|\\w+)|\\w+)([,(\\r?\\n)]\\w+=(\\$(\\{\\w+}|\\w+)|\\w+))*");
private static final Pattern PARAMS_PATTERN = Pattern.compile("\\w+=(\\$(\\{\\w+}|\\w+)|\\w+)([,\\n]\\w+=(\\$(\\{\\w+}|\\w+)|\\w+))*");

private final TaskExecutorFactory taskExecutorFactory;

Expand Down Expand Up @@ -76,7 +76,7 @@ private GoPluginApiResponse handleValidation(GoPluginApiRequest requestMessage)
Map<String, String> errors = new HashMap<>();
Map request = fromJSON(requestMessage.requestBody(), Map.class);

String paramsValue = getValueOrEmpty(request, PARAMS_PROPERTY);
String paramsValue = getParamValue(request);
if (!paramsValue.isEmpty() && !PARAMS_PATTERN.matcher(paramsValue).matches()) {
errors.put(PARAMS_PROPERTY, "Params syntax is <PARAM>=<VALUE>, with COMMA or NEWLINE delimiter");
}
Expand Down Expand Up @@ -107,17 +107,21 @@ private TaskContext createTaskContext(Map context) {
}

TaskConfig createTaskConfig(Map config, Map<String, String> environmentVariables) {
String params = getValueOrEmpty(config, PARAMS_PROPERTY);
String params = getParamValue(config);
return new TaskConfig(
replaceWithEnv(getValueOrEmpty(config, URL_PROPERTY), environmentVariables),
replaceWithEnv(getValueOrEmpty(config, JOB_PROPERTY), environmentVariables),
replaceWithEnv(getValueOrEmpty(config, USERNAME_PROPERTY), environmentVariables),
replaceWithEnv(getValueOrEmpty(config, PASSWORD_PROPERTY), environmentVariables),
params.isEmpty() ? emptyMap() : Arrays.stream(replaceWithEnv(params, environmentVariables).split(",|\\r?\\n"))
params.isEmpty() ? emptyMap() : Arrays.stream(replaceWithEnv(params, environmentVariables).split("[,\\n]"))
.map(s -> s.split("=")).collect(Collectors.toMap(s -> s[0].trim(), s -> s[1].trim()))
);
}

private String getParamValue(Map request) {
return getValueOrEmpty(request, PARAMS_PROPERTY).replaceAll("\\r", "");
}

private GoPluginApiResponse handleTaskView() {
Map<String, Object> view = new HashMap<>();
view.put("displayValue", "Jenkins");
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/validate-request.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"params": {
"secure": false,
"value": "var=${GO_FROM_REVISION_TEST}\nvar2=blabla,var3=lol",
"value": "var=${GO_FROM_REVISION_TEST}\nvar2=blabla,var3=lol\r\nvar4=bla",
"required": false
},
"url": {
Expand Down

0 comments on commit 023383f

Please sign in to comment.