I'm using PDI API to get the language distribution for code in my projects.
Using a request like
var url = "http://<my_sonar_instance>/api/measures/component?additionalFields=metrics&component=<sonar_key>&metricKeys=duplicated_lines_density%2Cblocker_violations%2Ccomment_lines_density%2Ccritical_violations%2Cnew_maintainability_rating%2Cnew_duplicated_lines_density%2Cnew_reliability_rating%2Cnew_security_rating%2Cncloc%2Cncloc_language_distribution";
and parsing the JSON result by
$.component.measures[?(@.metric=="ncloc_language_distribution")].value
to assign the value at a variable named
sonar_ncloc_language_distribution
I obtain for example
java=10514;js=237;jsp=3995;web=5;xml=42
Now I'd like to assign those values at some variables in a PDI transformation using a Modified JavaScript value using this Javascript code
var map = new Map();
sonar_ncloc_language_distribution.split(";").forEach(x => map[x.split("=")[0]] = x.split("=")[1]);
var sonar_ncloc_java = map.java;
var sonar_ncloc_js = map.js;
var sonar_ncloc_jsp = map.jsp;
var sonar_ncloc_web = map.web;
var sonar_ncloc_xml = map.xml;
but it doesn't work and the error is
Unable compile javascript:
syntax error (script#2)
(NOTE: if I try to execute the javascript code "alone" in a HTML file all works fine ...)
<!DOCTYPE html>
<html>
<body>
<script>
var sonar_ncloc_language_distribution = "java=10514;js=237;jsp=3995;web=5;xml=42";
var map = new Map();
sonar_ncloc_language_distribution.split(";").forEach(x => map[x.split("=")[0]] = x.split("=")[1]);
console.log(map);
var sonar_ncloc_java = map.java;
var sonar_ncloc_js = map.js;
var sonar_ncloc_jsp = map.jsp;
var sonar_ncloc_web = map.web;
var sonar_ncloc_xml = map.xml;
console.log(map.java);
console.log(map.js);
console.log(map.jsp);
console.log(map.web);
console.log(map.xml);
</script>
</body>
</html>
Any suggestion will be appreciated and thank you in advance
from Pentaho Data Integration: extract language distribution code
No comments:
Post a Comment