Search in sources :

Example 1 with MetricsSerializerAdapter

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());
    }
}
Also used : Metrics(fr.inria.spirals.repairnator.process.inspectors.Metrics) MetricsSerializerAdapter(fr.inria.spirals.repairnator.process.inspectors.MetricsSerializerAdapter) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) SerializedData(fr.inria.spirals.repairnator.serializer.engines.SerializedData) SerializerEngine(fr.inria.spirals.repairnator.serializer.engines.SerializerEngine) Date(java.util.Date)

Example 2 with MetricsSerializerAdapter

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);
    }
}
Also used : Metrics(fr.inria.spirals.repairnator.process.inspectors.Metrics) MetricsSerializerAdapter(fr.inria.spirals.repairnator.process.inspectors.MetricsSerializerAdapter) GsonBuilder(com.google.gson.GsonBuilder) FileOutputStream(java.io.FileOutputStream) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File)

Aggregations

Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 Metrics (fr.inria.spirals.repairnator.process.inspectors.Metrics)2 MetricsSerializerAdapter (fr.inria.spirals.repairnator.process.inspectors.MetricsSerializerAdapter)2 JsonObject (com.google.gson.JsonObject)1 SerializedData (fr.inria.spirals.repairnator.serializer.engines.SerializedData)1 SerializerEngine (fr.inria.spirals.repairnator.serializer.engines.SerializerEngine)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1