Search in sources :

Example 1 with BuildToBeInspected

use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.

the class TestInitRepoToPush method testInitRepoShouldRemoveNotificationInTravisYML.

@Test
public void testInitRepoShouldRemoveNotificationInTravisYML() throws IOException {
    int buildId = 331637757;
    RepairnatorConfig repairnatorConfig = RepairnatorConfig.getInstance();
    repairnatorConfig.setClean(false);
    repairnatorConfig.setPush(true);
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_initRepoToPush");
    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.getRepoToPushLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repotopush");
    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);
    cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(new InitRepoToPush(inspector));
    cloneStep.execute();
    assertThat(jobStatus.getPushState(), is(PushState.REPO_INITIALIZED));
    File bak = new File(tmpDir.getAbsolutePath() + "/repotopush/bak.travis.yml");
    File travis = new File(tmpDir.getAbsolutePath() + "/repotopush/.travis.yml");
    assertTrue(bak.exists());
    assertTrue(travis.exists());
    boolean detected = false;
    List<String> lines = Files.readAllLines(travis.toPath());
    for (String l : lines) {
        if (l.contains("notification")) {
            assertTrue(l.trim().startsWith("#"));
            detected = true;
        }
        if (l.contains("script")) {
            assertFalse(l.trim().startsWith("#"));
        }
    }
    assertTrue(detected);
}
Also used : Path(java.nio.file.Path) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) File(java.io.File) Test(org.junit.Test)

Example 2 with BuildToBeInspected

use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.

the class TestInitRepoToPush method testInitRepoToPushSimpleCase.

@Test
public void testInitRepoToPushSimpleCase() throws IOException, GitAPIException, RepairnatorConfigException {
    // surli/failingProject build
    int buildId = 207924136;
    RepairnatorConfig repairnatorConfig = RepairnatorConfig.getInstance();
    repairnatorConfig.setClean(false);
    repairnatorConfig.setPush(true);
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_initRepoToPush");
    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.getRepoToPushLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repotopush");
    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);
    cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(new InitRepoToPush(inspector));
    cloneStep.execute();
    assertThat(jobStatus.getPushState(), is(PushState.REPO_INITIALIZED));
    Git gitDir = Git.open(new File(tmpDir, "repotopush"));
    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"));
    RevCommit firstCommit = iterator.next();
    assertThat(firstCommit.getShortMessage(), containsString("Bug commit"));
    assertThat(iterator.hasNext(), is(false));
}
Also used : Path(java.nio.file.Path) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Git(org.eclipse.jgit.api.Git) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 3 with BuildToBeInspected

use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.

the class Launcher method processOutput.

private void processOutput(List<BuildToBeInspected> listOfBuilds) {
    if (this.config.isSerializeJson()) {
        String outputPath = this.config.getOutputPath();
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(outputPath));
            for (BuildToBeInspected buildToBeInspected : listOfBuilds) {
                if (this.config.getLauncherMode() == LauncherMode.REPAIR) {
                    writer.write(buildToBeInspected.getBuggyBuild().getId() + "");
                } else {
                    writer.write(buildToBeInspected.getBuggyBuild().getId() + Utils.COMMA + buildToBeInspected.getPatchedBuild().getId());
                }
                writer.newLine();
                writer.flush();
            }
            writer.close();
            return;
        } catch (IOException e) {
            LOGGER.error("Error while writing file " + outputPath + ". The content will be printed in the standard output.", e);
        }
    }
    for (BuildToBeInspected buildToBeInspected : listOfBuilds) {
        System.out.println(buildToBeInspected.getBuggyBuild().getId());
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) BufferedWriter(java.io.BufferedWriter)

Example 4 with BuildToBeInspected

use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.

the class Launcher method runScanner.

private List<BuildToBeInspected> runScanner() throws IOException {
    Launcher.LOGGER.info("Start to scan projects in travis...");
    ProjectScanner scanner = new ProjectScanner(this.config.getLookFromDate(), this.config.getLookToDate(), this.config.getRunId());
    List<BuildToBeInspected> buildsToBeInspected = scanner.getListOfBuildsToBeInspectedFromProjects(this.config.getInputPath());
    ProcessSerializer scannerSerializer;
    if (this.config.getLauncherMode() == LauncherMode.REPAIR) {
        scannerSerializer = new ScannerSerializer(this.engines, scanner);
    } else {
        scannerSerializer = new ScannerSerializer4Bears(this.engines, scanner);
        ScannerDetailedDataSerializer scannerDetailedDataSerializer = new ScannerDetailedDataSerializer(this.engines, buildsToBeInspected);
        scannerDetailedDataSerializer.serialize();
    }
    scannerSerializer.serialize();
    if (buildsToBeInspected.isEmpty()) {
        Launcher.LOGGER.info("No build has been found (" + scanner.getTotalScannedBuilds() + " scanned builds.)");
    }
    return buildsToBeInspected;
}
Also used : ScannerSerializer(fr.inria.spirals.repairnator.serializer.ScannerSerializer) ScannerSerializer4Bears(fr.inria.spirals.repairnator.serializer.ScannerSerializer4Bears) ProcessSerializer(fr.inria.spirals.repairnator.serializer.ProcessSerializer) ScannerDetailedDataSerializer(fr.inria.spirals.repairnator.serializer.ScannerDetailedDataSerializer) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected)

Example 5 with BuildToBeInspected

use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.

the class ProjectScanner method getListOfBuildsFromRepo.

private List<BuildToBeInspected> getListOfBuildsFromRepo(List<Repository> repos) {
    List<BuildToBeInspected> buildsToBeInspected = new ArrayList<BuildToBeInspected>();
    for (Repository repo : repos) {
        List<Build> repoBuilds = BuildHelper.getBuildsFromRepositoryInTimeInterval(repo, this.lookFromDate, this.lookToDate);
        for (Build build : repoBuilds) {
            this.totalScannedBuilds++;
            BuildToBeInspected buildToBeInspected = getBuildToBeInspected(build);
            if (buildToBeInspected != null) {
                buildsToBeInspected.add(buildToBeInspected);
            }
        }
    }
    return buildsToBeInspected;
}
Also used : BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected)

Aggregations

BuildToBeInspected (fr.inria.spirals.repairnator.BuildToBeInspected)48 Build (fr.inria.jtravis.entities.Build)44 File (java.io.File)40 Path (java.nio.file.Path)40 Test (org.junit.Test)40 JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)35 ProjectInspector (fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)33 GitHelper (fr.inria.spirals.repairnator.process.git.GitHelper)30 CheckoutBuggyBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild)24 Git (org.eclipse.jgit.api.Git)12 RepairnatorConfig (fr.inria.spirals.repairnator.config.RepairnatorConfig)11 ArrayList (java.util.ArrayList)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 CloneRepository (fr.inria.spirals.repairnator.process.step.CloneRepository)10 CheckoutPatchedBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutPatchedBuild)8 SerializedData (fr.inria.spirals.repairnator.serializer.engines.SerializedData)8 SerializerEngine (fr.inria.spirals.repairnator.serializer.engines.SerializerEngine)8 AbstractNotifier (fr.inria.spirals.repairnator.notifier.AbstractNotifier)7 GatherTestInformation (fr.inria.spirals.repairnator.process.step.gatherinfo.GatherTestInformation)7 AbstractDataSerializer (fr.inria.spirals.repairnator.serializer.AbstractDataSerializer)7