doumam
(Mamadou Sanoussy Diallo)
July 2, 2020, 2:53pm
1
Hello,
I have to develop a sonarqube plugin which takes care of adding a web page to the platform which will display data that I am able to recover in the project to be analyzed using a sensor. The problem that I have is how to transmit this data retrieved from the java side with the sensor to the javascript side and finally display it on my page.
Thank you for help.
doumam
(Mamadou Sanoussy Diallo)
July 8, 2020, 10:35pm
2
public class MySensor implements Sensor {
private static final Logger LOGGER = Loggers.get(MySensor.class);
private static final String[] DEFAULT_PATHS = {"target/report.json"};
static final String REPORT_PATHS_PROPERTY_KEY = "sonar.jsonReportPaths";
public static JsonArray JSON_ARRAY;
@Override
public void describe(SensorDescriptor descriptor) {
descriptor.name(" JSON Report Importer");
}
@Override
public void execute(SensorContext context) {
ReportPathsProvider reportPathsProvider = new ReportPathsProvider(context);
//Iterable<InputFile> inputFiles = context.fileSystem().inputFiles(context.fileSystem().predicates().all());
importReports(reportPathsProvider);
}
void importReports(ReportPathsProvider reportPathsProvider) {
Collection<Path> reportPaths = reportPathsProvider.getPaths(DEFAULT_PATHS,REPORT_PATHS_PROPERTY_KEY);
if (reportPaths.isEmpty()) {
LOGGER.info("No report imported, no coverage information will be imported by JSON Report Importer");
return;
}
for(Path reportPath : reportPaths) {
LOGGER.info("Reading report '{}'",reportPath);
File file = reportPath.toFile();
try {
// Create JsonReader from Json.
JsonReader reader = Json.createReader(new FileInputStream(file));
// Get the JsonArray structure from JsonReader.
JSON_ARRAY = reader.readArray();
reader.close();
LOGGER.info("FILE '{}' content ==> \n '{}'",reportPath, JSON_ARRAY.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
here my sensor i need te get JSON_ARRAY in my java side to desplay it in my web page extension.
Any idea??