Search in sources :

Example 16 with ProjectInspector

use of fr.inria.spirals.repairnator.process.inspectors.ProjectInspector in project repairnator by Spirals-Team.

the class TestCheckoutBuggyBuildSourceCode method testCheckoutPreviousBuildSourceCodeWithPR.

@Test
public void testCheckoutPreviousBuildSourceCodeWithPR() throws IOException, GitAPIException, RepairnatorConfigException {
    // HubSpot/Singularity
    int buildId = 223248816;
    int previousBuildId = 222209171;
    ScannedBuildStatus status = ScannedBuildStatus.PASSING_AND_PASSING_WITH_TEST_CHANGES;
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    assertThat(build.isPullRequest(), is(true));
    Build previousBuild = BuildHelper.getBuildFromId(previousBuildId, null);
    assertThat(previousBuild, notNullValue());
    assertThat(previousBuild.getId(), is(previousBuildId));
    assertThat(previousBuild.isPullRequest(), is(true));
    Path tmpDirPath = Files.createTempDirectory("test_checkoutprevious");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    BuildToBeInspected toBeInspected = new BuildToBeInspected(previousBuild, build, status, "");
    ProjectInspector inspector = mock(ProjectInspector.class);
    when(inspector.getWorkspace()).thenReturn(tmpDir.getAbsolutePath());
    when(inspector.getRepoLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getRepoToPushLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repotopush");
    when(inspector.getBuildToBeInspected()).thenReturn(toBeInspected);
    when(inspector.getPatchedBuild()).thenReturn(build);
    when(inspector.getBuggyBuild()).thenReturn(previousBuild);
    when(inspector.getGitHelper()).thenReturn(new GitHelper());
    JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getJobStatus()).thenReturn(jobStatus);
    CloneRepository cloneStep = new CloneRepository(inspector);
    CheckoutBuggyBuildSourceCode checkoutBuild = new CheckoutBuggyBuildSourceCode(inspector);
    cloneStep.setNextStep(checkoutBuild);
    cloneStep.execute();
    assertThat(checkoutBuild.getPipelineState(), is(PipelineState.PREVIOUSBUILDCODECHECKEDOUT));
    assertThat(jobStatus.getPipelineState(), is(PipelineState.PREVIOUSBUILDCODECHECKEDOUT));
    assertThat(checkoutBuild.isShouldStop(), is(false));
    Git gitDir = Git.open(new File(tmpDir, "repo"));
    Iterable<RevCommit> logs = gitDir.log().call();
    Iterator<RevCommit> iterator = logs.iterator();
    boolean foundRightCommitAfterRepairCommits = false;
    boolean foundUndoSourceCodeCommit = false;
    boolean stopSearch = false;
    while (iterator.hasNext() && !stopSearch) {
        RevCommit revCommit = iterator.next();
        System.out.println(revCommit.getShortMessage());
        if (revCommit.getShortMessage().equals("Undo changes on source code")) {
            foundUndoSourceCodeCommit = true;
            CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
            CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
            ObjectReader reader = gitDir.getRepository().newObjectReader();
            RevCommit prevCommit = iterator.next();
            oldTreeIter.reset(reader, prevCommit.getTree());
            newTreeIter.reset(reader, revCommit.getTree());
            List<DiffEntry> diff = gitDir.diff().setOldTree(oldTreeIter).setNewTree(newTreeIter).call();
            for (DiffEntry entry : diff) {
                assertThat(entry.getOldPath(), startsWith("src/main/java/"));
            }
            revCommit = prevCommit;
        }
        if (!revCommit.getShortMessage().contains("repairnator") && !revCommit.getShortMessage().contains("merge")) {
            stopSearch = true;
        }
    }
    assertThat(foundUndoSourceCodeCommit, is(true));
}
Also used : Path(java.nio.file.Path) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) CanonicalTreeParser(org.eclipse.jgit.treewalk.CanonicalTreeParser) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Git(org.eclipse.jgit.api.Git) ScannedBuildStatus(fr.inria.spirals.repairnator.states.ScannedBuildStatus) Build(fr.inria.jtravis.entities.Build) ObjectReader(org.eclipse.jgit.lib.ObjectReader) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DiffEntry(org.eclipse.jgit.diff.DiffEntry) Test(org.junit.Test)

Example 17 with ProjectInspector

use of fr.inria.spirals.repairnator.process.inspectors.ProjectInspector in project repairnator by Spirals-Team.

the class TestCheckoutBuild method testCheckoutBuildFromPROtherRepo.

@Test
public void testCheckoutBuildFromPROtherRepo() throws IOException, GitAPIException {
    // surli/failingProject build
    int buildId = 196568333;
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_checkout");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    BuildToBeInspected toBeInspected = new BuildToBeInspected(build, null, ScannedBuildStatus.ONLY_FAIL, "");
    ProjectInspector inspector = mock(ProjectInspector.class);
    when(inspector.getWorkspace()).thenReturn(tmpDir.getAbsolutePath());
    when(inspector.getRepoLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getBuildToBeInspected()).thenReturn(toBeInspected);
    when(inspector.getBuggyBuild()).thenReturn(build);
    when(inspector.getGitHelper()).thenReturn(new GitHelper());
    JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getJobStatus()).thenReturn(jobStatus);
    CloneRepository cloneStep = new CloneRepository(inspector);
    CheckoutBuggyBuild checkoutBuggyBuild = new CheckoutBuggyBuild(inspector);
    cloneStep.setNextStep(checkoutBuggyBuild);
    cloneStep.execute();
    // cannot get the PR information so it stop now
    assertThat(checkoutBuggyBuild.getPipelineState(), is(PipelineState.BUILDNOTCHECKEDOUT));
    assertThat(jobStatus.getPipelineState(), is(PipelineState.BUILDNOTCHECKEDOUT));
    assertThat(checkoutBuggyBuild.isShouldStop(), is(true));
}
Also used : Path(java.nio.file.Path) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Build(fr.inria.jtravis.entities.Build) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) File(java.io.File) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) Test(org.junit.Test)

Example 18 with ProjectInspector

use of fr.inria.spirals.repairnator.process.inspectors.ProjectInspector in project repairnator by Spirals-Team.

the class TestCheckoutBuild method testCheckoutBuildFromPRWithMissingMerge.

@Test
public void testCheckoutBuildFromPRWithMissingMerge() throws IOException, GitAPIException {
    // surli/failingProject build
    int buildId = 199527447;
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_checkout");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    BuildToBeInspected toBeInspected = new BuildToBeInspected(build, null, ScannedBuildStatus.ONLY_FAIL, "");
    ProjectInspector inspector = mock(ProjectInspector.class);
    when(inspector.getWorkspace()).thenReturn(tmpDir.getAbsolutePath());
    when(inspector.getRepoLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getBuildToBeInspected()).thenReturn(toBeInspected);
    when(inspector.getBuggyBuild()).thenReturn(build);
    when(inspector.getGitHelper()).thenReturn(new GitHelper());
    JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getJobStatus()).thenReturn(jobStatus);
    CloneRepository cloneStep = new CloneRepository(inspector);
    CheckoutBuggyBuild checkoutBuggyBuild = new CheckoutBuggyBuild(inspector);
    cloneStep.setNextStep(checkoutBuggyBuild);
    cloneStep.execute();
    assertThat(checkoutBuggyBuild.getPipelineState(), is(PipelineState.BUILDNOTCHECKEDOUT));
    assertThat(jobStatus.getPipelineState(), is(PipelineState.BUILDNOTCHECKEDOUT));
    assertThat(checkoutBuggyBuild.isShouldStop(), is(true));
}
Also used : Path(java.nio.file.Path) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Build(fr.inria.jtravis.entities.Build) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) File(java.io.File) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) Test(org.junit.Test)

Example 19 with ProjectInspector

use of fr.inria.spirals.repairnator.process.inspectors.ProjectInspector in project repairnator by Spirals-Team.

the class BuildShouldFail method shouldBeStopped.

@Override
public boolean shouldBeStopped(GatherTestInformation gatherTestInformation) {
    ProjectInspector inspector = gatherTestInformation.getInspector();
    if (gatherTestInformation.getPipelineState() == PipelineState.HASTESTFAILURE) {
        inspector.getJobStatus().setReproducedAsFail(true);
        return false;
    } else {
        if (gatherTestInformation.getPipelineState() == PipelineState.HASTESTERRORS) {
            gatherTestInformation.addStepError("Only get test errors, no failing tests. It will try to repair it.");
            inspector.getJobStatus().setReproducedAsError(true);
            return false;
        } else {
            return true;
        }
    }
}
Also used : ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)

Example 20 with ProjectInspector

use of fr.inria.spirals.repairnator.process.inspectors.ProjectInspector in project repairnator by Spirals-Team.

the class Launcher method mainProcess.

private void mainProcess() throws IOException {
    LOGGER.info("Start by getting the build (buildId: " + this.config.getBuildId() + ") with the following config: " + this.config);
    this.getBuildToBeInspected();
    HardwareInfoSerializer hardwareInfoSerializer = new HardwareInfoSerializer(this.engines, this.config.getRunId(), this.config.getBuildId() + "");
    hardwareInfoSerializer.serialize();
    List<AbstractDataSerializer> serializers = new ArrayList<>();
    if (this.config.getLauncherMode() == LauncherMode.REPAIR) {
        serializers.add(new InspectorSerializer(this.engines));
        serializers.add(new InspectorTimeSerializer(this.engines));
    } else {
        serializers.add(new InspectorSerializer4Bears(this.engines));
        serializers.add(new InspectorTimeSerializer4Bears(this.engines));
    }
    serializers.add(new NopolSerializer(this.engines));
    serializers.add(new NPEFixSerializer(this.engines));
    serializers.add(new AstorSerializer(this.engines));
    serializers.add(new MetricsSerializer(this.engines));
    serializers.add(new PipelineErrorSerializer(this.engines));
    ProjectInspector inspector;
    if (config.getLauncherMode() == LauncherMode.BEARS) {
        inspector = new ProjectInspector4Bears(buildToBeInspected, this.config.getWorkspacePath(), serializers, this.notifiers);
    } else {
        inspector = new ProjectInspector(buildToBeInspected, this.config.getWorkspacePath(), serializers, this.notifiers);
    }
    inspector.run();
    LOGGER.info("Inspector is finished. The process will now exit.");
    System.exit(0);
}
Also used : InspectorTimeSerializer4Bears(fr.inria.spirals.repairnator.serializer.InspectorTimeSerializer4Bears) HardwareInfoSerializer(fr.inria.spirals.repairnator.serializer.HardwareInfoSerializer) InspectorSerializer4Bears(fr.inria.spirals.repairnator.serializer.InspectorSerializer4Bears) ArrayList(java.util.ArrayList) InspectorTimeSerializer(fr.inria.spirals.repairnator.serializer.InspectorTimeSerializer) ProjectInspector4Bears(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector4Bears) AbstractDataSerializer(fr.inria.spirals.repairnator.serializer.AbstractDataSerializer) InspectorSerializer(fr.inria.spirals.repairnator.serializer.InspectorSerializer) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) PipelineErrorSerializer(fr.inria.spirals.repairnator.serializer.PipelineErrorSerializer) AstorSerializer(fr.inria.spirals.repairnator.serializer.AstorSerializer) NopolSerializer(fr.inria.spirals.repairnator.serializer.NopolSerializer) MetricsSerializer(fr.inria.spirals.repairnator.serializer.MetricsSerializer) NPEFixSerializer(fr.inria.spirals.repairnator.serializer.NPEFixSerializer)

Aggregations

ProjectInspector (fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)43 Test (org.junit.Test)40 JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)39 File (java.io.File)35 Path (java.nio.file.Path)35 Build (fr.inria.jtravis.entities.Build)33 BuildToBeInspected (fr.inria.spirals.repairnator.BuildToBeInspected)33 GitHelper (fr.inria.spirals.repairnator.process.git.GitHelper)30 CheckoutBuggyBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild)24 CloneRepository (fr.inria.spirals.repairnator.process.step.CloneRepository)10 CheckoutPatchedBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutPatchedBuild)8 GatherTestInformation (fr.inria.spirals.repairnator.process.step.gatherinfo.GatherTestInformation)7 Git (org.eclipse.jgit.api.Git)7 BuildShouldFail (fr.inria.spirals.repairnator.process.step.gatherinfo.BuildShouldFail)6 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 RepairnatorConfig (fr.inria.spirals.repairnator.config.RepairnatorConfig)4 ScannedBuildStatus (fr.inria.spirals.repairnator.states.ScannedBuildStatus)3 DiffEntry (org.eclipse.jgit.diff.DiffEntry)3 ObjectReader (org.eclipse.jgit.lib.ObjectReader)3 CanonicalTreeParser (org.eclipse.jgit.treewalk.CanonicalTreeParser)3