use of fr.inria.spirals.repairnator.process.inspectors.MetricsSerializerAdapter in project repairnator by Spirals-Team.
the class MetricsSerializer method serializeData.
@Override
public void serializeData(ProjectInspector inspector) {
Gson gson = new GsonBuilder().registerTypeAdapter(Metrics.class, new MetricsSerializerAdapter()).create();
JsonObject element = (JsonObject) gson.toJsonTree(inspector.getJobStatus().getMetrics());
element.addProperty("runId", RepairnatorConfig.getInstance().getRunId());
this.addDate(element, "reproductionDate", new Date());
element.addProperty("buggyBuildId", inspector.getBuggyBuild().getId());
element.addProperty("buildStatus", inspector.getBuildToBeInspected().getStatus().name());
if (inspector.getPatchedBuild() != null) {
element.addProperty("patchedBuildId", inspector.getPatchedBuild().getId());
}
element.addProperty("status", this.getPrettyPrintState(inspector));
List<SerializedData> dataList = new ArrayList<>();
dataList.add(new SerializedData(new ArrayList<>(), element));
for (SerializerEngine engine : this.getEngines()) {
engine.serialize(dataList, this.getType());
}
}
use of fr.inria.spirals.repairnator.process.inspectors.MetricsSerializerAdapter in project repairnator by Spirals-Team.
the class AbstractStep method writeProperty.
protected void writeProperty(String propertyName, Object value) {
if (value != null) {
this.properties.put(propertyName, value);
String filePath = this.inspector.getRepoLocalPath() + File.separator + PROPERTY_FILENAME;
File file = new File(filePath);
Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(Metrics.class, new MetricsSerializerAdapter()).create();
String jsonString = gson.toJson(this.properties);
try {
if (!file.exists()) {
file.createNewFile();
}
OutputStreamWriter outputStream = new OutputStreamWriter(new FileOutputStream(file));
outputStream.write(jsonString);
outputStream.flush();
outputStream.close();
} catch (IOException e) {
this.getLogger().error("Cannot write property to the following file: " + filePath, e);
}
} else {
this.getLogger().warn("Trying to write property null for key: " + propertyName);
}
}
Aggregations