Search in sources :

Example 6 with SerializerEngine

use of fr.inria.spirals.repairnator.serializer.engines.SerializerEngine in project repairnator by Spirals-Team.

the class NPEFixSerializer method serializeData.

@Override
public void serializeData(ProjectInspector inspector) {
    JsonElement result = inspector.getJobStatus().getNpeFixResults();
    if (result != null) {
        List<Object> dataAsList = new ArrayList<>();
        dataAsList.add(Utils.getHostname());
        dataAsList.add(inspector.getBuildToBeInspected().getRunId());
        dataAsList.add(Utils.formatCompleteDate(new Date()));
        dataAsList.add(Utils.formatOnlyDay(new Date()));
        dataAsList.add(inspector.getRepoSlug());
        dataAsList.add(inspector.getBuggyBuild().getId());
        dataAsList.add(result.toString());
        JsonObject dataAsJson = new JsonObject();
        dataAsJson.addProperty("hostname", Utils.getHostname());
        dataAsJson.addProperty("runId", inspector.getBuildToBeInspected().getRunId());
        dataAsJson.addProperty("buildId", inspector.getBuggyBuild().getId());
        dataAsJson.addProperty("repositoryName", inspector.getRepoSlug());
        this.addDate(dataAsJson, "computedDate", new Date());
        dataAsJson.addProperty("computedDateStr", Utils.formatCompleteDate(new Date()));
        dataAsJson.addProperty("computedDay", Utils.formatOnlyDay(new Date()));
        dataAsJson.add("result", result);
        List<SerializedData> serializedData = new ArrayList<>();
        serializedData.add(new SerializedData(dataAsList, dataAsJson));
        for (SerializerEngine engine : this.getEngines()) {
            engine.serialize(serializedData, this.getType());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) 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 7 with SerializerEngine

use of fr.inria.spirals.repairnator.serializer.engines.SerializerEngine in project repairnator by Spirals-Team.

the class NopolSerializer method serializeData.

@Override
public void serializeData(ProjectInspector inspector) {
    if (inspector.getJobStatus().getNopolInformations() != null) {
        BuildToBeInspected buildToBeInspected = inspector.getBuildToBeInspected();
        List<SerializedData> allDatas = new ArrayList<>();
        for (NopolInformation nopolInformation : inspector.getJobStatus().getNopolInformations()) {
            if (nopolInformation.getPatches().isEmpty()) {
                SerializedData data = new SerializedData(this.serializeNopolInfoAsList(buildToBeInspected, nopolInformation, null, 0), this.serializeNopolInfoAsJson(buildToBeInspected, nopolInformation, null, 0));
                allDatas.add(data);
            } else {
                int patchNumber = 1;
                for (PatchAndDiff patchAndDiff : nopolInformation.getPatches()) {
                    SerializedData data = new SerializedData(this.serializeNopolInfoAsList(buildToBeInspected, nopolInformation, patchAndDiff, patchNumber), this.serializeNopolInfoAsJson(buildToBeInspected, nopolInformation, patchAndDiff, patchNumber));
                    allDatas.add(data);
                    patchNumber++;
                }
            }
            for (SerializerEngine engine : this.getEngines()) {
                engine.serialize(allDatas, this.getType());
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SerializedData(fr.inria.spirals.repairnator.serializer.engines.SerializedData) SerializerEngine(fr.inria.spirals.repairnator.serializer.engines.SerializerEngine) MongoDBSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine) PatchAndDiff(fr.inria.spirals.repairnator.process.nopol.PatchAndDiff) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) NopolInformation(fr.inria.spirals.repairnator.process.nopol.NopolInformation)

Example 8 with SerializerEngine

use of fr.inria.spirals.repairnator.serializer.engines.SerializerEngine in project repairnator by Spirals-Team.

the class PipelineErrorSerializer method serializeData.

@Override
public void serializeData(ProjectInspector inspector) {
    List<Object> dataAsList = new ArrayList<>();
    dataAsList.add(Utils.getHostname());
    dataAsList.add(inspector.getBuildToBeInspected().getRunId());
    dataAsList.add(Utils.formatCompleteDate(new Date()));
    dataAsList.add(Utils.formatOnlyDay(new Date()));
    dataAsList.add(inspector.getRepoSlug());
    dataAsList.add(inspector.getBuggyBuild().getId());
    for (List<String> strings : inspector.getJobStatus().getStepErrors().values()) {
        dataAsList.add(StringUtils.join(strings, "       "));
    }
    JsonObject dataAsJson = new JsonObject();
    dataAsJson.addProperty("hostname", Utils.getHostname());
    dataAsJson.addProperty("runId", inspector.getBuildToBeInspected().getRunId());
    dataAsJson.addProperty("buildId", inspector.getBuggyBuild().getId());
    dataAsJson.addProperty("repositoryName", inspector.getRepoSlug());
    this.addDate(dataAsJson, "computedDate", new Date());
    dataAsJson.addProperty("computedDateStr", Utils.formatCompleteDate(new Date()));
    dataAsJson.addProperty("computedDay", Utils.formatOnlyDay(new Date()));
    for (Map.Entry<String, List<String>> stringListEntry : inspector.getJobStatus().getStepErrors().entrySet()) {
        JsonArray jsonElements = new JsonArray();
        for (String message : stringListEntry.getValue()) {
            jsonElements.add(message);
        }
        dataAsJson.add(stringListEntry.getKey(), jsonElements);
    }
    List<SerializedData> serializedData = new ArrayList<>();
    serializedData.add(new SerializedData(dataAsList, dataAsJson));
    for (SerializerEngine serializerEngine : this.getEngines()) {
        serializerEngine.serialize(serializedData, this.getType());
    }
}
Also used : ArrayList(java.util.ArrayList) 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) JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 9 with SerializerEngine

use of fr.inria.spirals.repairnator.serializer.engines.SerializerEngine in project repairnator by Spirals-Team.

the class TestProjectInspector method testRepairingWithNPEFix.

@Test
public void testRepairingWithNPEFix() throws IOException, GitAPIException {
    // surli/failingProject npe
    int buildId = 253130137;
    Path tmpDirPath = Files.createTempDirectory("test_complete_npe");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    Build failingBuild = BuildHelper.getBuildFromId(buildId, null);
    BuildToBeInspected buildToBeInspected = new BuildToBeInspected(failingBuild, null, ScannedBuildStatus.ONLY_FAIL, "testnpe");
    List<AbstractDataSerializer> serializers = new ArrayList<>();
    List<AbstractNotifier> notifiers = new ArrayList<>();
    List<SerializerEngine> serializerEngines = new ArrayList<>();
    SerializerEngine serializerEngine = mock(SerializerEngine.class);
    serializerEngines.add(serializerEngine);
    List<NotifierEngine> notifierEngines = new ArrayList<>();
    NotifierEngine notifierEngine = mock(NotifierEngine.class);
    notifierEngines.add(notifierEngine);
    serializers.add(new InspectorSerializer(serializerEngines));
    serializers.add(new NopolSerializer(serializerEngines));
    notifiers.add(new PatchNotifier(notifierEngines));
    RepairnatorConfig config = RepairnatorConfig.getInstance();
    config.setLauncherMode(LauncherMode.REPAIR);
    ProjectInspector inspector = new ProjectInspector(buildToBeInspected, tmpDir.getAbsolutePath(), serializers, notifiers);
    inspector.run();
    JobStatus jobStatus = inspector.getJobStatus();
    assertThat(jobStatus.getAstorStatus(), is(AstorOutputStatus.MAX_GENERATION));
    assertThat(jobStatus.getPipelineState(), is(PipelineState.NOPOL_PATCHED));
    assertThat(jobStatus.getPushState(), is(PushState.REPAIR_INFO_COMMITTED));
    assertThat(jobStatus.getFailureLocations().size(), is(1));
    assertThat(jobStatus.getMetrics().getFailureNames().size(), is(1));
    assertThat(jobStatus.isHasBeenPatched(), is(true));
    assertThat(jobStatus.getNpeFixPatches().size(), is(6));
    // Nopol and NPEFix
    verify(notifierEngine, times(2)).notify(anyString(), anyString());
    verify(serializerEngine, times(1)).serialize(anyListOf(SerializedData.class), eq(SerializerType.INSPECTOR));
    verify(serializerEngine, times(1)).serialize(anyListOf(SerializedData.class), eq(SerializerType.NOPOL));
    Git gitDir = Git.open(new File(inspector.getRepoToPushLocalPath()));
    Iterable<RevCommit> logs = gitDir.log().call();
    Iterator<RevCommit> iterator = logs.iterator();
    assertThat(iterator.hasNext(), is(true));
    RevCommit commit = iterator.next();
    assertThat(commit.getShortMessage(), containsString("End of the repairnator process"));
    commit = iterator.next();
    assertThat(commit.getShortMessage(), containsString("Automatic repair"));
    commit = iterator.next();
    assertThat(commit.getShortMessage(), containsString("Bug commit"));
    assertThat(iterator.hasNext(), is(false));
}
Also used : PatchNotifier(fr.inria.spirals.repairnator.notifier.PatchNotifier) AbstractNotifier(fr.inria.spirals.repairnator.notifier.AbstractNotifier) ArrayList(java.util.ArrayList) AbstractDataSerializer(fr.inria.spirals.repairnator.serializer.AbstractDataSerializer) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) Build(fr.inria.jtravis.entities.Build) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Path(java.nio.file.Path) RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) SerializerEngine(fr.inria.spirals.repairnator.serializer.engines.SerializerEngine) SerializedData(fr.inria.spirals.repairnator.serializer.engines.SerializedData) InspectorSerializer(fr.inria.spirals.repairnator.serializer.InspectorSerializer) Git(org.eclipse.jgit.api.Git) NotifierEngine(fr.inria.spirals.repairnator.notifier.engines.NotifierEngine) NopolSerializer(fr.inria.spirals.repairnator.serializer.NopolSerializer) File(java.io.File) Test(org.junit.Test)

Example 10 with SerializerEngine

use of fr.inria.spirals.repairnator.serializer.engines.SerializerEngine in project repairnator by Spirals-Team.

the class TestProjectInspector method testPatchFailingProjectM70.

@Ignore
@Test
public void testPatchFailingProjectM70() throws IOException, GitAPIException {
    // surli/failingProject only-one-failing
    int buildId = 269201915;
    Path tmpDirPath = Files.createTempDirectory("test_complete");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    Build failingBuild = BuildHelper.getBuildFromId(buildId, null);
    BuildToBeInspected buildToBeInspected = new BuildToBeInspected(failingBuild, null, ScannedBuildStatus.ONLY_FAIL, "test");
    List<AbstractDataSerializer> serializers = new ArrayList<>();
    List<AbstractNotifier> notifiers = new ArrayList<>();
    List<SerializerEngine> serializerEngines = new ArrayList<>();
    SerializerEngine serializerEngine = mock(SerializerEngine.class);
    serializerEngines.add(serializerEngine);
    List<NotifierEngine> notifierEngines = new ArrayList<>();
    NotifierEngine notifierEngine = mock(NotifierEngine.class);
    notifierEngines.add(notifierEngine);
    serializers.add(new InspectorSerializer(serializerEngines));
    serializers.add(new NopolSerializer(serializerEngines));
    notifiers.add(new PatchNotifier(notifierEngines));
    RepairnatorConfig config = RepairnatorConfig.getInstance();
    config.setLauncherMode(LauncherMode.REPAIR);
    ProjectInspector inspector = new ProjectInspector(buildToBeInspected, tmpDir.getAbsolutePath(), serializers, notifiers);
    inspector.run();
    JobStatus jobStatus = inspector.getJobStatus();
    assertThat(jobStatus.getAstorStatus(), is(AstorOutputStatus.STOP_BY_PATCH_FOUND));
    assertThat(jobStatus.getPipelineState(), is(PipelineState.NOPOL_NOTPATCHED));
    assertThat(jobStatus.getPushState(), is(PushState.REPAIR_INFO_COMMITTED));
    assertThat(jobStatus.getFailureLocations().size(), is(1));
    assertThat(jobStatus.getMetrics().getFailureNames().size(), is(1));
    // notify for Astor, NPEFix and Nopol
    verify(notifierEngine, times(3)).notify(anyString(), anyString());
    verify(serializerEngine, times(1)).serialize(anyListOf(SerializedData.class), eq(SerializerType.INSPECTOR));
    verify(serializerEngine, times(1)).serialize(anyListOf(SerializedData.class), eq(SerializerType.NOPOL));
    Git gitDir = Git.open(new File(inspector.getRepoToPushLocalPath()));
    Iterable<RevCommit> logs = gitDir.log().call();
    Iterator<RevCommit> iterator = logs.iterator();
    assertThat(iterator.hasNext(), is(true));
    RevCommit commit = iterator.next();
    assertThat(commit.getShortMessage(), containsString("End of the repairnator process"));
    commit = iterator.next();
    assertThat(commit.getShortMessage(), containsString("Automatic repair"));
    commit = iterator.next();
    assertThat(commit.getShortMessage(), containsString("Bug commit"));
    assertThat(iterator.hasNext(), is(false));
}
Also used : PatchNotifier(fr.inria.spirals.repairnator.notifier.PatchNotifier) AbstractNotifier(fr.inria.spirals.repairnator.notifier.AbstractNotifier) ArrayList(java.util.ArrayList) AbstractDataSerializer(fr.inria.spirals.repairnator.serializer.AbstractDataSerializer) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) Build(fr.inria.jtravis.entities.Build) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Path(java.nio.file.Path) RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) SerializerEngine(fr.inria.spirals.repairnator.serializer.engines.SerializerEngine) SerializedData(fr.inria.spirals.repairnator.serializer.engines.SerializedData) InspectorSerializer(fr.inria.spirals.repairnator.serializer.InspectorSerializer) Git(org.eclipse.jgit.api.Git) NotifierEngine(fr.inria.spirals.repairnator.notifier.engines.NotifierEngine) NopolSerializer(fr.inria.spirals.repairnator.serializer.NopolSerializer) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SerializerEngine (fr.inria.spirals.repairnator.serializer.engines.SerializerEngine)28 ArrayList (java.util.ArrayList)24 SerializedData (fr.inria.spirals.repairnator.serializer.engines.SerializedData)23 BuildToBeInspected (fr.inria.spirals.repairnator.BuildToBeInspected)8 RepairnatorConfig (fr.inria.spirals.repairnator.config.RepairnatorConfig)8 Build (fr.inria.jtravis.entities.Build)7 AbstractNotifier (fr.inria.spirals.repairnator.notifier.AbstractNotifier)7 AbstractDataSerializer (fr.inria.spirals.repairnator.serializer.AbstractDataSerializer)7 MongoDBSerializerEngine (fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine)7 File (java.io.File)7 Path (java.nio.file.Path)7 Test (org.junit.Test)7 NotifierEngine (fr.inria.spirals.repairnator.notifier.engines.NotifierEngine)5 InspectorSerializer (fr.inria.spirals.repairnator.serializer.InspectorSerializer)5 NopolSerializer (fr.inria.spirals.repairnator.serializer.NopolSerializer)5 Git (org.eclipse.jgit.api.Git)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 JsonObject (com.google.gson.JsonObject)4 Date (java.util.Date)4 PatchNotifier (fr.inria.spirals.repairnator.notifier.PatchNotifier)3