Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Simple JSON with Gson #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import java.io.IOException;
import java.util.Map;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.io.FileUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.measures.CoverageMeasuresBuilder;
Expand All @@ -27,23 +28,30 @@ public Map<String, CoverageMeasuresBuilder> parse(File file) throws IOException

String fileString = FileUtils.readFileToString(fileToFindCoverage, "UTF-8");

JSONObject resultJsonObject = (JSONObject) JSONValue.parse(fileString);
JSONObject coverageJsonObj = (JSONObject) ((JSONObject) resultJsonObject.get("RSpec")).get("coverage");
JsonParser parser = new JsonParser();

JsonObject resultJsonObject = parser.parse(fileString).getAsJsonObject();
JsonObject coverageJsonObj = resultJsonObject.get("RSpec").getAsJsonObject().get("coverage").getAsJsonObject();


// for each file in the coverage report
for (int j = 0; j < coverageJsonObj.keySet().size(); j++)
for (int j = 0; j < coverageJsonObj.entrySet().size(); j++)
{
CoverageMeasuresBuilder fileCoverage = CoverageMeasuresBuilder.create();

String filePath = coverageJsonObj.keySet().toArray()[j].toString();
String filePath = ((Map.Entry)coverageJsonObj.entrySet().toArray()[j]).getKey().toString();
LOG.debug("filePath " + filePath);

JSONArray coverageArray = (JSONArray) coverageJsonObj.get(coverageJsonObj.keySet().toArray()[j]);
JsonArray coverageArray = coverageJsonObj.get(filePath).getAsJsonArray();

// for each line in the coverage array
for (int i = 0; i < coverageArray.size(); i++)
{
Long line = (Long) coverageArray.toArray()[i];
Long line = null;

if (!coverageArray.get(i).isJsonNull()) {
line = coverageArray.get(i).getAsLong();
}
Integer intLine = 0;
int lineNumber = i + 1;
if (line != null)
Expand Down