Search in sources :

Example 1 with Build

use of fr.inria.jtravis.entities.Build 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 Build

use of fr.inria.jtravis.entities.Build 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 Build

use of fr.inria.jtravis.entities.Build in project repairnator by Spirals-Team.

the class BuildRunner method submitBuild.

public void submitBuild(Build build) {
    if (this.limitDateNextRetrieveDockerImage.before(new Date())) {
        this.refreshDockerImage();
    }
    if (getRunning() < this.nbThreads) {
        LOGGER.info("Build (id: " + build.getId() + ") immediately submitted for running.");
        this.executorService.submit(this.submitBuild(this.dockerImageId, new InputBuildId(build.getId())));
    } else {
        LOGGER.info("All threads currently running (Limit: " + this.nbThreads + "). Add build (id: " + build.getId() + ") to list");
        if (this.waitingBuilds.size() == this.nbThreads) {
            Build b = this.waitingBuilds.removeLast();
            LOGGER.debug("Remove oldest build (id: " + b.getId() + ")");
        }
        this.waitingBuilds.push(build);
    }
}
Also used : InputBuildId(fr.inria.spirals.repairnator.InputBuildId) Build(fr.inria.jtravis.entities.Build) Date(java.util.Date)

Example 4 with Build

use of fr.inria.jtravis.entities.Build in project repairnator by Spirals-Team.

the class RTScanner method isRepositoryInteresting.

public boolean isRepositoryInteresting(int repositoryId) {
    if (this.blackListedRepository.contains(repositoryId)) {
        // LOGGER.debug("Repo already blacklisted (id: "+repositoryId+")");
        return false;
    }
    if (this.whiteListedRepository.contains(repositoryId)) {
        // LOGGER.debug("Repo already whitelisted (id: "+repositoryId+")");
        return true;
    }
    if (this.tempBlackList.containsKey(repositoryId)) {
        if (this.tempBlackList.get(repositoryId).after(new Date())) {
            return false;
        } else {
            this.tempBlackList.remove(repositoryId);
        }
    }
    Repository repository = RepositoryHelper.getRepositoryFromId(repositoryId);
    if (repository != null) {
        Build masterBuild = BuildHelper.getLastSuccessfulBuildFromMaster(repository, false, 5);
        if (masterBuild == null) {
            this.addInTempBlackList(repository, "No successful build found.");
            return false;
        } else {
            if (masterBuild.getConfig().getLanguage() == null || !masterBuild.getConfig().getLanguage().equals("java")) {
                this.addInBlacklistRepository(repository, BlacklistedSerializer.Reason.OTHER_LANGUAGE, masterBuild.getConfig().getLanguage());
                return false;
            }
            if (masterBuild.getBuildTool() == BuildTool.GRADLE) {
                this.addInBlacklistRepository(repository, BlacklistedSerializer.Reason.USE_GRADLE, "");
                return false;
            } else if (masterBuild.getBuildTool() == BuildTool.UNKNOWN) {
                this.addInBlacklistRepository(repository, BlacklistedSerializer.Reason.UNKNOWN_BUILD_TOOL, "");
                return false;
            }
            if (!masterBuild.getJobs().isEmpty()) {
                Job firstJob = masterBuild.getJobs().get(0);
                Log jobLog = firstJob.getLog();
                if (jobLog.getTestsInformation() != null && jobLog.getTestsInformation().getRunning() > 0) {
                    LOGGER.info("Tests has been found in repository " + repository.getSlug() + " (id: " + repositoryId + ") build (id: " + masterBuild.getId() + "). The repo is now whitelisted.");
                    this.addInWhitelistRepository(repository);
                    return true;
                } else {
                    this.addInTempBlackList(repository, "No test found");
                }
            } else {
                LOGGER.info("No job found in repository " + repository.getSlug() + " (id: " + repositoryId + ") build (id: " + masterBuild.getId() + "). It is not considered right now.");
            }
        }
    } else {
        LOGGER.info("Repository not found with the following id: " + repositoryId + " it will be temporary blacklisted");
        Date expirationDate = new Date(new Date().toInstant().plusSeconds(DURATION_IN_TEMP_BLACKLIST).toEpochMilli());
        this.tempBlackList.put(repositoryId, expirationDate);
    }
    return false;
}
Also used : Repository(fr.inria.jtravis.entities.Repository) Log(fr.inria.jtravis.entities.Log) Build(fr.inria.jtravis.entities.Build) Job(fr.inria.jtravis.entities.Job) Date(java.util.Date)

Example 5 with Build

use of fr.inria.jtravis.entities.Build 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)

Aggregations

Build (fr.inria.jtravis.entities.Build)60 BuildToBeInspected (fr.inria.spirals.repairnator.BuildToBeInspected)44 File (java.io.File)41 Path (java.nio.file.Path)40 Test (org.junit.Test)40 JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)37 ProjectInspector (fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)33 GitHelper (fr.inria.spirals.repairnator.process.git.GitHelper)31 CheckoutBuggyBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild)28 ArrayList (java.util.ArrayList)15 Git (org.eclipse.jgit.api.Git)13 JsonObject (com.google.gson.JsonObject)12 CloneRepository (fr.inria.spirals.repairnator.process.step.CloneRepository)12 RepairnatorConfig (fr.inria.spirals.repairnator.config.RepairnatorConfig)11 Date (java.util.Date)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 CheckoutPatchedBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutPatchedBuild)10 GatherTestInformation (fr.inria.spirals.repairnator.process.step.gatherinfo.GatherTestInformation)9 AbstractNotifier (fr.inria.spirals.repairnator.notifier.AbstractNotifier)7 AbstractDataSerializer (fr.inria.spirals.repairnator.serializer.AbstractDataSerializer)7